Repository navigation
[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
Open
weireweire wants to merge 4 commits into
weireweire wants to merge 4 commits into
Conversation
…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.
Oasis-Git
approved these changes
Nov 24, 2026
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_SLOTSlist (the shipped slots plus eight opt-in ones),SGLANG_DSV4_KV_LAYOUT=v41_newfor slot
attn_core_lean, and--ep-num-redundant-experts 384for slotmoe_balanced, which the spec refused.A default start ran none of those. With this PR the launch needs
--enable-nvidia-megakerneland--max-running-requests 1;--ep-num-redundant-experts 384is 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
moe/routed.py,spec.py): the spec admitsep_num_redundant_experts0 or 384; therouter'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_balancedtakes the rank's storage whole and deals on its EP rank.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 asTP8_DEFAULT_SLOTS: a default starttakes 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'sv41_newKV layout,the only layout its build serves steps on.
runtime.default_takesholds the rule; the target attention build and the draft build read it; the startupsummary lists a default slot left off as before.
draft_embedis left off, not refused, when the draft has itsown vocabulary.
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.serving.py, registered byplugin.register): a resolution step SGLang runs ahead ofhandle_nvidia_megakernel(register_resolution_hook). With the megakernel on, DeepSeek-V4.1 at--tp 8 --ep-size 2,--max-running-requests 1and no PD disaggregation, it setsSGLANG_DSV4_KV_LAYOUT=v41_newwhen the user left it unset and
attn_core_leanis requested, and logs it. Underv41_newswap-AB declines, somore requests and TP4 keep SGLang's V4 layout (and a default start leaves
attn_core_leanoff there). It does notdepend on
SGLANG_ENABLE_NV_MEGA_RUNTIME_OPTIMIZATION.--ep-num-redundant-expertsthe steplogs that
moe_balancedis idle and that--ep-num-redundant-experts 384turns it on at about 47 GB more weightsper GPU and a smaller KV pool.
SGLANG_NVIDIA_MEGAKERNEL_SLOTSstill replaces the list; a user-set layout is kept.docs/models/deepseek_v41.md: the default / opt-in tables and a "One request at TP8" section with the cost and gainof the redundant experts.
test_deepseek_v41_serving.py(where the layout applies and where not, the idle note with and without theflag, 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 ownsplit and merge order), an already declared numerics change. With
--ep-num-redundant-experts 384passed,moe_balanced's deal runs too (also already declared). The seven newly default bitwise slots do not change outputs atTP8 (identity below).
What the user sets
SGLANG_DSV4_KV_LAYOUTv41_newby hand--max-running-requests 1, TP8 + EP2--ep-num-redundant-experts 384Validation
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.--ep-num-redundant-experts 384moe_balancedleft offattn_core_lean,moe_balancedleft offThe 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):The only engaged difference is
lm_head_pinned_tactic(in the hand-written list, opt-in here: FlashInfer tunes the BF16LM head at startup instead); it shows no resolved step difference.
--ep-num-redundant-experts 384withmoe_balanced: about 67.3 us less per step at one request than SGLang's defaultexpert 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 plus21-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) anddraft_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/uniton SGLang main, failing test cases from junit:The branch's 16 added cases pass (
test_deepseek_v41_serving.py10/10,test_deepseek_v41_default_slots.py28/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.