Skip to content

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

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

bhimrazy wants to merge 8 commits into
Lightning-AI:mainfrom
bhimrazy:fix/torch-213-named-tensor-import

Conversation

@bhimrazy

@bhimrazy bhimrazy commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes import thunder failing on PyTorch 2.13.

torch 2.13 removed the named tensor feature, so Tensor.align_as, align_to, has_names, refine_names and rename are gone. default_torch_ops.py references all five 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 five entries on a new _TORCH_GREATER_EQUAL_2_13 constant so they are simply not registered on torch 2.13+.

Note

Stacked on #2830 and #2831, both merged into this branch so CI here is not drowned by failures that belong to those. Diff shrinks as they land.

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.

The removal landed via ghstack (see pytorch#173895, which shows closed rather than merged). Its torch/overrides.py diff is the authoritative list: Tensor.align_as, align_to, has_names, names, refine_names, rename, _update_names, plus torch.align_tensors. Of those, only the five above ever appear in this repo.

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
torch/testing/_internal/common_utils.py reads the deprecated
torch._dynamo.config.inline_inbuilt_nn_modules as a default argument, so the
FutureWarning fires when the module is imported. With `error::FutureWarning`
set, that fails collection of all the distributed tests.

Ignore that one message; every other FutureWarning stays fatal.
torchaudio is not imported anywhere in the repo, but CI's adjust-torch-versions.py
pins it in lockstep with torch. torchaudio stopped tracking torch releases after
2.11 ('compatible with future versions of torch'), so on torch 2.14 CI resolves
torchaudio==2.14.0, which does not exist, and every job fails at dependency
install before running a single test.
has_names went away in the same named-tensor removal as align_as/align_to/
refine_names/rename, so import still failed on torch 2.13 without it.
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