Skip to content

[Refactor] speculative: One definition of logit adjustments and truncated sampling for verify gates - #52159

Merged
hnyls2002 merged 1 commit into
mainfrom
lsyin/verify-adjust-flags
Nov 22, 2026
Merged

hnyls2002 merged 1 commit into
mainfrom
lsyin/verify-adjust-flags

Conversation

@hnyls2002

@hnyls2002 hnyls2002 commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

Speculative verify decides in many places whether a step adjusts its logits or truncates the target distribution, and so whether it may use vocab shards, a CUDA graph, or a fused or temperature-only accept. Each place had its own copy of the condition, and the copies had drifted: some missed the custom logit processor, the watermark, the grammar, or min-p.

Modifications

  • Add adjusts_logits(info, *, has_grammar) (grammar, penalties, logit bias, custom logit processor, watermark) and need_truncated_sampling(info) (top-k, top-p, min-p) next to SamplingBatchInfo.
  • Use them in the sharded-verify LM-head gate, the EAGLE post-verify graph key, the DSPARK fold, simulated-greedy, sampling-accept-region, sharded-accept, and blockwise-rejection gates, the DSPARK block-accept recorder, the DFLASH skip-verify-logits gate, and the UNO batch check.
  • sampling_allows_vocab_shards takes the caller's adjusts_logits answer. The sample-time check in eagle_sample may see the provider's VerifySamplingView, which carries no custom-processor flag, so it passes the adjustments eagle_sample applies itself (grammar mask, watermark, penalties, logit bias), as before.
  • Delete _verify_logits_unadjusted and the per-site field lists. Conditions that belong to one path (seeds, sampling masks, logprobs, top-k in a graph key) stay at their sites.
  • GraphSamplingInfo gains need_min_p_sampling, which the blockwise-rejection gate now reads.

Behavior changes

Each gate now refuses a step that the path behind it does not handle:

  • The sharded-verify LM-head gate (EAGLE, multi-layer EAGLE, NGRAM, UNO) keeps whole logits for batches with a custom logit processor. The EAGLE post-verify CUDA graph also refuses them. Neither verify path applies the processor yet, so tokens do not change; such batches only stop using shards and the graph.
  • DSPARK refuses watermark batches on the greedy fold (it accepts inside the verify graph, before the watermark is applied), on the simulated-greedy downgrade (it drops the sampling info, and the watermark with it), and on the sampling-accept region (it accepts with the batch temperatures, not the sampling info the watermark returns).
  • DSPARK sends min-p batches to the classic accept instead of the sampling-accept region, the sharded accept, or blockwise rejection, which read only temperatures. The classic accept does not apply min-p yet either.
  • The DSPARK block-accept recorder no longer counts grammar or watermark steps as having unadjusted logits.
  • The DFLASH skip-verify-logits gate and the UNO batch check also refuse watermark batches. This cannot happen today, because --enable-watermark rejects both algorithms. UNO's separate errors for grammar, penalties, logit bias, and custom processors become one error.

Accuracy Tests

This change moves gate conditions and does not touch any kernel or sampling math.

  • CPU unit tests in test/registered/unit/{spec,speculative,sampling}: 713 passed and 40 skipped. 9 failed, and the same 9 fail on main (test_eagle_seeded_coins x6, test_fast_prefill_plan x2, test_rust_sampling_schema_stays_in_lockstep).
  • A local truth-table check, not committed, ran every rewritten gate over every combination of its boolean inputs. Each gate matches the old condition everywhere except on the cases listed under Behavior changes.

Checklist


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_eagle_post_verify_graphs.py test_sharded_verify.py test_dspark_sampling_accept_graph.py test_dspark_blockwise_rejection.py test_spec_eagle.py test_eagle_constrained_decoding.py test_eagle_reject_sampling.py test_dspark_simulated_bonus.py test_uno.py test_uno_request_validation.py

@github-actions

github-actions Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

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

cd test/ && python3 registered/unit/spec/test_eagle_post_verify_graphs.py  # base-b
cd test/ && python3 registered/unit/spec/test_sharded_verify.py  # base-b
cd test/ && python3 registered/unit/speculative/test_dspark_sampling_accept_graph.py  # base-b
cd test/ && python3 registered/unit/spec/test_dspark_blockwise_rejection.py  # base-b
cd test/ && python3 registered/spec/eagle/test_spec_eagle.py  # base-b
cd test/ && python3 registered/spec/eagle/test_eagle_constrained_decoding.py  # base-b
cd test/ && python3 registered/spec/dspark/test_dspark_simulated_bonus.py  # base-b

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

cd test/ && python3 registered/spec/eagle/test_eagle_reject_sampling.py  # base-b

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

cd test/ && python3 registered/spec/uno/test_uno.py  # extra-a

🚀 ubuntu-latest (1 test): ✅ View workflow run

cd test/ && python3 registered/unit/spec/test_uno_request_validation.py  # base-a

@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 9c1d41ac988d: ❌ View workflow run

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