Repository navigation
[2/N][Mixed] Mixed chunk prefill with spec enabled - #36933
Merged
Oasis-Git merged 28 commits intoAug 31, 2026
Merged
Conversation
… runner Mixed batches (--enable-mixed-chunk) have always replayed through the prefill CUDA graph runner, with an inline MIXED->EXTEND normalization for the dynamo guards. Give MIXED its own runner without a second capture: MixedCudaGraphRunner subclasses PrefillCudaGraphRunner and is constructed instead of it when mixed chunking is on, so one instance serves the whole extend family and the base only ever sees pure extend. The normalization becomes the _graph_replay_forward_mode hook, overridden by the subclass, which also logs the first mixed replay. The subclass asserts the breakable backend at construction: tc_piecewise and full cannot serve mixed batches (full's fixed request-slot geometry does not cover mixed decode tails; may be supported later), and both previously degraded silently. Future mixed-only logic (decode-tail split-kernel capture variants via ShapeKey, mixed-specific admission mirrored in the dp vote) has a home in the subclass; the module docstring records that contract. No dispatch or ModelRunner changes: the prefill_cuda_graph_runner field simply holds the subclass. Co-Authored-By: Claude Fable 5 <[email protected]>
…eous steps Under DP attention, graph replay requires a mode-homogeneous step: when one rank runs extend and a peer runs decode, both CG votes fail and every rank falls to eager (decode loses the decode graph, the extend rank loses BCG). A decode batch is one relabel away from a plain extend batch: each request a 1-token extend with its full context as prefix, token count unchanged so the gathered global_num_tokens stay valid. After the mlp-sync gather, an eligible decode batch converts to EXTEND when a peer runs extend and the global breakable vote passed; the step then replays BCG on every rank through the ordinary prefill runner. The local vote gains a matching arm factored with the extend arm into _local_prefill_cuda_graph_vote; eligibility (spec until degradation lands, TBO split-metadata ordering, CP zigzag, logprob, a real graph runner) is evaluated only in the vote and travels through the min-reduce, so the conversion site just reads the gathered flags. Homogeneous decode steps are untouched (the decode graph is strictly better). Two lifecycle hazards found by test_dp_attention.py::TestDPRetract and fixed in convert_decode_to_extend / the scheduler: - the converted batch re-enters through the last_batch extend-merge path, so the scheduler hands back an empty running_batch (converting the persistent running_batch in place merged it with itself); - the recycled batch object can carry a stale chunked_req from its former life as a prefill batch; the extend-merge path would exclude - silently drop - that request once the batch is relabeled EXTEND, stranding its radix lock (the pool "memory leak" the invariant checker caught). Conversion clears the field: a decode batch has no in-flight chunk. Co-Authored-By: Claude Fable 5 <[email protected]>
A converted batch routes through process_batch_result_prefill, whose report_prefill_stats dereferences batch.prefill_stats. In the normal DP path this happened to survive: running_batch adopts the prefill-born last_batch object (scheduler.get_next_batch_to_run), so conversion carried stale-but-non-None stats and spuriously re-reported them every converted step. Under --enable-hisparse the decode batch is built fresh by the hisparse coordinator (prefill_stats=None), and the first converted step crashed every dp rank with AttributeError: 'NoneType' object has no attribute 'log_input_tokens' (seen in test_dsa_glm52_hisparse, GLM-5.2-FP8 tp8 dp8). Fixes, verified on GB300 (DeepSeek-Coder-V2-Lite tp2 dp2 dp-attention, mixed decode+prefill load): - convert_decode_to_extend clears prefill_stats: converted batches are decode work; before the fix 17/17 converted steps re-reported stale stats, after it 15/15 arrived with None. - process_batch_result_prefill skips report_prefill_stats when prefill_stats is None, so a stats-less extend batch can never hit the deref again. - The dp vote gates conversion off under enable_hisparse entirely: hisparse decode batches have their own prefill-to-decode transition, host-offloaded KV, and decode-path coordinator bookkeeping that the extend view and prefill result path would bypass. Co-Authored-By: Claude Fable 5 <[email protected]>
…MIXED as EXTEND MIXED is a schedule-time concept only. The prefill graph runner keeps the inline MIXED->EXTEND normalization at replay (as upstream), and the eager runner now normalizes the same way before dispatch, so worker-side code sees a single extend family regardless of replay-vs-eager. The mixed-chunk breakable-backend assert moves to PrefillCudaGraphRunner __init__, gated on enable_mixed_chunk. Eager normalization is skipped on NPU (dedicated forward_mixed kernel dispatch) and under CP (cp_utils excludes MIXED from the zigzag split); both keep their existing MIXED behavior. The dp mlp-sync vote and decode->extend conversion are unchanged. Co-Authored-By: Claude Fable 5 <[email protected]>
…runner # Conflicts: # python/sglang/srt/managers/scheduler_components/dp_attn.py
…ain decode Allow --enable-mixed-chunk with EAGLE/EAGLE3. Inside a mixed step the running (decode) requests skip draft/verify entirely: each forwards its pending bonus token as a 1-token extend (the mixed forward writes that token's KV into the slot eagle_prepare_for_decode reserved in req_to_token), and the prefill path's draft-extend re-seeds their draft state from the mixed forward's hidden states. Mixed chunking already saturates compute, so drafting adds latency for little gain there. Ported from Yuhao Yang's tierA on dsv4-dev (1a0bd60), minus tierB (SGLANG_EAGLE_MIXED_VERIFY two-forward verify) and the env-gated extras: - arg gates: allow EAGLE-family, keep other spec algorithms disabled - mix_with_running: spec-aware out_cache_loc gather (no per-step out_cache_loc on a spec running batch) - prefill result path: kv_committed_len += 1 for the decode tail - EAGLEWorkerV2 prefill branch: advance the tail's new_seq_lens by one The overlap FutureMap needs no changes on this base: spec publishes bonus_tokens into output_tokens_buf at req_pool rows, which is exactly what the mixed input resolve gathers. Not yet GPU-verified; overlap-mode tail seq_lens staleness is the open risk to test (non-overlap first). Co-Authored-By: Claude Fable 5 <[email protected]>
…_mixed_chunk The degradation contract is algorithm-agnostic (spec runs only on pure-decode steps; a mixed step commits one plain token per running request and the worker resumes drafting), so express enablement as a worker capability instead of hardcoded EAGLE/EAGLE3 string tuples. Plugin algorithms default to False. standalone stays off until its draft-KV resume is verified; ngram stays off because its overlap relay publishes into the accept bufs, not output_tokens_buf, which the mixed input resolve reads. Co-Authored-By: Claude Fable 5 <[email protected]>
…dspark Both dflash-family workers already satisfy the degradation contract: their decode prep over-allocates KV slots in req_to_token from kv_committed_len (which the mixed result path advances by one), their prefill branch injects target hidden states into the draft KV over out_cache_loc (covering the mixed decode tails), and their relay publishes bonus tokens into output_tokens_buf (what the mixed input resolve reads). The only worker-side change needed is the same tail seq-lens advance as EAGLE: +1 for decode-tail entries in the published new_seq_lens and the next draft input. Flip supports_mixed_chunk for DFLASH/DSPARK and drop their hook-level mixed-chunk disables, now covered by the capability gate. GPU verification pending (dspark first: DeepSeek-V4-Flash-DSpark draft is cached on the B300 box). Co-Authored-By: Claude Fable 5 <[email protected]>
merge_batch nulls seq_lens_cpu when either side lacks it; under overlap+spec the running batch has none at schedule time, and the DSV4 extend metadata asserts on it (first mixed step crashed all ranks on DeepSeek-V4-Flash MTP). Rebuild the merged mirror CPU-side from request state instead of syncing running_batch.seq_lens off the GPU. Co-Authored-By: Claude Fable 5 <[email protected]>
… resolve Non-overlap spec carries bonus tokens on the draft input and never writes output_tokens_buf, so the mixed input resolve gathered uninitialized rows for the decode tails (garbage token id -> embedding OOB -> cublas failure on DSV4-Flash MTP). Stash output_ids[-1] at the tails' pool rows at mix time, mirroring the hisparse decode builder; overlap mode keeps the published values untouched. Co-Authored-By: Claude Fable 5 <[email protected]>
Spec keeps a decode batch's seq_lens at the committed base (bonus token pending). The mixed forward commits that token, but the merged batch carried the base value, so attention metadata computed qo_len = seq_lens - prefix_lens = 0 for every tail: flashinfer rejects the shape (ragged prefill q rows != qo_indptr[-1], seen on Llama + DFlash at the first mixed step), and backends without that validation run the tail with a kv span that excludes the token's own row - the likely mechanism behind DSV4-Flash MTP's 0.965 -> 0.895 gsm8k drop. Bump the merged tail rows by one in mix_with_running (the reserved-slot gather still reads the pre-bump base) and drop the per-worker new_seq_lens tail adjustments, which would now double-count: the batch value is already the next-iter length. Co-Authored-By: Claude Fable 5 <[email protected]>
…rom requests Under overlap, a decode batch's schedule-time state lags its in-flight verify by the accept count, which is unknowable on the CPU - every schedule-time tail value (slot, prefix, lens) would be stale by it (measured: DSV4-Flash MTP gsm8k 0.805 vs 0.970 baseline). Instead of a forward-entry GPU refresh, gate mixing on settled tails: skip the one admission whose tail result is still in flight (the prefill runs alone, the running batch decodes next iteration), and mix every later chunk with fully processed request state. With settled tails, request state is authoritative in both scheduling modes, so derive the tail base from r.seqlen rather than the batch seq_lens tensor (refreshed only at decode forward entry under overlap), use the no-delay prefix bookkeeping for spec tails in both modes, and stash the pending bonus tokens unconditionally. Co-Authored-By: Claude Fable 5 <[email protected]>
Replace the settled-tails gate (which never engaged under load: some request is always in flight) with the same late-binding pure decode already uses. Schedule time keeps placeholder tail values from the stale request state and the KV over-allocation guarantees the slots exist; at forward entry resolve_mixed_spec_tails gathers the settled committed lengths from new_seq_lens_buf behind the publish fence and rebuilds the tail rows: seq_lens (base + 1), out_cache_loc (reserved slot at base), and the CPU mirrors the extend metadata reads (prefix_lens, seq_lens_cpu, seq_lens_sum) via the pinned D2H pattern of resolve_seq_lens_cpu. The bonus-token input gather already worked this way. The stash returns to non-overlap only: an in-flight tail's output_ids is stale and must not clobber the published relay value. Co-Authored-By: Claude Fable 5 <[email protected]>
# Conflicts: # python/sglang/srt/managers/scheduler_components/batch_result_processor.py
…overlap) One file, one cell per supported algorithm, all on the overlap scheduler with small chunks so eval prompts span multiple chunks and mixing engages. Each guards a bring-up failure mode: tail rows dropped from attention metadata (spec seq_lens convention zeroed the tail's qo len - hard crash on flashinfer, silent kv-span truncation and a 7-point gsm8k drop on DSV4), unwritten relay rows read as tail inputs (cublas crash), and stale schedule-time tail state under overlap (0.970 -> 0.390 gsm8k before late binding). All reproduced red on pre-fix code during on-GPU verification. Known limitation: these guard corruption, not engagement - a diff that silently stops mixing keeps them green. Co-Authored-By: Claude Fable 5 <[email protected]>
…-degrade # Conflicts: # python/sglang/srt/server_args.py
Co-Authored-By: Claude Fable 5 <[email protected]>
Oasis-Git
requested review from
Qiaolin-Yu,
Ying1123,
hnyls2002,
merrymercy and
xiezhq-hermann
as code owners
August 29, 2026 00:23
…ning mix_with_running now consults batch.spec_algorithm and Req.seqlen; give the minimal test batch the enum init_new always sets (NONE) and mirror the real seqlen property on _FakeReq. Co-Authored-By: Claude Fable 5 <[email protected]>
Co-Authored-By: Claude Fable 5 <[email protected]>
The spec-overlap rebuild of merged seq_lens_cpu from r.seqlen overwrote the running batch's prepared values on the non-spec path, where r.seqlen lags by one step under overlap; mixed tails then carried a CPU length one short (qo_len 0: tail row dropped, SWA page accounting drifts). Scope the rebuild to spec, where the unresolved relay makes merge_batch null the field. Verified on B300 (DSV4-Flash tp4, mixed chunk 512, overlap, gsm8k 200q): pre-fix 0.655 + pool-leak aborts, post-fix 0.975 clean; matches CI TestDSV4FlashFP4BreakableCudaGraphB200 0.81-vs-0.93 + leak signature. Co-Authored-By: Claude Fable 5 <[email protected]>
…nto feat/mixed-chunk-spec-degrade
# Conflicts: # python/sglang/srt/speculative/dflash_worker_v2.py # python/sglang/srt/speculative/dspark_components/dspark_worker_v2.py
Upstream moved kv_committed_len onto req.kv; the mixed-tail +1 still hit the removed Req attribute and killed the scheduler on every spec mixed step. Verified: all three test_spec_mixed_chunk cells green on B300. Co-Authored-By: Claude Fable 5 <[email protected]>
Collaborator
Author
Collaborator
Author
Co-Authored-By: Claude Fable 5 <[email protected]>
Co-Authored-By: Claude Fable 5 <[email protected]>
StevenChenSE
pushed a commit
to StevenChenSE/sglang
that referenced
this pull request
Sep 6, 2026
Co-authored-by: Claude Fable 5 <[email protected]>
This was referenced Sep 29, 2026
efschu
pushed a commit
to efschu/htsglang
that referenced
this pull request
Oct 18, 2026
…n E2 hand-off, PR sgl-project#36933 non-overlap stash, mixed forwards out of the D cost ring A1 (SOLL section 2 'X nie ein fester Wert', R2a, R11): the gate compared u against 0.5 x the rank riegel (--tp-prefill-max-tokens 12288 on NF -> 6144, above every curve X 4096..5800 the front decides with, the bound H16V review A3 removed from the resumed-tail extend). Now halbX = the smallest weg2_front_halfx the front carried with the batch's requests (replicated on every TP rank); a request without one is not mixed. A2: a batch holding an E2 END-state hand-off (tail_adopt.SKIP_PLANS, 405 skip extends in the rc9 D log) runs no target forward; folding decode rows into it made tail_adopt.skip_tokens raise 'mixed batch' on every rank. A3: the PR's non-overlap stash_bonus_tokens call ported 1:1 (the arming does not require overlap). A4: a MIXED forward's gpu-ms holds the decode rows; RankPrefillLog reports it untimed so it never feeds the D cost ring (X-COST-LINE re-solve of X), wake-cohort / mini-forward bounds or x_curves_build. Tests: test_weg2_mixed_d_short_s32_1018.py (18), mutants extended (H1 H2 H3 E1 N1 C1).
efschu
pushed a commit
to efschu/htsglang
that referenced
this pull request
Oct 18, 2026
…6c234) + S32 with S33 review (desk/nf-h16v7-s32-1018 79b2c55, 1f1a524), 6 steps, kit rule per source commit S35: Form A post-admit result uniform (R11; rc9 09:51:22Z death), L3 write-behind does not yield to a room-starved load (R7; rc9 restart 10:09Z stall), p5 pin comment (tree already carried the priority term: hand step, inline comment kept). S32 + review A1-A4: MIXED-D for short D prefills (SGLang PR sgl-project#36933 port), gate on the front's halbX, never an E2 hand-off, non-overlap stash, mixed forwards out of the D cost ring. catalog.json skipped (rebuilt in port 13). Byte proof vs rename(31ae98a609 = local merge of 7d6c234 + 1f1a524): 18 paths, 13 byte-equal, 4 with the pre-existing residual unchanged (environ 8, scheduler 4, hicache_storage 24, server_args 17 lines), pin 1537 residual = the inline comment of the 'priority' line only. Kit collision allowlist: pdflip/fLLiper in 5 files (prose rids).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Modifications
Accuracy Tests
Speed Tests and Profiling
Checklist
Review and Merge Process
/tag-and-rerun-ci,/tag-run-ci-label,/rerun-failed-ciCI States
Latest PR Test (Base): 🚫 Run #33412670050
Latest PR Test (Extra): 🚫 Run #33412669572
Latest PR Test (AMD ROCm 7.2): ⏳ Run #33412670111