Skip to content

Conversation

@xinxilwl
Copy link
Contributor

add expand test case

singh20anurag and others added 4 commits March 25, 2025 13:19
This fixes issue apache#17746 where the ONNX Expand operator was not correctly
expanding tensors to higher dimensions. The issue manifested when a
downstream ArgMin operation received a tensor with fewer dimensions than
expected, causing an 'axis out of bounds' error.

Specifically:
1. The Expand op was incorrectly skipping the broadcast when input and
   target shapes had the same values but different ranks
2. This caused a tensor with shape [5,60] to remain [5,60] when it
   should have been expanded to [1,1,5,60]
3. The subsequent ArgMin op with axis=2 then failed as the tensor only
   had 2 dimensions instead of the expected 4

The fix ensures that Expand always broadcasts to the target shape,
preserving the rank specified in the ONNX model. This allows downstream
operations to work with the correct tensor dimensions.

Fixes apache#17746
@yongwww yongwww merged commit 87b37b4 into apache:main Apr 27, 2025
10 checks passed
ShiboXing pushed a commit to ShiboXing/tvm that referenced this pull request Aug 10, 2025
* [ONNX] Fix Expand operator to properly handle target shapes

This fixes issue apache#17746 where the ONNX Expand operator was not correctly
expanding tensors to higher dimensions. The issue manifested when a
downstream ArgMin operation received a tensor with fewer dimensions than
expected, causing an 'axis out of bounds' error.

Specifically:
1. The Expand op was incorrectly skipping the broadcast when input and
   target shapes had the same values but different ranks
2. This caused a tensor with shape [5,60] to remain [5,60] when it
   should have been expanded to [1,1,5,60]
3. The subsequent ArgMin op with axis=2 then failed as the tensor only
   had 2 dimensions instead of the expected 4

The fix ensures that Expand always broadcasts to the target shape,
preserving the rank specified in the ONNX model. This allows downstream
operations to work with the correct tensor dimensions.

Fixes apache#17746

* add expand test case

* fix test case

* reformat

---------

Co-authored-by: Anurag Singh <10385586+singh20anurag@users.noreply.github.com>
Co-authored-by: taylor <xinxilwl@qq.com>
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