Skip to content

[Feat] [GB300] deepseek_v41: Serve one request at TP8 with no slot list or KV layout setting - #94

Open
weireweire wants to merge 4 commits into
sgl-project:mainfrom
weireweire:dsv41-auto-config
Open

weireweire wants to merge 4 commits into
sgl-project:mainfrom
weireweire:dsv41-auto-config

Conversation

@weireweire

@weireweire weireweire commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

Serving DeepSeek-V4.1-Flash at one request, attention TP8 + MoE TP4 x EP2, at its best needed a hand-written
SGLANG_NVIDIA_MEGAKERNEL_SLOTS list (the shipped slots plus eight opt-in ones), SGLANG_DSV4_KV_LAYOUT=v41_new
for slot attn_core_lean, and --ep-num-redundant-experts 384 for slot moe_balanced, which the spec refused.
A default start ran none of those. With this PR the launch needs --enable-nvidia-megakernel and
--max-running-requests 1; --ep-num-redundant-experts 384 is an explicit choice that trades memory for speed.
No SGLang change is needed. The megakernel API version is not touched here: on SGLang main the spec needs version 3,
which #85 declares for every model.

Modifications

  1. Redundant experts (moe/routed.py, spec.py): the spec admits ep_num_redundant_experts 0 or 384; the
    router's expert count is the layer's slots less the redundant ones; with 384 (every EP rank holds all routed experts
    in router-id order) slot moe_balanced takes the rank's storage whole and deals on its EP rank.
  2. Default slots (runtime/__init__.py, attention/__init__.py, draft_step.py, draft_slots.py):
    • attn_wo_a_fp8, attn_index_weights_bf16, attn_index_q_first, attn_cluster_merge, draft_stage0_first,
      draft_embed, draft_final_collapse (bitwise) join the default slots as TP8_DEFAULT_SLOTS: a default start
      takes them at attention TP8 (8 local heads) only. At attention TP4 the group measured about 70 us per step slower
      and changed seeded T=1 outputs (see Speed), so it stays off there; listed, they still run at TP4.
    • attn_core_lean (numerics change) joins them; a default start takes it only on SGLang's v41_new KV layout,
      the only layout its build serves steps on.
    • runtime.default_takes holds the rule; the target attention build and the draft build read it; the startup
      summary lists a default slot left off as before. draft_embed is left off, not refused, when the draft has its
      own vocabulary.
    • Still opt-in: hop_final_collapse (not bitwise at TP8, no resolved gain alone), lm_head_pinned_tactic
      (no resolved difference here, see Speed), draft_lm_head_mxfp8 (measurement only), hop_b_cap16,
      hop_b_quad_trigger.
  3. KV layout for one request (serving.py, registered by plugin.register): a resolution step SGLang runs ahead of
    handle_nvidia_megakernel (register_resolution_hook). With the megakernel on, DeepSeek-V4.1 at
    --tp 8 --ep-size 2, --max-running-requests 1 and no PD disaggregation, it sets SGLANG_DSV4_KV_LAYOUT=v41_new
    when the user left it unset and attn_core_lean is requested, and logs it. Under v41_new swap-AB declines, so
    more requests and TP4 keep SGLang's V4 layout (and a default start leaves attn_core_lean off there). It does not
    depend on SGLANG_ENABLE_NV_MEGA_RUNTIME_OPTIMIZATION.
  4. Redundant experts stay the user's choice: on that configuration without --ep-num-redundant-experts the step
    logs that moe_balanced is idle and that --ep-num-redundant-experts 384 turns it on at about 47 GB more weights
    per GPU and a smaller KV pool.
  5. SGLANG_NVIDIA_MEGAKERNEL_SLOTS still replaces the list; a user-set layout is kept.
  6. docs/models/deepseek_v41.md: the default / opt-in tables and a "One request at TP8" section with the cost and gain
    of the redundant experts.
  7. Tests: test_deepseek_v41_serving.py (where the layout applies and where not, the idle note with and without the
    flag, a user-set layout kept, a slot list without the slot, registration), test_deepseek_v41_default_slots.py
    (where a default start takes each new slot, TP8 vs TP4 widths), updated status asserts in four slot tests, two
    fixtures given the layer fields the redundant-expert check reads.

Numerics change: in one-request TP8 serving a default start now runs attn_core_lean (V4.1 KV encodings, its own
split and merge order), an already declared numerics change. With --ep-num-redundant-experts 384 passed,
moe_balanced's deal runs too (also already declared). The seven newly default bitwise slots do not change outputs at
TP8 (identity below).

What the user sets

Before After
Slot list hand-written 79-80 names none
SGLANG_DSV4_KV_LAYOUT v41_new by hand chosen at --max-running-requests 1, TP8 + EP2
--ep-num-redundant-experts 384 required by hand (spec refused it on main) optional: about 47 GB more weights per GPU (52 -> 99 GB), KV pool about 28 % smaller, about 67 us less per step

Validation

The accuracy table and the unit tests were run on this branch on current main, against SGLang main. The speed numbers
were measured before the branch was updated to current main (the code under test is unchanged by the update), on an
SGLang tree with pending host-path changes. The served runs and the SGLang-main unit runs declare megakernel API
version 3 for this spec, as #85 does, because SGLang main requires it.

Accuracy

GB300, two trays, attention TP8 + MoE TP4 x EP2, one request, DSpark block 5, real acceptance, FlashInfer autotune off,
--mem-fraction-static 0.8, on SGLang main for every column.
Hand-written = the shipped slots + the opt-in ones (without hop_final_collapse) + SGLANG_DSV4_KV_LAYOUT=v41_new +
--ep-num-redundant-experts 384. This PR = no slot list, no layout.

Check Hand-written This PR + --ep-num-redundant-experts 384 This PR, no flag This PR, 2 requests
Outputs, 56 prompts, T 0 reference 56/56 identical (moe_balanced idle) (V4 layout)
Outputs, 56 prompts, seeded T 1 reference 56/56 identical
Finish reasons (20 rows) reference 20/20 identical
Acceptance length T 0 / T 1 3.2075 / 2.9630 3.2075 / 2.9630 3.2289 / 3.0057 3.0984 / 2.9945
Startup summaries (target + draft slots) reference identical moe_balanced left off attn_core_lean, moe_balanced left off
Weights per GPU 98.66 GB 98.66 GB 51.99 GB 51.99 GB
KV pool (full tokens) 140,112,896 140,112,896 194,499,840 105,971,680

The no-flag and two-request runs were made without SGLANG_ENABLE_NV_MEGA_RUNTIME_OPTIMIZATION; the layout was chosen
(and logged) in the first and not in the second.

GSM8K / passkey of this slot set were measured on the hand-written configuration (with hop_final_collapse):
GSM8K-200 0.975 (sgl-eval 0.1.3, T 0, top_p 0.95), passkey 5/5, acceptance length 3.2075 / 2.9630.

Speed

Same setup on an SGLang tree with pending host-path changes, with --mem-fraction-static 0.91, 8K-token prompts from an agentic coding trace,
temperature 1, top_p 1, top_k all, acceptance forced to 3.51 (measurement only), FlashInfer tactics pinned from a fixed
table (140 pins incl. the 384-local-expert MoE shape, 140/140 on every rank), mirrored launch order in two separate
runs, 2 + 2 launches per run, 300 timed responses per launch. Hand-written vs this PR with
--ep-num-redundant-experts 384 (same server configuration otherwise):

Metric Hand-written This PR Difference (95 %, blocked by run)
Step p50 (us) 2497.5 2497.0 -0.4 [-2.7, +1.9]
Full-response ITL (ms) 0.720 0.719 -0.002 [-0.008, +0.004]
End minus first chunk (ms) 73.7 74.4 +0.7 [-0.3, +1.7]

The only engaged difference is lm_head_pinned_tactic (in the hand-written list, opt-in here: FlashInfer tunes the BF16
LM head at startup instead); it shows no resolved step difference.

--ep-num-redundant-experts 384 with moe_balanced: about 67.3 us less per step at one request than SGLang's default
expert storage, for about 47 GB more weights per GPU. Against a default start of the plugin before this PR (default
slots, V4 layout, no redundant experts) on plain SGLang main, this slot set + layout + storage measured about 57 us per
step less (2864 -> 2807 us, FlashInfer tactics not pinned): there SGLang main's host loop bounds the step, so most of the
kernel-side saving does not show. Startup without a pin table: FlashInfer also tunes the routed MoE for 384 local
experts (about 45 s).

Attention TP4 (one tray, --tp 4 --ep-size 1, one request, same workload, 2 + 2 mirrored launches, the 140 pins plus
21-23 autotuned GEMM shapes per launch): default start with the seven TP8 slots added vs without them: client step p50
3226 / 3259 us vs 3176 / 3168 us (about +70 us, every launch with them slower than every launch without); T 0 outputs
56/56 identical, seeded T 1 0/56 identical, finish 14/20. Of the seven, attn_cluster_merge (8 local heads only) and
draft_final_collapse (no draft hop at TP4) do not build at TP4. So the seven stay TP8-only on a default start.

Unit tests

CPU, plugin test/unit on SGLang main, failing test cases from junit:

Run Failing / total Failing only on this side
main (API version 2) 157 / 1599 21: the DeepSeek-V4.1 spec tests SGLang main refuses at version 2
main with version 3 declared for this spec 136 / 1599 0
this branch with version 3 declared for this spec 136 / 1615 0

The branch's 16 added cases pass (test_deepseek_v41_serving.py 10/10, test_deepseek_v41_default_slots.py 28/28).
The 136 remaining failures are the same on both sides and fail on CPU in that environment. On the SGLang the unit CI
pins, the suite passes.

…rts 384

Root cause: with SGLang's --ep-num-redundant-experts 384 and the trivial placement
each EP rank already holds every routed expert in router-id order, but the spec
refused the flag and the routed pair took the layer's slot count (768) as the
router's expert count.

Fix: admit 384 redundant experts; the router's expert count is the slots less the
redundant ones; under moe_balanced with that layout the pair takes the rank's
storage whole (offset 0) and deals on the EP rank.

Validation: served at attention TP8 + MoE TP4 x EP2 on GB300 at one request: step
time and weights match SGLang's balanced expert storage once the four FlashInfer
tactics of the 384-local-expert MoE shape are pinned. Numerics change (the deal),
as slot moe_balanced already is.
Root cause: serving DeepSeek-V4.1 at one request, attention TP8 + MoE TP4 x EP2,
at its best needed a hand-written SGLANG_NVIDIA_MEGAKERNEL_SLOTS list (the
shipped slots plus eight opt-in ones) and SGLANG_DSV4_KV_LAYOUT=v41_new for
slot attn_core_lean. A default start ran none of those.

Fix:
- Default-on slots: attn_wo_a_fp8, attn_index_weights_bf16, attn_index_q_first,
  attn_cluster_merge, draft_stage0_first, draft_embed and draft_final_collapse
  (bitwise; TP8_DEFAULT_SLOTS: a default start takes them at attention TP8
  only; at TP4 the group measured slower and changed seeded T=1 outputs, and
  listed they still run there), and attn_core_lean (numerics change; a default
  start takes it only on SGLang's v41_new KV layout). runtime.default_takes
  holds the rule; the attention and draft builds read it, and the startup
  summary lists a default slot left off as before. draft_embed is left off,
  not refused, when the draft has its own vocabulary.
- serving.py: a resolution step SGLang runs ahead of handle_nvidia_megakernel
  (register_resolution_hook, registered by plugin.register). With the
  megakernel on, DeepSeek-V4.1 at --tp 8 --ep-size 2, --max-running-requests 1
  and no PD disaggregation, it sets SGLANG_DSV4_KV_LAYOUT=v41_new when the user
  left it unset and attn_core_lean is requested, and logs it. Any other shape
  keeps SGLang's V4 layout.
- The redundant experts stay the user's choice: on that configuration without
  --ep-num-redundant-experts the step logs that moe_balanced is idle and that
  the flag turns it on at about 47 GB more weights per GPU.
- SGLANG_NVIDIA_MEGAKERNEL_SLOTS still replaces the list; hop_final_collapse,
  lm_head_pinned_tactic, draft_lm_head_mxfp8, hop_b_cap16 and
  hop_b_quad_trigger stay opt-in.
- docs/models/deepseek_v41.md: the default and opt-in tables, and the
  one-request launch without a slot list.

Numerics change: attn_core_lean (v41_new KV encodings, its own split and merge
order) now runs by default in one-request TP8 serving; it was already a
declared numerics change.

Validation: unit tests (test_deepseek_v41_serving.py, default-slot rules) on
CPU. Served at one request on two GB300 trays: with no slot list and
--ep-num-redundant-experts 384 the startup summaries, KV pool and outputs (T=0,
seeded T=1, finish reasons) equal the hand-written configuration's and the step
time is unchanged within 2 us; without the flag the layout is chosen and
moe_balanced logs idle; two requests keep the V4 layout.
Root cause: SGLang main #52054 raised MEGAKERNEL_API_VERSION from 2 to 3
(VerifySamplingView replaces additive_penalties / scaling_penalties with
step_penalties). SGLang refuses a spec whose api_version differs, so the
DeepSeek-V4.1 spec at version 2 cannot start on SGLang main.

Fix: the DeepSeek-V4.1 package reads none of the removed fields, so only the
declared version moves; the draft spec follows spec.API_VERSION.

Validation: served on GB300 on SGLang main past #52054 with outputs identical
to version 2 on the SGLang before it. SGLang before #52054 refuses this spec.
The move of every spec to megakernel API version 3, together with the unit
tests' SGLang pin, is sgl-project#85. Declaring version 3 for one model here fails the
unit tests on the pinned SGLang, which requires version 2.
@YAMY1234

Copy link
Copy Markdown
Collaborator

This changes the DeepSeek V4.1 runtime, so it should pass the DSv4.1 e2e on SGLang CI before merging. That run cannot pass yet because SGLang main now requires megakernel API 3, which #85 adds. Once #85 is merged, could you merge main into this branch? We will then add the run-ci-sglang:deepseek_v41 label.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants