Skip to content

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

Open
akaashrp wants to merge 1 commit into
apache:mainfrom
akaashrp:upstream/torch-expand-shape-alignment
Open

[Fix][Relax][Torch] Align retained expand dimensions by trailing rank#20137
akaashrp wants to merge 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
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.

2 participants