Skip to content

[executorch][cuda] Reuse PyTorch's access analysis of a repeated user Triton kernel call - #23951

Merged
Gasoonjia merged 1 commit into
gh/Gasoonjia/54/origfrom
gh/Gasoonjia/55/orig
Oct 18, 2026
Merged

Gasoonjia merged 1 commit into
gh/Gasoonjia/54/origfrom
gh/Gasoonjia/55/orig

Conversation

@pytorchbot

Copy link
Copy Markdown
Collaborator

This PR was created by the merge bot to help merge the original PR into the main branch.
ghstack PR number: #23739 by @Gasoonjia
^ Please use this as the source of truth for the PR details, comments, and reviews
ghstack PR base: https://github.com/pytorch/executorch/tree/gh/Gasoonjia/55/base
ghstack PR head: https://github.com/pytorch/executorch/tree/gh/Gasoonjia/55/head
Merge bot PR base: https://github.com/pytorch/executorch/tree/gh/Gasoonjia/54/orig
Merge bot PR head: https://github.com/pytorch/executorch/tree/gh/Gasoonjia/55/orig
Differential Revision: D124772365
@diff-train-skip-merge

… Triton kernel call

Pull Request resolved: #23739

Tracing a call of a user-defined Triton kernel runs `torch._higher_order_ops.triton_kernel_wrap.identify_accessed_tensors`, which generates the kernel's TTIR and walks it to find the tensors the kernel reads and writes. PyTorch runs it in functionalization, in Inductor's mutation propagation and in Inductor's lowering, and caches nothing, so a model whose every layer launches the same kernels repeats it for every call site of every exported method. In the Muse Glimmer batching export it was the largest single item on the main thread: ~21 minutes.

The analysis depends only on the kernel and on what `generate_ttir` makes of the arguments: a fake or Inductor tensor becomes a fresh tensor of its dtype, a symbolic value becomes 2, and any other value is used as is (a real tensor also by its pointer's 16-byte alignment). `backends/cuda/triton/kernels/triton_mutation_cache.py` keys calls on exactly that. The first call with a given key goes through PyTorch; repeats return a copy of its result. Calls it cannot key exactly (TMA descriptors, unhashable values) always go through PyTorch. It is installed when `executorch.backends.cuda.triton.kernels` is imported, by replacing the function on `triton_kernel_wrap`, which both of PyTorch's callers look it up on.

Full Muse Glimmer 30B batching export (`export_solo.py`, 10 methods; A100; empty Triton and Inductor caches), stacked on D124736179 (min):

| | before | this diff |
|---|---|---|
| main thread in the access analysis | ~21.1 | ~8.7 |
| lowering start -> forward_1 compiled | 23.3 | 19.1 |
| AOTI forward_2 / 4 / 8 / 16 / 32 / 64 | 13.3 / 12.0 / 8.5 / 9.8 / 11.6 / 15.5 | 9.8 / 8.3 / 7.2 / 9.5 / 10.8 / 13.8 |
| total | 123.3 | 108.6 |

(The rest of the host was busier during this run: ~15 other cores vs ~11.) What is left of the analysis is mostly its first call per key, since each method has its own shapes. The weight file is byte-identical, and the export generates the same tokens (greedy; 512 and 4 x 2k prompts) at the same speed (63.0 vs 63.2 tok/s; 110.6 vs 110.4).
ghstack-source-id: 451021042
@exported-using-ghexport

Differential Revision: [D124772365](https://our.internmc.facebook.com/intern/diff/D124772365/)
@pytorch-bot

pytorch-bot Bot commented Oct 18, 2026

Copy link
Copy Markdown

🔗 Helpful Links

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

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

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@Gasoonjia
Gasoonjia added this pull request to stack #23954 October 18, 2026 07:47
@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 Oct 18, 2026
@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.

@Gasoonjia
Gasoonjia merged commit f14129c into main Oct 18, 2026
265 of 273 checks passed
@Gasoonjia
Gasoonjia deleted the gh/Gasoonjia/55/orig branch October 18, 2026 07:49
@pytorchbot
pytorchbot deployed to upload-benchmark-results October 18, 2026 10:51 — with GitHub Actions Active

This branch was successfully deployed

2 active deployments
upload-benchmark-results — 588c1295 Deployed Oct 18, 2026 by pytorchbot via upload-benchmark-results #20986
cadence — 588c1295 Deployed Oct 18, 2026 by pytorchbot via hifi-op-test / hifi4 #33967
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.

2 participants