Skip to content

Enable breakable CUDA graph for eagle - #25795

Merged
merrymercy merged 3 commits into
mainfrom
lmzheng/bcg-prefill-draft-support
May 21, 2026
Merged

merrymercy merged 3 commits into
mainfrom
lmzheng/bcg-prefill-draft-support

Conversation

@merrymercy

@merrymercy merrymercy commented May 19, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

Enable breakable CUDA graph (BCG) support for eagle speculative decoding

Modifications

  • breakable_cuda_graph_runner.py: Add draft worker support (capture_hidden_mode, spec_info with hidden states, replay_prepare for draft hidden state copy), multimodal/input_embeds support in BCG replay path
  • model_runner.py: Add force parameter to init_piecewise_cuda_graphs so draft workers can explicitly initialize PCG/BCG after init_lm_head
  • eagle_worker_v2.py: Call init_piecewise_cuda_graphs(force=True) when BCG is enabled
  • server_args.py: Simplify prefill disaggregation — always disable CUDA graph for prefill mode (BCG handles it)
  • eagle_utils.py: Add get_draft_hidden_dim utility for deriving draft hidden state dimensions

Skipped files

  • http_server.py: Warmup logging fix already applied in OSS
  • eagle_draft_extend_cuda_graph_runner.py: Hidden dim calculation already refactored in OSS via EagleDraftExtendInput.hidden_size_for

Original commits

  • 5f2c73d2c

CI States

Latest PR Test (Base): ✅ Run #26179533584
Latest PR Test (Extra): ✅ Run #26179533125

@merrymercy

Copy link
Copy Markdown
Collaborator Author

/tag-and-rerun-ci

@github-actions github-actions Bot added the run-ci CI: run the baseline test suite on this PR label May 19, 2026

@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 enhances the BreakableCudaGraphRunner to support multimodal models and Eagle speculative decoding. Key updates include the introduction of CaptureHiddenMode for flexible hidden state management, implementation of a custom replay_prepare method for draft workers, and logic to handle input_embeds in multimodal scenarios. The PR also modifies the ModelRunner to allow forced initialization of piecewise CUDA graphs for draft workers and adds utility functions for calculating draft hidden dimensions. Feedback was provided regarding the use of assert statements for runtime validation, suggesting they be replaced with ValueError to prevent them from being optimized away in production environments.

@merrymercy merrymercy changed the title Enable breakable CUDA graph for prefill and draft workers Enable breakable CUDA graph for eagle May 20, 2026
Comment thread python/sglang/srt/server_args.py Resolved
@merrymercy merrymercy added the run-ci-extra CI: also run the extra suite (requires run-ci) label May 20, 2026
- Add draft worker support to BreakableCudaGraphRunner: capture_hidden_mode,
  spec_info with hidden states, and replay_prepare for draft hidden state copy
- Add multimodal/input_embeds support to BCG replay path
- Add force parameter to init_piecewise_cuda_graphs for draft workers
- Eagle worker calls init_piecewise_cuda_graphs(force=True) when BCG enabled
- Simplify prefill disaggregation: always disable CUDA graph for prefill mode
- Add get_draft_hidden_dim utility to eagle_utils

Co-authored-by: Lianmin Zheng <[email protected]>
- Move `import inspect` to top-level imports (merrymercy)
- Add TODO about fixing PiecewiseCudaGraphRunner for draft workers (merrymercy)
- Restore deleted comment block before replay_layer_forward (merrymercy)
- Replace assert with ValueError for runtime validation (gemini-code-assist)
- Fix black formatting (collapse multi-line conditions)
@merrymercy
merrymercy force-pushed the lmzheng/bcg-prefill-draft-support branch from 4f32300 to 4e07947 Compare May 20, 2026 17:40
@merrymercy
merrymercy merged commit c4a7d12 into main May 21, 2026
194 of 220 checks passed
@merrymercy
merrymercy deleted the lmzheng/bcg-prefill-draft-support branch May 21, 2026 01:02
mqhc2020 pushed a commit to mqhc2020/sglang that referenced this pull request Jun 2, 2026
Oasis-Git added a commit to Oasis-Git/sglang that referenced this pull request Jun 22, 2026
… from sgl-project#25795

The cuda graph runner refactor (sgl-project#23906) consolidated BCG and PCG into
PrefillCudaGraphRunner but dropped four sgl-project#25795 hooks needed for
BCG+EAGLE end to end:

  * __init__: capture_hidden_mode for BCG+EAGLE — draft worker LAST,
    target worker FULL.
  * __init__: allocate static_draft_hidden_states buffer for
    BCG+draft+EAGLE (captured segments hold its address).
  * capture_prepare: pass spec_info=EagleDraftInput(hidden_states=...)
    aliasing the static buffer instead of spec_info=None.
  * load_batch: copy live forward_batch.spec_info.hidden_states into
    the static buffer before replay.

Also narrow the existing model_runner.py skip block to non-BCG so the
restored target-FULL capture isn't short-circuited to eager_runner.
tc_piecewise stays on the skip — it has no pre-sgl-project#23906 logic to restore
here, and its dead-graph capture corrupts FP4 / TRTLLM-MoE decode
replay (see sgl-project#28386).

Alternative to PR sgl-project#28809, which only attempted the target-worker
capture_hidden_mode flip, botched the tc_piecewise branch (codex P1),
and dropped the skip block — reproducing the sgl-project#28386 corruption end to
end (gsm8k=0.0 on test_deepseek_v3_fp4_mtp_small in PR Test (Base)).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Chronostasys pushed a commit to MindLab-Research/sglang that referenced this pull request Aug 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

high priority run-ci CI: run the baseline test suite on this PR run-ci-extra CI: also run the extra suite (requires run-ci)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants