Repository navigation
[Fix] dspark: Keep the real verify accept cost under simulated acceptance - #46840
Conversation
nvpohanh
left a comment
There was a problem hiding this comment.
[by Claude Code] This review is done by agents. Please feel free to disagree if they do not make sense.
b2d6e05 to
c7b0254
Compare
|
@YAMY1234 @kpham-sgl could you review this? Thanks! |
kpham-sgl
left a comment
There was a problem hiding this comment.
(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( |
There was a problem hiding this comment.
(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.
|
/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 |
|
🚀 🚀 |
kpham-sgl
left a comment
There was a problem hiding this comment.
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.
c7b0254 to
a39f233
Compare
|
/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 |
|
🚀 🚀 |
…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.
…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]>
Motivation
SGLANG_SIMULATE_ACC_LENis 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:
accept_and_finalizepassedsampling_info=Noneunder simulation, so a sampling batch ranAcceptGreedy(row argmax) instead of the sampling accept that real serving runs: the draft and target softmax plus the rejection kernel.simulated_bonus_sampledrew 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.SGLANG_DSPARK_SIMULATE_FOLD(opt-in, withSGLANG_DSPARK_FUSED_ACCEPT_TAIL):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
TargetVerifyExecutor.accept_and_finalizeruns the accept that real serving runs, for greedy and sampling batches alike.build_accept_outsthen overridescorrect_lenwith the simulated value and draws the bonus at the simulated row, as before.simulated_bonus_sampledraws only the simulated row per request. It usessimulated_bonus_sample_graph, the row kernel the graph path already uses, seeded fromrandom.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).DsparkVerifyEpiloguetakes the same fused-tail decision as real serving: the tail is off whenever the accept-site broadcast is selected. Undersimulate_foldwith the broadcast, simulation now runs_acceptlike real serving and adds the in-graph row draw._static_accept_tailalways computes the row argmax. Undersimulate_foldthe tail still takes the simulated bonus and does not read the argmax.test_dspark_simulated_bonus.py::test_bf16_full_vocab_low_temperatureaccepts 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=1is still the explicit way to skip the sampling work. It sets the batch's sampling info toNonefor both the draft and the accept, but only for sampling batches that have:Greedy requests carry top_k=1, so a mixed greedy + sampled batch also keeps the real sampling work.
What does not change:
sample_simulated_acc_len), so its distribution is the same as before.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=1to keep the old cost for temperature-only batches.Other simulation-specific behavior I checked and left as is:
SGLANG_OPT_DSV41_DSPARK_SIM_DRAW_AHEADonly moves the simulation-only length and seed draw ahead of the draft launch. It skips no real work.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 > 1requires 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).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:
test_bf16_full_vocab_low_temperaturefailed 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:SIMULATE_FOLD+FUSED_ACCEPT_TAIL, default TP sync (tail off, as in real serving)SIMULATE_FOLD+FUSED_ACCEPT_TAIL,SGLANG_SPEC_TP_SYNC=rng(fused tail captured with the sim-fold bonus at every batch size)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:
SIMULATE_FOLDand 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.SIM_DRAW_AHEAD;Benchmarking and Profiling
Setup:
ignore_eos, 2048 output tokens, short prompts. All requests in a phase start together, giving 8, 32 or 128 running per rank.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.
speculative_sampling_classic_kernelAcceptGreedy)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):
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
CI States
Latest PR Test (Base): ❌ Run #40806461051
Latest PR Test (Extra): ❌ Run #40806460945
Latest PR Test (AMD ROCm 10): ❌ Run #40806461098