Repository navigation
[Inductor] Clear _original_gm in CompiledFxGraph.prepare_for_serialization - #182048
bobrenjc93 wants to merge 4 commits into
Conversation
…ation
CompiledFxGraph stores _original_gm (a deepcopy of the pre-compiled FX
graph) when wrap_inductor_compiled_regions is enabled. This field exists
solely for FakeTensor shape inference via inductor_compiled_code_fake —
it is never needed at runtime for actual execution.
When the compiled graph contains higher-order ops with lifted buffers
(e.g. flex_attention with BlockMask mask_mod_other_buffers), serializing
_original_gm causes a crash during deserialization. The crash path:
pickle.loads(AOTCompiledArtifact data)
→ CompiledFxGraph._original_gm is reconstructed
→ GraphModule.__reduce__ → reduce_graph_module
→ _deserialize_graph_module → KeepModules().trace()
→ flex_attention.__call__(... mask_mod_other_buffers=(Proxy,) ...)
→ validate_subgraph_args_types
→ AssertionError: Proxy is not Tensor/int/SymInt
This affects the AOTAutograd disk cache and torchtitan's graph_trainer
precompile path when FlexAttention uses a causal BlockMask (which adds
mask_mod closure tensors to mask_mod_other_buffers).
The fix: clear _original_gm in prepare_for_serialization(). The
inductor_compiled_code_fake handler already handles this case — it
raises a clear RuntimeError("... Recompile to restore") when
original_gm is None.
[ghstack-poisoned]
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/182048
Note: Links to docs will display an error until the docs builds have been completed. ❌ 1 New Failure, 42 PendingAs of commit 9718aee with merge base 00c683a ( NEW FAILURE - The following job has failed:
UNSTABLE - The following job is marked as unstable, possibly due to flakiness on trunk:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This PR needs a
|
…or_serialization"
CompiledFxGraph stores _original_gm (a deepcopy of the pre-compiled FX
graph) when wrap_inductor_compiled_regions is enabled. This field exists
solely for FakeTensor shape inference via inductor_compiled_code_fake —
it is never needed at runtime for actual execution.
When the compiled graph contains higher-order ops with lifted buffers
(e.g. flex_attention with BlockMask mask_mod_other_buffers), serializing
_original_gm causes a crash during deserialization. The crash path:
pickle.loads(AOTCompiledArtifact data)
→ CompiledFxGraph._original_gm is reconstructed
→ GraphModule.__reduce__ → reduce_graph_module
→ _deserialize_graph_module → KeepModules().trace()
→ flex_attention.__call__(... mask_mod_other_buffers=(Proxy,) ...)
→ validate_subgraph_args_types
→ AssertionError: Proxy is not Tensor/int/SymInt
This affects the AOTAutograd disk cache and torchtitan's graph_trainer
precompile path when FlexAttention uses a causal BlockMask (which adds
mask_mod closure tensors to mask_mod_other_buffers).
The fix: clear _original_gm in prepare_for_serialization(). The
inductor_compiled_code_fake handler already handles this case — it
raises a clear RuntimeError("... Recompile to restore") when
original_gm is None.
cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx ipiszy kadeng muchulee8 amjames chauhang aakhundov coconutruben jataylo
[ghstack-poisoned]
…ation
CompiledFxGraph stores _original_gm (a deepcopy of the pre-compiled FX
graph) when wrap_inductor_compiled_regions is enabled. This field exists
solely for FakeTensor shape inference via inductor_compiled_code_fake —
it is never needed at runtime for actual execution.
When the compiled graph contains higher-order ops with lifted buffers
(e.g. flex_attention with BlockMask mask_mod_other_buffers), serializing
_original_gm causes a crash during deserialization. The crash path:
pickle.loads(AOTCompiledArtifact data)
→ CompiledFxGraph._original_gm is reconstructed
→ GraphModule.__reduce__ → reduce_graph_module
→ _deserialize_graph_module → KeepModules().trace()
→ flex_attention.__call__(... mask_mod_other_buffers=(Proxy,) ...)
→ validate_subgraph_args_types
→ AssertionError: Proxy is not Tensor/int/SymInt
This affects the AOTAutograd disk cache and torchtitan's graph_trainer
precompile path when FlexAttention uses a causal BlockMask (which adds
mask_mod closure tensors to mask_mod_other_buffers).
The fix: clear _original_gm in prepare_for_serialization(). The
inductor_compiled_code_fake handler already handles this case — it
raises a clear RuntimeError("... Recompile to restore") when
original_gm is None.
ghstack-source-id: c3f1a84
Pull Request resolved: #182048
…or_serialization" CompiledFxGraph stores _original_gm (a deepcopy of the pre-compiled FX graph) when wrap_inductor_compiled_regions is enabled. This field exists solely for FakeTensor shape inference via inductor_compiled_code_fake — it is never needed at runtime for actual execution. When the compiled graph contains higher-order ops with lifted buffers (e.g. flex_attention with BlockMask mask_mod_other_buffers), serializing _original_gm causes a crash during deserialization. The crash path: pickle.loads(AOTCompiledArtifact data) → CompiledFxGraph._original_gm is reconstructed → GraphModule.__reduce__ → reduce_graph_module → _deserialize_graph_module → KeepModules().trace() → flex_attention.__call__(... mask_mod_other_buffers=(Proxy,) ...) → validate_subgraph_args_types → AssertionError: Proxy is not Tensor/int/SymInt This affects the AOTAutograd disk cache and torchtitan's graph_trainer precompile path when FlexAttention uses a causal BlockMask (which adds mask_mod closure tensors to mask_mod_other_buffers). The fix: clear _original_gm in prepare_for_serialization() since we don't need the original gm at runtime Authored with Claude cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx ipiszy kadeng muchulee8 amjames chauhang aakhundov coconutruben jataylo [ghstack-poisoned]
…ation
CompiledFxGraph stores _original_gm (a deepcopy of the pre-compiled FX
graph) when wrap_inductor_compiled_regions is enabled. This field exists
solely for FakeTensor shape inference via inductor_compiled_code_fake —
it is never needed at runtime for actual execution.
When the compiled graph contains higher-order ops with lifted buffers
(e.g. flex_attention with BlockMask mask_mod_other_buffers), serializing
_original_gm causes a crash during deserialization. The crash path:
pickle.loads(AOTCompiledArtifact data)
→ CompiledFxGraph._original_gm is reconstructed
→ GraphModule.__reduce__ → reduce_graph_module
→ _deserialize_graph_module → KeepModules().trace()
→ flex_attention.__call__(... mask_mod_other_buffers=(Proxy,) ...)
→ validate_subgraph_args_types
→ AssertionError: Proxy is not Tensor/int/SymInt
This affects the AOTAutograd disk cache and torchtitan's graph_trainer
precompile path when FlexAttention uses a causal BlockMask (which adds
mask_mod closure tensors to mask_mod_other_buffers).
The fix: clear _original_gm in prepare_for_serialization(). The
inductor_compiled_code_fake handler already handles this case — it
raises a clear RuntimeError("... Recompile to restore") when
original_gm is None.
ghstack-source-id: 3acba3d
Pull Request resolved: #182048
| self.recursively_apply_fns = None | ||
| self.compiled_fn_runner = None | ||
| # Note: _original_gm is already picklable (metadata stripped at creation) | ||
| self._original_gm = None |
There was a problem hiding this comment.
lgtm, but someone who understand InductorOutputCode should review this
…ation
CompiledFxGraph stores _original_gm (a deepcopy of the pre-compiled FX
graph) when wrap_inductor_compiled_regions is enabled. This field exists
solely for FakeTensor shape inference via inductor_compiled_code_fake —
it is never needed at runtime for actual execution.
When the compiled graph contains higher-order ops with lifted buffers
(e.g. flex_attention with BlockMask mask_mod_other_buffers), serializing
_original_gm causes a crash during deserialization. The crash path:
pickle.loads(AOTCompiledArtifact data)
→ CompiledFxGraph._original_gm is reconstructed
→ GraphModule.__reduce__ → reduce_graph_module
→ _deserialize_graph_module → KeepModules().trace()
→ flex_attention.__call__(... mask_mod_other_buffers=(Proxy,) ...)
→ validate_subgraph_args_types
→ AssertionError: Proxy is not Tensor/int/SymInt
This affects the AOTAutograd disk cache and torchtitan's graph_trainer
precompile path when FlexAttention uses a causal BlockMask (which adds
mask_mod closure tensors to mask_mod_other_buffers).
The fix: clear _original_gm in prepare_for_serialization(). The
inductor_compiled_code_fake handler already handles this case — it
raises a clear RuntimeError("... Recompile to restore") when
original_gm is None.
ghstack-source-id: df462db
Pull Request resolved: #182048
|
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
Merge failedReason: 1 jobs have failed, first few of them are: trunk / linux-jammy-rocm-py3.10-mi355 / test (default, 1, 6, linux.rocm.gpu.gfx950.1) Details for Dev Infra teamRaised by workflow job |
|
Closing in favor of #182048 |
…ts (#3178) Stack from [ghstack](https://github.com/ezyang/ghstack/tree/0.14.0) (oldest at bottom): * __->__ #3178 The FlexAttention precompile tests were skipped with "numerics mismatch — under investigation". The root cause was that _run_steps_with_precompile did not pass attention_masks to the model, while GraphTrainer's post_dataloading_process generates a causal BlockMask for FlexAttention models. This meant the two paths computed different attention patterns: - GraphTrainer path: causal mask via BlockMask - Precompile path: no mask (full attention) Fix by adding _get_extra_kwargs() to the test base class, which generates the same BlockMask attention masks that post_dataloading_process produces. _run_steps_with_precompile now passes these masks and calls maybe_register_blockmask_pytree_node() before tracing. Depends on pytorch/pytorch#182048
Stack from ghstack (oldest at bottom):
CompiledFxGraph stores _original_gm (a deepcopy of the pre-compiled FX
graph) when wrap_inductor_compiled_regions is enabled. When the compiled
graph contains higher-order ops with lifted buffers
(e.g. flex_attention with BlockMask mask_mod_other_buffers), serializing
_original_gm causes a crash during deserialization. The crash path:
pickle.loads(AOTCompiledArtifact data)
→ CompiledFxGraph._original_gm is reconstructed
→ GraphModule.reduce → reduce_graph_module
→ _deserialize_graph_module → KeepModules().trace()
→ flex_attention.call(... mask_mod_other_buffers=(Proxy,) ...)
→ validate_subgraph_args_types
→ AssertionError: Proxy is not Tensor/int/SymInt
This affects the AOTAutograd disk cache and torchtitan's graph_trainer
precompile path when FlexAttention uses a causal BlockMask (which adds
mask_mod closure tensors to mask_mod_other_buffers).
The fix: clear _original_gm in prepare_for_serialization() since we don't need
the original gm at runtime. NB: this is for the standalone compile node in the larger
fx graph. We will still have an "outer gm", it's just the inner standalone compile
nodes won't have the original gms, but that's fine, we just need the callable.
Authored with Claude
cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben @jataylo