Repository navigation
[Fix] DSv4.1: Size the encoder-replay SWA pool by the DSpark draft's stages, and keep more prefix tails - #43502
Conversation
Under --enable-encoder-swa-bounded-replay with DSpark, the paged SWA pool only holds the draft's KV. The DSpark head bundled in the DeepSeek-V4.1 checkpoint inherits the target's num_hidden_layers (40), so paged_draft_layers priced each paged SWA token at 40 layers while DeepseekV4DSpark builds len(dspark_target_layer_ids) = 3 stages. The configurator reserved ~13x the bytes the draft pool allocates and shrank the full KV pool by the difference: about 3.8 GiB per GPU at the default 256 prefix tails and 30 GiB at 4096. Record the DSpark stage count and price the paged SWA by it.
…r encoder replay Under --enable-encoder-swa-bounded-replay with DSpark, the paged SWA pool only stores the draft layers, so one cached prefix tail costs num_layers_total / paged_draft_layers times less than without replay. Keep the non-replay default's byte budget and give it proportionally more tails. The 4 x max_running_requests default leaves room for 256 tails at max_running_requests=64; on AgentX traces idle conversations lose their tail within minutes, the radix match stops at the shared system prompt, and 100K-750K-token prefixes are re-prefilled while the full KV is still resident.
nvpohanh
left a comment
There was a problem hiding this comment.
[by Claude Code] Severity: style | Confidence: High
Issue
The accuracy and speed sections give the server launch command, but not the commands that produced the results, so others cannot rerun them. The description does not include:
- the GSM8K command: the eval script, the 5-shot and 50-question settings, and how the second run was sent so that it hit the prefix cache;
- the script or command for the static prefix-reuse benchmark (N 16K-token prefixes at concurrency 16, pass 1, then pass 2 in reverse order with 256 new tokens) that reports prefix hits, uncached prompt tokens, and TTFT p50.
Fix
Add both commands, or link the scripts, for the main and PR runs.
The dense DSpark draft builds num_hidden_layers stages, so len(target_layer_ids) is the stage count only for DeepseekV4ForCausalLMDSpark. Fix the class name in the field comment and cover both cases in the resolver test.
test_dsv4_paged_dspark_budget_reserves_window_and_draft_layers already checks the 3-stage price; the stage count itself is now tested in the resolver test.
|
Added both to the description. GSM8K: the exact requests our client sends (5-shot prompt, |
|
/tag-and-rerun-ci |
|
[by Claude Code] I've started babysitting the NVIDIA CI of this PR. I'll check it every 30 minutes until all NV pipelines pass. If a relevant job fails, I may rerun it, merge the latest Anyone can stop me at any time: just post a comment asking me to stop (for example, |
|
[by Claude Code] The relevant CI failure (https://github.com/sgl-project/sglang/actions/runs/38518506289/job/115709633895) is not caused by this PR. It is a known breakage on |
Picks up sgl-project#44235, which fixes the unrelated CI failure https://github.com/sgl-project/sglang/actions/runs/38518506289/job/115709633895 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
[Codex]: Running the requested targeted CI at c763dae: the pool configurator and auxiliary hidden-state resolver unit tests, plus DeepSeek-V4.1-Flash DSPARK TP4+EP4 end-to-end GSM8K and MMLU accuracy tests on 4 GB300 GPUs. The existing E2E class does not enable encoder SWA bounded replay, so it provides DSPARK runtime/accuracy regression coverage; replay pool sizing is covered by the selected unit tests. |
|
/rerun-test test/registered/unit/model_executor/test_pool_configurator.py test/registered/unit/model_executor/test_spec_aux_hidden_state_resolver.py test/registered/e2e/models/test_deepseek_v41_flash_gb300.py::TestDSV41FlashTP4EP4DSpark |
|
|
[Codex]: Retrying the requested targeted CI after the branch update to 0de0506, which includes required baseline b677851. Scope remains the pool configurator and auxiliary hidden-state resolver unit tests, plus TestDSV41FlashTP4EP4DSpark (GSM8K and MMLU on 4 GB300 GPUs). This existing E2E class does not enable encoder SWA bounded replay. |
|
/rerun-test test/registered/unit/model_executor/test_pool_configurator.py test/registered/unit/model_executor/test_spec_aux_hidden_state_resolver.py test/registered/e2e/models/test_deepseek_v41_flash_gb300.py::TestDSV41FlashTP4EP4DSpark |
|
🚀 🚀 |
|
[Codex]: Targeted CI passed at current head 0de0506.
This is targeted coverage, not full CI. The selected E2E class does not enable encoder SWA bounded replay. |
Motivation
python3 -m sglang.launch_server --model-path deepseek-ai/DeepSeek-V4.1-Flash --trust-remote-code \ --tp 4 --ep-size 4 --mem-fraction-static 0.8 --max-running-requests 64 --chunked-prefill-size 8192 \ --speculative-algorithm DSPARK --speculative-dspark-block-size 5 \ --enable-encoder-swa-bounded-replay --enable-decoder-swa-bounded-replay # startup, TP0: DSV4 SWA sizing: ... prefix_tails=256 / DSV4 memory calculation: ... swa_fixed=4.55 GB ... full_token=60815360The pool is priced at the wrong layer count.
DSV4PoolConfiguratorprices that pool atpaged_draft_layers=dflash_draft_num_layers, the draft config'snum_hidden_layers. The DSpark head bundled with DeepSeek-V4.1 inherits the target's 40.DeepseekV4ForCausalLMDSparkbuildslen(dspark_target_layer_ids)= 3 stages. The configurator therefore reserves about 13× the bytes the draft allocates and takes them out of the full KV pool: 3.8 GB per GPU at the default, 33.5 GB at--swa-prefix-tails 4096. That memory stays free after graph capture.256 prefix tails are too few for multi-turn agentic traffic.
Modifications
SpecAuxHiddenStateConfig.dspark_num_stages; the dense DSpark draft buildsnum_hidden_layersstages, so it is left unset there) and price the encoder-replay paged SWA by it, falling back todflash_draft_num_layers.--swa-prefix-tailsto4 × max_running_requests × (num_layers_total // paged_draft_layers).test_spec_aux_hidden_state_resolver.py: a 40-layer draft config with threedspark_target_layer_idsresolves to 3 stages for the DeepSeek-V4 draft and leaves the field unset for a dense DSpark draft;test_pool_configurator.py: the DSpark budget test now uses a 40-layer draft config with 3 stages; the default tails rule and its override.Accuracy Tests
Only pool sizes change. GSM8K first 50 test questions, 5-shot, greedy, launch command above; each arm runs the 50 questions cold and then again as prefix hits:
GSM8K requests (our client)
Data:
test.jsonl(first 50) andtrain.jsonlfrom openai/grade-school-math.Prompt: the first 5 train examples as
Question: …\nAnswer: …\n\n, thenQuestion: <question>\nSolve the problem. End your answer with #### followed by the numeric answer., sent as one user message rendered byencoding_dsv41.encode_messages(messages, thinking_mode="chat")and tokenized without special tokens.One request per question, 50 in flight:
POST /flush_cache, then the cold pass, then the same 50 requests again as the hit pass. Every cold response reportedmeta_info.cached_tokens == 0, and every hit responsecached_tokens >= (len(input_ids) - 1) // 256 * 256(50/50 in both arms).Score: the last number in the output (commas removed) equals the last number in the reference answer.
Unit tests on CPU:
test_pool_configurator.py56 passed,test_spec_aux_hidden_state_resolver.py4 passed. With these tests on main's source, the 4 DSpark tests fail. Results below were measured atc5130ca00ba; the later review commits only restrict the stage count to the DeepSeek-V4 draft, and this checkpoint still resolves to 3 stages.Speed Tests and Profiling
Same node, 4×GB300; each arm uses its default prefix tails. The static benchmark below adds
--enable-cache-report --enable-metrics --tokenizer-backend fastokens --served-model-name deepseek-ai/DeepSeek-V4.1-Flash --reasoning-parser auto --tool-call-parser autoto the launch command above; the startup values are the same with and without them.3831e7e0918c5130ca00baswa_fixedStatic prefix reuse: N distinct 16K-token prefixes at concurrency 16, one output token. Pass 1 caches them; pass 2 revisits them in reverse order with 256 new prompt tokens. All prefixes fit in the full KV pool in both arms.
It flushes the cache before each population, then runs N=100, N=200 and N=1000 (this PR's job reached its time limit in N=1000 pass 2, so N=1000 is not reported). Prefix hits are pass-2 requests with
cached_tokens >= 16384; uncached prompt tokens are prompt minus cached tokens; TTFT is request start to the first streamed choice, p50 linearly interpolated.static_client.py
At N=200,
--swa-prefix-tails 8192reaches 200/200 (same client, N=200 only). The remaining misses at the default come from finished requests keeping their whole last chunk of SWA (~8.7K slots per 16K prefix) instead of one window; that retention is a separate issue and is not changed here.Checklist
--swa-prefix-tailshelp text is updated; no other docs).CI States
Latest PR Test (Base): ⏳ Run #38682609361
Latest PR Test (Extra): ❌ Run #38682609286
Latest PR Test (AMD ROCm 10): ⏳ Run #38682609271