[CUDA] Use Triton TMA for long-context causal prefill - #22414
Open
Gasoonjia wants to merge 2 commits into
Open
Conversation
Route SM90+ global causal attention with a device-resident KV bound and L_kv >= 16K through shape-specific Triton tensor-descriptor kernels. Cover common head dimensions 64 and 128 with separately profiled resource configurations; unsupported or non-beneficial shapes retain the portable fallback.
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/22414
Note: Links to docs will display an error until the docs builds have been completed. ❌ 1 New Failure, 2 Unrelated FailuresAs of commit 8da3f29 with merge base 5428092 ( NEW FAILURE - The following job has failed:
FLAKY - The following job failed but was likely due to flakiness present on trunk:
BROKEN TRUNK - The following job failed but was present on the merge base:👉 Rebase onto the `viable/strict` branch to avoid these failures
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
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 #22190. This PR supersedes #22193 after reordering the stack so TMA sits directly on the split-K baseline and the optional FP8 linear path sits above TMA.
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 implementation remains pure Triton and is not tied to Muse-Glimmer.Operator-level performance
RTX 5090, BF16 global causal GQA (
B=1, Hq=16, Hkv=2), TMA versus the existing Triton kernel:Holding the FP8 linear path fixed in the earlier isolation run, TMA improved 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 attention path.
TMA-only end-to-end performance
This branch is
#22190 + TMA, without the upper FP8 linear optimization. Single otherwise-idle RTX 5090, single-GPUllama-cli, P2409802035 protocol, ET and llama.cpp interleaved per repetition, runs 3-7 mean:Across the five lengths, TMA-only ET is 11.75% slower geometric mean than llama.cpp in prefill and 1.84% slower in decode. The result also shows the division of labor in the stack: TMA improves long-context attention, while the upper FP8 linear PR supplies the large model-wide prefill uplift.
NLL evaluation
notes_v5, 100 documents / 154,846 next-token labels. Relative to the A100 BF16 reference, the same/close bucket counts move from56/44for #22190 to59/41for TMA-only. 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 buckets84 same / 16 close / 0 match / 0 mismatch.Buckets use document mean-NLL gap:
<1e-3,[1e-3,1e-2),[1e-2,1e-1), and>=1e-1. Under the agreed conservative bucket-count rule, the optimization remains explicit opt-in.Test plan
lintrunner init && lintrunner -a: clean on this branch.git diff --check.