Skip to content

[DSpark] Fold draft sampling for DeepSeek-V4.1 heads under AUTO - #42987

Merged
hnyls2002 merged 2 commits into
sgl-project:mainfrom
weireweire:dspark-v41-auto-fold-sampling
Oct 9, 2026
Merged

hnyls2002 merged 2 commits into
sgl-project:mainfrom
weireweire:dspark-v41-auto-fold-sampling

Conversation

@weireweire

@weireweire weireweire commented Oct 7, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

SGLANG_DSPARK_FOLDED_SAMPLING=AUTO (the default) folds the draft sampling step into the draft CUDA graph when its static buffers fit in memory. One head type is excluded: any markov head with supports_sharded_greedy (DeepSeek-V4.1 under TP). For these heads AUTO always returns False, so every non-greedy batch runs the draft proposal eagerly.

This costs a lot at low concurrency. At TP4 c1 with temperature 1.0, median TPOT is 2.35 ms with AUTO and 1.51 ms with FORCE. The exception was meant to keep the compact sharded argmax for greedy batches, but in our measurements that only saves a few percent.

The exception also applies under DP attention with --enable-dp-lm-head. There the lm-head shard group has size 1, so the sharded argmax saves nothing, yet sampled batches still go eager.

Modifications

  • _resolve_folded_sampling: remove the supports_sharded_greedy exception. AUTO now decides on free memory alone for every DSpark head. When sampling is folded, greedy batches go through the general in-graph block sampler instead of the sharded argmax.
  • The unit test now checks that AUTO folds when the buffers fit and stays eager when they don't, with and without a sharded-greedy head, and that FORCE always folds.

Capturing both the sharded-greedy graph and the folded-sampling graph would recover the greedy-only cost (1-4%, see below). That adds a second draft graph per batch size, so it is left out of this PR.

Accuracy Tests

No change to the sampling math. FORCE mode already runs this exact path for V4.1. DeepSeek-V4.1-Flash on GB300 with SGLANG_DSPARK_FOLDED_SAMPLING=2 (FORCE) scores 0.975 GSM8K strict-match.

Speed Tests and Profiling

Setup

  • Hardware and model: GB300, DeepSeek-V4.1-Flash (FP4), DSpark gamma 5.
  • Workload: sglang.benchmark.serving, random 2048 in / 1024 out, range ratio 1, simulated acceptance length 3.51.
  • Runs: 2 repetitions per point.
  • Metric: median TPOT in ms, AUTO (before this PR) → FORCE (behavior after this PR). Lower is better.
  • DP2 config: --tp 2 --dp 2 --enable-dp-attention --enable-dp-lm-head.

Sampled traffic (temperature 1.0)

conc TP4 TP2 DP2
1 2.35 → 1.51 (-36%) 2.32 → 2.11 (-9%)
4 2.46 → 2.20 (-11%) 3.45 → 3.28 (-5%)
16 3.53 → 3.49 (-1%) 6.89 → 6.78 (-2%) 7.22 → 7.06 (-2%)
64 6.06 → 6.13 / 6.03 → 6.28 (noisy) 10.80 → 10.16 / 11.02 → 10.76 (-2 to -6%) 11.15 → 10.52 (-6%)
128 9.42 → 9.44 (0%) 11.04 → 10.75 (-3%) 11.91 → 11.40 (-4%)
256 15.22 → 15.19 (0%) 11.28 → 10.57 (-6%)

Greedy traffic (temperature 0)

conc TP4 TP2 DP2
1 1.42 → 1.44 (+1%) 2.05 → 2.07 (+1%)
4 2.12 → 2.15 (+1%) 3.32 → 3.20 (-4%)
16 3.36 → 3.43 (+2%) 6.59 → 6.65 (+1%) 6.98 → 7.11 (+2%)
64 6.02 → 6.12 / 6.27 → 6.57 (+2 to +5%) 10.43 → 10.00 / 10.68 → 10.55 (-1 to -4%) 10.90 → 10.35 (-5%)
128 8.94 → 9.28 (+4%) 11.71 → 11.80 (noisy, ~0%) 11.84 → 11.80 (0%)
256 14.20 → 14.82 (+4%) 10.95 → 10.53 (-4%)

Cells with two pairs come from two separate sessions.

Summary

  • Sampled traffic gains the most at low concurrency: TP4 c1 throughput rises about 49%. Under DP attention it gains 2-6% at every concurrency tested.
  • Greedy traffic under TP pays 1-4% TPOT, mostly at TP4 c64-c256, which is the cost of dropping the sharded argmax. Under DP attention the sharded path is not faster, and usually we use DP at high concurrency, so greedy is neutral or better.

Checklist


CI States

Latest PR Test (Base): ✅ Run #37744383637
Latest PR Test (Extra): ❌ Run #37744383359
Latest PR Test (AMD ROCm 10): ❌ Run #37744383595

Root cause: _resolve_folded_sampling returned False for any markov head with
supports_sharded_greedy, so on DeepSeek-V4.1 the default AUTO mode never
folded sampling into the draft CUDA graph. Every non-greedy batch then ran the
draft proposal eagerly. The head also reports sharded greedy under DP
attention with dp-lm-head, where the shard group has size 1 and the sharded
argmax saves nothing.

Fix: drop the V4.1 exception, so AUTO decides on free memory alone, as for
every other DSpark head. Greedy batches on a folded graph use the general
block sampler instead of the sharded argmax.

Validation: GB300, DeepSeek-V4.1-Flash, random 2k in / 1k out, AUTO vs FORCE.
Sampled (temperature 1.0) median TPOT: up to 36% lower at TP4 c1, 2-6% lower
under DP attention (c16-c256). Greedy median TPOT: 1-4% higher at TP (worst
at TP4 c64-c256), between 5% lower and 2% higher under DP attention.
Unit test updated; pre-commit passes.
@weireweire
weireweire force-pushed the dspark-v41-auto-fold-sampling branch from 44e55a9 to f3d5c02 Compare October 7, 2026 15:43
@nvpohanh

nvpohanh commented Oct 8, 2026

Copy link
Copy Markdown
Collaborator

cc @Oasis-Git

@nvpohanh nvpohanh left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[by Claude Code] Severity: style | Confidence: High

Issue

The speed and accuracy results do not have enough detail to rerun them:

  • There is no server launch command for the TP4 and TP2 runs. The DP2 line lists only the parallel flags, not the DSpark flags or env vars.
  • The description does not say how the 3.51 acceptance length was simulated (the SGLANG_SIMULATE_ACC_* env vars, and the SGLANG_RAGGED_VERIFY_MODE they require).
  • There is no sglang.benchmark.serving command (number of prompts, --max-concurrency, and how temperature is set).
  • The GSM8K 0.975 result has no eval command, GPU count, parallel config, or temperature.

Fix

Add the full server launch commands (with env vars) and the benchmark and eval commands to the description.

@Oasis-Git

Copy link
Copy Markdown
Collaborator

We also noticed that enable SGLANG_DSPARK_FOLDED_SAMPLING=2 is important in low latency. This should be a good change. also cc @hnyls2002 I think we should enable it by default now

@weireweire

Copy link
Copy Markdown
Collaborator Author

/tag-and-rerun-ci

@github-actions github-actions Bot added the run-ci CI: run the baseline test suite on this PR label Oct 8, 2026
@nvpohanh

nvpohanh commented Oct 8, 2026

Copy link
Copy Markdown
Collaborator

/rerun-failed-ci

@nvpohanh

nvpohanh commented Oct 8, 2026

Copy link
Copy Markdown
Collaborator

/rerun-failed-ci

@nvpohanh

nvpohanh commented Oct 8, 2026

Copy link
Copy Markdown
Collaborator

[by Claude Code] All NV pipelines have passed.

@nvpohanh

nvpohanh commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator

@Oasis-Git @hnyls2002 could we merge this? Thanks!

@hnyls2002
hnyls2002 merged commit 46c2585 into sgl-project:main Oct 9, 2026
402 of 488 checks passed
zozyo added a commit to Phala-Network/sglang that referenced this pull request Oct 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run-ci CI: run the baseline test suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants