Skip to content

refactor(runner): add EagerRunner, own the eager path, polymorphic dispatch - #28386

Merged
ch-wan merged 1 commit into
mainfrom
cheng/refactor/eager-runner-extract
Jun 19, 2026
Merged

ch-wan merged 1 commit into
mainfrom
cheng/refactor/eager-runner-extract

Conversation

@ch-wan

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

Copy link
Copy Markdown
Collaborator

Motivation

The eager forward path lived inline in ModelRunner. Extract it into a dedicated runner so the cuda-graph runners stay purely cuda-graph, and back it with one fixed-size static input buffer (allocated once at init) instead of grow-on-demand registries.

Modifications

  • New runner/eager_runner.py::EagerRunner(BaseRunner):
    • __init__ allocates one static input buffer via build_eager_registry, sized once at (max_running_requests, prefill token ceiling) — no grow/realloc. The decode slot set is a superset of eager prefill's needs, so a single registry serves both decode and prefill (a decode batch is the [:num_tokens] prefix).
    • load_batch copies the live batch into that buffer, sliced to the batch.
    • execute inits attention metadata and runs model.forward live, mode-dispatched (decode / extend / idle).
    • can_run_graph() returns False (the dispatch gate).
  • New cuda_graph_buffer_registry.py::build_eager_registry — the decode slot set sized at the prefill ceiling, share_pool=True so same-name / same-size slots coalesce through the process-wide input pool (the eager buffer is allocated before the cuda-graph runners, so it is canonical and they coalesce onto it).
  • ModelRunner builds eager_runner unconditionally — it serves both the cuda-graph-disabled case and the fallback when a cuda-graph runner can't run a batch (dispatch via isinstance(..., EagerRunner)); forward_decode / forward_extend / forward_idle / _eager_fb_view are removed and routed through it.
  • _forward_raw applies the DP/MLP-sync + attn-tp padding (_prepare_eager_forward_batch) once, before the split-prefill / prefill-cuda-graph / eager paths — only the decode cuda-graph path pre-pads its own static buffers and returns earlier. The cuda-graph runners gain no eager flag or backend.

Accuracy Tests

N/A — behavior-preserving refactor (no change to model outputs).

Speed Tests and Profiling

N/A — no inference-speed impact.

Checklist

  • Format your code with pre-commit.
  • Behavior-preserving; covered by the existing runner-mode attention unit tests (test/registered/attention/unittests/dense).
  • Follow the SGLang code style guidance.

Builds on #28385.

🤖 Generated with Claude Code


CI States

Latest PR Test (Base): ❌ Run #27816609952
Latest PR Test (Extra): ❌ Run #27816609827

@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!

@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: 429950e36d

ℹ️ 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".

@ch-wan
ch-wan force-pushed the cheng/refactor/eager-runner-extract branch from 429950e to 59c22c4 Compare June 16, 2026 04:26
@ch-wan
ch-wan force-pushed the cheng/refactor/base-runner-extract branch from e0db52c to ba709b2 Compare June 16, 2026 07:03
@ch-wan
ch-wan force-pushed the cheng/refactor/eager-runner-extract branch 2 times, most recently from 57ce299 to b42ee47 Compare June 16, 2026 07:15
@ch-wan
ch-wan force-pushed the cheng/refactor/base-runner-extract branch from ba709b2 to 8ba9b60 Compare June 16, 2026 20:47
@ch-wan
ch-wan force-pushed the cheng/refactor/eager-runner-extract branch from b42ee47 to 00c3a3c Compare June 16, 2026 20:47
@ch-wan
ch-wan force-pushed the cheng/refactor/base-runner-extract branch from 8ba9b60 to 9724829 Compare June 16, 2026 20:49
@ch-wan
ch-wan force-pushed the cheng/refactor/eager-runner-extract branch from 00c3a3c to 440c11b Compare June 16, 2026 20:49
@ch-wan
ch-wan force-pushed the cheng/refactor/base-runner-extract branch from 9724829 to 20d1a12 Compare June 16, 2026 20:59
@ch-wan
ch-wan force-pushed the cheng/refactor/eager-runner-extract branch from 440c11b to 94f722d Compare June 16, 2026 20:59
@ch-wan
ch-wan force-pushed the cheng/refactor/base-runner-extract branch from 20d1a12 to 7bf5308 Compare June 16, 2026 21:24
@ch-wan
ch-wan force-pushed the cheng/refactor/eager-runner-extract branch 2 times, most recently from 6dd9993 to c62f618 Compare June 16, 2026 23:18

@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: c62f618024

ℹ️ 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".

@ch-wan
ch-wan force-pushed the cheng/refactor/eager-runner-extract branch from c62f618 to efc7966 Compare June 17, 2026 00:01

@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: efc7966ef0

ℹ️ 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".

@ch-wan
ch-wan restored the cheng/refactor/eager-runner-extract branch June 19, 2026 20:10
ch-wan added a commit that referenced this pull request 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]>
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]>
thanhhao98 pushed a commit to thanhhao98/sglang that referenced this pull request Jul 15, 2026
…gl-project#30889)

sgl-project#30889 auto-upgrades the prefill CUDA-graph backend BREAKABLE -> TC_PIECEWISE for
multimodal-piecewise-allowlisted models (e.g. Kimi K2.5/K2.6). For a speculative
config on an FP4 / TRTLLM-MoE target (nvidia/Kimi-K2.6-NVFP4 DFlash, B200) this
silently forced tc_piecewise, whose captured prefill graph corrupts the target
FP4/MoE decode-graph replay that spec verify runs on (sgl-project#28386) -> CUDA illegal memory
access during generation (nightly test_kimi_k26_nvfp4_dflash.py, regressed 07-13).
Verified on 8xB200 that NO captured prefill graph (tc_piecewise OR breakable) avoids
the corruption -- it is a general captured-prefill-vs-FP4/MoE issue, so spec targets
must run eager prefill.

Exclude speculative configs from the silent upgrade (speculative_algorithm is None),
so they keep their default prefill backend (BREAKABLE -> auto-disabled for MLA ->
eager, the pre-sgl-project#30889 behavior). Explicitly pinned spec + tc_piecewise configs (the
dense DFlash+PCG test) lock the backend and short-circuit before this, unaffected.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
thanhhao98 pushed a commit to thanhhao98/sglang that referenced this pull request Jul 17, 2026
A tc_piecewise/breakable prefill capture session perturbs persistent state
that a decode/verify graph captured afterwards bakes a dependence on; on
trtllm_mla spec-decode targets the verify graph is born corrupted and hits
an async illegal memory access at replay (sgl-project#28386; Kimi-K2.6-NVFP4 DFlash
nightly red since sgl-project#30889). Verified on 8xB200 with the exact nightly
config: order swap alone fixes the crash with tc_piecewise prefill graphs
still capturing and replaying (two independent GSM8K passes), while every
alternative explanation was falsified by single-variable A/B (MoE runner
swap, torch.compile-free BCG, torch graph-pool isolation both channels,
PDL off, autotune off, flashinfer nightly, private workspaces, fp8-vs-bf16
KV, custom allreduce off). Eager verify on the same config is immune and
replay-prep inputs are provably clean at fault time, isolating the
corruption to capture-environment ordering.

Co-Authored-By: Claude Fable 5 <[email protected]>
thanhhao98 pushed a commit to thanhhao98/sglang that referenced this pull request Jul 19, 2026
…efill fallback

When prefill CUDA graphs (tc_piecewise or breakable) are captured before the
decode/verify graphs, the last prefill capture leaves the backend's
forward_prefill_metadata with fallback_to_flashinfer_impl=True (the piecewise
capture forces the flashinfer fallback; init_forward_metadata sets it on the
instance). The decode runner's TARGET_VERIFY capture then enters
forward_extend, whose first check consults that stale flag and silently
records the flashinfer-wrapper attention into the captured graph. Replay-prep
feeds the graph trtllm-gen-style metadata, so the replayed verify graph is
born corrupted and hits an asynchronous illegal memory access on the first
generation batch (sgl-project#28386, and the Kimi-K2.6 DFlash nightly IMA after sgl-project#30889).

init_forward_metadata already clears the stale metadata for verify /
draft-extend on the eager path (which is why eager verify was immune); the
CUDA-graph metadata path never got the same clear. Fix both sides:

- init_forward_metadata_out_graph(in_capture=True): clear
  forward_prefill_metadata before building decode/verify capture metadata,
  mirroring the eager path.
- forward_extend: never take the prefill fallback short-circuit for
  target-verify / draft-extend modes, matching the mode guards used by the
  metadata paths.

No capture-order change.
Chronostasys pushed a commit to MindLab-Research/sglang that referenced this pull request Aug 24, 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/refactor/eager-runner-extract branch September 14, 2026 04:41
@alexnails
alexnails restored the cheng/refactor/eager-runner-extract branch September 14, 2026 05:42
@ch-wan
ch-wan deleted the cheng/refactor/eager-runner-extract branch September 14, 2026 05:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-to-merge The PR is ready to merge after the CI is green.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant