[CUDA] Use Triton TMA for long-context causal prefill - #22193
Merged
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/22193
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
force-pushed
the
codex/stack-tma-prefill
branch
from
August 26, 2026 21:56
1520c69 to
5db55f0
Compare
Gasoonjia
force-pushed
the
codex/stack-q4k-fp8-prefill
branch
from
August 26, 2026 21:56
0088e51 to
d11d0c6
Compare
Gasoonjia
force-pushed
the
codex/stack-tma-prefill
branch
from
August 26, 2026 22:15
5db55f0 to
6f9b5e7
Compare
Gasoonjia
force-pushed
the
codex/stack-q4k-fp8-prefill
branch
from
August 26, 2026 22:50
d11d0c6 to
28a5119
Compare
Gasoonjia
force-pushed
the
codex/stack-tma-prefill
branch
from
August 26, 2026 22:50
6f9b5e7 to
583f94f
Compare
Gasoonjia
force-pushed
the
codex/stack-tma-prefill
branch
from
August 26, 2026 23:03
583f94f to
5f6c8e7
Compare
Gasoonjia
force-pushed
the
codex/stack-q4k-fp8-prefill
branch
from
August 26, 2026 23:03
28a5119 to
37690cd
Compare
Gasoonjia
force-pushed
the
codex/stack-tma-prefill
branch
from
August 26, 2026 23:28
5f6c8e7 to
0bb0613
Compare
Gasoonjia
force-pushed
the
codex/stack-tma-prefill
branch
from
August 26, 2026 23:30
0bb0613 to
2f693c3
Compare
Gasoonjia
force-pushed
the
codex/stack-q4k-fp8-prefill
branch
from
August 27, 2026 08:35
caf8e39 to
c6cd8e3
Compare
Gasoonjia
force-pushed
the
codex/stack-tma-prefill
branch
from
August 27, 2026 08:35
42863e7 to
3f31eca
Compare
Contributor
|
curious how much you are getting just from using TMA? |
Contributor
Author
|
We can get like 15%-ish operator-level perf improvement. Detailed can be found in PR summary |
Gasoonjia
force-pushed
the
codex/stack-q4k-fp8-prefill
branch
from
August 27, 2026 19:41
c6cd8e3 to
7722db7
Compare
Gasoonjia
force-pushed
the
codex/stack-tma-prefill
branch
from
August 27, 2026 19:41
3f31eca to
5a7d4c5
Compare
Gasoonjia
force-pushed
the
codex/stack-q4k-fp8-prefill
branch
from
September 1, 2026 07:42
7722db7 to
8f5d2a7
Compare
Gasoonjia
force-pushed
the
codex/stack-tma-prefill
branch
from
September 1, 2026 07:42
5a7d4c5 to
205948d
Compare
Gasoonjia
force-pushed
the
codex/stack-tma-prefill
branch
from
September 1, 2026 12:52
205948d to
ced35f7
Compare
Gasoonjia
force-pushed
the
codex/stack-tma-prefill
branch
from
September 1, 2026 14:18
ced35f7 to
51ff462
Compare
Gasoonjia
force-pushed
the
codex/stack-tma-prefill
branch
from
September 1, 2026 18:25
51ff462 to
8da3f29
Compare
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.
Stack dependency
Depends on #22192.
Summary
Use Triton tensor descriptors/TMA for long-context global causal attention on SM90+ GPUs.
TORCH_CUDA_ARCH_LIST, excluding ROCm, and avoiding CUDA context creation at module import.phi=5approximation.The path is controlled by the
enable_tma_causal_prefillCUDA compile spec and is disabled by default. Users must explicitly opt in; unsupported targets warn and retain the portable Triton path. The dispatch is not tied to Muse-Glimmer and can benefit any model whose attention semantics and shape satisfy the validated conditions.This is the top of the following stack:
Operator-level performance
RTX 5090, BF16 global causal GQA (
B=1, Hq=16, Hkv=2), TMA versus the existing Triton kernel:Holding the rest of the stack fixed, TMA alone improves end-to-end prefill from 5,019 to 5,388 tok/s at 32K (+7.4%) and from 3,341 to 4,172 tok/s at 130K (+24.8%). Inputs below 16K remain on the portable path.
NLL evaluation
notes_v5, 100 documents / 154,846 next-token labels. The supplied.ptstores one token chunk per document; labels arechunk[1:]for inputschunk[:-1](all chunks begin with BOS 200000).Compared directly with #22190, TMA-only has mean token absolute NLL gap 0.014022 (max 1.158961) and mean document gap 0.000579 (max 0.002262), with document buckets
84 same / 16 close / 0 match / 0 mismatch. Relative to the A100 BF16 reference, the same/close bucket counts move from56/44for #22190 to59/41for TMA-only. Under the agreed conservative bucket-count rule, the optimization therefore remains explicit opt-in.End-to-end comparison with llama.cpp
Both optional prefill paths enabled. Single otherwise-idle RTX 5090, single-GPU
llama-cli, P2409802035 protocol, ET and llama.cpp interleaved per repetition, runs 3-7 mean:Across the five lengths, ET prefill is 30.61% faster geometric mean than single-GPU
llama-cli; decode is effectively tied overall at -0.39% geometric mean.The isolated 8K miss is primarily launch overlap rather than SDPA kernel latency. In a matched Nsight trace, ET's stable decode graph is serialized (12.421 ms summed kernel time, 12.742 ms wall time), while llama.cpp overlaps up to seven kernels (16.114 ms summed kernel time, 12.460 ms wall time). llama.cpp enables Programmatic Dependent Launch by default: an idle-GPU 7-run A/B measured 76.58 tok/s with PDL and 75.24 tok/s with
GGML_CUDA_PDL=0(+1.78%). ET reaches 74.77 tok/s, only 0.63% below the no-PDL comparison. PDL remains intentionally outside this stack.Test plan
lintrunner init && lintrunner -aon [CUDA] Add Triton Q4_K-to-FP8 prefill linear #22192 and on the complete top stack: clean.git diff --check.