Repository navigation
[Fix] [NVIDIA] deepseek-v4: Pass a caller-owned multi-CTA counter buffer to the trtllm sparse MLA kernel - #48467
Merged
Conversation
…lm sparse MLA kernel Replace the monkeypatch of flashinfer.mla._core's private counter-buffer helper with FlashInfer's public multi_ctas_kv_counter_buffer argument. The patch never took effect on FlashInfer 0.7.2/0.7.2.post1 and raises AttributeError on 0.7.3. The buffer is sized by query rows via get_trtllm_gen_multi_ctas_kv_counter_bytes and shared per head count. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
leejnau
requested review from
Fridge003,
HaiShaw,
Qiaolin-Yu,
hebiao064,
ispobock and
merrymercy
as code owners
November 4, 2026 23:04
Collaborator
|
Can you do an e2e GSM8K test? |
Fridge003
approved these changes
Nov 4, 2026
Collaborator
|
/rerun-test test/registered/attention/unittests/dsv4/test_deepseek_v4.py test/registered/e2e/models/test_deepseek_v4_flash_fp4_b200_trtllm.py |
Contributor
|
🚀 🚀 |
Collaborator
Author
|
@trevor-m Done. Full GSM8K (1319 questions) on 4×GB200 with DeepSeek-V4-Flash, using the cookbook's GB200 low-latency recipe (TP=4,
No request errors in any run. The 0.7.3 run also caught a third incompatibility: FlashInfer #5352 changed |
Yuxingwang-intel
pushed a commit
to Yuxingwang-intel/sglang
that referenced
this pull request
Nov 6, 2026
…fer to the trtllm sparse MLA kernel (sgl-project#48467) Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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.
Motivation
--dsv4-attn-backend trtllmneeds a multi-CTA KV counter buffer sized by query rows. FlashInfer's default buffer is sized by request count, while the DSv4 VarSeq kernel indexes it by query row.The backend worked around this by replacing the private
flashinfer.mla._core._get_trtllm_gen_multi_ctas_kv_counter_buffer. That has two problems.trtllm_batch_decode_sparse_mla_dsv4gets its buffer throughflashinfer.utils._resolve_trtllm_gen_multi_ctas_kv_counter_buffer._get_trtllm_gen_multi_ctas_kv_counter_bufferfromflashinfer.utils's own namespace, not fromflashinfer.mla._core.flashinfer.mla._coreno longer imports that name, so backend init raisesAttributeError. This blocks the FlashInfer 0.7.3 bump ([Chore] deps: Bump FlashInfer to 0.7.2.post1 #46926).The workaround's docstring says to drop it "once FlashInfer accepts a caller-owned buffer". The function has accepted one through its public
multi_ctas_kv_counter_bufferargument since at least 0.7.2. The MLA, MHA and DSA trtllm backends already pass their own buffers this way.Modifications
All changes are in
python/sglang/srt/layers/attention/deepseek_v4_trtllm_backend.py.flashinfer.mla._core._reserve_trtllm_query_rows(renamed from_install_persistent_trtllm_semaphores) only records the query-row capacity, computed as before from chunked prefill, max prefill tokens and running requests × draft tokens._get_trtllm_kv_counter_buffer(num_heads, device)returns one zeroed persistent buffer per head count.get_trtllm_gen_multi_ctas_kv_counter_bytes(capacity_rows, num_heads, sm_count).trtllm_batch_decode_sparse_mla_dsv4call sites (decode and varlen prefill) pass it asmulti_ctas_kv_counter_buffer. The existing_check_trtllm_query_rowsguard still applies.This works with FlashInfer 0.7.2, 0.7.2.post1 and 0.7.3. The public argument and helpers exist in all three.
Tests
New unit test
test_trtllm_kv_counter_buffer_is_sized_by_query_rows_and_sharedintest/registered/attention/unittests/dsv4/test_deepseek_v4.py. It checks:On GB200 (SM100), in
lmsysorg/sglang:dev(arm64) with torch 2.14.1+cu130 and nvidia-cutlass-dsl 4.8.0:test_dsv4_trtllm_prefill.py(rows 1/16/17/8192)AttributeError: module 'flashinfer.mla._core' has no attribute '_get_trtllm_gen_multi_ctas_kv_counter_buffer'End-to-end on one 4×GB200 node: DeepSeek-V4-Flash with the cookbook's verified GB200 low-latency recipe (TP=4,
flashinfer_mxfp4MoE, EAGLE with 3 steps and 4 draft tokens) plus--dsv4-attn-backend trtllm, imagelmsysorg/sglang:dev(arm64). Full GSM8K (1319 questions) through sgl-eval 0.1.3 at temperature 1.0 and top_p 1.0, the cookbook's recommended sampling:🤖 Generated with Claude Code