Skip to content

[Fix][Relax][ONNX] Preserve rank-expanding Expand#19992

Merged
tlopex merged 1 commit into
apache:mainfrom
viiccwen:fix/onnx-expand-rank-broadcast
Jul 13, 2026
Merged

[Fix][Relax][ONNX] Preserve rank-expanding Expand#19992
tlopex merged 1 commit into
apache:mainfrom
viiccwen:fix/onnx-expand-rank-broadcast

Conversation

@viiccwen

@viiccwen viiccwen commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

What changed

Record the original input rank before Expand left-pads the input shape for broadcast validation. The no-op fast path now returns the input unchanged only when both the padded shape and the original rank match the target.

A regression test covers expanding [1] to [1, 1] when the target is represented as a Relax ShapeExpr.

Why

ONNX Expand right-aligns dimensions and may increase tensor rank by adding leading dimensions. Previously, a rank-expanding broadcast could look like a no-op after the frontend padded the input shape, causing it to return the original lower-rank tensor. Downstream operators could then receive inconsistent ranks.

This fixes the focused bug tracked in #19991 and is part of the investigation and fixes for #19971. It does not close #19971 because the attached model exposes additional independent importer issues after this Concat failure is resolved.

Fixes #19991
Part of #19971

Validation

Signed-off-by: viiccwen <vicwen@apache.org>
@viiccwen viiccwen marked this pull request as ready for review July 13, 2026 06:15
@viiccwen

Copy link
Copy Markdown
Contributor Author

cc @guan404ming, @tlopex. ✨🙌

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the ONNX frontend in TVM Relax to correctly handle the Expand operation when expanding a tensor to a higher rank with a same padded shape (for example, from shape [1] to [1, 1]). It ensures that the rank of the target shape matches the rank of the input data shape before skipping the broadcast_to operator. Additionally, a corresponding test case has been added to verify this behavior. There are no review comments, so I have no further feedback to provide.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@tlopex tlopex merged commit af4c3f4 into apache:main Jul 13, 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

2 participants