Repository navigation
feat: SM120 (Blackwell Desktop) support for GLM-5.1 inference - #26928
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces the flashinfer_sparse_mla DSA backend, making it the default for SM120 GPUs when using FP8 KV cache, and updates FlashInfer and DeepGEMM dependencies. Feedback on these changes highlights several critical issues: the environment variable SGLANG_FP8_PAGED_MQA_LOGITS_TORCH is missing its definition in envs.py, which will cause a runtime error; dynamically recreating the BatchSparseMLAPagedAttentionWrapper and allocating temporary tensors (mid_out, mid_lse) during the forward pass introduces CUDA graph hazards and performance overhead; potential UnboundLocalErrors exist if q_rope is None in the prefill and decode paths; and the FlashInfer version check should be extended to trigger when flashinfer_sparse_mla is selected as the DSA backend.
b15e020 to
604d1d9
Compare
604d1d9 to
70310d9
Compare
70310d9 to
604d1d9
Compare
|
Speculative decoding (MTP) needs the NextN draft arch in the flashinfer_sparse_mla validator Tested this PR on 8× RTX PRO 6000 (SM120) with GLM-5.2-NVFP4 + MTP (native NextN head, EAGLE algorithm). The draft worker crashes at attention-backend init: The draft worker's model_arch in ("GlmMoeDsaForCausalLM", "GlmMoeDsaForCausalLMNextN")(Also worth including Verified with this fix on top of your PR: TP4×PP2+MTP (with #30775) and TP8+MTP both work — GSM8K 0.900, accept_length 2.67–2.96, decode up to 664 tok/s @ bs32 on GLM-5.2-NVFP4. Happy to share logs. |
3fe3cb3 to
8849a7e
Compare
|
/rerun-failed-ci |
5db5694 to
d84badd
Compare
|
/rerun-test test/registered/kernels/test_dsa_indexer.py |
|
Results for 🚀 |
|
/rerun-test test/manual/test_dsa_alias_cli_registry_env.py test/registered/unit/model_executor/test_pool_configurator.py test/registered/unit/test_flashinfer_sparse_mla.py test/registered/unit/test_model_overrides.py |
|
Results for 🚀 ⛔ |
21fc7b3 to
a4505eb
Compare
718aa8c to
ee6067b
Compare
ee6067b to
065b57c
Compare
… SM120 Three gates kept the SM120 flashinfer_sparse_mla backend from serving GLM-5.3-Flash's DeepSeek-style attention (Glm5Next DSA); together they let the stack boot, capture, and serve through it: - flash_mla_sm120.py: allow Glm5Next DSA arches in the validator. sgl-project#26928 allowlisted only GlmMoeDsa*; GLM-5.3-Flash (Glm5NextForConditionalGeneration, Glm5NextForConditionalGenerationNextN) on SM120 with FP8 KV cache satisfies every other gate but hard-rejects at DeepseekSparseAttnBackend init. Ported from the ormandj sglang-glm53 integration patch (both arches, same list). - dsa_backend_kpool.py: allow flashinfer_sparse_mla in the kpool tail-token backend guard. index_kpool > 1 appends tail tokens to topk_indices; the SM120 flashinfer_sparse_mla backend handles those tails natively. Ported from the ormandj integration patch hunk. Surfaced by the ported stack's EAGLE target-verify leg (phase=decode at the profile run). - flash_mla_sm120.py: present GLM NoPE candidates at flashinfer's 2176-wide contract. GLM-5.3 emits 2,051 top-k candidates, but flashinfer's native glm53_nope prefill kernels are instantiated at the family's documented 2,176-wide physical contract (candidates tile in 64-wide blocks), while its decode kernels accept any runtime topk. A >64-token prefill-form call with the raw count therefore finds no kernel ("no matching decode instantiation ... the decode instantiations (num_tokens <= 64) and the prefill envelope both reject it") - surfaced at the prefill cuda-graph capture of shape 128; the <=64 decode-form capture ran the raw topk fine. Pad the indices tail with -1 sentinels (the kernel masks an invalid column payload as well as its logit) and bound the per-token candidate length by the LAST valid column, since a valid tail can follow -1 holes from defensive top-k selection - the mirror of the ormandj integration wrapper's padding. Guard the >2176 case with an explicit error.
… SM120 Three gates kept the SM120 flashinfer_sparse_mla backend from serving GLM-5.3-Flash's DeepSeek-style attention (Glm5Next DSA); together they let the stack boot, capture, and serve through it: - flash_mla_sm120.py: allow Glm5Next DSA arches in the validator. sgl-project#26928 allowlisted only GlmMoeDsa*; GLM-5.3-Flash (Glm5NextForConditionalGeneration, Glm5NextForConditionalGenerationNextN) on SM120 with FP8 KV cache satisfies every other gate but hard-rejects at DeepseekSparseAttnBackend init. Ported from the ormandj sglang-glm53 integration patch (both arches, same list). - dsa_backend_kpool.py: allow flashinfer_sparse_mla in the kpool tail-token backend guard. index_kpool > 1 appends tail tokens to topk_indices; the SM120 flashinfer_sparse_mla backend handles those tails natively. Ported from the ormandj integration patch hunk. Surfaced by the ported stack's EAGLE target-verify leg (phase=decode at the profile run). - flash_mla_sm120.py: present GLM NoPE candidates at flashinfer's 2176-wide contract. GLM-5.3 emits 2,051 top-k candidates, but flashinfer's native glm53_nope prefill kernels are instantiated at the family's documented 2,176-wide physical contract (candidates tile in 64-wide blocks), while its decode kernels accept any runtime topk. A >64-token prefill-form call with the raw count therefore finds no kernel ("no matching decode instantiation ... the decode instantiations (num_tokens <= 64) and the prefill envelope both reject it") - surfaced at the prefill cuda-graph capture of shape 128; the <=64 decode-form capture ran the raw topk fine. Pad the indices tail with -1 sentinels (the kernel masks an invalid column payload as well as its logit) and bound the per-token candidate length by the LAST valid column, since a valid tail can follow -1 holes from defensive top-k selection - the mirror of the ormandj integration wrapper's padding. Guard the >2176 case with an explicit error.
Related issue: #26087
Reference vLLM implementation: vllm-project/vllm#43477
Old version prebuilt image:
void0110/sglang-sm120-glm51:main-deepgemm324-flashinfer3395-cu130-20260602Motivation
GLM-5.1 NVFP4 uses DeepSeek Sparse Attention (DSA) with an FP8 KV cache.
Running this path on NVIDIA SM120/SM121 requires both the sparse-MLA attention
work merged in FlashInfer #3395
and the SM120 paged-MQA/indexer work merged in
DeepGEMM #324.
SGLang currently pins
flashinfer_python[cu13]==0.6.12,flashinfer_cubin==0.6.12, andsgl-deep-gemm==0.1.3. Those releaseddependencies do not provide the required SM120 API and kernel combination.
This PR migrates the attention integration to FlashInfer's merged public API,
preserves GLM's packed arbitrary-FP32-scale KV layout, corrects memory-pool
accounting for that layout, and provides opt-in source overlays for validation.
The existing
trtllmbackend remains the default for GLM DSA on SM120 with anFP8 KV cache.
flashinfer_sparse_mlais an explicit opt-in until compatibleFlashInfer and DeepGEMM releases can be adopted together.
Changes
flashinfer_sparse_mlaas a DSA prefill and decode backend.flashinfer.mla.trtllm_batch_decode_with_kv_cache_mlaAPI from SGLang'sprefill/extend and decode paths.
[tokens, heads, 576] -> [tokens, 1, heads, 576][pages, 1, 64, 656]128 bytes of BF16 RoPE data
[tokens, topk] -> [tokens, 1, topk],preserving inactive
-1entriesbackend="sparse",kv_scale_format="arbitrary_fp32",bmm1_scale=layer.scaling, andbmm2_scale=1.0arguments, and reject unsupported shapes, dtypes, layouts, and skip-softmax
settings before dispatch.
GlmMoeDsaForCausalLM, NVIDIA compute capabilitymajor 12, FP8 E4M3 KV, page size 64, and identical prefill/decode backends.
A single explicit backend selection is propagated to the unspecified side;
mixed TRTLLM/FlashInfer KV layouts are rejected.
instances in the process.
ModelRunner.calculate_mla_kv_cache_dim().For this packed layout, the main KV cost is 656 rather than 576 bytes per
token per layer; including the existing 132-byte indexer cache, the total is
788 rather than 708 bytes.
normal warmup exceeds the 64-token decode cutoff, also run a representative
small decode shape. Include the DSA prefill/decode pair in the autotune cache
key.
with extras such as
flashinfer_python[cu13]without dropping the extra.The CUDA indexer continues to call DeepGEMM metadata and MQA-logits paths, so a
compatible SM120 DeepGEMM build is required.
Dependency Integration
The normal Docker dependency path is unchanged. The two source overlays are
disabled unless their corresponding
*_SOURCE_REPObuild arguments are set,and they can be enabled independently.
2073ddb2814892014c33ef4cd1c7d4c148baf1fe,the merge commit for DeepGEMM Update version to v0.1.14 #324. The Docker overlay checks out and
verifies the full SHA, then installs the upstream source with
DG_FORCE_BUILD=1.5f2bdc41f9ffecef9d8ed590e688e7c0f108504f,which contains the merged [Bug] fix llama3/qwen 2/non greedy eagle2 issues #3395 implementation. The overlay installs the
Python, cubin, and JIT-cache packages from that checkout; the JIT-cache AOT
build targets
12.0fby default.These are Docker-only validation overlays; they do not change SGLang's normal
exact dependency pins. The DeepGEMM overlay installs the upstream distribution
without removing the installed
sgl-deep-gemmdependency metadata. TheFlashInfer checkout reports a newer version than the pinned
0.6.12metadata,so this path should not be described as a release-aligned dependency update.
Source build
For this GLM SM120 path, enable both overlays:
DOCKER_BUILDKIT=1 docker build \ -f docker/Dockerfile \ --target runtime \ --build-arg BRANCH_TYPE=local \ --build-arg CUDA_VERSION=13.0.1 \ --build-arg DEEPGEMM_SOURCE_REPO=https://github.com/deepseek-ai/DeepGEMM.git \ --build-arg DEEPGEMM_SOURCE_REF=2073ddb2814892014c33ef4cd1c7d4c148baf1fe \ --build-arg FLASHINFER_SOURCE_REPO=https://github.com/flashinfer-ai/flashinfer.git \ --build-arg FLASHINFER_SOURCE_REF=5f2bdc41f9ffecef9d8ed590e688e7c0f108504f \ --build-arg FLASHINFER_CUDA_ARCH_LIST=12.0f \ -t sglang-sm120-glm51:source .Launch
sglang serve \ --model-path nvidia/GLM-5.1-NVFP4 \ --tensor-parallel-size 4 \ --pp-size 2 \ --quantization modelopt_fp4 \ --kv-cache-dtype fp8_e4m3 \ --attention-backend dsa \ --dsa-prefill-backend flashinfer_sparse_mla \ --dsa-decode-backend flashinfer_sparse_mla \ --moe-runner-backend flashinfer_cutlass \ --disable-shared-experts-fusion \ --mem-fraction-static 0.8 \ --context-length 131072 \ --cuda-graph-max-bs-decode 8 \ --disable-prefill-cuda-graph \ --json-model-override-args '{"index_topk_pattern":"FFSFSSSFSSFFFSSSFFFSFSSSSSSFFSFFSFFSSFFFFFFSFFFFFSFFSSSSSSFSFFFSFSSSFSFFSFFSSS"}' \ --trust-remote-codeThe
index_topk_patternoverride is specific to the validation checkpoint. Itis a checkpoint compatibility and performance/quality choice, not a sparse-MLA
kernel requirement.
Current-Head Accuracy and Performance
8x NVIDIA RTX PRO 6000 Blackwell Server Edition, TP4PP2,
sglang@1ad864e0c,FlashInfer@5f2bdc4,DeepGEMM@2073ddb, GLM-5.1 NVFP4,FP8 E4M3 KV cache, and
flashinfer_sparse_mlaprefill/decode.Accuracy
No-cache E2E Performance
4K input / 512 output
32K input / 512 output
Shared-Prefix E2E Performance
32K nominal input / 512 output, concurrency 2.
Historical End-to-End Performance (Old Image)
8x NVIDIA RTX PRO 6000 Blackwell Server Edition, 32K input / 512 output,
16 requests. Image:
void0110/sglang-sm120-glm51:main-deepgemm324-flashinfer3395-cu130-20260602.tp4pp2, concurrency 2tp2pp4, parallelism 2tp4pp2, parallelism 2tp2pp4, parallelism 2CI States
Latest PR Test (Base): ✅ Run #30329482417
Latest PR Test (Extra): ❌ Run #30329482253