Skip to content

[Spec] Extract shared draft worker construction and generalize draft sampler capture - #30857

Merged
hnyls2002 merged 8 commits into
mainfrom
lsyin/dflash-draft-worker-refactor
Jul 11, 2026
Merged

hnyls2002 merged 8 commits into
mainfrom
lsyin/dflash-draft-worker-refactor

Conversation

@hnyls2002

@hnyls2002 hnyls2002 commented Jul 11, 2026

Copy link
Copy Markdown
Collaborator

Behavior-preserving DFLASH refactor, one logical change per commit:

  • rename DFlashVerifyInput.num_tokens_per_batch to num_tokens_per_req, matching the field name the attention backends and EagleVerifyInput already use
  • require a CUDA device for DFLASH at argument resolution instead of failing mid-startup
  • extract draft TpModelWorker construction into draft_worker_common (build_draft_tp_worker, make_draft_input_v2, make_draft_block_spec_info, build_block_pos_offsets); this also dedups two identical draft-input constructions inside the DFLASH worker
  • replace the runner's hardcoded dflash_draft_sampler special case with a generic model_runner.capture_tail_hooks list; the DFLASH sampler registers itself as a hook with the same fail-loudly semantics
  • extract build_dflash_verify_target_probs from the sampling accept helper

Verification: full test_dflash.py run has an identical pass/fail signature to the main baseline on the same machine (48 passed; the same 3 pre-existing environment-specific failures on both).


CI States

Latest PR Test (Base): ❌ Run #29162877753
Latest PR Test (Extra): 🚫 Run #29162877678

@hnyls2002

Copy link
Copy Markdown
Collaborator Author

/rerun-test test_dflash.py test_basic_sanity_dflash.py

@github-actions

github-actions Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Results for /rerun-test test_dflash.py test_basic_sanity_dflash.py:

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

cd test/ && python3 registered/spec/dflash/test_dflash.py
cd test/ && python3 registered/core/test_basic_sanity_dflash.py

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the speculative decoding draft worker setup by extracting common utilities into a new draft_worker_common.py module and generalizing the tail capture process using a list of hooks (capture_tail_hooks) in the model runner. It also adds a CUDA device check for DFLASH speculative decoding and extracts target probability building logic in dflash_utils.py. The review feedback highlights several improvement opportunities: wrapping the draft worker initialization in a try...finally block to guarantee the restoration of global server arguments, using the idiomatic is_hip() helper instead of torch.version.hip, and resetting or assigning capture_tail_hooks instead of appending to prevent duplicate hook accumulation if CUDA graphs are initialized multiple times.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread python/sglang/srt/speculative/draft_worker_common.py Outdated
Comment thread python/sglang/srt/speculative/draft_worker_common.py
Comment thread python/sglang/srt/speculative/dflash_worker_v2.py
@hnyls2002

Copy link
Copy Markdown
Collaborator Author

/tag-and-rerun-ci extra
Both red CI states are only the pr-gate failing for the missing run-ci label; no test stage has run yet.
Opting into the extra suite for the DFLASH pressure coverage: test_gemma4_dflash_31b_extra.py, test_kimi_k26_nvfp4_dflash.py.
Key targeted tests to watch once CI runs: test_basic_sanity_dflash.py, and test_pcg_with_speculative_decoding_dflash.py (direct coverage for the capture_tail_hooks change in the decode graph capture path).

@hnyls2002

Copy link
Copy Markdown
Collaborator Author

/rerun-test test_pcg_with_speculative_decoding_dflash.py test_kimi_k26_nvfp4_dflash.py test_gemma4_dflash_31b_extra.py

@github-actions

github-actions Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Results for /rerun-test test_pcg_with_speculative_decoding_dflash.py test_kimi_k26_nvfp4_dflash.py test_gemma4_dflash_31b_extra.py:

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

cd test/ && python3 registered/cuda_graph/piecewise/test_pcg_with_speculative_decoding_dflash.py

🚀 8-gpu-b200 (1 test): ❌ View workflow run

cd test/ && python3 registered/quant/test_kimi_k26_nvfp4_dflash.py

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

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

@hnyls2002

Copy link
Copy Markdown
Collaborator Author

Latest PR Test (Base): ✅ Run #29149096757
Latest PR Test (Extra): ❌ Run #29149096704

@hnyls2002

Copy link
Copy Markdown
Collaborator Author

/rerun-test test_kimi_k26_nvfp4_dflash.py

@github-actions

github-actions Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Results for /rerun-test test_kimi_k26_nvfp4_dflash.py:

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

cd test/ && python3 registered/quant/test_kimi_k26_nvfp4_dflash.py

@hnyls2002
hnyls2002 merged commit d8ef766 into main Jul 11, 2026
99 of 137 checks passed
@hnyls2002
hnyls2002 deleted the lsyin/dflash-draft-worker-refactor branch July 11, 2026 19:34
AliceChenyy added a commit to AliceChenyy/sglang that referenced this pull request Jul 14, 2026
Conflicts resolved:
- decode_cuda_graph_runner.py: kept the PP-proxy input-buffer refresh,
  adopted upstream's is_dflash_family()/is_ragged condition (sgl-project#30261),
  and renamed num_tokens_per_bs -> num_tokens_per_req in the PP proxy
  output slice (sgl-project#30977).
- eagle_worker_v2.py: dropped the local _get_plan_stream (extracted to
  a shared get_plan_stream upstream, sgl-project#31008/sgl-project#30857) and re-applied the
  pp_proxy_tensors parameter on the deduplicated
  forward_batch_generation signature.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Chronostasys pushed a commit to MindLab-Research/sglang that referenced this pull request Aug 24, 2026
jakki-amd pushed a commit to jakki-amd/sglang that referenced this pull request Sep 9, 2026
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.

1 participant