Arm backend: Add CanonicalizeViewCopyPermutePass#20276
Conversation
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
🔗 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 FailureAs of commit 9913688 with merge base e88fd04 ( 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. |
|
OK to merged but make sure no buck2 changes are needed. |
There was a problem hiding this comment.
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
CanonicalizeViewCopyPermutePassto canonicalize/fuse/swapview_copy/permute_copychains and handle singleton-only permutes (static shapes) as views. - Wire the new pass into the Arm TOSA pipeline and remove the old
PostponePermuteOpBelowSqueezeOrUnsqueezeLikeView/ConvertPermuteSingletonToViewPasssteps 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 |
So nothing should break but I could do the clean up. |
This pass replaces PostponePermuteOpBelowSqueezeOrUnsqueezeLikeView
using a more general condition for which permute-view combinations may be
fused, see docstrings.
cc @digantdesai @freddan80 @per @zingo @oscarandersson8218 @mansnils @Sebastian-Larsson @robell @rascani