Skip to content

Add CSEPass to the default edge compilation pipeline (#19849)#19849

Open
billmguo wants to merge 1 commit into
pytorch:mainfrom
billmguo:export-D106584552
Open

Add CSEPass to the default edge compilation pipeline (#19849)#19849
billmguo wants to merge 1 commit into
pytorch:mainfrom
billmguo:export-D106584552

Conversation

@billmguo
Copy link
Copy Markdown
Contributor

@billmguo billmguo commented May 28, 2026

Summary:

CSEPass (Common Subexpression Elimination) was previously only used by specific backends (MLX, Cadence) and export scripts. This change adds it to base_post_op_replace_passes in the default to_edge / to_edge_transform_and_lower pipeline so all backends benefit from CSE automatically.

The pass is placed before dead_code_elimination_pass so any dead nodes CSE creates get cleaned up, and before DebugHandleGeneratorPass so debug handles are assigned to the final deduplicated graph.

CSE can merge structurally-identical nodes across different source partitions, which caused ConvertToLinearPass in XNNPACK to see extra output nodes in a partition. This is fixed by filtering outputs to only those reachable from the mm/addmm node within the partition.

The test_dim_order_revert_pass test is updated to expect 2 _to_copy ops (instead of 4) after to_edge, since CSE deduplicates the two identical branches.

Reviewed By: mohankumarkumar

Differential Revision: D106584552

@pytorch-bot
Copy link
Copy Markdown

pytorch-bot Bot commented May 28, 2026

🔗 Helpful Links

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

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

❌ 3 New Failures, 4 Unrelated Failures

As of commit cc4c35e with merge base 84c0484 (image):

NEW FAILURES - The following jobs have failed:

BROKEN TRUNK - The following jobs 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.

@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla Bot commented May 28, 2026

CLA Not Signed

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

meta-codesync Bot commented May 28, 2026

@billmguo has exported this pull request. If you are a Meta employee, you can view the originating Diff in D106584552.

@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.

@billmguo billmguo force-pushed the export-D106584552 branch from d32fd3c to 721be34 Compare May 28, 2026 17:04
@billmguo billmguo requested a review from digantdesai as a code owner May 28, 2026 17:04
@billmguo billmguo force-pushed the export-D106584552 branch from 721be34 to be45ec5 Compare May 28, 2026 18:42
@github-actions github-actions Bot added ciflow/trunk module: arm Issues related to arm backend labels May 28, 2026
Summary:

`CSEPass` (Common Subexpression Elimination) was previously only used by specific backends (MLX, Cadence) and export scripts. This change adds it to `base_post_op_replace_passes` in the default `to_edge` / `to_edge_transform_and_lower` pipeline so all backends benefit from CSE automatically.

The pass is placed before `dead_code_elimination_pass` so any dead nodes CSE creates get cleaned up, and before `DebugHandleGeneratorPass` so debug handles are assigned to the final deduplicated graph.

CSE can merge structurally-identical nodes across different source partitions, which caused `ConvertToLinearPass` in XNNPACK to see extra output nodes in a partition. This is fixed by filtering outputs to only those reachable from the mm/addmm node within the partition.

The `test_dim_order_revert_pass` test is updated to expect 2 `_to_copy` ops (instead of 4) after `to_edge`, since CSE deduplicates the two identical branches.

Reviewed By: mohankumarkumar

Differential Revision: D106584552
@meta-codesync meta-codesync Bot changed the title Add CSEPass to the default edge compilation pipeline Add CSEPass to the default edge compilation pipeline (#19849) May 29, 2026
@billmguo billmguo force-pushed the export-D106584552 branch from be45ec5 to cc4c35e Compare May 29, 2026 18:40
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.

1 participant