Skip to content

[Refactor] speculative: One target-verify ring for EAGLE, NGRAM and DSpark - #52174

Merged
hnyls2002 merged 9 commits into
mainfrom
lsyin/target-verifier
Nov 22, 2026
Merged

hnyls2002 merged 9 commits into
mainfrom
lsyin/target-verifier

Conversation

@hnyls2002

@hnyls2002 hnyls2002 commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

EAGLE, NGRAM and DSpark wrap their accept cores in the same steps, and each worker wrote its own copy of them:

  1. build the grammar vocab mask over the verify's draft tree or chain;
  2. bind the verify watermark;
  3. run the accept core;
  4. commit the accept with commit_verify_accept;
  5. compute the verify logprobs with compute_spec_logprobs.

NGRAM also copied EAGLE's whole tree accept core, including the switch between the NV runtime hooks' post-verify and eagle_sample. A new spec worker, or a new step such as another per-request sampling state, had to be added to every copy.

Modifications

  • New speculative/target_verify.py with TargetVerify, a frozen msgspec.Struct:
    • TargetVerify.prepare(batch, *, logits_output, grammar_tree, grammar_barrier, watermark_engine, watermark_full_mask) builds the grammar mask and binds the watermark. It returns the struct the accept core reads: grammar_mask, watermark and watermark_full_mask.
    • verify.commit(batch, *, logits_output, accept) commits the VerifyAccept through commit_verify_accept. When the batch returns logprobs, it then computes them: a tree accept gathers through its accept_index, and a chain accept reads its rows at the width of its token block.
  • The paths differ only where their verifies really differ, and each passes that as an argument:
    • the grammar tree: EAGLE reads it back from the device, NGRAM derives it from its host tree, and DSpark builds a linear chain;
    • the grammar barrier: NGRAM passes none, because its corpus lookup is synchronous;
    • the watermark mask layout: EAGLE derives it from the attention backend's verify mask, NGRAM always uses the full mask, and DSpark never does.
  • New accept_draft_tree in eagle_worker_common.py. It is the tree accept core that EAGLE and NGRAM now share: the NaN/Inf probe, then the runtime hooks' post-verify under SGLANG_ENABLE_NV_MEGA_RUNTIME_OPTIMIZATION, otherwise eagle_sample. EAGLE passes its sparse and simulated-acceptance options, and NGRAM keeps the defaults.
  • DSpark keeps its own block accept core, and its folded and region graph accepts. It uses prepare and commit around them, and still applies the grammar mask and the watermark to its logits itself.
  • EAGLE's post-verify graphs keep their early return. That return now commits through verify.commit, which does nothing for the batches those graphs take (no penalties, no watermark) and computes the same logprobs.

No behavior change. Steps that moved only changed their order against independent work: the logprobs now run right after the commit, and the probe runs after the watermark bind.

Accuracy Tests

Differential end-to-end run of base #52164 against this PR, on one GPU, with Llama-3.1-8B-Instruct in float16 (the EAGLE3 draft checkpoint is float16). Each configuration sent the same 9 chat requests one at a time:

  • 3 prompts: 2 with a JSON-schema response_format and 1 free-form;
  • per prompt: greedy; greedy with the watermark requested; greedy with the watermark plus frequency and presence penalties;
  • top_logprobs=2 on every request.

Sampled requests were left out, because the host's CUDA toolchain could not JIT-build the sampled tree verify kernel on either tree.

config requests (reqs) token ids identical (reqs) logprobs identical (reqs) accept length, base / PR (tokens)
EAGLE3, topk 1, 4 draft tokens 9 9 9 2.375 / 2.375
EAGLE3, topk 4, 8 draft tokens 9 9 9 2.905 / 2.905
NGRAM, 8 draft tokens 9 9 9 2.0875 / 2.0875

Checklist

  • Unit tests: test_nv_runtime_gates.py now calls accept_draft_tree directly with EAGLE's options and with the defaults, instead of executing the gate it extracted from each worker's source.

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_target_verify.py test_nv_runtime_gates.py test_model_runner_kv_weight_versions.py test_eagle_post_verify_graphs.py test_sharded_verify.py test_dspark_accept_tail.py test_dspark_sampling_accept_graph.py test_verify_penalty_paths.py test_spec_eagle.py test_spec_eagle_topk.py test_eagle_constrained_decoding.py test_spec_ngram.py test_dspark_simulated_bonus.py test_watermark.py test_synthid_watermark.py test_constrained_decoding_spec_reasoning.py

@github-actions

github-actions Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

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

cd test/ && python3 registered/unit/spec/test_target_verify.py  # base-a
cd test/ && python3 registered/unit/spec/test_nv_runtime_gates.py  # base-a
cd test/ && python3 registered/unit/model_executor/test_model_runner_kv_weight_versions.py  # base-a
cd test/ && python3 registered/unit/spec/test_verify_penalty_paths.py  # base-a

🚀 1-gpu-5090 (10 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/spec/test_dspark_accept_tail.py  # base-b
cd test/ && python3 registered/unit/speculative/test_dspark_sampling_accept_graph.py  # base-b
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/eagle/test_eagle_constrained_decoding.py  # base-b
cd test/ && python3 registered/spec/dspark/test_dspark_simulated_bonus.py  # base-b
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

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

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

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

cd test/ && python3 registered/spec/test_constrained_decoding_spec_reasoning.py  # extra-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 287457f56f6e: ❌ View workflow run

# Conflicts:
#	python/sglang/srt/speculative/dflash_worker_v2.py
#	python/sglang/srt/speculative/dspark_components/dspark_worker_v2.py
# Conflicts:
#	python/sglang/srt/speculative/dspark_components/dspark_worker_v2.py
Base automatically changed from lsyin/spec-accept-commit to main November 22, 2026 08:00
# Conflicts:
#	python/sglang/srt/speculative/dspark_components/dspark_worker_v2.py
#	python/sglang/srt/speculative/eagle_worker_common.py
#	python/sglang/srt/speculative/ngram_worker.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 2156c7649bed: ✅ View workflow run

@hnyls2002
hnyls2002 merged commit 73ee961 into main Nov 22, 2026
131 of 133 checks passed
@hnyls2002
hnyls2002 deleted the lsyin/target-verifier branch November 22, 2026 08:11
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