Skip to content

[Fix][Relax][Torch] Align retained expand dimensions by trailing rank - #20137

Merged
tlopex merged 1 commit into
apache:mainfrom
akaashrp:upstream/torch-expand-shape-alignment
Aug 26, 2026
Merged

[Fix][Relax][Torch] Align retained expand dimensions by trailing rank#20137
tlopex merged 1 commit into
apache:mainfrom
akaashrp:upstream/torch-expand-shape-alignment

Conversation

@akaashrp

Copy link
Copy Markdown
Contributor

torch.Tensor.expand aligns existing input dimensions with the trailing dimensions of the requested shape when new leading dimensions are introduced. The Torch frontend previously resolved -1 using the output dimension index directly. For an input shaped (tokens, 3), x.expand(2, -1, -1) thus selected the wrong input dimensions and eventually accessed beyond the input rank.

This PR:

  • Accounts for newly introduced leading dimensions when resolving -1
  • Aligns retained dimensions against the trailing input rank
  • Rejects -1 for new leading dimensions, matching PyTorch semantics.=
  • Preserves the FX metadata fallback when the Relax input shape is unavailable

@yongwww yongwww closed this Aug 17, 2026
@yongwww yongwww reopened this Aug 17, 2026
@akaashrp
akaashrp requested a review from tlopex August 25, 2026 02:41
@tlopex

tlopex commented Aug 25, 2026

Copy link
Copy Markdown
Member

@akaashrp Hi, could you resolve the conflict?

@akaashrp
akaashrp force-pushed the upstream/torch-expand-shape-alignment branch from 3f634a1 to 3013b95 Compare August 25, 2026 17:30
@tlopex
tlopex merged commit 7f61973 into apache:main Aug 26, 2026
8 checks passed
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.

3 participants