Skip to content

[executorch][arm] Speed up lowering: cache constant names, fix quadratic permute chain collection, dedup producer queue, defer cleanup, and drop redundant recompiles - #21696

Open
apullin wants to merge 5 commits into
pytorch:mainfrom
apullin:export-D114790177

Conversation

@apullin

@apullin apullin commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Summary:

This is a stack of 5 commits that speed up various parts of the model lowering process. I have been testing with ~1M param models, and lowering time has been 60+ minutes. This is an unfortunate reality from being implemented in Python, and ET will always struggle with networks of even moderate size BUT there is still plenty of performance left on the table.

The summary for each commit/diff are as follow:


D114790177:
Remove redundant GraphModule.recompile() at end of PropagateViewCopyPermutePass.call().

When pass modifies graph it already calls _retrace(), which eliminates dead code, lints, and runs ARM ExportPass retracing to return rebuilt graph module. Immediately following recompile() recompiles Python code not needed before pass manager continues, adding wall time.

Keep _retrace() and drop extra compile step.


D114790155:
Drop redundant recompile() before ARM pass retracing.
Remove redundant GraphModule.recompile() calls immediately before super().call(graph_module) in CanonicalizeViewCopyPermutePass and FuseDuplicateUsersPass. The following ExportPass retrace/interpreter does not consume compiled Python code object, so recompile adds wall time without changing graph.
Keep graph.lint() in modified paths for invariant checking. Behavior-preserving lowering speedup.


D114790128:
Skip redundant recompile in identical-input transform fusion.
Remove redundant GraphModule.recompile() immediately before super().call() in FuseIdenticalInputTransformsPass. Pass already eliminates dead code and lints before handing to ARM framework for retracing. Recompiling Python GraphModule at that point is unnecessary because ExportPass call reconstructs/interprets graph rather than relying on just-compiled code object. Behavior-preserving speedup.


D114224762:
Speed up permute propagation cleanup.
ARM lowering spends significant time in permute propagation. Reduce avoidable repeated work while keeping same optimizations:
Canonicalize view/permute chain collection now uses deque + membership set instead of list pop(0) and remove(), avoiding quadratic bookkeeping.
FuseDuplicateUsersPass deduplicates pending producer revisits while preserving same revisit behavior after fusions.
PropagateViewCopyPermutePass still retraces after each moved transform for metadata safety, but defers horizontal/vertical cleanup until full scan finds no more direct propagation moves. Preserves fixed-point behavior while avoiding expensive cleanup after every single moved transform.
Behavior-preserving speedup, all existing pass tests pass.


D114224782:
RemovePermutesAroundElementwiseTosaOps._is_constant called is_param_node() for every node reached during recursive visit() walk. Each is_param_node rebuilds immutable dict over full input_specs via uncached graph_signature properties. This made pass O(nodes * inputs). Precompute union of param/buffer/lifted-constant placeholder names once in init and use O(1) set membership. Semantics unchanged.


Differential Revision: D114224782 D114224762 D114790128 D114790155 D114790177

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

apullin added 5 commits August 8, 2026 18:16
…osaOps

Summary: RemovePermutesAroundElementwiseTosaOps._is_constant called is_param_node() for every node reached during recursive visit() walk. Each is_param_node rebuilds immutable dict over full input_specs via uncached graph_signature properties. This made pass O(nodes * inputs). Precompute union of param/buffer/lifted-constant placeholder names once in __init__ and use O(1) set membership. Semantics unchanged.

Differential Revision: D114224782
Summary:
Speed up permute propagation cleanup.

ARM lowering spends significant time in permute propagation. Reduce avoidable repeated work while keeping same optimizations:
- Canonicalize view/permute chain collection now uses deque + membership set instead of list pop(0) and remove(), avoiding quadratic bookkeeping.
- FuseDuplicateUsersPass deduplicates pending producer revisits while preserving same revisit behavior after fusions.
- PropagateViewCopyPermutePass still retraces after each moved transform for metadata safety, but defers horizontal/vertical cleanup until full scan finds no more direct propagation moves. Preserves fixed-point behavior while avoiding expensive cleanup after every single moved transform.

Behavior-preserving speedup, all existing pass tests pass.

Differential Revision: D114224762
Summary:
Skip redundant recompile in identical-input transform fusion.

Remove redundant GraphModule.recompile() immediately before super().call() in FuseIdenticalInputTransformsPass. Pass already eliminates dead code and lints before handing to ARM framework for retracing. Recompiling Python GraphModule at that point is unnecessary because ExportPass call reconstructs/interprets graph rather than relying on just-compiled code object. Behavior-preserving speedup.

Differential Revision: D114790128
Summary:
Drop redundant recompile() before ARM pass retracing.

Remove redundant GraphModule.recompile() calls immediately before super().call(graph_module) in CanonicalizeViewCopyPermutePass and FuseDuplicateUsersPass. The following ExportPass retrace/interpreter does not consume compiled Python code object, so recompile adds wall time without changing graph.

Keep graph.lint() in modified paths for invariant checking. Behavior-preserving lowering speedup.

Differential Revision: D114790155
Summary:
Remove redundant GraphModule.recompile() at end of PropagateViewCopyPermutePass.call().

When pass modifies graph it already calls _retrace(), which eliminates dead code, lints, and runs ARM ExportPass retracing to return rebuilt graph module. Immediately following recompile() recompiles Python code not needed before pass manager continues, adding wall time.

Keep _retrace() and drop extra compile step.

Differential Revision: D114790177
@apullin
apullin requested a review from digantdesai as a code owner August 9, 2026 01:17
@pytorch-bot

pytorch-bot Bot commented Aug 9, 2026

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❌ 2 New Failures, 1 Unrelated Failure

As of commit 1c91383 with merge base 730b77a (image):

NEW FAILURES - The following jobs have failed:

  • Cadence Build & Test / hifi-build / hifi4 (gh)
    ##[error]Refusing to check out fork pull request code from a 'pull_request_target' workflow. This workflow runs with the base repository's GITHUB_TOKEN, secrets, default-branch cache scope, and runner access. Fetching and executing a fork's code in that trusted context commonly leads to "pwn request" vulnerabilities. To opt in, review the risks at https://gh.io/securely-using-pull_request_target and set 'allow-unsafe-pr-checkout: true' on the actions/checkout step.
  • Cadence Build & Test / vision-build / vision (gh)
    ##[error]Refusing to check out fork pull request code from a 'pull_request_target' workflow. This workflow runs with the base repository's GITHUB_TOKEN, secrets, default-branch cache scope, and runner access. Fetching and executing a fork's code in that trusted context commonly leads to "pwn request" vulnerabilities. To opt in, review the risks at https://gh.io/securely-using-pull_request_target and set 'allow-unsafe-pr-checkout: true' on the actions/checkout step.

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 9, 2026
@meta-codesync

meta-codesync Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

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

@github-actions

github-actions Bot commented Aug 9, 2026

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.

@apullin apullin changed the title Skip redundant recompile after permute propagation retrace [executorch][arm] Speed up lowering: cache constant names, fix quadratic permute chain collection, dedup producer queue, defer cleanup, and drop redundant recompiles Aug 9, 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. meta-exported module: arm Issues related to arm backend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant