Skip to content

Extend permute removal through singleton and sink views (#22549) - #22549

Merged
meta-codesync[bot] merged 1 commit into
mainfrom
export-D116686835
Sep 9, 2026
Merged

meta-codesync[bot] merged 1 commit into
mainfrom
export-D116686835

Conversation

@mcremon-meta

@mcremon-meta mcremon-meta commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary:

Widen the regions RemovePermutesAroundElementwiseOps can collapse by handling two view patterns that previously terminated a region, and extend the permutable set to the amax/amin reductions.

Singleton boundary views: when a view that only inserts unit dimensions sits between a region's incoming and outgoing layout transforms, compose the pair across it and rewrite the view's target shape, so the boundary is removed instead of ending the region. Reject the composition unless the view has a single user and the outgoing permutation restores the incoming axis labels to identity order.

Broadcast sink views: replace the conservative consumer walk with an exact shape remap. A sink reshape carrying at most one non-unit dimension has layout-invariant element order, so remap its target shape into the layout preceding the region, letting its broadcast axes line up once the boundary transforms are dropped. Reject sinks whose output has more than one non-unit dimension or whose rank does not match the region permutation, along with shared boundary views whose replacements would be ambiguous.

Reductions: amax and amin join mean.dim and sum.dim_IntList in the permutable op set, and the dim-remapping helper (renamed update_reduction_dim) now accepts a scalar dim in addition to a list.

The transform is shared rather than backend-specific, so the widened region coverage applies to every backend that runs it.

Reviewed By: rascani

Differential Revision: D116686835

@pytorch-bot

pytorch-bot Bot commented Sep 4, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

✅ No Failures

As of commit 43544a2 with merge base 7dc8641 (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 Sep 4, 2026
@meta-codesync

meta-codesync Bot commented Sep 4, 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 D116686835.

@github-actions github-actions Bot added ciflow/trunk module: arm Issues related to arm backend labels Sep 4, 2026
@github-actions

github-actions Bot commented Sep 4, 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.

@zingo zingo added the partner: arm For backend delegation, kernels, demo, etc. from the 3rd-party partner, Arm label Sep 4, 2026

@sylvesterkaczmarek sylvesterkaczmarek left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The conservative sink-view rules look well chosen: only a single non-unit dimension is relocatable without changing element order, rank must match the surrounding permutation, and single-user ownership avoids rewriting a shape consumed under two layout assumptions. Extending reductions requires remapping the reduced axis as well as removing permutes, so the new amax/amin cases are important. The numerical before/after graph execution checks make this substantially safer than node-count assertions alone.

@meta-codesync meta-codesync Bot changed the title Extend permute removal through singleton and sink views Extend permute removal through singleton and sink views (#22549) Sep 8, 2026
meta-codesync Bot pushed a commit that referenced this pull request Sep 8, 2026
Summary:

Widen the regions `RemovePermutesAroundElementwiseOps` can collapse by handling two view patterns that previously terminated a region, and extend the permutable set to the `amax`/`amin` reductions.

Singleton boundary views: when a view that only inserts unit dimensions sits between a region's incoming and outgoing layout transforms, compose the pair across it and rewrite the view's target shape, so the boundary is removed instead of ending the region. Reject the composition unless the view has a single user and the outgoing permutation restores the incoming axis labels to identity order.

Broadcast sink views: replace the conservative consumer walk with an exact shape remap. A sink reshape carrying at most one non-unit dimension has layout-invariant element order, so remap its target shape into the layout preceding the region, letting its broadcast axes line up once the boundary transforms are dropped. Reject sinks whose output has more than one non-unit dimension or whose rank does not match the region permutation, along with shared boundary views whose replacements would be ambiguous.

Reductions: `amax` and `amin` join `mean.dim` and `sum.dim_IntList` in the permutable op set, and the dim-remapping helper (renamed `update_reduction_dim`) now accepts a scalar `dim` in addition to a list.

The transform is shared rather than backend-specific, so the widened region coverage applies to every backend that runs it.

Differential Revision: D116686835
meta-codesync Bot pushed a commit that referenced this pull request Sep 8, 2026
Summary:

Widen the regions `RemovePermutesAroundElementwiseOps` can collapse by handling two view patterns that previously terminated a region, and extend the permutable set to the `amax`/`amin` reductions.

Singleton boundary views: when a view that only inserts unit dimensions sits between a region's incoming and outgoing layout transforms, compose the pair across it and rewrite the view's target shape, so the boundary is removed instead of ending the region. Reject the composition unless the view has a single user and the outgoing permutation restores the incoming axis labels to identity order.

Broadcast sink views: replace the conservative consumer walk with an exact shape remap. A sink reshape carrying at most one non-unit dimension has layout-invariant element order, so remap its target shape into the layout preceding the region, letting its broadcast axes line up once the boundary transforms are dropped. Reject sinks whose output has more than one non-unit dimension or whose rank does not match the region permutation, along with shared boundary views whose replacements would be ambiguous.

Reductions: `amax` and `amin` join `mean.dim` and `sum.dim_IntList` in the permutable op set, and the dim-remapping helper (renamed `update_reduction_dim`) now accepts a scalar `dim` in addition to a list.

The transform is shared rather than backend-specific, so the widened region coverage applies to every backend that runs it.

Differential Revision: D116686835

@rascani rascani left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review automatically exported from Phabricator review in Meta.

Summary:

Widen the regions `RemovePermutesAroundElementwiseOps` can collapse by handling two view patterns that previously terminated a region, and extend the permutable set to the `amax`/`amin` reductions.

Singleton boundary views: when a view that only inserts unit dimensions sits between a region's incoming and outgoing layout transforms, compose the pair across it and rewrite the view's target shape, so the boundary is removed instead of ending the region. Reject the composition unless the view has a single user and the outgoing permutation restores the incoming axis labels to identity order.

Broadcast sink views: replace the conservative consumer walk with an exact shape remap. A sink reshape carrying at most one non-unit dimension has layout-invariant element order, so remap its target shape into the layout preceding the region, letting its broadcast axes line up once the boundary transforms are dropped. Reject sinks whose output has more than one non-unit dimension or whose rank does not match the region permutation, along with shared boundary views whose replacements would be ambiguous.

Reductions: `amax` and `amin` join `mean.dim` and `sum.dim_IntList` in the permutable op set, and the dim-remapping helper (renamed `update_reduction_dim`) now accepts a scalar `dim` in addition to a list.

The transform is shared rather than backend-specific, so the widened region coverage applies to every backend that runs it.

Reviewed By: rascani

Differential Revision: D116686835
@mcremon-meta

Copy link
Copy Markdown
Contributor Author

cc @zingo @freddan80 just a test update on Arm side, so should be pretty safe

huydhn added a commit that referenced this pull request Sep 8, 2026
Two things, one enabling the other.

**`ciflow/trunk/*` on `pull.yml` is a mistake.** It arrived in #18172,
which moved the ARM Cortex-M size test from `trunk.yml` to `pull.yml`
and carried trunk's tag trigger across with the job. `ciflow/trunk`
should run `trunk.yml`; `pull.yml` already runs on every pull request
via `pull_request`, so those tag runs were duplicates — on #22549 the
tag run had 120 jobs against the pull request run's 121. `trunk.yml`
keeps the trigger.

**With no tag push reaching this workflow, the concurrency key can go
back to pytorch's.** #21622 added `github.ref_type == 'branch' &&
github.sha` to stop ciflow tag re-pushes flooding the fleet, but that
term is truthy on `pull_request` too, where `github.sha` is the merge
commit and changes with every push — so pushes stopped cancelling
superseded runs. Before #21622: eight consecutive runs on one branch,
seven cancelled. After: three overlapping full runs on
`bump-torch-pin-2.14`, none cancelled. The key now matches pytorch's
`pull.yml` exactly, `github.run_id` included so two manual dispatches
don't cancel each other.

Authored with Claude Code.
@meta-codesync
meta-codesync Bot merged commit 0a4ec57 into main Sep 9, 2026
91 checks passed
@meta-codesync
meta-codesync Bot deleted the export-D116686835 branch September 9, 2026 02:37

This branch was previously deployed

1 inactive deployment
cadence — 43544a28 Deployed Sep 8, 2026 by meta-codesync[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. meta-exported module: arm Issues related to arm backend partner: arm For backend delegation, kernels, demo, etc. from the 3rd-party partner, Arm

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants