Skip to content

Fix import thunder on PyTorch 2.13 (named tensor removal) - #2829

Open
bhimrazy wants to merge 1 commit into
Lightning-AI:mainfrom
bhimrazy:fix/torch-213-named-tensor-import
Open

Fix import thunder on PyTorch 2.13 (named tensor removal)#2829
bhimrazy wants to merge 1 commit into
Lightning-AI:mainfrom
bhimrazy:fix/torch-213-named-tensor-import

Conversation

@bhimrazy

@bhimrazy bhimrazy commented Aug 13, 2026

Copy link
Copy Markdown

What does this PR do?

Fixes import thunder failing on PyTorch 2.13.

torch 2.13 removed the named tensor feature (pytorch/pytorch#173895), so Tensor.align_as, align_to, refine_names and rename are gone. default_torch_ops.py references all four inside torch_auto_registered_ops, a module-level dict literal — so the lookups happen at import time and the whole package fails to load:

AttributeError: type object 'Tensor' has no attribute 'align_as'

This gates those four entries on a new _TORCH_GREATER_EQUAL_2_13 constant so they are simply not registered on torch 2.13+.

How it surfaced

Downstream, in litgpt#2295. litgpt's constants.py probes thunder with RequirementCache("thunder"); on torch 2.13 that probe raises, breaking all CPU test collection on Linux. That PR caps torch<2.13 as a stopgap and notes it should be dropped once thunder supports 2.13 — this is the thunder-side fix. thunder itself is unpinned (torch >=2.7.1), so the break is latent for anyone on 2.13; litgpt just hit it first.

torch 2.13 hard-removed the named tensor feature (pytorch/pytorch#173895), so
Tensor.align_as, align_to, refine_names and rename no longer exist. The auto
registration table in default_torch_ops.py dereferences them while building a
module-level dict literal, which makes `import thunder` fail outright there with
`AttributeError: type object 'Tensor' has no attribute 'align_as'`.

Gate those four entries on a new `_TORCH_GREATER_EQUAL_2_13` constant, and add
thunder/constants.py as a home for such checks, following litgpt/constants.py.
@bhimrazy
bhimrazy requested a review from mruberry as a code owner August 13, 2026 09:08
@bhimrazy bhimrazy changed the title Fix import failure on torch 2.13 by gating named tensor ops Fix import thunder on PyTorch 2.13 (named tensor removal) Aug 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant