Skip to content

Handle rank-changing views in FuseCascadedTransposeOrPermuteOps (#19539)#19539

Open
mcremon-meta wants to merge 2 commits into
mainfrom
export-D104775245
Open

Handle rank-changing views in FuseCascadedTransposeOrPermuteOps (#19539)#19539
mcremon-meta wants to merge 2 commits into
mainfrom
export-D104775245

Conversation

@mcremon-meta
Copy link
Copy Markdown
Contributor

@mcremon-meta mcremon-meta commented May 13, 2026

Summary:

Extend FuseCascadedTransposeOrPermuteOps to fuse permute→view_copy→permute patterns where a squeeze/unsqueeze view sits between two permutes. The pass computes the combined effect of permute+view+permute: if the permutation components cancel out (identity), the entire chain is replaced with a single view_copy.

This handles patterns like permute_3D([0,2,1]) → view(unsqueeze) → permute_4D([0,2,3,1]) which composes to a simple view_copy (the permutations cancel, leaving only the reshape).

Reviewed By: DrJessop

Differential Revision: D104775245

@pytorch-bot
Copy link
Copy Markdown

pytorch-bot Bot commented May 13, 2026

🔗 Helpful Links

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

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:

❌ 1 Unclassified Failure

As of commit 5e33840 with merge base 7c495fa (image):

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:

  • Check Labels / Check labels (gh) (this job did not run on the merge base, so DrCI cannot tell whether the failure is pre-existing)
    RuntimeError: GraphQL query

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 May 13, 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 May 13, 2026
@meta-codesync
Copy link
Copy Markdown
Contributor

meta-codesync Bot commented May 13, 2026

@mcremon-meta has exported this pull request. If you are a Meta employee, you can view the originating Diff in D104775245.

@github-actions
Copy link
Copy Markdown

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

@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 May 13, 2026
@meta-codesync meta-codesync Bot changed the title Handle rank-changing views in FuseCascadedTransposeOrPermuteOps Handle rank-changing views in FuseCascadedTransposeOrPermuteOps (#19539) May 13, 2026
meta-codesync Bot pushed a commit that referenced this pull request May 13, 2026
Summary:

Extend FuseCascadedTransposeOrPermuteOps to fuse permute→view_copy→permute patterns where a squeeze/unsqueeze view sits between two permutes. The pass computes the combined effect of permute+view+permute: if the permutation components cancel out (identity), the entire chain is replaced with a single view_copy.

This handles patterns like permute_3D([0,2,1]) → view(unsqueeze) → permute_4D([0,2,3,1]) which composes to a simple view_copy (the permutations cancel, leaving only the reshape).

Differential Revision: D104775245
@meta-codesync meta-codesync Bot force-pushed the export-D104775245 branch from b6fb904 to 7699a00 Compare May 13, 2026 06:55
meta-codesync Bot pushed a commit that referenced this pull request May 14, 2026
Summary:

Extend FuseCascadedTransposeOrPermuteOps to fuse permute→view_copy→permute patterns where a squeeze/unsqueeze view sits between two permutes. The pass computes the combined effect of permute+view+permute: if the permutation components cancel out (identity), the entire chain is replaced with a single view_copy.

This handles patterns like permute_3D([0,2,1]) → view(unsqueeze) → permute_4D([0,2,3,1]) which composes to a simple view_copy (the permutations cancel, leaving only the reshape).

Differential Revision: D104775245
@meta-codesync meta-codesync Bot force-pushed the export-D104775245 branch from 7699a00 to 80ca296 Compare May 14, 2026 04:45
meta-codesync Bot pushed a commit that referenced this pull request May 14, 2026
Summary:

Extend FuseCascadedTransposeOrPermuteOps to fuse permute→view_copy→permute patterns where a squeeze/unsqueeze view sits between two permutes. The pass computes the combined effect of permute+view+permute: if the permutation components cancel out (identity), the entire chain is replaced with a single view_copy.

This handles patterns like permute_3D([0,2,1]) → view(unsqueeze) → permute_4D([0,2,3,1]) which composes to a simple view_copy (the permutations cancel, leaving only the reshape).

Differential Revision: D104775245
@meta-codesync meta-codesync Bot force-pushed the export-D104775245 branch from 80ca296 to 88fea01 Compare May 14, 2026 05:23
meta-codesync Bot pushed a commit that referenced this pull request May 14, 2026
Summary:

Extend FuseCascadedTransposeOrPermuteOps to fuse permute→view_copy→permute patterns where a squeeze/unsqueeze view sits between two permutes. The pass computes the combined effect of permute+view+permute: if the permutation components cancel out (identity), the entire chain is replaced with a single view_copy.

This handles patterns like permute_3D([0,2,1]) → view(unsqueeze) → permute_4D([0,2,3,1]) which composes to a simple view_copy (the permutations cancel, leaving only the reshape).

Differential Revision: D104775245
@meta-codesync meta-codesync Bot force-pushed the export-D104775245 branch from 88fea01 to 476ce41 Compare May 14, 2026 14:51
)

Summary:

Extend RemovePermutesAroundElementwiseOps to cancel permute pairs across rank-changing squeeze/unsqueeze view boundaries. When a permute's sole user is a view_copy that adds or removes a single size-1 dimension, the pass adapts the expected permutation to the new rank and continues traversal. This enables removing permutes that sit on opposite sides of an unsqueeze→elementwise→squeeze chain (e.g. the NHWC↔NTC layout conversion around convolutions in the cascade detector model).

Key changes:
- Accept extra_permutable_ops constructor parameter for backend-specific ops
- Track per-node expected permutations across view boundaries
- Run dimension updates before edges_in bypass to preserve original metadata
- Handle view_copy, unsqueeze_copy, squeeze_copy rank changes
- Treat aten.full.default as a compile-time constant

Reviewed By: DrJessop

Differential Revision: D104775244
Summary:

Extend FuseCascadedTransposeOrPermuteOps to fuse permute→view_copy→permute patterns where a squeeze/unsqueeze view sits between two permutes. The pass computes the combined effect of permute+view+permute: if the permutation components cancel out (identity), the entire chain is replaced with a single view_copy.

This handles patterns like permute_3D([0,2,1]) → view(unsqueeze) → permute_4D([0,2,3,1]) which composes to a simple view_copy (the permutations cancel, leaving only the reshape).

Reviewed By: DrJessop

Differential Revision: D104775245
@meta-codesync meta-codesync Bot force-pushed the export-D104775245 branch from 476ce41 to 5e33840 Compare May 18, 2026 20:57
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. fb-exported meta-exported module: arm Issues related to arm backend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants