Skip to content

feat: SM120 (Blackwell Desktop) support for GLM-5.1 inference - #26928

Merged
Fridge003 merged 1 commit into
sgl-project:mainfrom
yilin-void:feat/sm120_glm51
Jul 28, 2026
Merged

Fridge003 merged 1 commit into
sgl-project:mainfrom
yilin-void:feat/sm120_glm51

Conversation

@yilin-void

@yilin-void yilin-void commented Jun 1, 2026 •

Copy link
Copy Markdown
Contributor

Related issue: #26087

Reference vLLM implementation: vllm-project/vllm#43477

Old version prebuilt image: void0110/sglang-sm120-glm51:main-deepgemm324-flashinfer3395-cu130-20260602

Motivation

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, and sgl-deep-gemm==0.1.3. Those released
dependencies 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 trtllm backend remains the default for GLM DSA on SM120 with an
FP8 KV cache. flashinfer_sparse_mla is an explicit opt-in until compatible
FlashInfer and DeepGEMM releases can be adopted together.

Changes

  • Add flashinfer_sparse_mla as a DSA prefill and decode backend.
  • Call the public
    flashinfer.mla.trtllm_batch_decode_with_kv_cache_mla API from SGLang's
    prefill/extend and decode paths.
  • Adapt SGLang's GLM tensors to the FlashInfer SM120 sparse-MLA contract:
    • BF16 query [tokens, heads, 576] -> [tokens, 1, heads, 576]
    • packed byte-addressable KV [pages, 1, 64, 656]
    • 656 bytes per token: 512 FP8 KV bytes, 16 bytes of FP32 scales, and
      128 bytes of BF16 RoPE data
    • int32 physical sparse indices [tokens, topk] -> [tokens, 1, topk],
      preserving inactive -1 entries
    • backend="sparse", kv_scale_format="arbitrary_fp32",
      bmm1_scale=layer.scaling, and bmm2_scale=1.0
  • Fail early when the installed FlashInfer API predates the merged sparse-MLA
    arguments, and reject unsupported shapes, dtypes, layouts, and skip-softmax
    settings before dispatch.
  • Restrict this backend to GlmMoeDsaForCausalLM, NVIDIA compute capability
    major 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.
  • Reuse a dedicated zero-initialized FlashInfer workspace across DSA backend
    instances in the process.
  • Size the MLA memory pool through 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.
  • Enable FlashInfer autotuning when sparse MLA decode is selected. When the
    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.
  • Fix the FlashInfer release bump helper so it reads and updates dependencies
    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_REPO build arguments are set,
and they can be enabled independently.

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-gemm dependency metadata. The
FlashInfer checkout reports a newer version than the pinned 0.6.12 metadata,
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-code

The index_topk_pattern override is specific to the validation checkpoint. It
is 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_mla prefill/decode.

Accuracy

Test Result Latency / duration Output TPS
GSM8K, 5-shot 1273/1314 (96.8798%) 3549.472 s total 209.789
Cold passkey, 32,764 input tokens, positions 10%/50%/90% 3/3 4.665 s -
Cold passkey, 65,528-65,529 input tokens, positions 10%/50%/90% 3/3 8.872 s -

No-cache E2E Performance

4K input / 512 output

Concurrency Mean TTFT Mean TPOT Output TPS Total TPS
1 0.782 s 20.82 ms 44.83 403.49
2 1.005 s 24.97 ms 74.38 669.40
4 1.892 s 29.44 ms 120.87 1087.83
8 2.695 s 33.92 ms 204.43 1839.87

32K input / 512 output

Concurrency Mean TTFT Mean TPOT Output TPS Total TPS
1 4.427 s 20.60 ms 34.24 2225.50
2 6.249 s 27.69 ms 50.19 3262.05
4 9.893 s 38.54 ms 69.21 4498.42
8 19.182 s 58.27 ms 83.64 5436.79

Shared-Prefix E2E Performance

32K nominal input / 512 output, concurrency 2.

Nominal prefix Actual avg. input Actual cache hit Mean TTFT Mean TPOT Output TPS Total TPS
30% 34,109.8 27.97% 6.332 s 25.70 ms 52.60 3556.90
50% 34,026.6 46.73% 4.765 s 25.39 ms 57.72 3893.83
70% 34,147.8 65.54% 3.577 s 25.46 ms 61.73 4179.10

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.

Workload Selected mapping Mean TTFT (s) Mean TPOT (ms) Output TPS Total TPS
No cache tp4pp2, concurrency 2 6.041 32.390 45.32 2945.91
30% nominal prefix tp2pp4, parallelism 2 5.336 34.450 44.64 2901.29
50% nominal prefix tp4pp2, parallelism 2 4.713 33.510 46.88 3047.37
70% nominal prefix tp2pp4, parallelism 2 2.663 33.270 52.07 3384.37

CI States

Latest PR Test (Base): ✅ Run #30329482417
Latest PR Test (Extra): ❌ Run #30329482253

@github-actions github-actions Bot added the dependencies Pull requests that update a dependency file label Jun 1, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread python/sglang/srt/entrypoints/engine.py Resolved
@AliceChenyy

Copy link
Copy Markdown
Contributor

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:

ValueError: flashinfer_sparse_mla supports only GLM DSA with FP8 KV cache on NVIDIA SM120/SM121.

The draft worker's model_config rewrites the arch to the NextN variant (GlmMoeDsaForCausalLMNextN), but _validate_flashinfer_sparse_mla_backend only accepts the target arch. One-line fix so the draft worker can share the sparse backend:

model_arch in ("GlmMoeDsaForCausalLM", "GlmMoeDsaForCausalLMNextN")

(Also worth including model_arch / device_sm_major / kv_cache_dtype in the error message for self-diagnosis.)

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.

@yilin-void

Copy link
Copy Markdown
Contributor Author

/rerun-failed-ci

@b8zhong

b8zhong commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

/rerun-test test/registered/kernels/test_dsa_indexer.py

@github-actions

github-actions Bot commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Results for /rerun-test test/registered/kernels/test_dsa_indexer.py:

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

cd test/ && python3 registered/kernels/test_dsa_indexer.py

@b8zhong

b8zhong commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

/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

@github-actions

github-actions Bot commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

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:

🚀 ubuntu-latest (3 tests): ✅ View workflow run

cd test/ && python3 registered/unit/model_executor/test_pool_configurator.py
cd test/ && python3 registered/unit/test_flashinfer_sparse_mla.py
cd test/ && python3 registered/unit/test_model_overrides.py

⛔ test/manual/test_dsa_alias_cli_registry_env.py: No register_cuda_ci(runner_config=...) or register_cpu_ci() found in test/manual/test_dsa_alias_cli_registry_env.py. This file may not be a registered CI test.

@yilin-void
yilin-void force-pushed the feat/sm120_glm51 branch 3 times, most recently from 718aa8c to ee6067b Compare July 27, 2026 06:02
@Fridge003
Fridge003 merged commit 7f438a6 into sgl-project:main Jul 28, 2026
142 of 151 checks passed
Atituiset pushed a commit to Atituiset/sglang that referenced this pull request Sep 10, 2026
adubkov added a commit to adubkov/sglang that referenced this pull request Oct 26, 2026
… 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.
adubkov added a commit to adubkov/sglang that referenced this pull request Nov 3, 2026
… 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file jit-kernel run-ci CI: run the baseline test suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants