Skip to content

[SM120] DeepSeek-V4: DeepGEMM paged-MQA indexer +FP4 MoE+ page-split - #29927

Merged
Fridge003 merged 68 commits into
sgl-project:mainfrom
AliceChenyy:sm120-dsv4-deepgemm-pagedmqa
Sep 2, 2026
Merged

Fridge003 merged 68 commits into
sgl-project:mainfrom
AliceChenyy:sm120-dsv4-deepgemm-pagedmqa

Conversation

@AliceChenyy

@AliceChenyy AliceChenyy commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

Motivation: a 4x RTX PRO 6000 Blackwell (SM120) box can hold DeepSeek-V4-Flash, but on
current main the only configuration that starts there is the slow torch fallback — this PR
makes the DeepGEMM and FlashInfer paths work on SM120, cutting decode latency up to 3.4x.

It routes the sparse-MLA indexer to DeepGEMM's paged-MQA-logits kernel, enables batched
sparse-MLA prefill through FlashInfer, and unblocks the DeepGEMM FP4 MoE backend.

Split out of this PR

Following @Fridge003's review, the changes here that were not SM120 enablement now have
their own PRs:

This PR now depends on #35116: without it the page-split buffer is allocated under
inference mode during autotune and CUDA graph capture cannot write to it. Will rebase once
it lands.

The E2E tables below were measured with #35118 still in this tree. Measured separately on
the same box with only that kernel toggled (ISL 8K, BS1, TP4, deep_gemm MoE), it accounts
for 3.2% of the TPOT gain (12.81 -> 12.40 ms, two repeats each, run-to-run spread
0.01 ms) and roughly 2% of TTFT. Discount the tables by that much, or land #35118 first to
reproduce them as written.

What is in it

  1. Sparse-MLA indexer on DeepGEMM — route the indexer to DeepGEMM's paged-MQA-logits
    kernel instead of the eager-torch fallback that scales with batch x context and dominates
    decode. Opt in with SGLANG_FP8_PAGED_MQA_LOGITS_TORCH=0 SGLANG_OPT_USE_TILELANG_INDEXER=0.
  2. Batched sparse-MLA prefill — prefill (q_len > 64) goes through FlashInfer's
    _sparse_mla_sm120_paged_attention; indexer metadata is chunked at M=4096 (the DeepGEMM
    row cap is SKU-dependent) and built once per batch instead of per layer.
  3. Page-split dirty mask — _split_kv_pages_to_64 re-laid out the whole SWA KV pool
    (~105 MB/layer) every decode step; now only the pages this step's top-k references are
    split (CUDA-graph safe, bit-identical).
  4. DeepGEMM FP4 MoE on SM120 — probe the block-scale entry point (DeepGEMM#324) instead
    of hard-disabling DeepGEMM at sm==120, plus the contiguous grouped-GEMM prefill path,
    the UE8M0 pow2-scale quant fix, and the swiglu-clamp fallback for TP>=2 shapes.
  5. SM120 kernel fixes — u64 page-split copy, sparse-prefill head pad removal, TileLang
    mhc_pre compile fix, and the paged-MQA metadata kernel now sizes its shared-memory
    request from the device budget instead of a fixed 128 KB.

Non-SM120 architectures are unchanged: every behavioural change is either gated on
is_sm120_supported() or is a fix that only engages where the previous code was wrong
(the UE8M0 pow2-scale quant and the shared-memory cap).

E2E benefit

"main" is marlin MoE + the torch paged-MQA fallback, because that is the only SM120 path on
14bd315d that starts: the default (flashinfer_mxfp4 + TileLang indexer) dies in the
TileLang JIT for sm_120a (TileLang ships nvcc 13.3, lmsysorg/sglang:dev-cu13 has CUDA 13.0
headers), and --moe-runner-backend deep_gemm raises AttributeError: module 'sglang.srt.layers.deep_gemm_wrapper' has no attribute 'get_mn_major_tma_aligned_tensor'
(SM120 disables ENABLE_JIT_DEEPGEMM while the runner stays selectable).

Both sides then run identical server args, only the tree differs: TP4, marlin MoE, CUTLASS
FP8, chunked prefill 8192, --disable-radix-cache, and no speculative decoding except
where the tables say otherwise. 4x RTX PRO 6000
Blackwell (SM120, 96 GB, PCIe), DeepSeek-V4-Flash, OSL 256, --warmup-requests 0 so every
measured request is a real prefill. TTFT is a median.

Single request (BS=1) — 3 sequential requests, median. TTFT:

ISL main this PR
8K 1124 ms 899 ms −20%
32K 4540 ms 3585 ms −21%
128K 20107 ms 15481 ms −23%

TPOT, without and with MTP-2 (EAGLE, 2 steps / 3 draft tokens) on both sides:

ISL main this PR main + MTP-2 this PR + MTP-2
8K 36.1 ms 10.5 ms 3.4x 13.6 ms 6.0 ms 2.3x
32K 35.8 ms 10.7 ms 3.3x 12.6 ms 5.7 ms 2.2x
128K 36.1 ms 11.9 ms 3.0x 13.4 ms 6.8 ms 2.0x

Accepted length is within 0.2 of each other on the two sides at every context length, so the
MTP gain comes from the decode path itself, not from better speculation.

Concurrent (ISL 8K) — --num-prompts BS --max-concurrency BS:

BS TTFT main TTFT this PR TPOT main TPOT this PR output tok/s main output tok/s this PR
4 3574 ms 2826 ms −21% 42.9 ms 16.8 ms 2.6x 71 147
8 5660 ms 4530 ms −20% 51.9 ms 24.3 ms 2.1x 108 191
16 10482 ms 8365 ms −20% 71.6 ms 40.9 ms 1.8x 143 219

TTFT holds at −20% across batch sizes; the decode multiple decays with batch (3.4x at BS1,
1.8x at BS16) because what this PR removes is per-step fixed cost, which amortises as the
batch grows. Speculative decoding amortises it the same way.

GSM8K (50 questions) is 0.980 on main and 0.960 on this PR at 8K — one question apart.

All tables are without prefill context parallelism, which is upstream code this PR does not
touch.

Recipes

Common to both: --fp8-gemm-backend cutlass --chunked-prefill-size 8192 --max-prefill-tokens 8192 --swa-full-tokens-ratio 0.15 --cuda-graph-max-bs 32,
plus SGLANG_SM120_FLASHMLA_BACKEND=flashinfer SGLANG_FP8_PAGED_MQA_LOGITS_TORCH=0 SGLANG_OPT_USE_TILELANG_INDEXER=0.

Prefill-optimised — --moe-runner-backend deep_gemm --mem-fraction-static 0.85,
SGLANG_OPT_FIX_MEGA_MOE_MEMORY=1 SGLANG_OPT_DEEPGEMM_HC_PRENORM=1.

Decode-optimised — --moe-runner-backend marlin --mem-fraction-static 0.90 --speculative-algorithm EAGLE --speculative-eagle-topk 1 --speculative-num-steps 2 --speculative-num-draft-tokens 3, SGLANG_OPT_USE_TILELANG_MHC_PRE=1.

Dependencies

  • FlashInfer 0.6.15.post1 (SM120 sparse-MLA kernels) and sglang-kernel 0.4.5 — both are
    what lmsysorg/sglang:dev-cu13 currently ships.
  • DeepGEMM at or after feat: add sm120 support for DeepGEMM  deepseek-ai/DeepGEMM#324 for the FP4 MoE backend. The
    fp8_paged_mqa_logits indexer path additionally needs DeepGEMM's attention host-gates to
    accept SM120 (a 3-line arch gate, not yet upstream in sgl-project/DeepGEMM); without it,
    keep the TileLang indexer default.

Tests

test/registered/kernels/ops/attention/test_silu_and_mul_contig_post_quant.py (9 cases,
registered for CI) covers the fused swiglu-clamp + silu_mul + fp8-quant kernel against a
reference. GSM8K numbers are from sglang.test.few_shot_gsm8k.

Reviewed and validated with @ormandj (conflict resolution) and @moxcat (inference-mode
buffer fix, now #35116) on 2x and 4x RTX PRO 6000 Blackwell.

Re-validated after the split on 4x RTX PRO 6000 Blackwell, FlashInfer 0.6.15.post1 (the
pinned version), this tree plus #35116: GSM8K-50 1.000 with --moe-runner-backend deep_gemm, 0.960 with MTP-2; ISL 8K BS1 TTFT 116/88 ms, TPOT 12.8/7.3 ms.


CI States

Latest PR Test (Base): 🚫 Run #33691107019
Latest PR Test (Extra): 🚫 Run #33691106716
Latest PR Test (AMD ROCm 7.2): 🚫 Run #33691106965

AliceChenyy and others added 3 commits July 2, 2026 02:46
…LA prefill

On SM120, DeepSeek-V4 forced the sparse-MLA indexer to compute paged-MQA
logits in eager torch ops (SGLANG_FP8_PAGED_MQA_LOGITS_TORCH=True), which
scales with batch x context and dominates decode. Route to the DeepGEMM
paged-MQA-logits CUDA kernel instead:
- server_args: on SM120 stop forcing the torch fallback; also default
  SGLANG_OPT_FLASHMLA_SPARSE_PREFILL=False so sparse-MLA prefill uses the
  FlashInfer SM120 path (the unified sgl_kernel flash_mla_sparse_fwd prefill
  is SM90a/SM100f-only and errors on SM120).
- metadata: on SM120 always use the DeepGEMM metadata kernel, never the JIT
  one (its dynamic-smem request exceeds SM120 limits, incl. large prefill).

Requires DeepGEMM with SM120 support (deepseek-ai/DeepGEMM#324).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The FlashInfer SM120 sparse-MLA decode needs page_block_size=64, but the SWA
KV pool uses page_size=256, so _split_kv_pages_to_64 re-lays-out the KV every
decode step. It split the ENTIRE pool (~105MB/layer/step) even though sparse
MLA only reads the top-k pages. Mark the pages referenced by this step's
sparse indices in a fixed-size mask and have the split kernel early-return for
the rest; the persistent dst buffer keeps stale contents for skipped pages
(never read -> bit-identical). Static shapes -> CUDA-graph safe.

Measured RTX PRO 6000, DSv4-Flash, marlin MoE, TP4, ISL=8K, CUDA graph:
decode TPOT BS1/8/16 25.2/26.8/29.1 -> 13.3/14.6/17.4 ms; GSM8K unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Enable the DeepGEMM grouped-GEMM FP4 MoE runner on SM120
(--moe-runner-backend deep_gemm); marlin stays the SM120 default (faster
decode), this is opt-in for prefill throughput / FP4 experts. Requires
DeepGEMM with SM120 support (deepseek-ai/DeepGEMM#324):
- configurer: enable JIT DeepGEMM on SM120 when the SM120 grouped-GEMM symbol
  is present; enable UE8M0 block scales on SM120.
- moe_runner/deep_gemm + ep_moe/kernels: SM120 handling (pow2 UE8M0 FP8 quant,
  TMA-aligned e8m0 scales, JIT-EP-activation fallback for TP>=2, in-place
  swiglu_limit clamp on the Triton fallback path).
- fp8/fp8_utils: contiguous scale for the layout transform; keep dense w8a8
  fp8 linear off DeepGEMM on SM120.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@AliceChenyy AliceChenyy changed the title [SM120] DeepSeek-V4: DeepGEMM paged-MQA indexer + page-split + FP4 MoE [SM120] DeepSeek-V4: DeepGEMM paged-MQA indexer +FP4 MoE+ page-split Jul 2, 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 compatibility and performance optimizations for SM120 (Blackwell) architectures, including page-split kernel optimizations to avoid redundant KV pool copies, custom power-of-2 FP8 quantization, TMA alignment for scales, and in-place SwiGLU clamping to reduce overhead. The review feedback highlights several critical issues, including an undefined variable _is_sm120_supported causing a NameError, potential undefined values in Triton's masked loads, compilation failures if Triton block sizes are not powers of two, and potential RuntimeErrors from calling .view() on non-contiguous tensors.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

…dexer chunking)

- deepseek_v4_backend: gate SM120 off the SM90a/SM100f-only flash_mla_sparse_fwd
  so sparse-MLA prefill routes to the SM120 FlashInfer path instead of crashing.
- flash_mla_sm120: add _flash_mla_sm120_prefill using FlashInfer
  _sparse_mla_sm120_paged_attention for prefill (num_tokens>64); decode path unchanged.
- dsv4 indexer/metadata: chunk get_paged_mqa_logits_metadata + fp8_paged_mqa_logits by
  query rows (<=16384) so the DeepGEMM metadata kernel fits SM120 shared-memory cap on
  large batched prefill.

Validated on RTX PRO 6000 (SM120), TP4 marlin: GSM8K 10q=100%, batched prefill bs1-64
works (previously crashed at bs>=4); bs1 ISL8K TTFT ~0.9s.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Two decode/prefill wins on SM120 (RTX PRO 6000), found by profiling a
bs1 decode step: the triton _w8a8_block_fp8_matmul was 49% of decode
time (6.5ms of 13.3ms TPOT), not NCCL (9%).

1. fp8_utils: default the SM120 FP8 GEMM backend to CUTLASS instead of
   (untuned) Triton. Graph-replay of the 43-layer x 7 DSv4-Flash fp8
   GEMM sequence: 24-28% faster at M=1/8/64, ~24% at M=16384.
2. deepseek_v4/server_args: enable SGLANG_OPT_DEEPGEMM_HC_PRENORM on
   SM120, gated to M >= 1024 tokens so prefill takes the deepgemm tf32
   gemm while decode keeps the (faster at small M) torch impl. This
   removes the previous prefill-vs-decode tradeoff of this env.

TP4 marlin, ISL8K (validated on two nodes):
- TTFT bs1/4/8: 1.12/3.78/6.77 -> 0.90/3.21/5.25 s
- pure batched-decode TPOT (unique prompts, all-decode window,
  distinct KV): bs1/8/32/64 = 10.9/16.3/25.4/32.4 ms
  (bs64 needs --swa-full-tokens-ratio 0.2; SWA pool is the binding
  constraint at high concurrency since DSA topk keeps full-seq KV)
- bench_serving ISL8000/OSL1000 c1: TTFT ~875ms / TPOT 10.9ms
  (vLLM PR#43477 TP2 reference: 718ms / 10.65ms); c32 with
  --mem-fraction-static 0.85: TTFT 15.1s, 591 tok/s output
- GSM8K 50q accuracy 0.96, invalid 0.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
AliceChenyy and others added 7 commits July 9, 2026 23:25
The hc_pre tail computed y = (pre.unsqueeze(-1) * x_flat.view(M, hc, H))
.sum(dim=1) in eager torch, materializing an [M, hc, H] fp32
intermediate on the prefill critical path (~7.5% of prefill kernel
time as fp32 broadcast-mul + reduce).

Add a fused triton kernel hc_combine (fp32 accumulate, bf16/fp32
input, direct store) in sglang/srt/layers/mhc.py and call it from
deepseek_v4.hc_pre. CUDA-graph capture safe (fixed shapes per capture).

TP2 marlin ISL8K A/B: TTFT bs1/4/8 = 0.920/3.308/5.406 ->
0.837/2.990/4.892 s (-9.5%); decode TPOT unchanged; GSM8K 10q 1.000.
Post-fusion profile: kernel is 2.0% of prefill (was ~7.5% unfused).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The deep_gemm runner's masked layout allocates
[num_local_experts, capacity, k] transients that scale with expert
capacity and OOM at prefill chunk sizes. Add a contiguous grouped GEMM
path (ep_scatter to 128-aligned expert slots + m_grouped contiguous
kernels) taken when dispatched tokens >= 1024, mirroring vLLM PR#43477's
DeepGEMM MXFP4 MoE prefill route.

TP2 chunk8192 honest-median TTFT vs marlin: 4K 432/440, 8K 791/886,
16K 1570/1798, 32K 3191/3581, 64K 6744/7616, 128K 14537/16138 ms
(-10~13%); GSM8K 50q 0.980. Decode via masked path remains slow
(33.9ms bs1 vs marlin 11.5) -- use marlin for decode-heavy serving
until an M-gated dual route lands.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Prefill AllReduce messages at chunk 8192 are 64MB (8192 tokens x 4096
hidden bf16), far above the 8MB _MAX_CAR_SIZE cap, so every prefill AR
fell back to the NCCL ring. At world_size 2 the one-shot kernel is a
single p2p hop and stays faster well past 8MB.

TP2 deep_gemm 8K honest-median TTFT: 791 -> 773-781 ms; profile confirms
cross_device_reduce_1stage replaces ncclDevKernel_AllReduce (160 -> 143
ms per 8K prefill). GSM8K 10q 1.000. Gated to world_size == 2 so TP4/TP8
(where one-shot traffic scales with N-1) keep the 8MB default.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
SGLANG_OPT_FIX_MEGA_MOE_MEMORY enabled use_swizzle unconditionally, but
the DeepGEMM#324 SM120 contiguous grouped GEMM consumes standard-layout
activations; the swizzled output of silu_and_mul_contig_post_quant reads
as garbage (unit diff: fp8 byte-match 0.6% swizzled vs 96.7% standard;
GSM8K 10q 0.40 -> 1.00 after fix). This was the root cause of the
historic "deepgemm+fused-swiglu GSM8K 5%" regression.

With the fused kernel now correct, TP2 chunk8192 honest-median 8K TTFT:
773 -> 741-744 ms (fuses the 21ms swiglu clamp + 14ms silu_mul + 9ms
fp8 quant into one kernel); GSM8K 50q 0.980. vLLM PR#43477 same-node
reference: 723 ms (gap 1.025x).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Pad slots carry m_indices == -1 and are skipped by the DeepGEMM
contiguous grouped GEMM; their row contents are never read (output_index
only maps real rows), so the [all_tokens, K] fp8 buffer does not need a
zero fill (8.4ms FillFunctor per 8K prefill).

TP2 chunk8192 honest-median 8K TTFT: 741-744 -> 736-740 ms;
GSM8K 10q 1.000.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The flag cleared is_hybrid_swa, but the DSv4 KV pool always carries
per-layer SWA buffers, so pool init crashed on the unset
swa_max_total_num_tokens. A truly unified pool is economically
identical to equal-size pools (every token pays both pools' bytes), so
implement the flag as swa_full_tokens_ratio=1.0 with a log line.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
>1 is meaningful for models whose full-attention KV lives mostly in
separate compressed pools (DSv4: c4/c128), leaving the SWA pool as the
per-request-dominant consumer. Measured on DSv4 TP2: ratio 2.0 gives the
best 8K BS8 serving cell (TTFT 3748->3471ms, TPOT 17.1->13.4ms), though
it shrinks the full pool enough to hurt 16K BS8 - workload-dependent.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@ormandj

ormandj commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Tested selected commits on SGLang main 96a04cb13f with #30272, #30438,
#29609, and #30859. Hardware was 2x RTX PRO 6000 Blackwell Max-Q at 300 W,
TP2 over PCIe, metrics enabled, no speculative decoding.

291e4a7660 page mask, with the Torch 2.11 mutable-buffer fix:

  • C1: 67.7 -> 90.6 tok/s
  • C32: 870.1 -> 988.6 tok/s
  • _page_split_kernel: 3.781 -> 0.663 ms/token

d178c7413b fused hc_combine applies and serves. I did not run an isolated
throughput A/B for this commit. In the diagnostic post-change trace,
_hc_combine_kernel is 2.38% of extend wall and the remaining unfused multiply
is 0.02%. That trace contains ten C1 extend steps and one mixed bs2 step, so it
is not used for headline throughput.

I also screened the current cross-layer fused-MHC path with
SGLANG_OPT_FUSE_MHC_POST_PRE=1 and the unsupported DeepGEMM HC path disabled.
One 20-second decode run produced C1 86.9 and C32 1,000.4 tok/s; one cold-64K
run produced 6,270 client / 6,394 server tok/s. The selected-stack medians are
C1 90.0, C32 995.3, and 6,545 / 6,680 cold-64K. This is a one-run screening
comparison, not an isolated repeated A/B. I excluded the fused-MHC variant
because it regressed C1 and prefill.

7d3bf19778 with a 128 MiB custom-all-reduce cap regresses cold 64K prefill on
this PCIe topology:

Path Client tok/s Server tok/s
Default 8 MiB cap; 64 MiB messages use NCCL 6,545 [6,421, 6,702], n=3 6,680 [6,538, 6,835], n=3
128 MiB custom-AR cap 6,426 [6,294, 6,594], n=3 6,543 [6,422, 6,718], n=3

In the 128 MiB trace, custom AR takes 2.992 s, 23.27% of extend wall, and each
full 64 MiB reduction takes 269-290 ms. In the original NCCL trace, NCCL takes
1.647 s, 20.82% of extend wall, approximately 235 ms per full chunk. I excluded
the 128 MiB change from the final configuration. Its registered buffer also
consumes memory otherwise available to the auto-sized KV pool.

With released deep_gemm==0.1.4.post1, the grouped-FP4 symbol probe passes, but
the first large prefill fails in tf32_hc_prenorm_gemm:

InternalError: deepgemm/csrc/apis/hyperconnection.hpp:56 Unsupported architecture

The grouped-FP4 symbol does not establish SM120 support for the
hyperconnection operation. This path needs an operation-specific capability
check or a DeepGEMM release with SM120 hyperconnection support.

Final selected stack, excluding the 128 MiB custom-AR change and DeepGEMM
hc-prenorm:

  • C1: 90.0 [90.0, 90.1] tok/s, n=3
  • C32: 995.3 [992.4, 998.5] tok/s, n=3
  • cold 64K prefill client: 6,545 [6,421, 6,702] tok/s, n=3
  • cold 64K prefill server counter: 6,680 [6,538, 6,835] tok/s, n=3

AliceChenyy and others added 3 commits July 12, 2026 21:48
Drop benchmark numbers and restated-code comments flagged in review of
the sibling PR; reword the SM120 DeepGEMM probe comment now that
DeepGEMM#324 is merged (installed builds may still predate it).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The contiguous grouped-GEMM prefill path is only viable with the fused
swiglu+quant kernel (the unfused fallback keeps a bf16 [all_tokens, N]
transient alive across the FC2 GEMM); with the swizzle fix it is also
the accurate path. Respect an explicit user setting.

Validated without the env: TP2 8K TTFT 741ms (fused-path speed),
GSM8K 10q 1.000.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Covers ue8m0 x swiglu_limit x M against the unfused reference (fp8 byte
agreement; accuracy parity where fp32 scale storage conventions differ),
and pins the standard output layout as the contract: the swizzled layout
is not consumed by the SM120 DeepGEMM contiguous grouped GEMM and
regressed GSM8K 1.00 -> 0.40 before the use_swizzle fix.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@github-actions github-actions Bot added the quant LLM Quantization label Jul 13, 2026
AliceChenyy and others added 3 commits July 12, 2026 22:56
Review findings on the PR branch, all one theme — changes needed for
SM120 were left unconditional:

- contiguous MoE path: only take it when all experts are local (the
  standard dispatcher maps non-local experts to -1 under EP, which
  bincount/scatter cannot handle); count expert slots with a masked
  index_add_ instead of bincount, which also removes a per-layer
  GPU->CPU sync; preserve the activation dtype in the gather instead of
  hardcoding bf16; drop a duplicated use_jit_ep_activation guard
- use_swizzle: keep the swizzled activation layout everywhere except
  SM120 (the SM100 masked GEMM consumes swizzled)
- custom allreduce 128MB max_size: PCIe-only 2-GPU groups; NVLink TP2
  keeps the 8MB default (avoids ~360MB/rank of extra buffers)
- should_deepgemm_weight_requant_ue8m0: False on SM120 — dense
  block-FP8 GEMMs route to CUTLASS/Triton there, which expect fp32
  scales; clarify the DeepEPMoE assert for the unsupported
  FP8-experts + standard-dispatch combination

TP2 regression after the batch: config P GSM8K 20q 0.950 / 8K TTFT
725-731ms; config D GSM8K 20q 1.000 / c1 TPOT 6.41ms accept 2.75.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
- SGLANG_OPT_DEEPGEMM_HC_PRENORM is now set from a configurer probe of
  deep_gemm.tf32_hc_prenorm_gemm (same idiom as the SM120 grouped-GEMM
  probe) instead of unconditionally, so older DeepGEMM builds fall back
  to the torch impl instead of failing on the first large prefill
- chunked indexer metadata is identical for every layer in a forward
  pass; compute the per-chunk list once in PagedIndexerMetadata instead
  of per layer (~61x) in the indexer, and drop the sentinel
- pow2 quant kernel: remove the dead bounds check (launch grid is
  exactly (M, num_groups)) and the now-unused M parameter

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Notable resolutions against the refactored main:
- page-split buffers migrated to the new ctx.resources registry
  (main already carries the whole-pool split; our dirty-mask ref-mask
  moved to a shared _build_ref_page_mask helper on the same registry)
- chunked SM120 indexer re-integrated into the NonPagedIndexerPlan
  dispatch (per-chunk metadata list computed once in
  PagedIndexerMetadata; sentinel removed)
- DSv4 arg defaults moved to the overrides registry
  (disable_hybrid_swa_memory conversion + swa ratio); env writes stay
  in the residual hook per its policy (MEGA_MOE default for deep_gemm)
- swa-full-tokens-ratio validation merged with main's _resolved()
  semantics, limit raised to 4.0
- _per_token_group_quant_fp8_pow2 deleted: superseded by main's fused
  per_token_quant_fp8_ue8m0_scatter (use_mxfp8) path
- masked-path swiglu handling follows main (gemm1_alpha/clamp native in
  silu_and_mul_masked_post_quant_fwd); pre-commit formatting reapplied

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
AliceChenyy and others added 6 commits August 18, 2026 20:13
…per index

`_page_mark_kernel` launched one program per index and each program did a
single load plus a single store; the `BLOCK` parameter was passed but unused
(the call site said as much: "BLOCK (unused, kept for JIT signature)"). At
ISL 8K the grid is tens of thousands of near-empty blocks.

Process BLOCK indices per program with a masked load/store, dropping the grid
by three orders of magnitude. The mask `valid & (idx >= 0)` reproduces the two
early returns exactly.

Measured on 4x RTX 6000D (SM120), TP4, deepseek-ai/DeepSeek-V4-Flash-0731,
--moe-runner-backend flashinfer_mxfp4, ISL 8K / OSL 256 / BS1, median of 3:

  before  TTFT 914.61 ms  TPOT 11.12 ms  GSM8K-50 0.960
  after   TTFT 882.00 ms  TPOT 11.12 ms  GSM8K-50 0.960

TTFT -32.6 ms (-3.6%); TPOT unchanged, as expected -- page-split runs in
prefill. In a torch profile of that workload the kernel was 35.8 ms over 2795
launches (2.1% of GPU kernel time).

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
SM120 forced the TileLang MHC pre kernel off, so hc_pre fell back to the torch
path. That path does

    x_flat = x.flatten(1).float()

which materialises [tokens, hc_mult * hidden] in fp32 -- 8192 x 16384 x 4B =
512 MB at ISL 8K -- once per layer, and its fp32 F.linear then dispatches to
cutlass_80_simt_sgemm, i.e. no Tensor Core. In a torch profile of ISL 8K on
4x RTX 6000D that fallback accounted for ~208 ms of GPU kernel time across four
kernels (43 layers x 2 launches each):

  unrolled_elementwise (the .float() copy)   57.0 ms / 151
  vectorized_elementwise                     70.4 ms /  86
  cutlass_80_simt_sgemm (fp32 F.linear)      40.7 ms /  86
  reduce_kernel (.square().mean(-1))         39.6 ms /  86

With the TileLang kernel the first, third and fourth disappear entirely and GPU
kernel time drops 1695.6 -> 1458.6 ms.

The kernel itself already works here -- the warp-specialization workaround in
this PR is what makes it compile on SM120 -- so the off default was leaving that
work unused.

Measured on 4x RTX 6000D (SM120), TP4, deepseek-ai/DeepSeek-V4-Flash-0731,
--moe-runner-backend flashinfer_mxfp4, BS1, median of 3:

  ISL     TTFT off -> on            TPOT off -> on
  8K      882.91 -> 670.39 ms  -24.1%    11.08 -> 10.38 ms  -6.3%
  32K    3644.07 -> 2810.75 ms  -22.9%   11.59 -> 10.90 ms  -6.0%
  128K  16864.04 -> 13546.18 ms -19.7%   12.98 -> 12.27 ms  -5.5%

GSM8K-50 0.960 in both cases. Still env-overridable, as the surrounding knobs are.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Context for the revert in 383b9d7. Upstream landed 1af761a ("[SM12x] Default
the fused MHC post+pre path on", sgl-project#34019), which defaults
SGLANG_OPT_FUSE_MHC_POST_PRE on for SM12x. That path already covers SM120 --
the gate reads

    FUSE_MHC_POST_PRE and USE_TILELANG_MHC_POST and
    (USE_TILELANG_MHC_PRE or is_sm120_supported())

so the standalone pre flag is not needed once the fused path is on.

Measured on 4x RTX 6000D, TP4, DeepSeek-V4-Flash-0731, flashinfer_mxfp4, BS1:

  config                          TTFT 8K   TTFT 32K   TPOT    GSM8K-100
  both off (the stale baseline)    881.17    3639.09   10.85   0.950
  FUSE_MHC_POST_PRE=1 (upstream)   673.06    2826.30    9.86   0.950
  USE_TILELANG_MHC_PRE=1 (mine)    673.37    2816.43   10.15   0.950
  both                             673.72    2823.01    9.87   0.970

Same TTFT, and upstream's fused path is 2.9% better on TPOT. Enabling both adds
nothing over upstream alone, so the reverted commit was redundant and slightly
worse.

The -24% figure in the reverted commit message was measured against a baseline
that no longer exists upstream: this branch predates sgl-project#34019, so its "off" state
fell through to the torch fp32 fallback. The fallback analysis itself still
holds -- x.flatten(1).float() materialises [tokens, hc_mult*hidden] in fp32 and
its F.linear lands on a SIMT GEMM -- upstream just fixes it by a different route.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Four conflicts, resolved as follows.

deep_gemm.py -- upstream sgl-project#34926 replaced the SGLANG_OPT_FIX_MEGA_MOE_MEMORY env
gate on use_swizzle with `get_moe_a2a_backend().is_megamoe()`. Our SM120 hook
hangs off the same assignment but answers a different question (SM120's
contiguous GEMM takes standard-layout activations only), so the two are ANDed:

    self.use_swizzle = (
        get_moe_a2a_backend().is_megamoe() and deep_gemm_sm120.use_swizzle()
    )

server_args.py -- both sides changed the SM120 block for different reasons.
Upstream sgl-project#34019 added the SGLANG_OPT_FUSE_MHC_POST_PRE default; this branch had
made the surrounding knobs env-overridable. Kept both.

indexer.py -- upstream sgl-project#34926 dropped SGLANG_TOPK_TRANSFORM_512_TORCH. Kept this
branch's chunked run_topk_transform refactor and removed the deleted env from
its condition.

paged_mqa_metadata.cuh -- took upstream wholesale. Upstream sgl-project#25855 rewrote the
kernel into tiny/small/multi-block paths; the single smxx_paged_mqa_logits_metadata
kernel this branch clamped shared memory for no longer exists, and the new paths
do not request over-limit dynamic smem at all (no cudaFuncSetAttribute in the
file). The clamp had nothing left to clamp.

Symbol audit after resolution -- envs deleted upstream have no remaining
references (SGLANG_OPT_FIX_MEGA_MOE_MEMORY, SGLANG_OPT_USE_DEEPGEMM_MEGA_MOE,
SGLANG_TOPK_TRANSFORM_512_TORCH, SGLANG_OPT_USE_OLD_COMPRESSOR,
SGLANG_OPT_DPSK_V4_RADIX: 0 each), and this PR's symbols are intact
(deep_gemm_sm120 6, allows_masked_standard_layout 2, _SM120_INDEXER_M_CHUNK 7,
_page_mark_kernel 2).

Not yet re-validated on hardware; that is the next step.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Two lint failures introduced by merging current main:

- ruff now rejects the quoted forward references in deep_gemm_sm120.py;
  both names are already imported, so the quotes were never needed.
- check-registered-tests rejects the legacy `suite="nightly-kernel-1-gpu"`
  registration. Per its own diagnostic that name "matches no suite the
  PR-test workflows invoke, so the test silently never runs", so this
  line was dead; the base-b-kernel-unit registration above already runs
  the test in PR CI. Dropped rather than converted to `stage="nightly"`,
  which would add a nightly run that never previously happened.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@AliceChenyy

Copy link
Copy Markdown
Contributor Author

@Fridge003 Thanks for the review — replied to each inline thread. Accuracy results below.

Accuracy on sm100/sm103 + sm120 with --moe-runner-backend flashinfer_mxfp4 --speculative-algorithm DSPARK (sgl-eval run aime25)

sm100 — done

4x B200 (SM100), TP4, your server command verbatim, on this PR's branch:

metric value
AIME25 pass@1, mean of 16 repeats 98.96% (475/480)
per-repeat spread min 93.3%, max 100%, stdev 2.01%
problems solved in all 16 repeats 25 / 30
truncated generations (finish_reason != stop) 0
wall clock / output throughput 31.6 min / 2072 tok/s

Hardest items, each missed once in 16: aime25-6, -13, -14, -22, -23 (93.75% each).

Two notes on how to read this number:

  1. --thinking did not take effect. chat_template_kwargs.thinking=true is recorded
    in the run metrics and was accepted by the server, but num_reasoning_tokens is 0 for
    every one of the 480 samples and reasoning_content comes back null. The answers are
    genuinely produced (mean 8078 generated tokens, all finish_reason=stop), so the
    accuracy stands on its own — but this is presumably not the thinking-mode path you
    intended to measure. Happy to re-run if there is a different flag or chat template for
    it on this checkpoint.
  2. The deepseek-ai/DeepSeek-V4-Flash-0731 config declares quant_method: fp8
    (fmt: e4m3, scale_fmt: ue8m0), and the server auto-detects
    is_fp4_experts=True for the routed experts. --moe-runner-backend flashinfer_mxfp4
    was accepted without complaint.

sm103 — cannot run

No B300/GB300 available here.

sm120 — done, but not on your command as written

4x RTX 6000D (SM120), TP4:

metric sm100 (B200) sm120 (RTX 6000D)
AIME25 pass@1, mean of 16 98.96% (475/480) 98.33% (472/480)
per-repeat spread 93.3–100%, stdev 2.01% 86.7–100%, stdev 3.65%
truncated 0 0
wall clock / throughput 31.6 min / 2072 tok/s 85 min / 798 tok/s

Accuracy is on par. Two changes were required to get sm120 to run at all, and both are
worth your attention:

1. DSPARK does not start on sm120 with this PR as it stands. Graph capture aborts:

Check failed: (ok) is false: Unsupported sparse-MLA prefill configuration:
model=DSV4 num_heads=16 topk=192 page_block_size=64

FlashInfer's sparse_mla_sm120_prefill.cu only instantiates topk ∈ {128, 512, 1024,
2048}, while DSPARK's swa_window + block_size aligns to 192. num_heads=16 itself is
fine. The number above came from a local patch that widens an uninstantiated index width
to the next instantiated one (192 -> 512, tail is -1 and masked per row via
topk_length, so it only costs padding). That patch is not in this PR. Happy to add
it here, or send it separately — your call on scope, given you just asked me to make this
PR smaller.

2. --mem-fraction-static 0.90 does not fit an 85 GB card. 0.90 OOMs during graph
capture; 0.85 boots but dies mid-run in hc_pre_torch_impl with 0.11 GiB free. The
numbers above use 0.80 plus --num-threads 32 on the client. So the sm120 column is
not the identical configuration as sm100 — flagging rather than presenting them as one
run.

thinking mode — did not engage on either arch

Same on both: num_reasoning_tokens is 0 for all 960 samples and no generation contains
a <think> block; the models reason inline in content instead (mean ~8.1k / ~8.5k
generated tokens, every sample finish_reason=stop).

Root cause: this checkpoint ships no Jinja chat template — the model card says so
explicitly and points at the encoding/ folder with encode_messages(..., thinking_mode="thinking", reasoning_effort=...). The server logs
No chat template found, defaulting to 'string' content format, and reasoning_parser
is unset. sglang does have a dsv4 encoder path (serving_chat.py ->
chat_encoding.resolve_chat_encoding_spec returns "dsv4" for DeepseekV4*
architectures), so the plumbing exists — but with the command as given, thinking is not
what got measured.

Both numbers are still valid as accuracy measurements; they are just not thinking-mode
measurements. If you want the thinking path specifically, please advise which flags you
use (--reasoning-parser? a chat_template_kwargs variant?) and I will re-run both.


CI: lint now passes on b19fd53b92. The remaining checks are all the 4–7s admission gates waiting on a run-ci label — could you add it so the real test suites can run? This PR has never had them execute.

@Fridge003 Fridge003 added run-ci-extra CI: also run the extra suite (requires run-ci) run-ci CI: run the baseline test suite on this PR labels Aug 29, 2026
@Fridge003

Copy link
Copy Markdown
Collaborator

/rerun-test test/registered/models_e2e/test_deepseek_v4_flash_fp4_b200.py test/registered/models_e2e/test_deepseek_v4_flash_fp4_megamoe_b200.py

@github-actions

github-actions Bot commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Results for /rerun-test test/registered/models_e2e/test_deepseek_v4_flash_fp4_b200.py test/registered/models_e2e/test_deepseek_v4_flash_fp4_megamoe_b200.py:

🚀 4-gpu-b200 (2 tests): ❌ View workflow run

cd test/ && python3 registered/models_e2e/test_deepseek_v4_flash_fp4_b200.py
cd test/ && python3 registered/models_e2e/test_deepseek_v4_flash_fp4_megamoe_b200.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

deepseek jit-kernel quant LLM Quantization release-highlight Candidate PR for release note highlight 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.

6 participants