Repository navigation
[Refactor] speculative: Describe verify accepts with VerifyAccept and commit them in one call - #52164
Conversation
There was a problem hiding this comment.
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.
|
/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 |
|
🚀 🚀 🚀 |
|
/run-cpu-ci |
|
🚀 Running |
|
/run-cpu-ci |
|
🚀 Running |
# Conflicts: # python/sglang/srt/speculative/dflash_worker_v2.py # python/sglang/srt/speculative/dspark_components/dspark_worker_v2.py
|
/run-cpu-ci |
|
🚀 Running |
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) andcommit_block_accept_tokens_to_penalties(DFlash, DSpark);VerifyWatermark.record, called from insideeagle_samplefor EAGLE and NGRAM and from the DSpark worker;WatermarkEngine.append_accept_tokens, which EAGLE, NGRAM and DSpark reached throughmodel_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
sampling/verify_accept.py:VerifyAccept, a frozenmsgspec.Struct, describes what a verify accepted:tokens,accept_lens, and anaccept_index. A tree verify passes its flat predictions and theaccept_indexinto 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)becomesVerifyWatermark.commit(accept). It records the forced contexts and appends the accepted tokens, soWatermarkEngine.append_accept_tokensis removed.SynthIDVerifykeeps thereq_pool_indicesof itsapply, asGumbelVerifyalready did.eagle_sampleno longer records the watermark. EAGLE, NGRAM, DFlash and DSpark each callcommit_verify_acceptonce, right after acceptance. No worker callsmodel_runner.watermarkto commit anymore.commit_accept_tokens_to_penaltiesandcommit_block_accept_tokens_to_penalties.Behavior changes
None. Penalty counts, watermark state and outputs are unchanged:
tokens[accept_index]instead oftokens[accept_index.clamp(min=0)]. The two differ only at-1pads, which the accept mask drops in both the kernel and the torch fallback.predict,accept_indexandaccept_lenswithout writing them and touches no watermark state. The append runs on the same stream.Accuracy Tests
test_verify_penalty_commit.pycommits a tree accept and a chain accept throughcommit_verify_accept. It checks the penalty counts and that the watermark receives the same accept. The tree case puts a token in the-1pad slot to check that it is not counted.VerifyWatermark.commit.Checklist
CI States
Latest PR Test (Base): ⊘ Skipped -- add the
run-cilabel to run CI tests.Latest PR Test (Extra): ⊘ Skipped -- add the
run-cilabel to run CI tests.Latest PR Test (AMD ROCm 10): ⊘ Skipped -- add the
run-cilabel to run CI tests.Tip
Base CI only covers the core cases, and its workload may not exercise your change. Use
/rerun-testto run the tests your change touches, or copy this prompt for an agent: