[Attention] Skip stage2 for single-split Triton MLA decode - #52019
Open
BabyDrangoner wants to merge 3 commits into
Open
[Attention] Skip stage2 for single-split Triton MLA decode#52019BabyDrangoner wants to merge 3 commits into
BabyDrangoner wants to merge 3 commits into
Conversation
Co-authored-by: OpenAI Codex <codex@openai.com> Signed-off-by: kiroxu <148877251+BabyDrangoner@users.noreply.github.com>
Reuse existing grouped-kernel pointer, stride, and mode slots for the single-split direct-output specialization. This avoids adding runtime launch parameters to legacy grouped attention while retaining the stage2 skip. Co-authored-by: OpenAI Codex <codex@openai.com> Signed-off-by: kiroxu <148877251+BabyDrangoner@users.noreply.github.com>
BabyDrangoner
marked this pull request as ready for review
August 13, 2026 13:16
BabyDrangoner
requested review from
AndreasKaratzas,
LucasWilkinson,
MatthewBonanni,
WoosukKwon,
mgoin,
pavanimajety,
tlrmchlsmth,
yewentao256 and
zyongye
as code owners
August 13, 2026 13:16
BabyDrangoner
marked this pull request as draft
August 15, 2026 17:32
BabyDrangoner
marked this pull request as ready for review
August 15, 2026 17:54
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.
Purpose
When grouped Triton MLA uses one KV split, its second-stage reduction has one input and is mathematically an identity. This PR lets stage1 write the final output and LSE directly and skips the stage2 launch.
The fast path is restricted to MLA shapes for which the normal performance heuristic selects one split. Multi-split attention, MHA/GQA, and long contexts where batch invariance alone forces one split keep the existing two-stage path. The existing scratch workspace remains reserved, so this reduces HBM traffic and one launch when eligible but does not reduce reserved memory capacity.
The final implementation reuses pointer, stride, and mode slots already present in the grouped kernel. This keeps the fallback Triton launch parameter list identical to the pre-patch implementation. For empty/padded rows, the direct path writes the attention-combine neutral values
output=0andLSE=-inf. The old identity stage happened to produceNaN/-inffor those rows; they are not consumed as ordinary outputs, and the new values are safe for DCP merging.Duplicate-work check
I searched open PRs for Triton MLA, single split, direct output, and stage2 and found no implementation of this optimization. Related work such as #33529 (split-selection/query-load tuning) and #42885 (full CUDA graph capture) is complementary; neither writes single-split MLA results directly nor skips the identity stage2 reduction.
Test plan
The tests cover BF16/FP16 output, BF16/FP8 KV cache, active-row bitwise equivalence with the two-stage oracle, empty rows, grouped/multi-split fallback, and CUDA graph replay with changed sequence lengths. The behavior test was also run before implementation and failed because stage2 was still called once.
Cross-platform validation
The RTX PRO 6000 and H20 runs are independent, peer validations using DeepSeek-V2-Lite-Chat and
TRITON_MLA. They use the same 15-shape kernel set: 13 shapes for which the production heuristic selects one split (max_seq_len < 1024on both GPUs), plus forced-single-splitB32/S2048andB64/S4096controls.The tested revisions must be kept explicit: the RTX PRO 6000 was rerun on the current final source,
fa0bb68; the H20 run evaluated the initial direct-output revision,39b3e04. The H20 results therefore validate the direct fast path on Hopper and identify the initial fallback-launch overhead, but they do not claim an H20 rerun of the final slot-reuse implementation.fa0bb68(final)39b3e04(initial)6accb779)324f452f, ported to the installed vLLM treeA B C C B Ablocks per processA B C C B AblocksResult definitions
true pre-patch two-stage time / direct time; values above 1 are faster.true pre-patch two-stage time - direct time; positive values are faster.candidate two-stage host-enqueue time - true pre-patch host-enqueue time; positive values are overhead.For the three-arm microbenchmarks,
Ais true pre-patch two-stage,Bis the tested revision with direct output disabled, andCis the tested revision with direct output enabled.Correctness
fa0bb68)39b3e04)All applicable pre-commit hooks passed on the final source, and
git diff --checkpassed.Kernel performance
The graph region includes the same output-zeroing work used by the production path.
fa0bb68)39b3e04)The two control shapes were benchmarked with one split even though the production heuristic selects multiple splits:
fa0bb68)39b3e04)B32/S2048, graph / eagerB64/S4096, graph / eagerFor the RTX PRO 6000
B64/S4096graph control, per-process savings ranged from -1.262 to +0.359 us, so the small median regression is not treated as a stable architecture-level effect. The control results are not uniformly beneficial, and the production guard remains conservative rather than forcing one split for long contexts.End-to-end decode
Both workloads used DeepSeek-V2-Lite-Chat,
TRITON_MLA,FULL_DECODE_ONLY,max_model_len=512, batch 32, 64 forced decode tokens, 3 warmups, and 12 timed samples per process. The RTX PRO 6000 used two fresh processes per arm inA-B-C-C-B-Aorder; its estimate is the median of the two process medians and the bracketed values are their range. The H20 used an independent two-stage/direct/two-stage run.fa0bb68)39b3e04)On the RTX PRO 6000, both mirrored halves independently favored direct output; direct versus the final-source two-stage arm was also -1.044%. Profiling measured target-kernel totals of 18.318 ms for true pre-patch, 18.406 ms for final two-stage, and 14.765 ms for direct output. The H20 direct samples were completely separated from its two baseline sample ranges. The forced-token arrays only establish identical fixed work because token ID 198 was the sole allowed token; natural-token correctness is reported separately above. Cross-GPU absolute latency differences are not used to infer the size or cause of the speedup.
Fallback launch audit
The initial revision added five direct-only runtime values to every stage1 launch. The H20 experiment found host-enqueue overhead on
write_direct=False; the same issue was reproduced independently on the RTX PRO 6000. The final revision reuses existing grouped-kernel slots and restores the pre-patch runtime/constexpr signature.Values below are fallback host deltas as defined above, reported for
B32/S128,B32/S512, andB32/S2048respectively:39b3e04fa0bb68On the RTX PRO 6000, final-minus-pre-patch CUDA-event deltas for the GPU-bound S512/S2048 cases were +0.013/-0.010 us. On H20, the initial revision's two-stage graph-region deltas across the production shapes were -0.048 to +0.016 us. These measurements support a host argument-packing cause for the initial overhead, rather than a fallback-kernel GPU regression. On the PRO 6000, the final source reduces the central host deltas from about 2.7-2.8 us to at most 0.21 us.
AI assistance
OpenAI Codex assisted with code analysis, implementation, validation and benchmark scripting, and drafting this PR description.