Skip to content

Arm backend: Add CanonicalizeViewCopyPermutePass#20276

Open
AdrianLundell wants to merge 1 commit into
pytorch:mainfrom
AdrianLundell:change-1265152
Open

Arm backend: Add CanonicalizeViewCopyPermutePass#20276
AdrianLundell wants to merge 1 commit into
pytorch:mainfrom
AdrianLundell:change-1265152

Conversation

@AdrianLundell

@AdrianLundell AdrianLundell commented Jun 15, 2026

Copy link
Copy Markdown
Collaborator

This pass replaces PostponePermuteOpBelowSqueezeOrUnsqueezeLikeView
using a more general condition for which permute-view combinations may be
fused, see docstrings.

  • remove stale comments in mha test

cc @digantdesai @freddan80 @per @zingo @oscarandersson8218 @mansnils @Sebastian-Larsson @robell @rascani

This pass replaces PostponePermuteOpBelowSqueezeOrUnsqueezeLikeView
and FuseCascadedTransposeOrPermuteOps pass reordering and fusing
in the same step, and improves performance by using
a more general condition for which combinations may be
fused, see docstring.

+ remove stale comments in mha test

Signed-off-by: Adrian Lundell <adrian.lundell@arm.com>
Change-Id: I5e9d28f2fd9a71aa277039d66fe644d988227729
Copilot AI review requested due to automatic review settings June 15, 2026 12:07
@AdrianLundell AdrianLundell added help wanted Extra attention is needed partner: arm For backend delegation, kernels, demo, etc. from the 3rd-party partner, Arm ciflow/trunk release notes: none Do not include this in the release notes labels Jun 15, 2026
@pytorch-bot

pytorch-bot Bot commented Jun 15, 2026

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❌ 5 New Failures, 1 Cancelled Job, 1 Unclassified Failure

As of commit 9913688 with merge base e88fd04 (image):

NEW FAILURES - The following jobs have failed:

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:

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

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 Jun 15, 2026
@github-actions github-actions Bot added the module: arm Issues related to arm backend label Jun 15, 2026
@zingo

zingo commented Jun 15, 2026

Copy link
Copy Markdown
Collaborator

OK to merged but make sure no buck2 changes are needed.

Copilot AI 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.

Pull request overview

This PR introduces a new Arm backend graph pass, CanonicalizeViewCopyPermutePass, to more generally canonicalize/fuse view_copy/permute_copy chains (including swapping adjacent view/permute when it enables additional fusions), replacing the previous squeeze/unsqueeze-focused permute postponing transform in the Arm pipeline.

Changes:

  • Add CanonicalizeViewCopyPermutePass to canonicalize/fuse/swap view_copy/permute_copy chains and handle singleton-only permutes (static shapes) as views.
  • Wire the new pass into the Arm TOSA pipeline and remove the old PostponePermuteOpBelowSqueezeOrUnsqueezeLikeView/ConvertPermuteSingletonToViewPass steps from that pipeline.
  • Add targeted unit tests for swap/canonicalization behavior and update transpose-count expectations impacted by the new canonicalization.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
backends/arm/_passes/canonicalize_view_copy_permute_pass.py New canonicalization pass that fuses adjacent ops and swaps compatible view/permute pairs while preserving shape meta (incl. SymInt).
backends/arm/_passes/arm_pass_manager.py Integrates the new pass into the Arm pipeline and removes older permute-view reordering steps from that pipeline stage.
backends/arm/_passes/init.py Exposes CanonicalizeViewCopyPermutePass from the Arm passes package.
backends/arm/test/passes/test_canonicalize_view_copy_permute_pass.py New end-to-end tests validating graph rewrites and numerical equivalence for canonicalization behavior (incl. symbolic shapes).
backends/arm/test/passes/test_view_permute_swap.py New unit tests validating view -> permute swap logic against tensor semantics (static + symbolic cases).
backends/arm/test/passes/test_permute_view_swap.py New unit tests validating permute -> view swap logic against tensor semantics (static + symbolic cases).
backends/arm/test/misc/test_transpose_counts.py Updates expected transpose counts for affected models/cases after canonicalization changes.
backends/arm/test/misc/test_high_rank_permute_view_invariants.py Updates expected transpose counts for generated high-rank permute/view invariant cases.
backends/arm/test/ops/test_multihead_attention.py Removes now-stale MHA test configuration/comments related to quantization settings.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

]

while view_permute_nodes:
node = view_permute_nodes.pop(0)
node.target == self._VIEW_TARGET
and next_node.target == self._VIEW_TARGET
):
# Fuse conscutive views
@AdrianLundell

Copy link
Copy Markdown
Collaborator Author

• No required Buck2 changes for the latest commit.

The relevant targets already cover the new files:

  • New pass source is picked up by glob(["*.py"]) in backends/arm/_passes/TARGETS:44.
  • New pass tests are picked up by native.glob(["passes/test_*.py"]) in backends/arm/test/targets.bzl:15.

One optional cleanup: backends/arm/_passes/TARGETS:29 still has //executorch/backends/transforms:postpone_permute_below_squeeze_view, but arm_pass_manager.py no longer imports that pass.
It is stale, not necessary to fix target resolution.

So nothing should break but I could do the clean up.

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. help wanted Extra attention is needed module: arm Issues related to arm backend partner: arm For backend delegation, kernels, demo, etc. from the 3rd-party partner, Arm release notes: none Do not include this in the release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants