Skip to content

[AMD][V4.1][*/N] Greedy dspark draft/accept under SGLANG_SIMULATE_ACC_LEN - #41981

Merged
HaiShaw merged 6 commits into
sgl-project:mainfrom
RolaoDenthu:dsv41/dspark-sample
Oct 1, 2026
Merged

HaiShaw merged 6 commits into
sgl-project:mainfrom
RolaoDenthu:dsv41/dspark-sample

Conversation

@1am9trash

@1am9trash 1am9trash commented Oct 1, 2026 •

Copy link
Copy Markdown
Collaborator

co-authored-by: @kkHuang-amd

Motivation

When SGLANG_SIMULATE_ACC_LEN is set, dspark overwrites correct_len with 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.

# python/sglang/srt/speculative/dspark_components/dspark_verify.py
# sampling accept
correct_len, bonus, cap_trim_lens = accept_draft_tokens(
    ...
)
# correct_len is overwritten right away
if self._simulate_acc_len > 0:
    correct_len = self._simulated_correct_len(
        bs=bs, dtype=correct_len.dtype, device=correct_len.device
    )

Modifications

All changes only take effect on HIP with SGLANG_SIMULATE_ACC_LEN set.
No impact on the NV code path.

  • Accept: For non-greedy requests, draft softmax, target softmax, and rejection sampling are no longer run. All requests take AcceptGreedy only.
  • Draft: With SGLANG_SIMULATE_ACC_GREEDY on (default), draft temperature sampling is no longer run for requests without grammar, penalties, top-p, top-k, or min-p. Other requests are unchanged.
  • Bonus: For those draft requests, the bonus token is now temperature-sampled from the target-logit row at the simulated correct_len.
  • Env var gate: adds SGLANG_SIMULATE_ACC_GREEDY (default on) to turn off the greedy draft/accept path for temperature-only requests.

Accuracy Tests

  • Unit test test_dspark_simulated_bonus.py passed.
  • GSM8K (without simulation, on top of main): 0.906.

Speed Tests and Profiling

Agentic workload:

  • ds-v4.1-flash, TP2
  • conc: 1
  • temperature:1.0 (>0)
  • SGLANG_SIMULATE_ACC_LEN > 0
Before After
TTT 10,306 10,970 (+6.4%)
P90 interactivity 292.8 317.5 (+8.4%)

Checklist

Review and Merge Process

  1. Ping Merge Oncalls to start the process. See the PR Merge Process.
  2. Get approvals from CODEOWNERS and other reviewers.
  3. Trigger CI tests with comments or contact authorized users to do so.
    • Common commands include /tag-and-rerun-ci, /tag-run-ci-label, /rerun-failed-ci
  4. After green CI and required approvals, ask Merge Oncalls or people with Write permission to merge the PR.

CI States

Latest PR Test (Base): ❌ Run #36810760352
Latest PR Test (Extra): ❌ Run #36825391412
Latest PR Test (AMD ROCm 10): ❌ Run #36810760206

1am9trash and others added 5 commits October 1, 2026 02:24
…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 1am9trash added amd run-ci CI: run the baseline test suite on this PR labels Oct 1, 2026

@HaiShaw HaiShaw 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.

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

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.

accept_sampling_info can be None above?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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:

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.

this condition only valid to hip?

@1am9trash 1am9trash Oct 1, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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
HaiShaw merged commit d669efb into sgl-project:main Oct 1, 2026
128 of 155 checks passed
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.
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants