Repository navigation
Conversation
…E workspace The TRTLLM backend serves a non-causal windowed draft block as the causal windowed decode plus a log-sum-exp merge of the later block keys. Run eagerly, the merge launched dozens of small kernels per layer: 61-148 us on GB300, on top of a 7-94 us decode. The merge is now unrolled over the block keys and runs compiled (maybe_compile, automatic dynamic shapes), in place on the decode's base-2 log-sum-exp: 5-29 us per layer, the same result up to bf16 rounding. Blocks without later keys (one block token, or no right window) skip the log-sum-exp and the merge. The workspace now also holds the softmax stats that flashinfer takes off its front when the decode returns the log-sum-exp. Without them, 64 query heads per rank with a 3-token block outgrew the workspace beyond ~400 requests, and flashinfer refused the launch. Signed-off-by: Zheyu Fu <zheyuf@nvidia.com>
This branch has not been 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.
@coderabbitai summary
Description
Makes the TRTLLM lowering of the non-causal windowed DSpark draft block cheap. This matters most when acceptance is fixed and only the per-step cost shows.
Why: since efa53ad, the TRTLLM backend serves a non-causal windowed draft layer as the causal windowed trtllm-gen decode plus a log-sum-exp merge of the block keys after each query (
dflash_merge_future_block_attention). The merge ran eagerly: dozens of small kernels per layer. On GB300 it cost 61-148 us per layer on top of a 7-94 us decode; the MiniMax-M3.1 drafter runs it in 5 layers every step. #20922 carries the same eager merge (7d172e6).Changes (one commit; the code is in
modeling_dflash.py):dflash_merge_future_block_attentioncomputes the same math, unrolled over the (at most block-size) block keys.dflash_merge_future_block_attention_runs it undermaybe_compile, in place on the decode's base-2 LSE. Default (automatic) dynamic shapes are used, so only the batch dimension becomes symbolic. It compiles at the eager warm-up that precedes each CUDA-graph capture.dflash_merges_future_block_keys).trtllm_fmha_kernel_launcher.cu:279-305). The kernel scratch gets the rest. The drafter sized its workspace without the stats; only the 32 MiB trtllm-gen reservation (kTrtllmGenWorkspaceSize) left room for them. At 64 query heads per rank with a 3-token block that ran out above ~400 requests, and flashinfer refused the launch. The size now includes the stats whenever a layer takes the merge (dflash_trtllm_gen_workspace_size). No out-of-bounds write was possible: the carve is bounds-checked, and a byte-pattern probe measured the multi-CTA scratch at <= 4.1 MiB, used only at small batch, where the stats are small.How the formulation was chosen (merge only, us per call, CUDA graphs, GB300; 16 q / 1 kv heads = MiniMax-M3.1 TP4 rank, K = 7):
torch.compile, automatic dynamicdynamic=TrueAt 64 q / 4 kv heads (attention DP), B=64: eager 139-156, einsum +
dynamic=True114, einsum automatic 30-35, unrolled 25.6 us. Every compiled form matches the eager merge to bf16 rounding (max relative difference 3.4e-3).Results on GB300 (the base's release image + this branch's Python):
Per-layer drafter attention: the cost of the non-causal layer over the causal decode, base -> this PR (us per layer; window 4096, 64-token pages, contexts 2K/8K/16K, CUDA graphs, mean of 2 runs in opposite order):
The whole layer is 2.0-6.9x faster (geomean 4.0x over the 42 K > 1 points). K = 1 output is bit-identical to before.
E2E: MiniMax-M3.1-Flash TP4 with its DSpark drafter, K = 7, acceptance forced (
TLLM_SPEC_DECODE_FORCE_NUM_ACCEPTED_TOKENS=2.6, AL 3.6 on both sides). Device step time is the median over generation-only iterations with exactly B requests (print_iter_log). Base (efa53ad) and this PR ran interleaved on one node, 2 rounds each:AL is unchanged (80 SPEED-Bench coding prompts,
/v1/completions, T=1, top_p 0.95, 4096 tokens, c64; mean of an unseeded and a seeded pass, K = 7):use_rejection_sampling: false), TP4Test Coverage
tests/unittest/_torch/speculative/hw_agnostic/test_dspark_noncausal_window.py:_PagedCasesizes the workspace as the drafter does.test_dflash2_semantics.py,test_minimax_dspark_draft.py,test_modeling_speculative.py: 423 passed, 8 skipped. One failure,test_mla_dspark_auto_backend_resolves_to_cutedsl, fails the same way in this image without this PR.api_stability: 38 passed.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.🤖 Generated with Claude Code