Repository navigation
[AMD][V4.1][*/N] Greedy dspark draft/accept under SGLANG_SIMULATE_ACC_LEN - #41981
Merged
Merged
Conversation
…N, temperature-sampled bonus With a simulated acceptance length the sampling accept result is overwritten, so temperature-only sampling requests now run the greedy draft + greedy accept path and only the bonus token is temperature-sampled (Gumbel-max over every verify row in a two-stage Triton kernel). Grammar, penalties and top-p/top-k/min-p keep the full path. Knob: SGLANG_SIMULATE_ACC_GREEDY (default on). AgentX TP2 c1 (default temperature 1.0): 10,306 -> 10,970 TTT, P90 interactivity 292.8 -> 317.5; GSM8K (no simulation) 0.899. Co-authored-by: Cursor <[email protected]>
1am9trash
requested review from
BBuf,
DarkSharpness,
HaiShaw,
HydraQYH,
Qiaolin-Yu,
Ying1123,
celve,
hnyls2002,
merrymercy and
yuan-luo
as code owners
October 1, 2026 03:29
HaiShaw
reviewed
Oct 1, 2026
HaiShaw
left a comment
Collaborator
There was a problem hiding this comment.
nit: a few code clarification / comment questions
| site = ( | ||
| SpecTpSyncSite.DSPARK_ACCEPT_GREEDY | ||
| if sampling_info is None or sampling_info.is_all_greedy | ||
| if accept_sampling_info is None or accept_sampling_info.is_all_greedy |
Collaborator
There was a problem hiding this comment.
accept_sampling_info can be None above?
Collaborator
Author
There was a problem hiding this comment.
Yeah.
# Line 170
accept_sampling_info = None if simulate and _is_hip else sampling_info
| correct_len = self._simulated_correct_len( | ||
| bs=bs, dtype=correct_len.dtype, device=correct_len.device | ||
| ) | ||
| if simulate_bonus_sampling_info is not None: |
Collaborator
There was a problem hiding this comment.
this condition only valid to hip?
Collaborator
Author
There was a problem hiding this comment.
Yeah, simulate_bonus_sampling_info may always be None on nv code path.
# dspark_worker_v2.py, Line 851
simulate_bonus_sampling_info = None
if (
...... # conditions, including hip check
):
simulate_bonus_sampling_info = sampling_info
HaiShaw
approved these changes
Oct 1, 2026
jhinpan
added a commit
to jhinpan/sglang-fork
that referenced
this pull request
Oct 1, 2026
Resolve conflicts with sgl-project#41981 (greedy DSpark draft/accept under SGLANG_SIMULATE_ACC_LEN): accept_and_finalize takes both the per-step verify_width/epilogue and simulate_bonus_sampling_info, and the simulated bonus reads target_logits at the step's verify width like the rest of the eager accept.
4 of 5 tasks
4 of 5 tasks
This was referenced Oct 3, 2026
2 tasks done
weireweire
added a commit
to weireweire/sglang
that referenced
this pull request
Oct 29, 2026
…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.
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.
co-authored-by: @kkHuang-amd
Motivation
When
SGLANG_SIMULATE_ACC_LENis set, dspark overwritescorrect_lenwith the simulated value right after verify. But the draft and accept steps still go through the full sampling path, and most of that result is thrown away. The only thing we still need from it is the bonus token, which should keep following the request's temperature.Modifications
All changes only take effect on HIP with
SGLANG_SIMULATE_ACC_LENset.No impact on the NV code path.
SGLANG_SIMULATE_ACC_GREEDYon (default), draft temperature sampling is no longer run for requests without grammar, penalties, top-p, top-k, or min-p. Other requests are unchanged.correct_len.SGLANG_SIMULATE_ACC_GREEDY(default on) to turn off the greedy draft/accept path for temperature-only requests.Accuracy Tests
test_dspark_simulated_bonus.pypassed.Speed Tests and Profiling
Agentic workload:
SGLANG_SIMULATE_ACC_LEN> 0Checklist
Review and Merge Process
/tag-and-rerun-ci,/tag-run-ci-label,/rerun-failed-ciCI States
Latest PR Test (Base): ❌ Run #36810760352
Latest PR Test (Extra): ❌ Run #36825391412
Latest PR Test (AMD ROCm 10): ❌ Run #36810760206