Skip to content

[Fix] dspark: Keep the real verify accept cost under simulated acceptance - #46840

Merged
kpham-sgl merged 1 commit into
sgl-project:mainfrom
weireweire:dspark-sim-real-accept-cost
Oct 29, 2026
Merged

kpham-sgl merged 1 commit into
sgl-project:mainfrom
weireweire:dspark-sim-real-accept-cost

Conversation

@weireweire

@weireweire weireweire commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

SGLANG_SIMULATE_ACC_LEN is a benchmark mode. It should change only the accepted length. Every operation real serving runs in a verify step should still run at real cost, so a simulated run's step time matches a real run at the same acceptance length.

What this PR delivers is parity in the accept region. After this change, the GPU work a simulated step does in its accept region is the real accept plus one row draw. Step time from the batch logs barely moves: at 128 running per rank, simulation is ~0.6 ms slower than real both before and after this PR. The remaining gap is in MegaMoE, most likely routing on the simulated text, which this PR does not touch.

DSpark had three paths that changed the per-step work only under simulation:

  1. Eager accept ([Perf] [NVIDIA] DSpark: Enable the simulated-acceptance fast paths on CUDA #45421). accept_and_finalize passed sampling_info=None under simulation, so a sampling batch ran AcceptGreedy (row argmax) instead of the sampling accept that real serving runs: the draft and target softmax plus the rejection kernel.
  2. Eager simulated bonus ([AMD][V4.1][*/N] Greedy dspark draft/accept under SGLANG_SIMULATE_ACC_LEN #41981). simulated_bonus_sample drew a Gumbel-max sample over the full vocabulary for all bs x (gamma+1) verify rows, then kept only the row at the simulated length. This is simulation-only work, about 6x what one row needs.
  3. Fused static accept tail under SGLANG_DSPARK_SIMULATE_FOLD (opt-in, with SGLANG_DSPARK_FUSED_ACCEPT_TAIL):
    • The verify graph skipped the row argmax that the greedy accept runs.
    • With TP > 1 and the accept-site broadcast selected (the default SGLANG_SPEC_TP_SYNC=all), real serving turns the fused tail off and runs _accept: 3 broadcasts, finalize, out-tokens and the static-buffer copies. Simulation kept the fused tail with 2 broadcasts.

Items 1 and 2 roughly cancel at large batch and do not cancel at small batch, so the error changes sign with batch size (numbers below). Fixing only item 2 would make simulation cheaper than real serving at every batch size.

Modifications

  • Eager accept. TargetVerifyExecutor.accept_and_finalize runs the accept that real serving runs, for greedy and sampling batches alike. build_accept_outs then overrides correct_len with the simulated value and draws the bonus at the simulated row, as before.
  • Simulated bonus. simulated_bonus_sample draws only the simulated row per request. It uses simulated_bonus_sample_graph, the row kernel the graph path already uses, seeded from random.getrandbits(31) as the graph path is. The all-rows kernels are removed. The only simulation-only work left in the accept is this one row draw (+73 us at 128 per rank).
  • Fused static accept tail.
    • DsparkVerifyEpilogue takes the same fused-tail decision as real serving: the tail is off whenever the accept-site broadcast is selected. Under simulate_fold with the broadcast, simulation now runs _accept like real serving and adds the in-graph row draw.
    • _static_accept_tail always computes the row argmax. Under simulate_fold the tail still takes the simulated bonus and does not read the argmax.
  • Test. test_dspark_simulated_bonus.py::test_bf16_full_vocab_low_temperature accepts any token whose logit equals the row max. bf16 logits tie at the max, and Gumbel-max may pick any tied token, while the test expected the first argmax.

SGLANG_SIMULATE_ACC_GREEDY=1 is still the explicit way to skip the sampling work. It sets the batch's sampling info to None for both the draft and the accept, but only for sampling batches that have:

  • no grammar;
  • no penalties, logit bias or custom logit processor;
  • no top-k, top-p or min-p.

Greedy requests carry top_k=1, so a mixed greedy + sampled batch also keeps the real sampling work.

What does not change:

  • The accepted length comes from the same CPU draw (sample_simulated_acc_len), so its distribution is the same as before.
  • The bonus keeps the request's sampling law: a Gumbel-max sample at the request's temperature, argmax for greedy, and unchanged top-k / top-p handling. Sampled tokens differ from before only through the RNG stream.
  • Non-simulated paths are unchanged.

AMD / HIP. Simulated runs on HIP get slower. #41981 skipped the sampling accept under simulation on HIP on purpose, and #45421 extended that skip to CUDA. With this PR the softmax and rejection kernels run under simulation on HIP too, as they do in real serving there. Set SGLANG_SIMULATE_ACC_GREEDY=1 to keep the old cost for temperature-only batches.

Other simulation-specific behavior I checked and left as is:

  • SGLANG_OPT_DSV41_DSPARK_SIM_DRAW_AHEAD only moves the simulation-only length and seed draw ahead of the draft launch. It skips no real work.
  • The sampling-accept region graph (SGLANG_OPT_DSV41_SAMPLING_ACCEPT_GRAPH) already runs the full sampling accept under simulation, then applies the simulated length and the row-c bonus. The eager path now matches it.
  • SGLANG_SIMULATE_ACC_LEN > 1 requires a verify-all schedule. A simulated run therefore cannot reproduce a deployment that trims verify windows (cap-accept, or compact with a profiled SPS table).
  • The block-accept estimator refuses to run under simulation. It is observability only.
  • Grammar: simulation commits drafts[:c] without checking them against the grammar, so a json-schema request can fail with "Grammar accept_token failed". It is not caused by this PR. On TP4 at T=1, main under simulation failed 2 of 32 requests, and this PR failed 0 of 32 in the same run and 1 of 4 in another. Every request that completed produced valid JSON.

Accuracy Tests

Existing DSpark tests on GB300:

  • test_dspark_simulated_bonus, test_dspark_accept_tail, test_dspark_sim_draw_ahead, test_dspark_sampling_accept_graph, test_dspark_kernel_parity, test_block_verification;
  • test_dspark_blockwise_rejection, test_dspark_deferred_commit, test_dspark_greedy_draft_accept, test_dspark_step_inputs_once, test_dspark_engram_commit_in_graph, test_dsv41_target_verify_metadata_glue.

Results:

  • With this PR: 64 passed.
  • Before the test fix, test_bf16_full_vocab_low_temperature failed with and without the code change (63 passed, 1 failed). The fixed test also passes against main's all-rows sampler.

GPU smoke under simulation (SGLANG_SIMULATE_ACC_LEN=2.45, one node, 4x GB300). No errors other than the grammar case above, and the outputs are coherent text:

config batches logged AL
TP4, SIMULATE_FOLD + FUSED_ACCEPT_TAIL, default TP sync (tail off, as in real serving) greedy; mixed greedy + T=1; top-p 0.9 / top-k 50; json schema (3/4 valid, 1 grammar error) 2.43 / 2.42 / 2.49 / 2.31
TP4, default env json schema x32 (32/32 valid) 2.49
TP4, SIMULATE_FOLD + FUSED_ACCEPT_TAIL, SGLANG_SPEC_TP_SYNC=rng (fused tail captured with the sim-fold bonus at every batch size) greedy; mixed greedy + T=1 2.46 / 2.48
DEP4 (DP attention, MegaMoE), default env mixed greedy + T=1; top-p / top-k; json schema (4/4 valid) 2.51 / 2.47 / 2.63

In the end-to-end runs below, the accepted length was 2.45 for real acceptance and 2.43-2.50 per phase for both simulated arms (match-expected, target 2.45).

GPU coverage:

  • Covered: the eager accept under DP attention (sampled, mixed, top-p / top-k, grammar); TP4 static verify with SIMULATE_FOLD and the fused tail on (captured, rng sync) and off (default sync); the existing unit tests. The server does not log whether a step replayed the folded accept, so folded-step coverage rests on the capture log and the outputs.
  • Not covered:
    • the sampling-accept region graph;
    • SIM_DRAW_AHEAD;
    • block-wise rejection;
    • compact verify;
    • PD disaggregation;
    • AMD.

Benchmarking and Profiling

Setup:

  • Hardware and model: GB300, DeepSeek-V4.1-Flash FP4, DSpark block 5.
  • Serving: DEP4 (TP4, DP-attention 4, EP4, MegaMoE), static verify, default env.
  • Load: chat requests at temperature 1, ignore_eos, 2048 output tokens, short prompts. All requests in a phase start together, giving 8, 32 or 128 running per rank.
  • Arms:
    • real acceptance (no simulation);
    • main under simulation;
    • this PR under simulation.
      The simulated arms use SGLANG_SIMULATE_ACC_LEN=2.45, the real run's AL.

GPU kernel time per decode step (torch profiler, 20 steps, mean of 4 ranks). Decode is GPU-bound here: kernel time is 99% of the step.

kernels (us per step) 128 / rank: real main, sim this PR, sim 8 / rank: real main, sim this PR, sim
target softmax (sampling accept) 282.2 - 281.9 26.4 - 26.2
speculative_sampling_classic_kernel 118.8 - 115.8 56.5 - 53.1
row argmax (AcceptGreedy) - 105.1 - - 8.8 -
all-rows simulated bonus - 413.8 - - 31.4 -
row-only simulated bonus - - 74.8 - - 9.2
other accept-region (rand, bonus gather, seed) 6.0 - 7.7 5.6 - 7.3
accept region total 407 519 480 89 40 96
all kernels 30,066 30,288 30,207 14,185 14,303 14,466
of which MegaMoE 16,038 16,246 16,215 8,152 8,341 8,431
all kernels minus MegaMoE 14,029 14,042 13,991 6,033 5,962 6,036
  • Main under simulation: the accept region was 112 us slower than real at 128 per rank and 48 us faster at 8 per rank.
  • This PR: the accept region is the real accept plus the one row draw (+73 us at 128, +7.7 us at 8).
  • Outside the accept region, both simulated arms spend +0.18-0.28 ms more in MegaMoE. This is most likely routing on the simulated text, and this PR does not change it. Non-MoE time is within 0.07 ms of real.

Decode step time from the batch logs (running x accept len / gen throughput, p50, mean of 4 runs: two repetitions in each of two arm orders):

running per rank real main, sim this PR, sim
8 14.14 ms 14.29 ms 14.36 ms
32 18.92 ms 19.12 ms 19.19 ms
128 30.15 ms 30.77 ms 30.76 ms

The log-based gap to real is larger than the kernel-time gap, for two reasons: the MegaMoE difference, and a smaller logged batch in the real run (requests with a higher accepted length finish earlier: 126.8 vs 128 running at the 128 point). Run-to-run spread is up to 0.21 ms per cell.

Checklist

  • Format code with pre-commit.
  • No new test file; one existing test made tie-tolerant; tests and smoke run on GPU as above.

CI States

Latest PR Test (Base): ❌ Run #40806461051
Latest PR Test (Extra): ❌ Run #40806460945
Latest PR Test (AMD ROCm 10): ❌ Run #40806461098

@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] This review is done by agents. Please feel free to disagree if they do not make sense.

@weireweire
weireweire force-pushed the dspark-sim-real-accept-cost branch from b2d6e05 to c7b0254 Compare October 28, 2026 07:01
@nvpohanh

Copy link
Copy Markdown
Collaborator

@YAMY1234 @kpham-sgl could you review this? Thanks!

@kpham-sgl kpham-sgl self-assigned this Oct 28, 2026

@kpham-sgl kpham-sgl 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.

(from Claude) One thing outside the diff: SGLANG_SIMULATE_ACC_LEN in environ.py has no comment, and #41981 and #45421 both added sim-only shortcuts. Worth a one-liner there saying simulation only changes the accepted length and every verify op still runs at real cost (SGLANG_SIMULATE_ACC_GREEDY being the opt-out)?

num_warps=8,
"""Gumbel-max temperature sample of each request's row at ``correct_len``.
[bs] int64."""
seed = torch.randint(

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.

(from Claude) Nit: this seeds from the CUDA generator, but the in-graph path (begin_sim_bonus) seeds from random.getrandbits(31). Both are fine since the bonus gets broadcast, but one seed source for both would be easier to reason about.

@kpham-sgl

Copy link
Copy Markdown
Collaborator

/rerun-test test_dspark_accept_tail.py test_dspark_engram_commit_in_graph.py test_dspark_sim_draw_ahead.py test_dspark_sampling_accept_graph.py test_dspark_deferred_commit.py test_dspark_step_inputs_once.py

@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

🚀 1-gpu-5090 (5 tests): ✅ View workflow run

cd test/ && python3 registered/unit/spec/test_dspark_accept_tail.py
cd test/ && python3 registered/unit/speculative/test_dspark_engram_commit_in_graph.py
cd test/ && python3 registered/unit/speculative/test_dspark_sampling_accept_graph.py
cd test/ && python3 registered/unit/spec/test_dspark_deferred_commit.py
cd test/ && python3 registered/unit/spec/test_dspark_step_inputs_once.py

🚀 ubuntu-latest (1 test): ✅ View workflow run

cd test/ && python3 registered/unit/spec/test_dspark_sim_draw_ahead.py

@kpham-sgl kpham-sgl 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.

Only 2 small nits from Claude

…ance

Root cause: under SGLANG_SIMULATE_ACC_LEN only the accepted length should
differ from real serving, but sim-only paths changed the per-step work:
- the eager accept ran AcceptGreedy instead of the sampling accept (draft and
  target softmax plus the rejection kernel) whenever the batch samples;
- the eager simulated bonus Gumbel-sampled all bs x (gamma+1) verify rows over
  the full vocabulary and kept only the row at the simulated length;
- with SGLANG_DSPARK_SIMULATE_FOLD and the fused accept tail, the static verify
  graph skipped the row argmax, and with TP > 1 and the accept-site broadcast
  it kept the fused tail (2 broadcasts) where real serving turns the tail off
  and runs _accept (3 broadcasts, finalize, out-tokens, buffer copies).

Fix:
- accept_and_finalize always runs the accept real serving runs, then
  build_accept_outs overrides correct_len and draws the bonus at the
  simulated row.
- simulated_bonus_sample draws only the simulated row per request through the
  row kernel the graph path already uses, seeded from random.getrandbits(31)
  as the graph path is; the all-rows kernels are removed. The only sim-only work left in the accept is that one
  row draw (+73 us at 128 running per rank).
- The fused tail decision ignores simulate_fold: it is off whenever the
  accept-site broadcast is selected, as in real serving. _static_accept_tail
  always computes the row argmax, so static_accept_tail drops the unused
  bonus_in input and takes target_predict as required.
- test_dspark_accept_tail covers the simulate_fold case: under the
  accept-site broadcast the fused tail stays off.
- environ.py states the SGLANG_SIMULATE_ACC_LEN contract: only the accepted
  length changes, and SGLANG_SIMULATE_ACC_GREEDY is the opt-out.
- test_bf16_full_vocab_low_temperature accepts any token whose logit equals
  the row max: bf16 logits tie at the max, and Gumbel-max may pick any of them.
SGLANG_SIMULATE_ACC_GREEDY=1 still skips the sampling work, for sampling
batches without grammar, penalties / logit bias / custom logit processors,
top-k, top-p or min-p. The accepted length comes from the same CPU draw and
the bonus keeps the request's sampling law, so the accept-length
distribution and the output law do not change.

AMD / HIP: simulated runs get slower. sgl-project#41981 skipped the sampling accept
under simulation on HIP on purpose; now the softmax and rejection kernels run
there too, as in real serving.

Validation (GB300, DeepSeek-V4.1-Flash FP4, DSpark block 5, DEP4 decode,
temperature 1, real AL 2.45, simulated AL 2.43-2.50 per phase). The win is
accept-region parity; batch-log step time barely moves, and the remaining
sim-vs-real gap is MoE routing on simulated text.
- Accept-region GPU kernels per step at 128 / 8 running per rank: real
  407 / 89 us, sim before 519 / 40 us, sim after 480 / 96 us (real accept
  plus the row draw).
- GPU kernel time per step at 128: real 30.07, sim before 30.29, sim after
  30.21 ms. MegaMoE is +0.18-0.28 ms in both simulated arms; non-MoE time is
  within 0.07 ms of real.
- Decode step from the batch logs at 8 / 32 / 128 per rank, two runs in each
  of two orders: real 14.1 / 18.9 / 30.2 ms, sim before 14.3 / 19.1 / 30.8 ms,
  sim after 14.4 / 19.2 / 30.8 ms; run-to-run spread up to 0.21 ms. The real
  run's logged batch is also smaller (126.8 vs 128) because requests finish
  unevenly.
- DSpark unit tests (simulated bonus, accept tail, sim draw-ahead,
  sampling-accept graph, kernel parity, block verification, blockwise
  rejection, deferred commit, greedy draft accept, step inputs, engram commit
  in graph, target-verify metadata glue): 64 passed. Before the test fix the
  bf16 case failed with and without the code change.
- After removing bonus_in and adding the simulate_fold case: accept tail,
  sim draw-ahead, sampling-accept graph, simulated bonus and kernel parity
  on one GB300: 18 passed, 28 subtests passed.
- GPU smoke under simulation, no errors and AL 2.42-2.63: TP4 with
  SIMULATE_FOLD + FUSED_ACCEPT_TAIL under the default TP sync (tail off) and
  under SGLANG_SPEC_TP_SYNC=rng (fused tail captured with the sim-fold bonus);
  DEP4 with mixed greedy + T=1, top-p / top-k and json-schema requests.
  json-schema under simulation can fail with "Grammar accept_token failed"
  because forced drafts skip the grammar; this predates the change (TP4, T=1:
  main 2/32 failed, this change 0/32 and 1/4).
- Not run on GPU: the sampling-accept region graph, SIM_DRAW_AHEAD,
  block-wise rejection, compact verify, PD disaggregation, AMD.
@weireweire
weireweire force-pushed the dspark-sim-real-accept-cost branch from c7b0254 to a39f233 Compare October 29, 2026 02:27
@kpham-sgl

Copy link
Copy Markdown
Collaborator

/rerun-test test_dspark_accept_tail.py test_dspark_engram_commit_in_graph.py test_dspark_sim_draw_ahead.py test_dspark_sampling_accept_graph.py test_dspark_deferred_commit.py test_dspark_step_inputs_once.py

@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

🚀 1-gpu-5090 (5 tests): ✅ View workflow run

cd test/ && python3 registered/unit/spec/test_dspark_accept_tail.py
cd test/ && python3 registered/unit/speculative/test_dspark_engram_commit_in_graph.py
cd test/ && python3 registered/unit/speculative/test_dspark_sampling_accept_graph.py
cd test/ && python3 registered/unit/spec/test_dspark_deferred_commit.py
cd test/ && python3 registered/unit/spec/test_dspark_step_inputs_once.py

🚀 ubuntu-latest (1 test): ✅ View workflow run

cd test/ && python3 registered/unit/spec/test_dspark_sim_draw_ahead.py

@kpham-sgl
kpham-sgl merged commit 3a01d4c into sgl-project:main Oct 29, 2026
111 of 128 checks passed
weireweire added a commit to SemiAnalysisAI/InferenceX that referenced this pull request Nov 1, 2026
…e simulated verify accept cost fix

Root cause: nightly-dev-cu13-20261029-c10e0e17 predates sgl-project/sglang#46840,
so simulated acceptance skipped the real verify accept cost and the TP4 c1 point
was not measured on the methodology-conformant path.

Fix: pin lmsysorg/sglang:nightly-dev-cu13-20261030-302b78cc by digest. It is
63 commits past the #46840 merge and bundles the same sgl-nvidia-mega
54b428921749 (megakernel API 2). Update this PR's changelog entry to name the image
and #46840.

Validation: Dynamo + SGLang TP4 c1 megakernel, c4 and c16 started and completed
on 302b78cc with target and draft megakernels active on all four ranks.
nvpohanh added a commit to SemiAnalysisAI/InferenceX that referenced this pull request Nov 3, 2026
…ly with the tuned low-latency settings and TP4 c1 megakernel / [NVIDIA][AgentX] GB300 DSV4.1-Flash SGLang 升级到 20261030 nightly,采用调优后的低延迟配置并在 TP4 c1 启用 megakernel (#4603)

* Update GB300 DSV4.1-Flash SGLang AgentX image to nightly-dev-cu13-20261025-65633129

Move dsv41flash-fp4-gb300-sglang-agentic-dspark from nightly-dev-cu13-20261021-c1c287a4 to the digest-pinned nightly-dev-cu13-20261025-65633129, the image the Dynamo + SGLang agg key already uses. Recipes and search space are unchanged.

* Set perf-changelog pr-link to #4603

* Move GB300 DSV4.1-Flash SGLang AgentX to 20261028 nightly with the tuned low-latency settings

Use nightly-dev-cu13-20261028-586355a8, which includes sgl-project/sglang#46404 and #46891. TP4 c1 runs as the batch-1 NVIDIA megakernel point of the Dynamo + SGLang aggregated row, without SIM_DRAW_AHEAD so the simulated step does the same work as a real one. TP4 c4/c16 and TP2/EP2 c16/c32 pin the flashmla attention backend instead of auto (MegaAttention pads per-rank heads to 64).

* Keep SIM_DRAW_AHEAD on the TP4 c1 megakernel point

The gate only moves the simulated-acceptance draw, a host-side sample plus a fill that real acceptance never runs, ahead of the draft launch. It does not skip work that a real-acceptance step performs.

* Keep TP4 c1 off the megakernel until the image ships a megakernel API 2 plugin

nightly-dev-cu13-20261028-586355a8 bundles sgl-nvidia-mega 6fd7ac30 (megakernel API 1), while its SGLang requires API 2 since sgl-project/sglang#45266, so --enable-nvidia-megakernel fails at startup. TP4 c1 keeps its previous engine settings and pins flashmla like the other TP-sharded points.

* Move the GB300 DSV4.1-Flash SGLang curve to the 20261029 nightly and run TP4 c1 on the megakernel

nightly-dev-cu13-20261029-c10e0e17 bundles sgl-nvidia-mega 54b428921749
(megakernel API 2), so TP4 c1 returns to its megakernel config. The 16
runtime-optimization variables it set one by one are replaced by
SGLANG_ENABLE_NV_MEGA_RUNTIME_OPTIMIZATION (sgl-project/sglang#47105).

* Move the GB300 DSV4.1-Flash SGLang key to the 20261030 nightly for the simulated verify accept cost fix

Root cause: nightly-dev-cu13-20261029-c10e0e17 predates sgl-project/sglang#46840,
so simulated acceptance skipped the real verify accept cost and the TP4 c1 point
was not measured on the methodology-conformant path.

Fix: pin lmsysorg/sglang:nightly-dev-cu13-20261030-302b78cc by digest. It is
63 commits past the #46840 merge and bundles the same sgl-nvidia-mega
54b428921749 (megakernel API 2). Update this PR's changelog entry to name the image
and #46840.

Validation: Dynamo + SGLang TP4 c1 megakernel, c4 and c16 started and completed
on 302b78cc with target and draft megakernels active on all four ranks.

---------

Co-authored-by: weireweire <[email protected]>
Co-authored-by: Po-Han Huang <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants