Skip to content

Fix stale dims and constants in downward permute propagation - #24739

Open
apullin wants to merge 1 commit into
pytorch:mainfrom
apullin:export-D130233379
Open

apullin wants to merge 1 commit into
pytorch:mainfrom
apullin:export-D130233379

Conversation

@apullin

@apullin apullin commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Summary:
As PropagateViewCopyPermuteDownPass walks a permute down, it rewrites each node it crosses for the permute's input layout: the dims of a slice or reduction, and a binary op's constant input, which it permutes in place. When the fork at the end of the walk could not be split, the pass fell back to a pointwise region move planned from the permute's original position. That region stops at the first node it cannot include, such as a slice, a reduction or a backend op that is not pointwise, and left the crossed nodes from there on applying their rewritten dims or constants to the permuted tensor.

For example, permute(x, [0, 3, 1, 2]) -> clamp -> slice_copy(dim=1, 0, 4) feeding both permute(0, 2, 3, 1) and neg, the pattern Arm's RewriteConvPass leaves around a channel split between convs, became slice_copy(clamp(x), 2, 0, 4): for x of shape [1, 3, 5, 8] the outputs had shapes [1, 3, 4, 8] and [1, 8, 3, 4] instead of [1, 3, 5, 4] and [1, 4, 3, 5]. A keepdim sum in the same place made the pass raise while re-tracing, and a constant added after a crossed backend op that is not pointwise failed to broadcast or was broadcast along the wrong axis.

Plan the region move only when the walk has not advanced. Otherwise the permute moves past the frontier, where every rewrite is valid, and the next iteration retries the fork from there.

The test target now also depends on //executorch/exir:lib, for to_edge.

Differential Revision: D130233379

Summary:
As PropagateViewCopyPermuteDownPass walks a permute down, it rewrites each node it crosses for the permute's input layout: the dims of a slice or reduction, and a binary op's constant input, which it permutes in place. When the fork at the end of the walk could not be split, the pass fell back to a pointwise region move planned from the permute's original position. That region stops at the first node it cannot include, such as a slice, a reduction or a backend op that is not pointwise, and left the crossed nodes from there on applying their rewritten dims or constants to the permuted tensor.

For example, `permute(x, [0, 3, 1, 2]) -> clamp -> slice_copy(dim=1, 0, 4)` feeding both `permute(0, 2, 3, 1)` and `neg`, the pattern Arm's RewriteConvPass leaves around a channel split between convs, became `slice_copy(clamp(x), 2, 0, 4)`: for x of shape [1, 3, 5, 8] the outputs had shapes [1, 3, 4, 8] and [1, 8, 3, 4] instead of [1, 3, 5, 4] and [1, 4, 3, 5]. A keepdim sum in the same place made the pass raise while re-tracing, and a constant added after a crossed backend op that is not pointwise failed to broadcast or was broadcast along the wrong axis.

Plan the region move only when the walk has not advanced. Otherwise the permute moves past the frontier, where every rewrite is valid, and the next iteration retries the fork from there.

The test target now also depends on `//executorch/exir:lib`, for `to_edge`.

Differential Revision: D130233379
@pytorch-bot

pytorch-bot Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❌ 1 Pending, 1 Unclassified Failure

As of commit 5b7c155 with merge base 97971ca (image):

UNCLASSIFIED FAILURE - DrCI could not classify the following job because the workflow did not run on the merge base. The failure may be pre-existing on trunk or introduced by this PR:

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 Nov 6, 2026
@meta-codesync

meta-codesync Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

@apullin has exported this pull request. If you are a Meta employee, you can view the originating Diff in D130233379.

@github-actions

github-actions Bot commented Nov 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.

This branch has not been deployed

No deployments
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.

1 participant