Skip to content

Transforms: scope duplicate-user fusion for layout propagation - #22374

Open
rascani wants to merge 4 commits into
mainfrom
rascani/cortex-m-01-fusion
Open

Transforms: scope duplicate-user fusion for layout propagation#22374
rascani wants to merge 4 commits into
mainfrom
rascani/cortex-m-01-fusion

Conversation

@rascani

@rascani rascani commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Summary

Layout propagation uses FuseDuplicateUsersPass to merge duplicate view and permute users exposed while transforms move through a graph.

This PR adds two optional controls:

  • allowed_targets limits fusion to the layout-copy operators owned by propagation.
  • semantic_key includes backend metadata not represented in FX arguments.

Arm uses the semantic key for input and output qparams, preventing otherwise-identical layout copies with different
quantization semantics from being merged.

Existing callers retain their current behavior. This PR does not change the generic pass’s handling of mutation, aliasing, effects, literals, or graph outputs. Arm’s existing RESCALE exclusion and output cleanup also remain unchanged.

Review guide

  1. fuse_duplicate_users_pass.py: the two optional configuration points.
  2. propagate_view_copy_permute_pass.py: restricting fusion to layout copies.
  3. Arm propagation: adding qparams to the semantic key.
  4. Tests: distinct qparams remain distinct and unrelated duplicate users are ignored.

AI-assisted: Codex.

Stack created with GitHub Stacks CLIGive Feedback 💬

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

@pytorch-bot

pytorch-bot Bot commented Aug 31, 2026

Copy link
Copy Markdown

🔗 Helpful Links

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

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

✅ No Failures

As of commit 871143b with merge base 684d4bd (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 Aug 31, 2026
@github-actions github-actions Bot added ciflow/trunk module: arm Issues related to arm backend labels Aug 31, 2026
@rascani
rascani marked this pull request as ready for review August 31, 2026 23:04
@rascani
rascani requested a review from digantdesai as a code owner August 31, 2026 23:04
@rascani
rascani requested a review from AdrianLundell August 31, 2026 23:04
Comment thread backends/arm/_passes/fuse_duplicate_users_pass.py Outdated
@AdrianLundell

Copy link
Copy Markdown
Collaborator

This patch does at least 5 different things, would it be possible to split it or at least document it a bit to help the review?

@rascani rascani added the release notes: none Do not include this in the release notes label Sep 1, 2026
@rascani
rascani force-pushed the rascani/cortex-m-01-fusion branch from 8518bd7 to 9576d24 Compare September 1, 2026 21:52
@rascani

rascani commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

This patch does at least 5 different things, would it be possible to split it or at least document it a bit to help the review?

Sorry about that. It does a lot, but I'd prefer not to split it because its all related to making a safe decision about whether two nodes can share the same output. I've updated the summary to (hopefully) better explain what it is doing and also included a suggested review order.

FuseDuplicateUsersPass previously identified duplicates from operator and arguments alone. That could merge nondeterministic or mutating calls, distinct literal tensors, values with backend-specific metadata, or independently returned tensors.

Restrict fusion to schema-known pure non-aliasing operators, respect intervening effects and downstream mutations, and preserve output identity by default. Arm includes quantization metadata in the signature and opts into output aliasing only where EnsureUniqueOutputNodesPass repairs it before serialization.

AI-assisted: Codex.
Build the duplicate-fusion semantic key through the existing FoldAndAnnotateQParamsPass accessors while retaining the empty-metadata behavior used by float graphs.

AI-assisted: Codex.
Limit horizontal duplicate fusion to the view and permute transforms owned by the propagation pass. Thread the existing semantic-key policy through that call site so Arm transformations with different folded quantization parameters remain distinct.

AI-assisted: Codex.
@AdrianLundell

Copy link
Copy Markdown
Collaborator

The operator is nondeterministic / equal-looking literal tensors are different objects. -> Seems reasonable but how often are literal tensors and non deterministic ops users of previous ops? Could the relevant ops be listed for simplicity?

Operator is mutable, or returns an alias. / An effect occurs between the two calls. / One result, or an alias of it, is later mutated. -> All of these are about aliasing and muteability, do we handle such cases usually and would this not be an issue for all decompositions in that case? Also, the code is a bit complex, could it be simplified by just doing one pass of marking nodes which are mutated by another node and directly bailing on them or is there any case which is missed?

Both results are independently returned. -> Could this be simplified by just not fusing nodes which are inputs to the output node or am I missing some subtlety?

Backend metadata changes the meaning of the operation. -> OK

Keep only the target allowlist and backend semantic key needed by layout propagation. Restore the existing generic fusion behavior and Arm cleanup policy, while restricting propagation fusion to non-aliasing layout-copy operators.

AI-assisted: Codex.
@rascani rascani changed the title Transforms: make duplicate-user fusion semantics-preserving Transforms: scope duplicate-user fusion for layout propagation Sep 3, 2026
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 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