Skip to content

Support spec v2 for Frozen-KV MTP; remove v1 worker - #27607

Merged
hnyls2002 merged 7 commits into
mainfrom
lsyin/frozen-mtp-spec-v2
Jun 9, 2026
Merged

hnyls2002 merged 7 commits into
mainfrom
lsyin/frozen-mtp-spec-v2

Conversation

@hnyls2002

@hnyls2002 hnyls2002 commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Run Frozen-KV MTP on the spec v2 worker — FrozenKVMTPWorkerV2 (orchestrator, subclasses EAGLEWorkerV2) + FrozenKVMTPDraftWorker (draft layer) — supporting both overlap and non-overlap scheduling
  • Remove the v1 FrozenKVMTPWorker
  • Add spec_stage_span nvtx markers on the orchestrator (parity with the v1 worker / EAGLEWorkerV2)

Mechanical verification

The draft layer is a byte-faithful move of the v1 FrozenKVMTPWorker methods into FrozenKVMTPDraftWorker. AST move-equivalence (reproducible script + results): https://gist.github.com/hnyls2002/08fb69f9857f011750ba2455816701ad

  • 19/19 pure-move methods byte-equal (incl. draft_forward and every frozen-KV metadata/view helper)
  • __init__: only super().__init__ -> TpModelWorker.__init__, two None inits, and assert-message text
  • draft: only the penalty-cumulate block removed (now handled by the inherited EagleDraftInputV2Mixin.prepare_for_decode, matching EAGLE v2)

Validation

  • GSM8K first-200, gemma-4-E4B-it + assistant: v1 0.725 vs v2 overlap 0.730 vs v2 sync 0.730; overall accept length ~2.83 across all three paths
  • 26B-A4B, deterministic, few-shot GSM8K (topk=1): v2 recovers to v1's 0.445. This relies on the spec-v2 stop-string finish fix (fix: stop-string check misses early matches during speculative decoding #23802, Fix spec v2 stop output boundary #25980, now on main): under v2 a step commits multiple tokens, so a stop string landing mid-chunk was missed and the model over-generated past it — the few-shot eval then extracted the wrong final number (~0.365). With those merged, v2 matches v1.
  • Covers topk=1; topk>1 tree path still to validate

Test plan

  • /rerun-test test_frozen_kv_mtp.py test_gemma4_mtp_26b_a4b_extra.py test_gemma4_mtp_31b_extra.py
  • test_gemma4_mtp_26b_a4b_extra.py is currently disabled in CI; with the stop-string fix on main it can be re-enabled in a follow-up

CI States

Latest PR Test (Base): ❌ Run #27235719910
Latest PR Test (Extra): ❌ Run #27235719724

Co-Authored-By: Khoa Pham <khoa.pham@radixark.ai>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

hnyls2002 and others added 2 commits June 8, 2026 16:44
Co-Authored-By: Khoa Pham <khoa.pham@radixark.ai>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Khoa Pham <khoa.pham@radixark.ai>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@hnyls2002

Copy link
Copy Markdown
Collaborator Author

/rerun-test test_frozen_kv_mtp.py test_gemma4_mtp_26b_a4b_extra.py test_gemma4_mtp_31b_extra.py

@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Results for /rerun-test test_frozen_kv_mtp.py test_gemma4_mtp_26b_a4b_extra.py test_gemma4_mtp_31b_extra.py:

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

cd test/ && python3 registered/spec/test_frozen_kv_mtp.py

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

cd test/ && python3 registered/spec/test_gemma4_mtp_26b_a4b_extra.py
cd test/ && python3 registered/spec/test_gemma4_mtp_31b_extra.py

@kpham-sgl kpham-sgl self-assigned this Jun 9, 2026
@hnyls2002

Copy link
Copy Markdown
Collaborator Author

/rerun-test registered/spec/test_gemma4_mtp_31b_extra.py

@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Results for /rerun-test registered/spec/test_gemma4_mtp_31b_extra.py:

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

cd test/ && python3 registered/spec/test_gemma4_mtp_31b_extra.py

@kpham-sgl kpham-sgl mentioned this pull request Jun 9, 2026
8 tasks
@hnyls2002

hnyls2002 commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator Author

/rerun-test test_frozen_kv_mtp.py test_gemma4_mtp_31b_extra.py test_gemma4_mtp_26b_a4b_extra.py

@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Results for /rerun-test test_frozen_kv_mtp.py test_gemma4_mtp_31b_extra.py test_gemma4_mtp_26b_a4b_extra.py:

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

cd test/ && python3 registered/spec/test_frozen_kv_mtp.py

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

cd test/ && python3 registered/spec/test_gemma4_mtp_31b_extra.py
cd test/ && python3 registered/spec/test_gemma4_mtp_26b_a4b_extra.py

@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Results for /rerun-test test_frozen_kv_mtp.py test_gemma4_mtp_31b_extra.py test_gemma4_mtp_26b_a4b_extra.py:

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

cd test/ && python3 registered/spec/test_frozen_kv_mtp.py

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

cd test/ && python3 registered/spec/test_gemma4_mtp_31b_extra.py
cd test/ && python3 registered/spec/test_gemma4_mtp_26b_a4b_extra.py

@hnyls2002

Copy link
Copy Markdown
Collaborator Author

/rerun-test test_frozen_kv_mtp.py test_gemma4_mtp_26b_a4b_extra.py test_gemma4_mtp_31b_extra.py test/registered/attention/unittests/dense/test_triton.py

@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Results for /rerun-test test_frozen_kv_mtp.py test_gemma4_mtp_26b_a4b_extra.py test_gemma4_mtp_31b_extra.py test/registered/attention/unittests/dense/test_triton.py:

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

cd test/ && python3 registered/spec/test_frozen_kv_mtp.py
cd test/ && python3 registered/attention/unittests/dense/test_triton.py

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

cd test/ && python3 registered/spec/test_gemma4_mtp_26b_a4b_extra.py
cd test/ && python3 registered/spec/test_gemma4_mtp_31b_extra.py

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

cd test/ && python3 registered/attention/unittests/dense/test_triton.py

@hnyls2002
hnyls2002 merged commit decb88e into main Jun 9, 2026
98 of 110 checks passed
@hnyls2002
hnyls2002 deleted the lsyin/frozen-mtp-spec-v2 branch June 9, 2026 22:30
Oasis-Git added a commit to Oasis-Git/sglang that referenced this pull request Jun 9, 2026
Three conflicts resolved + four-site API-migration port:

1. piecewise_cuda_graph_runner.py (deleted in HEAD, modified in main).
   Accept the deletion (cg-refactor's unified
   runner/prefill_cuda_graph_runner.py replaces it). Port main's
   sgl-project#27468 dflash-aux-hidden-states change to the new runner:
   capture_hidden_mode = FULL when spec_algorithm.is_dflash(), and
   use self.capture_hidden_mode (not NULL) in capture_prepare so
   dflash spec captures with the right variant.

2. frozen_kv_mtp_worker.py (deleted in main, modified in HEAD).
   Accept main's deletion (V1 -> V2 worker migration, sgl-project#27607). Apply
   the four cuda_graph_config API migration sites that cg-refactor
   had in V1 to V2 (frozen_kv_mtp_worker_v2.py):
   - backup_disable_cuda_graph -> backup_decode_mode (using new
     cuda_graph_config.decode.backend field)
   - server_args.disable_cuda_graph = True ->
     server_args.cuda_graph_config.decode.backend = Backend.DISABLED
   - matching restoration on draft_model_runner.server_args
   - init_cuda_graphs early-exit:
     self.server_args.disable_cuda_graph ->
     check_cuda_graph_backend(Phase.DECODE, Backend.DISABLED)

3. test/registered/cuda_graph/piecewise/
   test_pcg_with_speculative_decoding_dflash.py (file location).
   Accept at the cg-refactor-renamed location (new test/registered/
   cuda_graph/piecewise/ tree, not the legacy
   test/registered/piecewise_cuda_graph/).

Audited the auto-merged code-side files (scheduler.py,
schedule_batch.py, memory_pool.py, cuda_graph_buffer_registry.py,
arg_groups/speculative_hook.py, spec_info.py,
speculative_draft_runner.py) for unused-arg artifacts introduced by
the merge. None found — added kwargs (e.g. mamba_indices on
DSATokenToKVPool.get_cpu_copy/load_cpu_copy, padding_policy on
positions/mrope_positions GraphSlots) are all referenced at the
call sites and in the function bodies.

Sanity-checked imports on touched files (frozen_kv_mtp_worker_v2,
prefill_cuda_graph_runner) and AST-parsed cleanly.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
kpham-sgl added a commit that referenced this pull request Jun 22, 2026
Resolve conflicts from spec v2 refactor:
- frozen_kv_mtp_worker.py: removed (replaced by frozen_kv_mtp_worker_v2.py
  in #27607); ported trtllm_mha draft-attn-backend branch into the v2 worker.
- frozen_kv_mtp_cuda_graph_runner.py: adopt shared DecodeCudaGraphRunner
  surface (_replay_graph + _make_graph_key) from #28081 / #28384.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Chronostasys pushed a commit to MindLab-Research/sglang that referenced this pull request Aug 24, 2026
Co-authored-by: Khoa Pham <khoa.pham@radixark.ai>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
jakki-amd pushed a commit to jakki-amd/sglang that referenced this pull request Sep 9, 2026
Co-authored-by: Khoa Pham <khoa.pham@radixark.ai>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants