Give op override wrappers descriptive names for stack traces#4491
Open
Ashutosh0x wants to merge 1 commit into
Open
Give op override wrappers descriptive names for stack traces#4491Ashutosh0x wants to merge 1 commit into
Ashutosh0x wants to merge 1 commit into
Conversation
When debugging tensor subclass issues, stack traces show 'in _' for every op override because the decorator pattern uses _ as the function name (a common Python idiom for throwaway names). This makes it impossible to identify which op handler is failing without cross-referencing line numbers with source files. The fix adds _op_display_name() to derive readable names from the op/function being registered, then overrides __name__ and __qualname__ on the wrapper after functools.wraps. This is done centrally in both _implements() and _implements_torch_function() decorators, so all 89+ existing call sites automatically get descriptive names without any changes. Before: 'File ...float8_tensor.py, line 432, in _' After: 'File ...float8_tensor.py, line 432, in impl_aten_narrow_default' Fixes pytorch#3045 Test Plan: Verified by inspection that _op_display_name produces correct names: - torch.ops.aten.narrow.default -> impl_aten_narrow_default - torch.nn.functional.linear -> impl_linear The change only affects __name__/__qualname__ on wrapper functions, with no runtime behavior change. This change was authored with the assistance of an AI coding assistant.
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/ao/4491
Note: Links to docs will display an error until the docs builds have been completed. This comment was automatically generated by Dr. CI and updates every 15 minutes. |
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.
Summary
When debugging tensor subclass issues, stack traces show
in _for every op override because the@implementsdecorator pattern uses_as the function name. This makes it impossible to identify which op handler is failing without cross-referencing line numbers with source files.Before:
After:
Approach
Added
_op_display_name()helper that derives readable names from the op/function being registered, then overrides__name__and__qualname__on the wrapper afterfunctools.wrapsin both_implements()and_implements_torch_function()decorators.This is done centrally in the decorator, so all 89+ existing call sites automatically get descriptive names without any changes to other files.
I chose this approach over renaming every
def _across the codebase because:def _will automatically get descriptive namesExamples of generated names:
torch.ops.aten.narrow.default->impl_aten_narrow_defaulttorch.nn.functional.linear->impl_lineartorch.ops.aten.detach.default->impl_aten_detach_defaultFixes #3045
Test Plan
Verified by inspection that
_op_display_nameproduces correct names for both aten ops and torch functions. The change only affects__name__/__qualname__attributes on wrapper functions, with no runtime behavior change.This change was authored with the assistance of an AI coding assistant.