Fix import thunder on PyTorch 2.13 (named tensor removal) - #2829
Open
bhimrazy wants to merge 1 commit into
Open
Conversation
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.
import thunder on PyTorch 2.13 (named tensor removal)
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.
What does this PR do?
Fixes
import thunderfailing on PyTorch 2.13.torch 2.13 removed the named tensor feature (pytorch/pytorch#173895), so
Tensor.align_as,align_to,refine_namesandrenameare gone.default_torch_ops.pyreferences all four insidetorch_auto_registered_ops, a module-level dict literal — so the lookups happen at import time and the whole package fails to load:This gates those four entries on a new
_TORCH_GREATER_EQUAL_2_13constant so they are simply not registered on torch 2.13+.How it surfaced
Downstream, in litgpt#2295. litgpt's
constants.pyprobes thunder withRequirementCache("thunder"); on torch 2.13 that probe raises, breaking all CPU test collection on Linux. That PR capstorch<2.13as 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.