Skip to content

[Refactor] speculative: Describe verify accepts with VerifyAccept and commit them in one call - #52164

Merged
hnyls2002 merged 4 commits into
mainfrom
lsyin/spec-accept-commit
Nov 22, 2026
Merged

hnyls2002 merged 4 commits into
mainfrom
lsyin/spec-accept-commit

Conversation

@hnyls2002

@hnyls2002 hnyls2002 commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

Stacked on #52158.

Motivation

After a speculative verify, two pieces of per-request device state learn which tokens were committed: the penalty history (StepPenalties) and the watermark context. Each spec worker wired this by hand with four differently shaped calls:

  • commit_accept_tokens_to_penalties (EAGLE, NGRAM) and commit_block_accept_tokens_to_penalties (DFlash, DSpark);
  • VerifyWatermark.record, called from inside eagle_sample for EAGLE and NGRAM and from the DSpark worker;
  • WatermarkEngine.append_accept_tokens, which EAGLE, NGRAM and DSpark reached through model_runner.watermark, each at a different point of its verify.

A new spec worker had to know all four, and in which order to call them.

Modifications

  • New sampling/verify_accept.py:
    • VerifyAccept, a frozen msgspec.Struct, describes what a verify accepted: tokens, accept_lens, and an accept_index. A tree verify passes its flat predictions and the accept_index into them. A chain verify passes its [bs, width] blocks and no index.
    • commit_verify_accept(sampling_info, accept, *, watermark) commits the accept to the penalty history, then to the watermark.
  • VerifyWatermark.record(accept_index, accept_lens) becomes VerifyWatermark.commit(accept). It records the forced contexts and appends the accepted tokens, so WatermarkEngine.append_accept_tokens is removed. SynthIDVerify keeps the req_pool_indices of its apply, as GumbelVerify already did.
  • eagle_sample no longer records the watermark. EAGLE, NGRAM, DFlash and DSpark each call commit_verify_accept once, right after acceptance. No worker calls model_runner.watermark to commit anymore.
  • Removed commit_accept_tokens_to_penalties and commit_block_accept_tokens_to_penalties.

Behavior changes

None. Penalty counts, watermark state and outputs are unchanged:

  • The tree verify's penalty commit gathers tokens[accept_index] instead of tokens[accept_index.clamp(min=0)]. The two differ only at -1 pads, which the accept mask drops in both the kernel and the torch fallback.
  • The watermark append now runs at the commit point instead of after the mamba and KV bookkeeping. That work reads predict, accept_index and accept_lens without writing them and touches no watermark state. The append runs on the same stream.
  • An idle EAGLE batch has no watermark rows and no penalties, so the commit does nothing there, as before.

Accuracy Tests

  • test_verify_penalty_commit.py commits a tree accept and a chain accept through commit_verify_accept. It checks the penalty counts and that the watermark receives the same accept. The tree case puts a token in the -1 pad slot to check that it is not counted.
  • The SynthID adapter test and the Gumbel watermark-state kernel tests commit through VerifyWatermark.commit.
  • The unit tests in sampling, spec and speculative, the verify penalty and SynthID kernel tests, and the related scheduler, kernel-plugin and model-executor tests pass, except failures that also fail on main.

Checklist

  • Unit tests updated.

CI States

Latest PR Test (Base): ⊘ Skipped -- add the run-ci label to run CI tests.
Latest PR Test (Extra): ⊘ Skipped -- add the run-ci label to run CI tests.
Latest PR Test (AMD ROCm 10): ⊘ Skipped -- add the run-ci label to run CI tests.

Tip

Base CI only covers the core cases, and its workload may not exercise your change. Use /rerun-test to run the tests your change touches, or copy this prompt for an agent:

Find the registered tests this PR affects and run them with /rerun-test, following https://github.com/sgl-project/sglang/blob/main/.agents/skills/rerun-test/SKILL.md

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.

Tip: disable this comment in your organization's Code Review settings.

@hnyls2002

Copy link
Copy Markdown
Collaborator Author

/rerun-test test_verify_penalty_commit.py test_verify_penalty_paths.py test_verify_penalties.py test_watermark_state.py registered/kernels/ops/sampling/test_synthid.py test_synthid_adapter.py test_watermark.py test_synthid_watermark.py test_spec_eagle.py test_spec_eagle_topk.py test_spec_ngram.py test_dflash.py test_dspark_simulated_bonus.py

@github-actions

github-actions Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

🚀 ubuntu-latest (3 tests): ✅ View workflow run

cd test/ && python3 registered/unit/spec/test_verify_penalty_commit.py  # base-a
cd test/ && python3 registered/unit/spec/test_verify_penalty_paths.py  # base-a
cd test/ && python3 registered/unit/sampling/test_synthid_adapter.py  # base-a

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

cd test/ && python3 registered/kernels/ops/sampling/test_verify_penalties.py  # base-b-kernel-unit
cd test/ && python3 registered/kernels/ops/sampling/test_watermark_state.py  # base-b-kernel-unit
cd test/ && python3 registered/e2e/openai_server/test_watermark.py  # extra-a
cd test/ && python3 registered/e2e/openai_server/test_synthid_watermark.py  # extra-a
cd test/ && python3 registered/spec/eagle/test_spec_eagle.py  # base-b
cd test/ && python3 registered/spec/eagle/test_spec_eagle_topk.py  # extra-a
cd test/ && python3 registered/spec/dflash/test_dflash.py  # extra-a
cd test/ && python3 registered/spec/dspark/test_dspark_simulated_bonus.py  # base-b

🚀 1-gpu-h100 (2 tests): ✅ View workflow run

cd test/ && python3 registered/kernels/ops/sampling/test_synthid.py  # base-b-kernel-unit
cd test/ && python3 registered/spec/test_spec_ngram.py  # base-b

@hnyls2002

Copy link
Copy Markdown
Collaborator Author

/run-cpu-ci

@github-actions

github-actions Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

🚀 Running base-a-test-cpu on b70633bf1527: ❌ View workflow run

Base automatically changed from lsyin/watermark-step-rows to main November 22, 2026 07:26
@hnyls2002

Copy link
Copy Markdown
Collaborator Author

/run-cpu-ci

@github-actions

github-actions Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

🚀 Running base-a-test-cpu on 1724c34ce9b9: ✅ View workflow run

# Conflicts:
#	python/sglang/srt/speculative/dflash_worker_v2.py
#	python/sglang/srt/speculative/dspark_components/dspark_worker_v2.py
@hnyls2002

Copy link
Copy Markdown
Collaborator Author

/run-cpu-ci

@github-actions

github-actions Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

🚀 Running base-a-test-cpu on a60df0d8f3b1: ✅ View workflow run

@hnyls2002 hnyls2002 changed the title [Refactor] speculative: Commit accepted tokens through one hook [Refactor] speculative: Describe verify accepts with VerifyAccept and commit them in one call Nov 22, 2026
@hnyls2002
hnyls2002 merged commit 83b892e into main Nov 22, 2026
131 of 133 checks passed
@hnyls2002
hnyls2002 deleted the lsyin/spec-accept-commit branch November 22, 2026 08:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant