Skip to content

Arm backend: Improve permute/view fusing#21055

Merged
AdrianLundell merged 5 commits into
pytorch:mainfrom
AdrianLundell:temp
Jul 23, 2026
Merged

Arm backend: Improve permute/view fusing#21055
AdrianLundell merged 5 commits into
pytorch:mainfrom
AdrianLundell:temp

Conversation

@AdrianLundell

@AdrianLundell AdrianLundell commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator
  • Makes view/permutes always split to all branches of a node with multiple outputs for downward propagation. Note that this will never increase the number of permutes/views in the graph, since any non-fused permutes/views will propagate back and be fused together again by the upward propagation pass.

  • Adds support for where operator to fuse_identical_input_transforms

  • Replaces _would_strand_layout_op_on_wider_elements with MoveDataMovementOpsToSmallerDtypePass to allow ops to
    propagate more freely during the fusing phase

  • Adds tosa ops to MatchArgsPass since it is run after some ops have been rewritten to TOSA.

  • Generalizes refresh_permute_view_meta into refresh_node_meta which works for any operators and uses that.

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

Adds transpose counting to pixel-shuffle tests including
a mixed precision case with decomposed Q/DQ nodes which
the previous permute propagation did not handle.

This is fixed by adding support for propagating views and
permutes over across forks in the graph, as long as it can
be proven that the branches will eventually converge.

Also adds support for where to fuse_identiacal_input_transforms

Signed-off-by: Adrian Lundell <adrian.lundell@arm.com>
Change-Id: If66ff26d8020cdeab9ea88bc87a687a63a57dda0
@AdrianLundell AdrianLundell added 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 Jul 21, 2026
@pytorch-bot

pytorch-bot Bot commented Jul 21, 2026

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

✅ You can merge normally! (1 Unrelated Failure)

As of commit b69a130 with merge base 266e0dc (image):

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 Jul 21, 2026
@github-actions github-actions Bot added the module: arm Issues related to arm backend label Jul 21, 2026
@AdrianLundell
AdrianLundell requested a review from rascani July 21, 2026 08:24
Comment thread backends/arm/_passes/arm_pass_utils.py Outdated
lambda arg: arg.meta["val"] if isinstance(arg, torch.fx.Node) else arg,
)
node.meta["val"] = cast(Any, node.target)(*args, **kwargs)
except Exception:

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.

Is there any way to narrow this to expected Exception classes?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Good question, let's see what happens if I remove it completely. When I think about it it seems that the only thing this would do is to hide real errors, I am not sure that there are any cases where it is valid to simply pass

AdrianLundell and others added 4 commits July 22, 2026 08:44
Signed-off-by: Adrian Lundell <adrian.lundell@arm.com>
Change-Id: I1986dc95047d87a0f325c7ebbb86db50c7deef72
Change-Id: Id0595962b9d49c2c5828379769a7631895101910
Signed-off-by: Adrian Lundell <adrian.lundell@arm.com>
While the simple meta-data update was faster, it
is difficult to ensure a fully safe update this way since
there is no clear contract on what is expected from the Node.

This means the only way to use such a method would be
a) Skip errors and hope nothing breaks from it
b) Handle errors case-by-case when finding them by trial and error
This is also error-prone and not future-proof.

Instead use the slower full retrace.

Signed-off-by: Adrian Lundell <adrian.lundell@arm.com>
Change-Id: I0c55457122dae4a60f7db86cd5e997b5cf983a17
@AdrianLundell
AdrianLundell merged commit 179c4ee into pytorch:main Jul 23, 2026
492 of 494 checks passed
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. 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.

2 participants