Skip to content

Fix IndexError when a squeeze view is reached upstream (#21620) - #21620

Merged
meta-codesync[bot] merged 1 commit into
mainfrom
export-D115002472
Aug 7, 2026
Merged

Fix IndexError when a squeeze view is reached upstream (#21620)#21620
meta-codesync[bot] merged 1 commit into
mainfrom
export-D115002472

Conversation

@mcremon-meta

@mcremon-meta mcremon-meta commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Summary:

RemovePermutesAroundElementwiseOps._adapt_permute_across_view assumes the
permutation it is handed lives in the view's input-rank space. That holds for
the two downstream call sites, but visit() also calls it when a
squeeze/unsqueeze view is reached by upstream traversal, where the permutation
is expressed at the view's output rank. For a squeeze view the squeezed
position is then out of range for the permutation, and permute[index] raises
IndexError: list index out of range, aborting the whole ArmPassManager
pipeline during lowering.

This is the same class of bug as D105787161, which added a guard in
permute_subgraph() — but that guard runs after traversal, so it never gets a
chance to fire on this path.

Bail out of _adapt_permute_across_view (return None) when the permutation
rank does not match the view's input rank. The existing visit() call sites
already treat None as "cannot adapt" and drop the subgraph, so the pass
degrades to leaving the permutes in place instead of crashing or silently
mis-adapting the permutation.

Reviewed By: aliafzal

Differential Revision: D115002472

@pytorch-bot

pytorch-bot Bot commented Aug 6, 2026

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/21620

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit c709c73 with merge base 74f1ce8 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 6, 2026
@meta-codesync

meta-codesync Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

@mcremon-meta has exported this pull request. If you are a Meta employee, you can view the originating Diff in D115002472.

@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

@meta-codesync meta-codesync Bot changed the title Fix IndexError when a squeeze view is reached upstream Fix IndexError when a squeeze view is reached upstream (#21620) Aug 6, 2026
meta-codesync Bot pushed a commit that referenced this pull request Aug 6, 2026
Summary:

`RemovePermutesAroundElementwiseOps._adapt_permute_across_view` assumes the
permutation it is handed lives in the view's *input-rank* space. That holds for
the two downstream call sites, but `visit()` also calls it when a
squeeze/unsqueeze view is reached by *upstream* traversal, where the permutation
is expressed at the view's *output* rank. For a squeeze view the squeezed
position is then out of range for the permutation, and `permute[index]` raises
`IndexError: list index out of range`, aborting the whole `ArmPassManager`
pipeline during lowering.

This is the same class of bug as D105787161, which added a guard in
`permute_subgraph()` — but that guard runs after traversal, so it never gets a
chance to fire on this path.

Bail out of `_adapt_permute_across_view` (return `None`) when the permutation
rank does not match the view's input rank. The existing `visit()` call sites
already treat `None` as "cannot adapt" and drop the subgraph, so the pass
degrades to leaving the permutes in place instead of crashing or silently
mis-adapting the permutation.

Reviewed By: aliafzal

Differential Revision: D115002472
@meta-codesync
meta-codesync Bot force-pushed the export-D115002472 branch from 838fb82 to de2efc1 Compare August 6, 2026 22:22
Summary:

`RemovePermutesAroundElementwiseOps._adapt_permute_across_view` assumes the
permutation it is handed lives in the view's *input-rank* space. That holds for
the two downstream call sites, but `visit()` also calls it when a
squeeze/unsqueeze view is reached by *upstream* traversal, where the permutation
is expressed at the view's *output* rank. For a squeeze view the squeezed
position is then out of range for the permutation, and `permute[index]` raises
`IndexError: list index out of range`, aborting the whole `ArmPassManager`
pipeline during lowering.

This is the same class of bug as D105787161, which added a guard in
`permute_subgraph()` — but that guard runs after traversal, so it never gets a
chance to fire on this path.

Bail out of `_adapt_permute_across_view` (return `None`) when the permutation
rank does not match the view's input rank. The existing `visit()` call sites
already treat `None` as "cannot adapt" and drop the subgraph, so the pass
degrades to leaving the permutes in place instead of crashing or silently
mis-adapting the permutation.

Reviewed By: aliafzal

Differential Revision: D115002472
@meta-codesync
meta-codesync Bot force-pushed the export-D115002472 branch from de2efc1 to c709c73 Compare August 6, 2026 22:37
@meta-codesync
meta-codesync Bot merged commit 28a7fac into main Aug 7, 2026
192 checks passed
@meta-codesync
meta-codesync Bot deleted the export-D115002472 branch August 7, 2026 05:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. meta-exported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants