Repository navigation
feat: SM120 (Blackwell Desktop) support for DeepSeek-V4 inference - #24692
Conversation
There was a problem hiding this comment.
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.
8779574 to
a4b24dd
Compare
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]>
…o sm120-dsv4-rebase
…l-project#24692) Co-authored-by: Claude Opus 4.6 <[email protected]>
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
…4692) Co-authored-by: Claude Opus 4.6 <[email protected]>
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.
…l-project#24692) Co-authored-by: Claude Opus 4.6 <[email protected]>
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 pathstest_sm120_mqa_fallback.py— Unit tests for MQA fallback correctnessSM120 guards (10 modified files):
deepseek_v4_backend.pymarlinbackend on SM120.unique()/.item()/.nonzero()→ vectorized)Bug fix (found during latest-image validation):
uint8dtype (upstream changed fromfloat8_e4m3fn)Results (8× RTX PRO 6000, TP=8, CUDA graph)
On
sglang:dev-cu13(sgl-kernel 0.4.2.post1, PyTorch 2.11+cu130):On older nightly-dev-20260430 (sgl-kernel 0.4.1, PyTorch 2.9.1+cu129):
Motivation
Notes
deepseek_v4branch) ontomainis_sm120_supported()— zero impact on SM100/SM103 pathsSGLANG_SM120_TRITON_FLASHMLA=1(default on),SGLANG_SM120_MQA_FALLBACK=0(default off)Test plan
sglang:dev-cu13imagetest_sm120_mqa_fallback.pyCI States
Latest PR Test (Base): ✅ Run #26636621318
Latest PR Test (Extra): ✅ Run #26636621157