Skip to content

Fold non-matching end permutes instead of discarding the region (#22293) - #22293

Open
abeakkas wants to merge 1 commit into
pytorch:mainfrom
abeakkas:export-D117939968
Open

Fold non-matching end permutes instead of discarding the region (#22293)#22293
abeakkas wants to merge 1 commit into
pytorch:mainfrom
abeakkas:export-D117939968

Conversation

@abeakkas

@abeakkas abeakkas commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Summary:

RemovePermutesAroundElementwiseOps gave up on an entire region whenever it
reached an outgoing permute that was not the inverse of the region's start
permute, so a single mismatched boundary cost every permute removal in that
region.

Such a permute is now kept and its permutation rewritten to absorb the start
permute being removed. With the producer back in the original layout,
permute(permute(x, start), end) is permute(x, R) for R[k] = start[end[k]],
so the consumer sees the same tensor and one permute still disappears. No
permute is added on a live edge: the existing matching case is just the
instance where R is the identity.

Since a permute can now be rewritten in place while staying wired,
_subgraph_edges_are_current also re-validates that an edges_in permutation
still matches what the candidate was planned against.

Reviewed By: DrJessop

Differential Revision: D117939968

@pytorch-bot

pytorch-bot Bot commented Aug 28, 2026

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❌ 1 Cancelled Job, 1 Unrelated Failure

As of commit 23815c1 with merge base c27baa8 (image):

CANCELLED JOB - The following job was cancelled. Please retry:

BROKEN TRUNK - The following job failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

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

meta-codesync Bot commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

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

@github-actions

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 Fold non-matching end permutes instead of discarding the region Fold non-matching end permutes instead of discarding the region (#22293) Aug 29, 2026
abeakkas added a commit to abeakkas/executorch that referenced this pull request Aug 29, 2026
…rch#22293)

Summary:

`RemovePermutesAroundElementwiseOps` gave up on an entire region whenever it
reached an outgoing permute that was not the inverse of the region's start
permute, so a single mismatched boundary cost every permute removal in that
region.

Such a permute is now kept and its permutation rewritten to absorb the start
permute being removed. With the producer back in the original layout,
`permute(permute(x, start), end)` is `permute(x, R)` for `R[k] = start[end[k]]`,
so the consumer sees the same tensor and one permute still disappears. No
permute is added on a live edge: the existing matching case is just the
instance where `R` is the identity.

Since a permute can now be rewritten in place while staying wired,
`_subgraph_edges_are_current` also re-validates that an `edges_in` permutation
still matches what the candidate was planned against.

Reviewed By: DrJessop

Differential Revision: D117939968
…rch#22293)

Summary:

`RemovePermutesAroundElementwiseOps` gave up on an entire region whenever it
reached an outgoing permute that was not the inverse of the region's start
permute, so a single mismatched boundary cost every permute removal in that
region.

Such a permute is now kept and its permutation rewritten to absorb the start
permute being removed. With the producer back in the original layout,
`permute(permute(x, start), end)` is `permute(x, R)` for `R[k] = start[end[k]]`,
so the consumer sees the same tensor and one permute still disappears. No
permute is added on a live edge: the existing matching case is just the
instance where `R` is the identity.

Since a permute can now be rewritten in place while staying wired,
`_subgraph_edges_are_current` also re-validates that an `edges_in` permutation
still matches what the candidate was planned against.

Reviewed By: DrJessop

Differential Revision: D117939968
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.

2 participants