Repository navigation
[executorch][cuda] Reuse PyTorch's access analysis of a repeated user Triton kernel call - #23951
Merged
Merged
Conversation
… 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/)
🔗 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
approved these changes
Oct 18, 2026
This PR needs a
|
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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