Skip to content

Transforms: make layout-copy rewrites backend-configurable - #22375

Open
rascani wants to merge 5 commits into
rascani/cortex-m-01-fusionfrom
rascani/cortex-m-02-propagation
Open

Transforms: make layout-copy rewrites backend-configurable#22375
rascani wants to merge 5 commits into
rascani/cortex-m-01-fusionfrom
rascani/cortex-m-02-propagation

Conversation

@rascani

@rascani rascani commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Summary

The layout propagation passes currently assume every layout copy is aten.permute_copy. That prevents a backend from using the shared propagation algorithms when its layout copies must remain visible as a backend-specific operator.

This PR separates the shared transformation mechanics from that backend policy:

  • permute_targets defines a closed set of operators representing layout copies.
  • Synthesized copies preserve the source operator, and metadata refresh recognizes the configured targets.
  • Mixed-dialect chains and regions are left unchanged.
  • can_propagate lets a backend stop movement at barriers without adding backend-specific operators to the shared pass.
  • Lower-rank constants are reshaped only when the permutation moves unit dimensions. Reordering non-unit dimensions still emits a real copy in the source dialect.

Existing callers retain the current defaults. In particular, this PR does not add multi-input upward distribution, boundary compensation, or output-layout policy, and it does not change the handling of aten.view.default. Those decisions are not required to support backend-defined layout-copy operators.

Review guide

  1. canonicalize_view_copy_permute_pass.py and permute_view_meta.py
    • Recognizing configured copy targets and refreshing their metadata.
  2. propagate_view_copy_permute_pass.py
    • Keeping the target family closed and preserving the source dialect.
  3. remove_permutes_around_elementwise_ops.py
    • Backend barriers, constant handling, and conservative mixed-dialect behavior.
  4. Arm tests
    • Verifying that existing Arm policy remains unchanged.

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/22375

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

❌ 1 New Failure, 15 Cancelled Jobs, 13 Pending, 1 Unrelated Failure

As of commit 57e4816 with merge base 684d4bd (image):

NEW FAILURE - The following job has failed:

CANCELLED JOBS - The following jobs were cancelled. Please retry:

FLAKY - The following job failed but was likely due to flakiness present on trunk:

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 and removed CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. labels Aug 31, 2026
@rascani
rascani requested a review from AdrianLundell August 31, 2026 23:04
@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
@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
@AdrianLundell

Copy link
Copy Markdown
Collaborator

It seems like the patch is doing some things that are not that well advertised, why is test_mixed_reconvergence_fork_does_not_strand_a_permute removed and why is the new _maybe_distribute_upwards_permute_over_elementwise required just to support backend defined layout copies?

@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-02-propagation branch from 8158e2d to 6e404f7 Compare September 1, 2026 21:52
@rascani rascani changed the title Transforms: support backend-defined layout copies Transforms: make layout-copy rewrites backend-configurable Sep 1, 2026
@rascani
rascani force-pushed the rascani/cortex-m-02-propagation branch from 6e404f7 to 4bc4208 Compare September 2, 2026 00:31
@rascani

rascani commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

It seems like the patch is doing some things that are not that well advertised, why is test_mixed_reconvergence_fork_does_not_strand_a_permute removed and why is the new _maybe_distribute_upwards_permute_over_elementwise required just to support backend defined layout copies?

Agreed, sorry again about that. I have updated the summary to go in-depth and provided a review order suggestion. Upward distribution is not required to support backend-defined layout copies, and the unrestricted version can increase the copy count. I removed it from this PR and restored the mixed-reconvergence xfail. I also removed boundary compensation and the output-layout policy for the same reason.

The existing view and permute optimizers assumed that every layout change used the ATen permute target. Backends with a graph-visible layout dialect therefore could not reuse propagation or region cancellation without changing the operator family mid-rewrite.

Make permute targets, emitted targets, fusion scope, propagation barriers, and output-boundary compensation explicit extension points while preserving existing defaults. Keep synthesized nodes in their source dialect, refresh their metadata, reject mixed-dialect chains conservatively, and cover reconvergent and rank-changing regions.

AI-assisted: Codex.
Restore the shared mixed-reconvergence xfail and document that upward distribution is a backend opt-in because it can increase layout-copy count.

AI-assisted: Codex.
Track each cancellation region's source permute target so constant and output compensation cannot silently switch dialects. Document why propagation excludes aliasing view.default and why backend policy hooks are opt-in.

AI-assisted: Codex.
Keep this stack focused on preserving configured layout-copy dialects and stopping cancellation at backend barriers. Remove upward distribution and output-boundary compensation because either can increase the number of copies, and drop the unused noncontiguous-formation override. Preserve the existing aten.view.default behavior so alias handling can be reviewed separately with a dedicated reproducer.

AI-assisted: Codex.
Drop the unrelated transpose-pair guard and the general lower-rank constant reorder fix. Retain only the dialect, metadata, barrier, and region-cancellation behavior consumed by Cortex-M explicit layout.

AI-assisted: Codex.
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