Skip to content

Fix the perf regression of zeroing of TensorRT-LLM MLA (and sparse) workspace - #31607

Closed
b8zhong wants to merge 4 commits into
mainfrom
fixi
Closed

b8zhong wants to merge 4 commits into
mainfrom
fixi

Conversation

@b8zhong

@b8zhong b8zhong commented Jul 17, 2026 •

Copy link
Copy Markdown
Collaborator

flashinfer's trtllm_batch_decode_with_kv_cache_mla instantiates a fresh runner per call (even in cuda graph). Instead use the buffer by multi_ctas_kv_counter_buffer= instead.

For prefill, it will reshape to (num_tokens, 1, num_heads, head_dim). So we also need to grow the workspace, in case some users set chunk prefill larger than 8k. It just grows the buffer once.

note: trtllm ragged prefill deepseek doesn't have this bug. It's recently introduced in #31502 after flashinfer-ai/flashinfer#3949

Main:
Screenshot 2026-07-17 at 12 24 02 PM

This branch:
Screenshot 2026-07-17 at 12 24 21 PM


CI States

Latest PR Test (Base): ❌ Run #29622595001
Latest PR Test (Extra): ❌ Run #29622594907

flashinfer's trtllm_batch_decode_with_kv_cache_mla instantiates a fresh
runner per call, so its internal counter-buffer cache never survives
across decode steps and it torch.zeros() a new one every call by
default. Own a persistent buffer in TRTLLMMLABackend and
DeepseekSparseAttnBackend and pass it via multi_ctas_kv_counter_buffer=
instead.

DSA's trtllm sparse-indexer path flattens every token in a prefill/
extend/verify chunk into its own decode-shaped batch entry, so its
batch dimension can exceed max_running_requests; grow the buffer on
demand there instead of assuming a fixed bound.
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@github-actions github-actions Bot added the blackwell SM100/SM120 label Jul 17, 2026
@b8zhong

b8zhong commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator Author

/rerun-test test_dsa_glm52_nvfp4_dp_mtp.py

@b8zhong b8zhong changed the title Fix the zeroing of TensorRT-LLM MLA (and sparse) Fix the perf regression of zeroing of TensorRT-LLM MLA (and sparse) workspace Jul 17, 2026
@github-actions

github-actions Bot commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

Results for /rerun-test test_dsa_glm52_nvfp4_dp_mtp.py:

🚀 4-gpu-b200 (1 test): ✅ View workflow run

cd test/ && python3 registered/models_e2e/test_dsa_glm52_nvfp4_dp_mtp.py

@b8zhong b8zhong added the run-ci CI: run the baseline test suite on this PR label Jul 17, 2026
Brayden Zhong added 2 commits July 17, 2026 23:11
@b8zhong
b8zhong marked this pull request as draft July 18, 2026 00:18
b8zhong added a commit that referenced this pull request Jul 21, 2026
flashinfer's trtllm_batch_decode_with_kv_cache_mla instantiates a fresh
runner per call, so its internal counter-buffer cache never survives
across decode steps and it torch.zeros() a new one every call by
default. Own a persistent buffer in TRTLLMMLABackend and
DeepseekSparseAttnBackend and pass it via multi_ctas_kv_counter_buffer=
instead.

DSA's trtllm sparse-indexer path flattens every token in a prefill/
extend/verify chunk into its own decode-shaped batch entry, so its
batch dimension can exceed max_running_requests; grow the buffer on
demand there instead of assuming a fixed bound.

Cherry-picked from #31607 (squashed from 0042fd9, 121c901,
a84b529, ed135a8).
@b8zhong

b8zhong commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator Author

Move #31927

@b8zhong b8zhong closed this Jul 22, 2026
@b8zhong
b8zhong deleted the fixi branch July 22, 2026 16:03
vincentzed pushed a commit to vincentzed/sglang that referenced this pull request Jul 23, 2026
…buffer for DCP

The persistent multi-CTAS KV counter buffer (sgl-project#31607) is sized by head
count; under DCP the trtllm decode runs with dcp-widened heads, so
pre-size it by num_q_heads * dcp_size and let the grow check use the
per-call head count. token_capacity in metrics and the load inquirer
now reports logical tokens (physical * dcp_size), matching the
allocator's accounting. Fix by @b8zhong, thanks.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

blackwell SM100/SM120 high priority run-ci CI: run the baseline test suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants