Skip to content

fix(runner): capture EAGLE-target prefill CG at FULL hidden mode - #28809

Closed
ch-wan wants to merge 4 commits into
mainfrom
cheng/fix/eagle-target-prefill-cg-full
Closed

ch-wan wants to merge 4 commits into
mainfrom
cheng/fix/eagle-target-prefill-cg-full

Conversation

@ch-wan

@ch-wan ch-wan commented Jun 20, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

`PrefillCudaGraphRunner` captures with `CaptureHiddenMode.NULL` by default and only flips to `FULL` when `enable_return_hidden_states` or DFLASH spec is set. EAGLE target prefill, however, must produce `FULL` hidden states to feed the draft — so `can_run_graph` (which rejects on hidden-mode mismatch) rejected every EAGLE-target prefill batch and the captured graph was allocated but never replayed (~0.7–0.8 GB of dead memory).

Root cause (a regression from #23906)

Before #23906 `BreakableCudaGraphRunner` had the right logic — it flipped `capture_hidden_mode` to `FULL` whenever `spec_algorithm.is_eagle() and not is_draft_worker`. #23906 consolidated BCG and PCG into `PiecewiseCudaGraphRunner` and dropped that branch, so EAGLE-target PCG has been dead since then.

#28386 added a workaround skip (`self.prefill_cuda_graph_runner = self.eager_runner` for EAGLE target) to stop the dead capture from wasting memory. That treats the symptom; this PR fixes the root cause.

Fix

  • Extend the `capture_hidden_mode = FULL` condition in `PrefillCudaGraphRunner.init` to include `spec_algorithm.is_eagle() and not is_draft_worker` — mirrors BCG's pre-[Refactor] Cuda Graph Runner/Backend Refactor #23906 logic for the target side.
  • Drop the now-redundant skip block in `ModelRunner.init_prefill_cuda_graph` (the captured graph is no longer dead, so there's nothing to skip).

Net effect: EAGLE-target prefill now actually replays the captured graph instead of falling back to eager, and the model_runner-side skip is gone.

🤖 Generated with Claude Code


CI States

Latest PR Test (Base): ❌ Run #27896849378
Latest PR Test (Extra): ✅ Run #27896849299

@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 simplifies and improves CUDA graph handling for EAGLE-family target workers. Instead of disabling the prefill CUDA graph entirely for the EAGLE target worker when return hidden states is disabled, the code now ensures that the prefill CUDA graph runner captures the FULL hidden states up front when running as an EAGLE target worker. There are no review comments, so I have no feedback to provide.

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.

@ch-wan ch-wan added bypass-fastfail run-ci-extra CI: also run the extra suite (requires run-ci) labels Jun 20, 2026
@ch-wan

ch-wan commented Jun 20, 2026

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 Jun 20, 2026
PrefillCudaGraphRunner captures with CaptureHiddenMode.NULL by default
and only flips to FULL for enable_return_hidden_states or DFLASH. EAGLE
target prefill, however, must produce FULL hidden states to feed the
draft model -- so can_run_graph (which rejects on hidden-mode mismatch)
rejected every EAGLE-target prefill batch and the captured graph was
allocated but never replayed (~0.7-0.8 GB of dead memory).

This was a regression from #23906 (Cuda Graph Runner/Backend Refactor),
which consolidated BreakableCudaGraphRunner into PiecewiseCudaGraphRunner
but dropped BCG's EAGLE-aware FULL-capture logic. Restore it so the
captured graph is actually usable, then drop the now-redundant skip
that #28386 added as a workaround in init_prefill_cuda_graph.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 894df71efc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +161 to +166
else:
if (
model_runner.server_args.enable_return_hidden_states
or model_runner.spec_algorithm.is_dflash()
):
self.capture_hidden_mode = CaptureHiddenMode.FULL

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Capture FULL hidden states for EAGLE tc_piecewise

When the prefill backend remains tc_piecewise (the default), this branch leaves capture_hidden_mode as NULL for EAGLE target workers. However EagleWorker.forward_batch_generation sets target prefill batches to CaptureHiddenMode.FULL so the draft can consume the hidden states, and can_run_graph rejects any mismatch; as a result every EAGLE target prefill still falls back to eager while ModelRunner no longer skips the capture, reintroducing the dead graph allocation/startup cost for the default backend. Include the EAGLE target condition in the tc_piecewise path too, not only BREAKABLE.

Useful? React with 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a32cf0eefc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

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]>
@ch-wan ch-wan closed this Jun 22, 2026
Duyi-Wang added a commit to Duyi-Wang/sglang that referenced this pull request Aug 31, 2026
…c_piecewise

PrefillCudaGraphRunner gated the EAGLE capture-hidden-mode override on the
prefill backend being BREAKABLE, so an EAGLE target on tc_piecewise fell
through to the server hidden-state ceiling (NULL by default). Because EAGLE
target prefill asks for FULL, can_replay_locally rejected that graph on every
replay -- it was captured but never usable.

capture_prefill_graph compensated by routing the EAGLE target to the
EagerRunner outright, citing sgl-project#28386. That skip's stated premise is "a NULL or
LAST graph is dead", which is a consequence of the gate above rather than an
independent constraint: the same backend and the same kernels do capture and
replay a prefill graph today whenever the server ceiling is already FULL
(--return-hidden-states), and BCG is exempt precisely because it captures FULL.

Pin the EAGLE target to FULL on every backend, which is what sgl-project#28809 set out to
do before it flipped only the BCG branch and left tc_piecewise dead, and drop
the now-unreachable skip. Speculative decoding (EAGLE/EAGLE3/NEXTN) keeps its
prefill CUDA graph instead of silently running eager.

capture_hidden_mode is read only by LogitsProcessor, which sits outside the
compiled region (tc_piecewise compiles the inner model), so this adds no
dynamo guard and no graph break. The EAGLE target's spec_info is None at
prefill on both capture and replay, so the two stay consistent.

The existing e2e coverage (test_pcg_with_speculative_decoding{,_extra}.py)
asserts only gsm8k score and accept length, so it passed with the graph
degraded to eager. Add unit coverage for the capture-mode matrix and for
capture_prefill_graph keeping the runner, and rewrite the case that pinned
the old skip.

Not addressed here: under DP attention the schedule-time vote in
dp_attn.py still recognises only BREAKABLE, so tc_piecewise prefill graphs
do not replay there regardless of capture mode.
@Jiminator
Jiminator deleted the cheng/fix/eagle-target-prefill-cg-full branch September 14, 2026 04:43
@alexnails
alexnails restored the cheng/fix/eagle-target-prefill-cg-full branch September 14, 2026 05:39
@ch-wan
ch-wan deleted the cheng/fix/eagle-target-prefill-cg-full branch September 14, 2026 05:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bypass-fastfail 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