Skip to content

Give op override wrappers descriptive names for stack traces#4491

Open
Ashutosh0x wants to merge 1 commit into
pytorch:mainfrom
Ashutosh0x:fix/descriptive-op-override-names
Open

Give op override wrappers descriptive names for stack traces#4491
Ashutosh0x wants to merge 1 commit into
pytorch:mainfrom
Ashutosh0x:fix/descriptive-op-override-names

Conversation

@Ashutosh0x

Copy link
Copy Markdown

Summary

When debugging tensor subclass issues, stack traces show in _ for every op override because the @implements decorator 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:

File '.../float8_tensor.py', line 432, in _
    block_size = self.block_size.copy()

After:

File '.../float8_tensor.py', line 432, in impl_aten_narrow_default
    block_size = self.block_size.copy()

Approach

Added _op_display_name() helper that derives readable names from the op/function being registered, then overrides __name__ and __qualname__ on the wrapper after functools.wraps in 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:

  1. It's a single-file change (minimal review surface)
  2. Future op overrides written as def _ will automatically get descriptive names
  3. It matches vkuzo's ask: 'we should have descriptive names for these to reduce the level of indirection when debugging'

Examples of generated names:

  • torch.ops.aten.narrow.default -> impl_aten_narrow_default
  • torch.nn.functional.linear -> impl_linear
  • torch.ops.aten.detach.default -> impl_aten_detach_default

Fixes #3045

Test Plan

Verified by inspection that _op_display_name produces 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.

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.
@pytorch-bot

pytorch-bot Bot commented Jun 15, 2026

Copy link
Copy Markdown

🔗 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.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jun 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

make subclass stack traces more informative by not using _ as function name for op overrides

1 participant