Skip to content

feat: SM120 (Blackwell Desktop) support for DeepSeek-V4 inference - #24692

Merged
Fridge003 merged 27 commits into
sgl-project:mainfrom
AliceChenyy:sm120-dsv4-rebase
Jun 1, 2026
Merged

Fridge003 merged 27 commits into
sgl-project:mainfrom
AliceChenyy:sm120-dsv4-rebase

Conversation

@AliceChenyy

@AliceChenyy AliceChenyy commented May 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds full SM120 (RTX PRO 6000 / RTX 5090 / DGX Spark, compute 12.0) support for DeepSeek-V4/V3 on SGLang. SM120 desktop Blackwell GPUs lack TMEM, tcgen05, and DeepGEMM support — this PR provides Triton-based fallback kernels for all critical paths and enables CUDA graph capture.

Key changes

New kernels (7 files):

  • mxfp4_moe_sm120_triton.py — Triton fused MXFP4 dequant + GEMM for MoE experts (4.1x vs PyTorch per-GEMM)
  • flash_mla_sm120_triton.py — Triton FlashMLA sparse decode kernel (3.2–5.4x vs FlashInfer fallback)
  • sm120_mqa_triton.py — FP8 paged MQA with wq-precompute + vectorized batch (CUDA graph compatible)
  • flash_mla_sm120_fallback.py / sm120_mqa_fallback.py / mxfp4_moe_fallback.py — PyTorch fallback paths
  • test_sm120_mqa_fallback.py — Unit tests for MQA fallback correctness

SM120 guards (10 modified files):

  • DeepGEMM / tilelang MHC disabled on SM120 (no TMEM/tcgen05)
  • NSA backend: tilelang default, skip DeepGEMM metadata allocation
  • FlashMLA: SM120 adapter in deepseek_v4_backend.py
  • MoE: auto-select marlin backend on SM120
  • 3 CUDA-graph-breaking paths fixed (.unique()/.item()/.nonzero() → vectorized)

Bug fix (found during latest-image validation):

  • FlashMLA Triton kernel: handle KV cache uint8 dtype (upstream changed from float8_e4m3fn)

Results (8× RTX PRO 6000, TP=8, CUDA graph)

On sglang:dev-cu13 (sgl-kernel 0.4.2.post1, PyTorch 2.11+cu130):

Metric Value
GSM8K 5-shot (200q) 99.0% accuracy
Decode (BS=1) 11.40 tok/s (TPOT = 87.7ms)
CUDA graph capture ✅ all batch sizes captured

On older nightly-dev-20260430 (sgl-kernel 0.4.1, PyTorch 2.9.1+cu129):

Metric Value
GSM8K 5-shot (200q) 98.0% accuracy
Decode (BS=1) 10.26 tok/s (TPOT = 97.5ms)
CUDA graph speedup 2.4× vs without (4.36 → 10.26 tok/s)

Motivation

  • SM120 is desktop Blackwell (RTX 5090, RTX PRO 6000) — no server-class features (TMEM, tcgen05, NVSwitch)
  • Prior to this PR, SGLang cannot run DSv4 on SM120 at all (DeepGEMM JIT crash, no MXFP4 MoE support)
  • Enables developer/researcher access to DSv4 on workstation GPUs

Notes

  • This is a rebase of feat: SM120 support for DeepSeek-V4 inference #24047 (which targeted deepseek_v4 branch) onto main
  • All SM120 kernel code is identical between the two PRs (verified by diff)
  • SM120 kernels are guarded by is_sm120_supported() — zero impact on SM100/SM103 paths
  • Environment variables: SGLANG_SM120_TRITON_FLASHMLA=1 (default on), SGLANG_SM120_MQA_FALLBACK=0 (default off)

Test plan

  • GSM8K 5-shot 200q: 99.0% on latest sglang:dev-cu13 image
  • GSM8K 5-shot 200q: 98.0% on older nightly-dev-20260430 image
  • Single request sanity check (15+27=42, capital of France, Chinese translation)
  • TPOT benchmark: 87.7ms BS=1 on dev-cu13 (11% faster than old image)
  • CUDA graph capture: all batch sizes captured successfully
  • Unit tests: test_sm120_mqa_fallback.py
  • PDL enabled on SM120: verified correct (GSM8K 10/10)
  • CI (no SM120 runner in CI — tested on local 8× RTX PRO 6000)

CI States

Latest PR Test (Base): ✅ Run #26636621318
Latest PR Test (Extra): ✅ Run #26636621157

@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 comprehensive support and fallbacks for NVIDIA SM120 (Blackwell Desktop) architectures, which lack certain hardware features like TMEM/tcgen05 required by DeepGEMM and FlashMLA. It implements both pure-PyTorch and optimized Triton fallback kernels for FlashMLA, MQA logits, and MXFP4 MoE operations. Additionally, it updates environment configurations, metadata handling, and server arguments to automatically detect SM120 and route to these compatible implementations. Review feedback highlighted misleading function aliasing in the MoE implementation, the replacement of descriptive assertion messages with "TODO" strings, and inconsistent backend selection logic in the new entrypoints.

@AliceChenyy
AliceChenyy force-pushed the sm120-dsv4-rebase branch 3 times, most recently from 8779574 to a4b24dd Compare May 9, 2026 04:20
Comment thread python/sglang/jit_kernel/utils.py Resolved
Fridge003 and others added 3 commits May 29, 2026 02:31
1. deepseek-v4-deployment.jsx: add SM120 (RTX PRO 6000) hardware
   toggle to the interactive command generator — Flash TP=4 only,
   low-latency recipe verified (GSM8K 20/20).
2. DeepSeek-V4.mdx: revert SM120 section to upstream — the JSX
   toggle is now the sole entry point.
3. server_args.py: remove SM120 block from DeepseekV3ForCausalLM
   branch (not DSv4, per Fridge003).
4. deepseek_v4.py: revert unnecessary _FP8_WO_A_GEMM change
   (per Fridge003).

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@Fridge003
Fridge003 merged commit 524ba10 into sgl-project:main Jun 1, 2026
346 of 425 checks passed
@Fridge003 Fridge003 mentioned this pull request Jun 1, 2026
24 of 36 tasks
mqhc2020 pushed a commit to mqhc2020/sglang that referenced this pull request Jun 2, 2026
AdamPlatin123 added a commit to AdamPlatin123/sglang that referenced this pull request Jun 2, 2026
The previous commit (ef8c80f) was developed on an older branch that
predated the AMD FP4/aiter code added by sgl-project#24692.  Rebase conflict
resolution incorrectly dropped 108 lines of upstream code, breaking
ROCm/MI300 FP4 expert support.

Changes:
- Restore fp8.py to exact upstream/main version
- Re-add SM120 uint8 scale conversion as a clean +16-line insertion
  in process_weights_after_loading_block_quant (elif after DeepGEMM path)
- All AMD aiter, Intel AMX, and FlashInfer paths fully preserved

Fixes: @samuellees review comment on PR sgl-project#24303
hanming-lu pushed a commit that referenced this pull request Jun 3, 2026
@masahi masahi mentioned this pull request Jun 14, 2026
25 of 68 tasks
@zorrofox zorrofox mentioned this pull request Jun 28, 2026
5 tasks done
efschu added a commit to efschu/htsglang that referenced this pull request Aug 2, 2026
Risk sgl-project#1 of the Cut 1/2 report predicted boot 12 stops at the DSpark indexer,
and a card window is not spent on a wall we have already named. Closed here.

The paged-MQA-logits step of the DSpark layers (40-42, compress_ratio 4/128)
defaults to deep_gemm.fp8_paged_mqa_logits: Hopper and datacenter Blackwell
only. Not an Ampere-only problem -- DeepGEMM declined SM12x (deepgemm PR
sgl-project#318), so after Cut 2 gets TP0 through attention the 5090 would have hit this
exactly like the 3080s. All three ranks of this rig need it.

Upstream first: PR sgl-project#31480 solves the same thing for the sibling dsa/ package,
and its structure is what is adopted -- explicit backend selections stay
authoritative, the capability-driven choice goes underneath them, and the
DeepGEMM schedule metadata is skipped for any backend that does not consume
it. The parts that PR had to BUILD (a torch implementation, a metadata
bypass) already exist here from sgl-project#24692, so our delta is the dispatch half
only. This cut writes no kernel; saying otherwise would overstate it.

New dsv4/indexer_arch.py: deepgemm_indexer_supported (per_device_gate,
major in (9, 10)), resolve_paged_mqa_logits_backend, the companion
deepgemm_indexer_metadata_needed, and the named warning. The kernel choice
and the schedule choice must never disagree -- a rank with a schedule and no
DeepGEMM, or a kernel and no schedule, is a crash either way -- so that
invariant is pinned over the whole env x capability matrix rather than left
to two functions happening to agree.

The fn selection is lifted out of _forward_paged_indexer into module-level
select_paged_mqa_logits_fn(). It is the whole of this cut and the kind of
decision that goes quietly wrong on a heterogeneous group; inline in a
600-line method it was untestable. Also: _can_use_nonpaged_indexer now
refuses a card without DeepGEMM (that branch calls fp8_mqa_logits directly
and has no torch twin; the paged path is its fallback).

APPROXIMATION, NAMED, NOT SILENT: this substitution is not bit-identical.
DeepGEMM computes the logits as an FP8 tensor-core GEMM; the torch path
dequantises to float32 and accumulates with bmm. Same quantity, different
arithmetic. The logits feed a top-k, so a near-tie between two KV positions
can be broken differently and output can differ from a Hopper run of the same
checkpoint. Warned once per device, naming the capability and the mechanism.
It stays quiet when the user asked for the torch path explicitly -- then it
is not a surprise.

Two findings from writing the test, both worth the branch on their own:

  * The FP4 indexer has no fallback at all (68-byte vs 132-byte index cache
    layout), so it now REFUSES by name instead of being routed at the FP8
    torch path, which would have read the cache wrongly and returned
    plausible numbers. Our GGUF checkpoint is unaffected.
  * The two torch implementations are not interchangeable, and the difference
    is not architectural. The paged call site passes seq_lens with a trailing
    dim of 1; only the _sm120 variant squeezes it, the other asserts
    shape == (batch_size,). So the old is_sm120_supported() split at
    indexer.py:667 would have sent every non-SM120 card at an implementation
    that ASSERTS -- including anyone setting SGLANG_FP8_PAGED_MQA_LOGITS_TORCH
    on a Hopper box today. The dispatch now always takes the trimmed variant,
    which is additionally the one that walks ceil(max_seq_len/64) pages
    instead of the full capture-time page-table width.

TESTS (desk, CUDA_VISIBLE_DEVICES=99, no GPU touched)
  test_dsv4_indexer_arch_417.py  21 tests / 68 subtests green, incl.
    PagedIndexerMetadata constructed on a mocked Ampere card without ever
    importing DeepGEMM, and the Hopper branch still being taken (observable
    because DeepGEMM raises in this CPU environment).
    CAN-FAIL, three ways: _DEEPGEMM_MAJORS -> (8,9,10) gives 22 failed /
    17 passed; returning fp8_paged_mqa_logits_torch from the dispatch gives
    8 failed / 21 passed; making the FP4 branch fall back silently instead of
    refusing gives 1 failed / 20 passed.
  Regression: unit/layers + unit/utils, 47 failed / 731 passed on this branch
    vs 47 failed / 682 passed at a56f33aafd. Failing set diff EMPTY.
    This comparison earned its keep: it caught the first version of the
    non-paged DeepGEMM check reaching into a metadata field that
    test_dsv4_nonpaged_indexer's stub does not provide. Asking the CURRENT
    device instead is both what that test expects and the more correct
    question after set_device.
  ruff findings identical to base on the touched files (E712 x3 pre-existing
    in indexer.py), new files clean. codespell, black, isort, mypy clean.

Plan file updated: Cut 3 section, matrix rows 9/9b/9c/10, the GPU-window
request restated for Cuts 1-3 in path (all three cards, ~90 min,
SGLANG_OPT_USE_TOPK_V2=0 on any sm86 boot, plus a new gate 6 that sizes the
top-k divergence between ranks rather than asserting the warning is
harmless), and a 5-line ticket note for the ue8m0 subnormal divergence so it
is not lost -- registered separately, deliberately untouched here.
Chronostasys pushed a commit to MindLab-Research/sglang that referenced this pull request Aug 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

deepseek documentation Improvements or additions to documentation jit-kernel run-ci CI: run the baseline test suite on this PR run-ci-extra CI: also run the extra suite (requires run-ci)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants