Repository navigation
squeeze.dims: keep listed dims whose size is not 1 - #146
Merged
Merged
Conversation
PyTorch leaves a listed dim in place when its size is not 1, and
x.squeeze() exports as squeeze.dims over every dim. The lowering passed
all listed dims to shrink_dims, which rejects a static dim of size 4
("Operation creation failed") and drops a dynamic dim that PyTorch keeps
(rank mismatch). Only dims of static size 1 in the exported input are
shrunk now.
gokulkrishna98
self-requested a review
November 9, 2026 21:53
gokulkrishna98
approved these changes
Nov 11, 2026
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.
Summary
x.squeeze(1)on a[1, 4, 8]tensor is a no-op in PyTorch, but the exportedaten.squeeze.dimsnode still lists dim 1.replace_squeeze_dimspassed every listed dim tocoreai.shrink_dims, which rejects a dim of size 4 (ValueError: Operation creation failed). With torch 2.13.0,x.squeeze()decomposes tosqueeze.dimsover every dim and fails the same way. A listed dynamic dim, which PyTorch keeps, was shrunk too, and conversion failed (squeeze[0]: rank 2 vs 3).The lowering now shrinks only the listed dims whose size is a static 1 in the exported input, and returns the input when there are none.
Testing
test_squeeze_dims_not_size_onerunstorch.squeeze(x, [1]),torch.squeeze(x, [0, 1])andx.squeeze()on[1, 4, 8], static and with dims 1 and 2 dynamic, against PyTorch. All six fail before the fix and pass after it.Fixes #143