Repository navigation
[None][perf] Pick the full-attention decode KV split per launch in FlashInfer trtllm-gen FMHA - #20934
Merged
Tabrizian merged 2 commits intoOct 27, 2026
Conversation
…ashInfer trtllm-gen FMHA The trtllm-gen generation kernel splits each sequence's KV over smCount / (batch x kvHeads) CTAs, one per SM, so at long context a decode launch lasts as long as the CTA streaming the longest sequence. Report k x the SM count to unwindowed decode launches, with k = ceil(36 x batch x sqrt(kvHeads) / smCount), capped at 8 and at what the FMHA workspace holds for the head dim. TRTLLM_GEN_DECODE_SM_SCALE=k forces one k (1 keeps the kernel's own split). Grouped launches (TRTLLM_GEN_DECODE_SEQS_PER_LAUNCH) pick k per group. Signed-off-by: Iman Tabrizian <[email protected]>
…to swapped flashinfer Replace the SM-count context manager with _trtllm_gen_decode(): no patch when k is 1, and a flashinfer that another caller swapped for the call (the modeling_v2 decode stand-ins) keeps that caller's SM count. Clamp k once. Test that flashinfer's decode still reads get_device_sm_count. Signed-off-by: Iman Tabrizian <[email protected]>
Member
Author
|
/bot run --disable-fail-fast |
Collaborator
|
PR_Github #80397 [ run ] triggered by Bot. Commit: |
Collaborator
|
PR_Github #80397 [ run ] completed with state |
1 task done
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.
@coderabbitai summary
Description
At long context the sequence lengths in a decode batch differ widely. The trtllm-gen generation kernel splits each sequence's KV over
smCount / (batch x kvHeads)CTAs, one CTA per SM. That split assumes equal lengths. A Muse Spark Open attention-DP batch of 6 or more sequences (16 KV heads per rank) therefore gets one CTA per (sequence, KV head). The launch then lasts as long as the one CTA streaming the longest sequence, at about 40 GB/s. At 1M context the full-attention decode FMHA ran at 1.5-2.2 TB/s on GB300 and took 12-27 ms of a 54 ms DEP8 decode step.This PR reports
k xthe SM count to unwindowed decode launches, so the kernel runs aboutk xmore KV splits in k waves through its MultiCtasKv path. Sliding-window layers keep the kernel's own split.k = ceil(36 x batch x sqrt(kvHeads per rank) / smCount), capped at 8 and at what the FMHA workspace holds for the head dim. With the 32 MiB workspace that cap is 8 at head dim 64, 6 at 128 and 3 at 256.TRTLLM_GEN_DECODE_SM_SCALE=kforces one k for every launch.TRTLLM_GEN_DECODE_SM_SCALE=1restores today's behavior.TRTLLM_GEN_DECODE_SEQS_PER_LAUNCH, [None][feat] Muse Spark Open modeling_v2 TEP target: mid-high-concurrency optimizations for Vera Rubin #20844) pick k per group._trtllm_gen_decode()therefore swapsflashinfer.decode.get_device_sm_countfor the one call, and makes no swap when k is 1.flashinferfor a call (itsdecode_kv_splitsand split-KV stand-ins), that target's SM count stands. Its behavior is unchanged.How k was chosen
The rule was fit on GB300 (152 SMs) with the FlashInfer trtllm-gen decode at Muse Spark Open shapes: FP8 Q/KV, head dim 64, 8 query heads per KV head, 8 query tokens per sequence (DFlash d7). The CUDA graph was captured at max_seq_len 1M, as serving captures it. The sweep timed k = 1-8 for 1-64 sequences at 1, 2, 4 or 16 KV heads per rank (TEP16 / TEP8 / TEP4 / DEP), 1950 launches in all.
Each shape got four batches drawn from 1M-context agentic first-turn lengths (lognormal, median 142k, mean about 190k) and one worst case (a 1M sequence among 142k ones). The best k was about batch at 16 KV heads, batch / 2 at 4, batch / 3 at 2 and batch / 4 at 1. More splits shorten the longest sequence's CTAs, but every CTA pays a fixed cost, and a rank with few KV heads streams little KV per launch.
Average slowdown against the best k for each batch:
All outputs are within 7.6e-4 of the kernel's own split (BF16 reduction of the partial results).
Serving results
Muse Spark Open, GB300, 1M context, gen-only, MegaMoE. These runs used the same logic as an overlay of this file on the
feat/musespark-openimage.In the per-batch run the ranks chose k = 1, 2, 4 and 6 for CUDA-graph batches 1, 2, 4 and 6. GSM8K through the DEP8 gen path with k = 8 scored 0.9409.
Impact and risk
TRTLLM_GEN_DECODE_SM_SCALE=1restores today's behavior.feat/musespark-openimage. This version differs in two ways: the cap now comes from the workspace size and head dim (still 8 at head dim 64), and grouped launches are handled.Test Coverage
tests/unittest/_torch/attention/test_flashinfer_trtllm_gen_fmha.py:test_decode_sm_scalecovers the per-batch rule, sliding windows, the env override and the workspace cap by head dim.test_decode_sm_scale_rejects_bad_envcovers an invalidTRTLLM_GEN_DECODE_SM_SCALEvalue.test_trtllm_gen_decode_reports_scaled_sm_countchecks that the launch sees the scaled SM count and that the real count is restored, including when the launch raises. It also checks that a swapped-inflashinferkeeps its own count.test_flashinfer_decode_reads_sm_countchecks that the installed FlashInfer still readsget_device_sm_countfromflashinfer.decode. Without that, the split would silently do nothing.PR Checklist
Please review the following before submitting your PR:
PR description clearly explains what and why. If using CodeRabbit's summary, please make sure it makes sense.
PR Follows TRT-LLM CODING GUIDELINES to the best of your knowledge.
Test cases are provided for new code paths (see test instructions)
If PR introduces API changes, an appropriate PR label is added - either
api-compatibleorapi-breaking. Forapi-breaking, includeBREAKINGin the PR title.Any new dependencies have been scanned for license and vulnerabilities
CODEOWNERS updated if ownership changes
Documentation updated as needed
Update tava architecture diagram if there is a significant design change in PR.
The reviewers assigned automatically/manually are appropriate for the PR.
Please check this after reviewing the above items as appropriate for this PR.
GitHub Bot Help
To see a list of available CI bot commands, please comment
/bot help.