Add structured call_hierarchy metadata to FX nodes - #1
Open
nklshy-aws wants to merge 4 commits into
Open
Conversation
nklshy-aws
force-pushed
the
call-hierarchy-metadata
branch
3 times, most recently
from
April 6, 2026 19:27
461ada2 to
c5d86c1
Compare
nklshy-aws
pushed a commit
that referenced
this pull request
Apr 6, 2026
## Summary Add `module_error_inputs_torch_nn_Embedding` function to test error messages for invalid inputs to `nn.Embedding` module. ## Motivation Currently, `torch.nn.Embedding` does not have `module_error_inputs_func` defined in `common_modules.py`. This PR adds error input tests to enable regression testing for error messages and follow the pattern already established for other modules (BatchNorm, GroupNorm, RNN cells, etc.). ## Test Cases Added 1. **Out of range indices**: Tests IndexError when index exceeds `num_embeddings` - Input: `Embedding(10, 3)` with indices `[0, 5, 15]` (15 is out of range) - Expected: `IndexError: index out of range in self` - **Note**: Only tested on CPU - CUDA triggers kernel assertion instead of Python exception 2. **Float indices**: Tests RuntimeError when float tensor used instead of Long/Int - Input: `Embedding(10, 3)` with float tensor `[1.5, 2.5]` - Expected: `RuntimeError: Expected tensor for argument #1 'indices' to have one of the following scalar types: Long, Int` 3. **Negative num_embeddings**: Tests RuntimeError when constructor has negative dimension - Input: `Embedding(-1, 3)` - Expected: `RuntimeError: Trying to create tensor with negative dimension` ## Test Environment - Tested on H200 GPU with CUDA 12.8 - Verified error messages match on CPU - CUDA tests pass for dtype and construction errors Fixes pytorch#174179 Pull Request resolved: pytorch#174180 Approved by: https://github.com/albanD
…pytorch#179511) Fixes an issue in guard serialization that would cause dataclass fields set to `init=False` to get serialized. Upon loading objects like `DefaultsSource`, it would receive the error ``` restored = pickle.loads(pickle.dumps(source)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TypeError: DefaultsSource.__init__() takes from 3 to 4 positional arguments but 6 were given ``` Pull Request resolved: pytorch#179511 Approved by: https://github.com/anijain2305
nklshy-aws
pushed a commit
that referenced
this pull request
Apr 7, 2026
## Summary Add `module_error_inputs_torch_nn_Embedding` function to test error messages for invalid inputs to `nn.Embedding` module. ## Motivation Currently, `torch.nn.Embedding` does not have `module_error_inputs_func` defined in `common_modules.py`. This PR adds error input tests to enable regression testing for error messages and follow the pattern already established for other modules (BatchNorm, GroupNorm, RNN cells, etc.). ## Test Cases Added 1. **Out of range indices**: Tests IndexError when index exceeds `num_embeddings` - Input: `Embedding(10, 3)` with indices `[0, 5, 15]` (15 is out of range) - Expected: `IndexError: index out of range in self` - **Note**: Only tested on CPU - CUDA triggers kernel assertion instead of Python exception 2. **Float indices**: Tests RuntimeError when float tensor used instead of Long/Int - Input: `Embedding(10, 3)` with float tensor `[1.5, 2.5]` - Expected: `RuntimeError: Expected tensor for argument #1 'indices' to have one of the following scalar types: Long, Int` 3. **Negative num_embeddings**: Tests RuntimeError when constructor has negative dimension - Input: `Embedding(-1, 3)` - Expected: `RuntimeError: Trying to create tensor with negative dimension` ## Test Environment - Tested on H200 GPU with CUDA 12.8 - Verified error messages match on CPU - CUDA tests pass for dtype and construction errors Fixes pytorch#174179 Pull Request resolved: pytorch#174180 Approved by: https://github.com/albanD
Add a new 'call_hierarchy' metadata field to FX nodes that provides a unified, ordered list of module and function call entries for each operation. Built during Dynamo's tx chain walk at proxy creation time, it uses nn_module_stack depth changes to distinguish module entries from function entries without relying on function name matching. Changes: - torch/_dynamo/config.py: Add record_call_hierarchy flag (default off) - torch/_dynamo/output_graph.py: Build call_hierarchy in create_proxy - torch/_dynamo/symbolic_convert.py: Add function_call_counts tracking - torch/fx/proxy.py: Add call_hierarchy to _COPY_META_FIELDS - test/dynamo/test_call_hierarchy.py: Tests for the new field
nklshy-aws
force-pushed
the
call-hierarchy-metadata
branch
from
April 7, 2026 19:47
bc25044 to
87948a2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds an opt-in
call_hierarchymetadata field to FX nodes that captures the interleaved module + function call chain as a structured list, built during Dynamo's tx chain walk at proxy creation time.Today
nn_module_stackonly tracks modules andstack_traceis an unstructured string; there's no reliable way to produce a unified hierarchy i.e. to know which calls correspond to which module entry's. This field gives compiler backends (profilers, debuggers, visualization tools) the merged view directly.Gated behind
config.record_call_hierarchy(defaultFalse). Uses set difference onnn_module_stackkeys between consecutive tx frames to distinguish module entries from function entries.Refs: pytorch#87659