Skip to content

Conversation

@singh20anurag
Copy link
Contributor

This fixes issue #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 #17746

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
Copy link
Member

yongwww commented Mar 26, 2025

it would be good to have a test case

@xinxilwl
Copy link
Contributor

hi, I add the test case in pr 17900

@yongwww
Copy link
Member

yongwww commented Apr 27, 2025

Thanks, @xinxilwl for the fix! Please feel free to chime in and re-open this issue if it persists

@yongwww yongwww closed this Apr 27, 2025
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.

[FRONTEND][ONNX] The onnx frontend cannot import ArgMin correctly: AssertionError: Axis is out of bounds

3 participants