[TorchOnnx] Fix ScatterND last unflatten step#4586
Open
juanigp wants to merge 3 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The issue was seen when trying to lower this bevformer-tiny checkpoint.
The ScatterND lowering flattens the first X dimensions of the data tensor for aten.scatter.src, then tries to restore the original ONNX result shape, which can produce invalid operations.
For bevformer-tiny, there is a ScatterND operation:
converted to:
and its lowering produces:
The latter IR is trying to reshape a [2500, 256] tensor into [2500, 1, 256] by replacing dim 0 (2500) by [2500, 1, 256] which is wrong: 2500 at dim 0 should be replaced by [2500, 1] instead (and leave the trailing 256 unaffected).
Fix:
This PR re-writes the unflattening step of ScatterND lowering to properly unflatten the flattened dim 0 into its original shape, and not the original shape of the whole data tensor. Replacing: