Skip to content

Introduce CSE pass to ExecuTorch#17752

Merged
metascroy merged 1 commit intomainfrom
add-cse-pass
Feb 27, 2026
Merged

Introduce CSE pass to ExecuTorch#17752
metascroy merged 1 commit intomainfrom
add-cse-pass

Conversation

@metascroy
Copy link
Copy Markdown
Contributor

This introduces a CSE pass to ExecuTorch, which eliminates common subexpressions that occur in exported programs.

This pass was first developed as part of the MLX delegate (#16718) to optimize transformers, but I'm introducing it to ExecuTorch more generally because I believe it could benefit many other backends.

Examples of common subexpressions that occur in transformers:

  • Repeated mask constructions per layer (only needs to be done once)
  • Repeated extraction of symints from 1d tensors for cache position (emits .item calls, which cause tensor materialization)

This pass eliminates these inefficiencies without having to rewrite the model.

@pytorch-bot
Copy link
Copy Markdown

pytorch-bot Bot commented Feb 26, 2026

🔗 Helpful Links

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

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

❌ 2 New Failures, 2 Pending

As of commit c0031e8 with merge base b5dbfb7 (image):

NEW FAILURES - The following jobs have failed:

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 Feb 26, 2026
@metascroy
Copy link
Copy Markdown
Contributor Author

@manuelcandales @mergennachin I think you can use this in the metal delegate

@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-codesync
Copy link
Copy Markdown
Contributor

meta-codesync Bot commented Feb 26, 2026

@metascroy has imported this pull request. If you are a Meta employee, you can view this in D94581516.

Copy link
Copy Markdown
Contributor

@larryliu0820 larryliu0820 left a comment

Choose a reason for hiding this comment

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

This is great! Should we turn it on by default?

@metascroy
Copy link
Copy Markdown
Contributor Author

This is great! Should we turn it on by default?

Could do as follow up

@metascroy metascroy merged commit 1f4ad07 into main Feb 27, 2026
204 of 208 checks passed
@metascroy metascroy deleted the add-cse-pass branch February 27, 2026 18:42
@mergennachin
Copy link
Copy Markdown
Contributor

mergennachin commented Feb 27, 2026

@metascroy

There's already CSE in torch fx that we can use from torch.fx.passes.dialect.common.cse_pass import CSEPass

See a draft PR on how I using (before running another fusion pass)

#15813

@metascroy
Copy link
Copy Markdown
Contributor Author

@metascroy

There's already CSE in torch fx that we can use from torch.fx.passes.dialect.common.cse_pass import CSEPass

See a draft PR on how I using (before running another fusion pass)

#15813

Oh sorry, I merged this already. I will check of the CSE pass in torch and unify with ExecuTorch pass as follow-up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants