Skip to content

[Fix] scheduler: keep chunked prefill within allocatable KV under memory pressure - #46643

Open
aryatsc wants to merge 17 commits into
sgl-project:mainfrom
modal-projects:devin/pr-sched
Open

aryatsc wants to merge 17 commits into
sgl-project:mainfrom
modal-projects:devin/pr-sched

Conversation

@aryatsc

@aryatsc aryatsc commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

Under overload on Kimi-K3 (MI355X, TP8, chunked prefill + hybrid KDA/MLA), the scheduler could stall or fail allocations:

  • A continuing chunk was sized only by the token budget, so it could ask alloc_extend for more KV than is free.
  • A latched batch_is_full was cleared only when the running batch shrank, so the waiting queue could stall after capacity came back.
  • On the aiter backend, an over-capacity extend inside graph replay could leave the chunked-KV path.

Modifications

  • Conditional batch_is_full latch (scheduler.py, schedule_batch.py): after a NO_TOKEN or capacity rejection the latch stays set and records (full available + evictable, mamba available + evictable, allocatable request slots, running rids). It clears only when the running batch is empty, the running set changes, or any availability rises past the recorded value. While it holds, the existing if running_batch.batch_is_full early return skips admission.
  • Continuing chunks fit allocatable KV (prefill_budget.py): PrefillBudget.available_chunk_tokens and SWAPrefillBudget.available_chunk_tokens cap a continuing chunk at remaining_current - page_size, floored to page_size. The page covers alloc_extend on an unaligned prefix, matching reserve(). ChainPrefillBudget is unchanged, since it commits whole requests through fit_chunk against live pool demand. When nothing fits the continuation is parked; if nothing else is running or in flight, so nothing can free KV, it is aborted with 503 instead of parked forever.
  • aiter (attention_backend_handler.py): inside piecewise/breakable graph replay, over-capacity non-speculative extends route to MHA_CHUNKED_KV. Capture (torch-compile warmup, PCG capture stream, stream capturing) and in-capacity replay stay on MHA.

The one-chunked-request guard is already on main; test_default_policy_rejects_second_unfinished_chunk locks it in.

Accuracy Tests

Unit tests in test_scheduler_batch_is_full_latch.py (latch retention after NO_TOKEN, each wake-up condition, lone parked abort), test_prefill_memory_budget.py (page rounding with page_size=1 and a non-empty offset, SWA cap), test_prefill_adder.py and test_aiter_attention_backend_handler.py (capture, in-capacity and over-capacity replay). 127 pass on CPU.

An earlier revision of this PR (unconditional batch_is_full reset) ran a 40-min overload soak on the Kimi-K3 MI355X build (48 concurrent requests against 12 slots): 901/901 requests returned 200, the queue peaked at 37, and there were no OOM, HSA or assert errors.

Speed Tests and Profiling

Scheduler step cost under overload, CPU micro-benchmark of _get_new_batch_prefill_raw over 5000 steps (12 running, 37 waiting, latched after NO_TOKEN): 7.9 us/step with the conditional latch vs 176.3 us/step with the previous unconditional reset. No kernel change.

Checklist


CI States

Latest PR Test (Base): ⊘ Skipped in Run #46956483657 -- its commit has no run-ci approval, or the run predates the labels; a maintainer's /approve-ci approves this commit and reruns it, or /rerun-failed-ci reruns an approved one.
Latest PR Test (Extra): ⊘ Skipped in Run #46956482930 -- its commit has no run-ci approval, or the run predates the labels; a maintainer's /approve-ci approves this commit and reruns it, or /rerun-failed-ci reruns an approved one.
Latest PR Test (AMD ROCm 10): ⚠️ Run #46956487703

Tip

Base CI only covers the core cases, and its workload may not exercise your change. Use /rerun-test to run the tests your change touches, or copy this prompt for an agent:

Find the registered tests this PR affects and run them with /rerun-test, following https://github.com/sgl-project/sglang/blob/main/.agents/skills/rerun-test/SKILL.md

aryatsc and others added 4 commits October 26, 2026 17:46
available_chunk_tokens only looked at the token budget, so under memory
pressure a continuing chunk could ask alloc_extend for more KV than is free
and fail. Cap it by the free + evictable KV (minus the page alloc_extend
over-asks); when the decode-headroom estimate leaves nothing, progress with
the free KV or defer the chunk.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…licy

Only one unfinished chunked request can be tracked, but the guard that
stops a second one was limited to shortest-prefill-first.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
batch_is_full was otherwise only cleared when the running batch shrank, so a
latched flag stalled the waiting queue until an unrelated request finished.
PrefillAdder already enforces the real limits.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

# Conflicts:
#	test/registered/unit/mem_cache/test_prefill_memory_budget.py
detain added a commit to detain/sglang that referenced this pull request Oct 29, 2026
[Fix] scheduler: keep chunked prefill within allocatable KV under memory
pressure. Three admission bugs: (1) a continuation chunk could ask
alloc_extend for more KV than is free -- PrefillBudget.
available_chunk_tokens now caps by real free KV minus the one-page
over-ask and defers (None) instead of forcing a full chunk; (2) the
single-unfinished-chunk guard now applies to ALL policies, not just
shortest-prefill-first (a second unfinished chunk was untrackable);
(3) batch_is_full is cleared unconditionally each round -- a latched
flag was otherwise only cleared when the running batch shrinks,
stalling the waiting queue until an unrelated finish (absorbs closed
sgl-project#35609).

UNION / DEVIATIONS:
- scheduler.py hunk hand-merged: our region carried the entry-198
  hybrid-SSM reset arm + is_empty arm; both are strict subsets of the
  unconditional clear and were removed. Entry-198's COW NO_TOKEN-retry
  semantics are unaffected (admission re-runs every round anyway).
- Consequently the two entry-198 gate tests were re-pinned to the new
  unconditional behavior (non-hybrid now retries every round too);
  their mamba-arm and COW-recovery cases pass unchanged.
- PR's new test_scheduler_batch_is_full_latch.py NOT imported: the
  file already exists in-tree (entry-222 wave) with fork stubs; kept
  ours, refreshed the stale sgl-project#37612-arm comment.
- AITER backend hunk + test_aiter_attention_backend_handler.py SKIPPED
  per instruction (ROCm aiter path irrelevant to this stack).
- test_prefill_memory_budget import hunk conflicted (our tree lacks the
  upstream ChainAllocator test rework): resolved as
  PrefillBudget + SWAPrefillBudget union; new TestContinuingChunkCap
  verbatim.
- Chunk-guard hunk applied verbatim: our _select_prefill_admission
  matched the PR base exactly; no mixed-chunk adaptation fights it
  (mixed-chunk tracks its rows via the scheduler, not new_chunked_req).

CPU: targeted (prefill_adder + memory_budget + 3 latch/retry +
held_row) 83P/67sub; full managers dir 993P/2F/3skip/904sub == the
2F are pre-existing order-dependent test_mm_process_config failures
(verified identical on the stashed baseline, 992P/2F).

(cherry picked from commit 0954308)
(cherry picked from commit d2bf2d29c4b5382291e672a3a1f0ac844cba196b)
detain added a commit to detain/sglang that referenced this pull request Oct 29, 2026
[Fix] scheduler: preserve Mamba fork+tail states across chunked
prefills via opt-in SGLANG_SPLIT_PREFILL_AT_MAMBA_FORK (EnvBool, default
False = byte-identical). One extend tracks one Mamba state, so a chunk
crossing the cached fork loses it; with the flag on (requires
extra-buffer radix strategy + hybrid SSM cache, non-dllm) eligible
prefills end at the aligned fork so the fork state and the tail state
both reach the cache — through initial admission, continuation, and a
host load-back that moved the prefix.

UNION / DEVIATIONS:
- Single-unfinished-chunk guard reconciled per instruction in favor of
  the landed sgl-project#46643 logic: the unconditional 'if has_chunked_req' guard
  is kept (it subsumes this PR's split-conditioned reopening); the PR's
  'or split_prefill_at_mamba_fork' term is a no-op against it.
- Consequently the PR's test
  test_second_unfinished_chunk_guard_follows_policy_unless_fork_split
  is re-pinned to test_second_unfinished_chunk_guard_is_unconditional:
  every policy + both flag states now refuse the second unfinished
  chunk. All other 8 fork tests verbatim.
- add_chunked_req: the fork cut is applied after the sgl-project#45607 hybrid
  page-align (both land on page multiples; order-safe) and before the
  request-slot reserve, matching the PR's position relative to that
  line. truncation_align_size now threads from the scheduler (PR's
  scheduler.py hunk) but is consumed only by _mamba_fork_split_len —
  our entry-177 _align_prefill_chunk call keeps its existing (default)
  argument so no QSA-continuation behavior drifts.
- Test import hunk: the PR base's PrefillBootstrapQueue import does not
  exist in our file; resolved to os + environ.envs + policy-enum
  additions only.

CPU: test_prefill_adder + held_row_admission 69P/85sub (8 fork-matrix
cases pass incl. re-pinned guard); full managers dir +
prefill_memory_budget + mamba donated/capacity +
unified_radix_cache_unittest = 1091P/2888skip/969sub; the only 2F are
the pre-existing order-dependent test_mm_process_config failures
(verified identical on the ported-branch baseline at sgl-project#46643).

(cherry picked from commit 0e20970)
(cherry picked from commit 8832eae148114995e251aed28c16a20985dfd8c5)
detain added a commit to detain/sglang that referenced this pull request Oct 29, 2026
…gl-project#45607/sgl-project#45789 (entries 267-270)

Second admission docs commit. Records: sgl-project#46496 DRAFT-upstream status;
sgl-project#46643's BEHAVIOR CHANGE (admission re-runs every round for ALL models --
TTFT/starvation watch at the owed restart, entry-198 precedent; the two
entry-198 arms removed as strict subsets, COW-retry semantics untouched);
sgl-project#45607 page-align composition with entry-177's lcm aligner (both shrink-
only; exact_chunk_fill arm untouched upstream too); sgl-project#45789 default-OFF
fork-split with the guard reconciliation vs sgl-project#46643 (policy-reopening term
proven no-op, test re-pinned), fork cut after sgl-project#45607 align, and the
deliberate no-thread of truncation_align_size into entry-177's aligner.

Battery: every worker number REPRODUCED EXACT AT THEIR OWN TREES (method
identity), then re-measured on the combined tree with full attribution of
every drift; managers dir RE-PINNED 1013P/2F/3S/933sub (base 988). The
worker's stashed-baseline '992P' decomposes only as fresh-base 988 +
their own picks (+5 at sgl-project#46643 EXACT) -- flagged as measurement noise.
detain added a commit to detain/sglang that referenced this pull request Oct 29, 2026
…20 commits since 12dc623 @ merge-sgl-project#4)

Conflicts: 167 files (149 content / 14 add/add / 4 modify/delete) at the settled
309 tip d28e7cd -- dossier predicted 146 +/-25; the +21 shift is entries
275-309 landing qsa-ring/hicache-ctrl/gdn/moe/llguard deltas into the conflict
zone. By class: A 13 (auto-takes-upstream, dedupe-verified), B 80, C 56, D 18.
102 TODO(merge5) re-plant/fold markers planted: B1 x15, B2 x29, B3 x12, B4 x23,
B5 x23. Re-plant stock: 117 files under /tmp/opencode/merge5-dossier/replant/
(76 fork-hunks patches, 19 upstream-side patches, 14 AA fork copies, 8
preremove snapshots) -- sessions 2/3 re-plant from real code, not memory.

D-list outcomes (must-not-auto-resolve, handled personally):
- sgl-project#45289-vs-sgl-project#44858 (entry 301): VERIFIED, not re-resolved -- the gate/up-order
  final form is in origin/main (5b1dbc2 in range); scales test taken as
  upstream oracle, fork 191-line version saved to replant/ for B5 diffing.
  sgl-project#44858's call-site shape CANNOT survive (our base never had it).
- entry-230 dispatcher vs sgl-project#44993/sgl-project#44994: took upstream structure in
  token_dispatcher/standard.py; published-value CONTRACT lives upstream via
  get_moe_runner_backend() in the LoRA-EP guard; fork's warn-once mismatch
  diagnostic re-plants (B5 marker). UNION GATE: standard_dispatcher 16P (was
  12P, suite grew), model_overrides 121P/1S/210sub (was 112P/1S/181sub),
  fold probe 6P/2F (upstream added a runner_backend arg to the predicate --
  B5 re-pins the probe).
- entry-219 gauge names vs sgl-project#43727 return + sgl-project#44968: PER-POOL NAMES KEPT as the
  serving schema -- hicache_host_pool_{used,total}_tokens{pool} dataclass
  fields, Gauge registrations and labels(pool=) emission re-restored over the
  #4697x structure; hicache_host_pool_evicted_tokens_total already survived
  auto-merge; producer dict restored by union in metrics_reporter. ANTI-NEEDLE
  SATISFIED: old mamba-only gauges are NOT the serving schema.
- entry-221 eager-direct add/add: DEDUPED to upstream (bodies identical except
  est_time 15->9); MEASUREMENT DEBT RECORDED: prefill t/s must be re-measured
  post-B4 before trusting the est_time.
- entry-168 D2H fence vs sgl-project#44800: the fence is ALREADY UPSTREAM (both
  load_fence_stream + write_fence_stream with the load-thread-corruption
  comment in origin/main's cache_controller.py) -- nothing re-planted; the two
  real regions resolved as import-union + comment wording (merge sgl-project#4 stale-tail
  pattern avoided). Fork hunks still saved to replant/ (belt).
- entry-209 clamp + 216/218 ordering + 288-295 hicache-ctrl-era vs #46970x KV
  rewrite: ADOPTED-UPSTREAM across unified_radix_cache/hicache_storage/
  hybrid_cache_controller/memory_pool/kv_cache_builder; EVERY fork hunk
  extracted to replant/*.fork-hunks.patch; B3 re-plant markers planted.
  sgl-project#45703's short-full-match seam arrives with upstream.
- sgl-project#45090 SGLANG_ENABLE_UNIFIED_RADIX_TREE: REMOVAL TAKEN (fork had already
  moved it to _DeprecatedEnv; now gone). grep: ZERO .py readers repo-wide;
  2 upstream-owned docs jsx snippets still export it (deepseek-v4, glm-5.2 --
  upstream's own debt). OPERATOR-OWED CHECK: confirm no /root harness exports
  it (unreadable from this seat).
- sgl-project#39727 unified L3 key: VERIFIED OPT-IN -- merged hicache_storage.py keeps
  the DEFAULT legacy suffix composition _<model>_<tp_rank>_<tp_size>
  (content-anchor: HiCacheFile._init_config_suffix, raise-guarded when
  _unified_chunk_spans is set). ANTI-NEEDLE: no silent key-scheme switch;
  warm /root/hicache_store contents stay addressable.

Modify/delete (4, all victims of upstream sgl-project#45672 test prune + URC split):
- test_unified_radix_cache_unittest.py: REMOVED (adopted split) -- its bare
  unified_tree_core_inspector imports are unreachable post-sgl-project#45236 re-home;
  fork source + hunks saved; B2 marker planted in the new core test.
- test_fused_moe_triton_config.py: REMOVED -- imports common_utils, absent
  from both sides post-sgl-project#45672; the 2 live entry-3/235 tests re-plant in B2.
- test_scheduler_batch_is_full_latch.py: REMOVED -- fork delta was 3 stub-attr
  lines documenting sgl-project#46643's absorbed arms; upstream deletion correct.
- test_qsa_kv_pool.py: KEPT -- fork's 147 added lines are entry-187/200
  sharding + 285-287 QSA-ring tests with NO upstream replacement;
  qsa_kv_pool.py sides converged byte-identical; collects clean. B2 marker.

Cascading silent-auto-merge repairs (classes not in the conflict set but
broken by auto-merge + union splices -- all found by gates, now fixed):
kernels/ops/activation/__init__.py (dead _CUDA registration dup), kernels/ops/
diffusion/__init__.py (5-tuple _SPECS entry), kernels ops embeddings/moe/
attention/mamba __init__ (KernelSpec fields removed upstream: description/
format_signature stripped, CapabilityRequirement->CUDA_ONLY), base_runner/
eager_runner cp_extend + shared_read_event imports retargeted per upstream's
"no imports in runner_utils/__init__" contract, and 4 fork helpers grafted
back onto their take-upstream homes because merged code/tests still import
them (memory_pool.spec_intermediate_bytes_per_req, kv_cache_builder.
_adjust_hicache_size_for_draft + _device_pool_size_per_token,
hybrid_cache_controller.local_restorable_mask, validation_hook.
validate_replayssm_spec_algorithm, arg_groups/moe_hook b12x validator).
flashinfer_cutlass.py flipped to FORK-OWNED (b12x route is fork-only, 760 vs
95 lines; upstream sgl-project#44993 hunks = B5 fold patch saved).

Silent-semantics notes: sgl-project#46127/sgl-project#44912 riders arrived via per-PR picks (union);
sgl-project#45520 (entry 302) is STILL OPEN upstream -- entry-230 fail-safe layer stays
as entry 303 records; if a future sync brings it, re-apply the fail-safe reads.
qwen4_exp holder-contract fused (ctor takes optional batch).

Gates at commit: import sglang OK (CVD=9, prod venv); check_registered_tests/
check_no_bare_pytest_main/check_no_registered_tests_in_package rc=0; ruff F821
+E9+format clean on the resolution set; collect-only over unit/{mem_cache,
model_executor,distributed,layers/moe} = 4337 nodes, 3 ERRORS: 2x cargo/torch-
sys libtorch probe (REPRODUCED IDENTICALLY AT THE PRE-MERGE TIP -- env issue,
not merge damage) + test_hicache_async_ready_sync.py (entry-253-era attribute
gone with the URC rewrite -- EXPECTED pre-B3).

sessions 2/3 owed: B2 test re-home, B3 mem_cache+rust re-plant (+hicache-ctrl
re-ports), B4 scheduler/admission, B5 moe/quant/dispatcher, B6 environ+C0a+
CAVEATS re-pin. PROD BOOT FORBIDDEN until B3 completes (209 clamp + 218
ordering re-plant).
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

# Conflicts:
#	python/sglang/srt/mem_cache/prefill_budget.py
detain added a commit to detain/sglang that referenced this pull request Oct 30, 2026
…entries 122,198,200,211,215,220,267,268,305

Re-plants the scheduler.py fork-hunks (replant/...managers__scheduler.py.fork-hunks.patch)
onto the post-sgl-project#46977 admission structure. tp_worker marker consumed (15/23 B4 markers
still on the tree; per-file counts, damage-state from entry 310's map).

PER-HUNK DECISIONS (all VERIFIED against the merged tree, not taken on faith):
- entry 122 (sgl-project#40458): grammar-sync overlap disable RE-PLANTED for mixed mode
  (is_decode() OR is_mixed()) + the fork's trimmed comments; upstream's
  host-draft-only arm was the pre-sgl-project#40458 form (origin/main verified: absent).
- entry 220 (sgl-project#39765, OPEN port): _has_pending_mamba_cache_update + the early
  pop_and_process/short-circuited disable-overlap RE-PLANTED into
  event_loop_overlap; the require_mlp_sync/disable/extra-buffer gate verbatim.
- entry 198 (sgl-project#37612): THE CATCHER — B3-5 landed the raiser; the
  try/except MambaCowAllocError around init_next_round_input (res=NO_TOKEN,
  request stays queued; the revert block + unconditional alloc_group_end were
  already in the merged tree = the no-leak halves VERIFIED PRESENT) RE-PLANTED
  with the import. COW component test re-anchored to the #46970x kv_storage
  seam the B3-5 replant moved _state() behind (stub was the pre-split
  mamba_allocator shape).
- entry 268 (sgl-project#46643, OPEN port -- VERIFIED NEVER MERGED: git log
  12dc623..2a6c204 --grep 46643 = ZERO; only sgl-project#45491/sgl-project#45435/sgl-project#45472/sgl-project#45670
  of the briefed merged-list arrived in-range): the UNCONDITIONAL batch_is_full
  clear RE-PLANTED on the scheduler side, subsuming the entry-198 hybrid-SSM
  arm and the priority-preemption/is_empty arms (policy side lands in B4-3).
- entry 267 (sgl-project#46496): retract_decode new_token_ratio FLOOR clamp RE-PLANTED.
- entry 211: triton_load_watch.prewarm_device_loads(self.model_worker) line
  RE-PLANTED between install() and mark_serving_started (the utils-side
  function survived the merge; only the call site was dropped).
- entry 200 (sgl-project#43527) CAPACITY PAIR RE-PLANTED: model_runner
  .logical_max_total_num_tokens passes allocator= again (the configurator's
  PageInterleavePoolAllocator -> allocator.size branch SURVIVED the merge
  byte-identical, so the merged tree had the fork predicate with upstream's
  consumer-side multiplications = DOUBLE-COUNT); the three scheduler
  * kv_shard_widening multipliers back to the fork form (pool-stats shape,
  load_inquirer, and the init_req one-page-per-shard subtraction);
  tp_worker drops page_interleave_shard_size x + import. Upstream's
  invariant-checker hunk: OBSOLETE (the constructor no longer takes
  max_total_num_tokens -- absorbed by refactor).
- entry 215 (sgl-project#44351/sgl-project#44401/sgl-project#44420): VERIFIED ALREADY PRESENT at the merge
  (filter_batch-every-step + reset ride, num_held_rows, budget_state FIRST
  statement, PD-gate deletion all byte-compare to the fork form) -- DEDUPED,
  no edit. Entry 107's local early-revision of sgl-project#40940 stays superseded
  (entry 215 rule), and its re-plant here would double-count.
- entry 220's/305's pause-window busy accounting + write_fence_stream +
  is_empty arm: VERIFIED PRESENT (entry 305 landed patch-identical via
  sgl-project#46127; the fence assignment is the B3-2 controller half) -- DEDUPED.

TEST FIXTURE RE-ANCHORS (not B2's: no markers, pure new-upstream-contract
drift, per the entry-198 fixture-adaptation precedent): the two hybrid-ssm
admission stubs gain disagg_prefill_bootstrap_queue=None (upstream's
routing-key bootstrap_queue arg in calc_priority arrived in-range).

PRUNE vs BREAKAGE (managers −523sub audit): the three managers test files
vanished in-range (test_schedule_policy_dfs_weight, test_scheduler_batch_is
_full_latch, test_uno_token_accounting) were ALL deleted by upstream's OWN
sgl-project#45672 prune (3438ed6). Two are byte-identical upstream copies = zero
fork delta. The third carried a 3-line fork comment/stub delta whose
SEMANTICS the re-planted unconditional clear pins: its case was the
is_empty-arm mirror of test_scheduler_hybrid_ssm_admission_latch (present,
green, hybrid_swa/non-hybrid arms included) -- NOT re-homed, recorded.

ACTUALS (damage -> after, CVD=9, prod venv, PYTHONPATH=python, per-file):
  test_scheduler_hybrid_ssm_admission_retry   4F -> ** 4P **
  test_scheduler_hybrid_ssm_admission_latch   3F -> ** 4P **
  test_mamba_prefill_cache_boundary  2F/12subF -> ** 5P/12sub EXACT (220 pin) **
  test_scheduler_retract_ratio                1F -> ** 2P EXACT (267 pin) **
  test_scheduler_init_req_max_new_tokens      1F -> ** 10P/6sub **
  test_scheduler_grammar_mixed_tail_sync      1F -> ** 4P **
  adjacent scheduler-stub files (held_row, running_batch_finished,
  pause_generation, disagg_idle, dp_converted, hicache_events) 56P/64sub
  UNMOVED -- no regression from the clear/catcher/capacity edits.
Lint: ruff format + F821/E9 clean on all five files; imports OK (no GPU
execution, no push).

Co-Authored-By: OpenCode <[email protected]>
detain added a commit to detain/sglang that referenced this pull request Oct 30, 2026
…46977 pricing reconciliation (entries 177,266,268,269,270 + 217)

2 markers consumed (schedule_policy.py, scheduler.py). B4 tree count now 15.
prefill_budget.py needed NO edit: sgl-project#46643's fix(1) (available_chunk_tokens
capped by real free KV minus the one-page over-ask, defer-not-force) SURVIVED
the merge byte-identical in the base class -- deduped with evidence (diff
309-tip vs HEAD shows only upstream's additive state_slot plumbing).

DECISION TABLE (per-hunk, sgl-project#46977 new admission pricing vs entries 265..270):
- entry 177 prefill_chunk_alignment: RE-PLANTED as-is -- kwarg + attribute +
  _align_prefill_chunk (LCM w/ kv_shard_granule) verbatim; the new tree's
  add_chunked_req grew a kv_shard_granule floor (upstream) that idempotently
  composes with the LCM (both floor-to-multiple); scheduler-side get_kvcache
  read RE-PLANTED too (dropped at the merge = the held_row/adder TypeErrors).
- entry 266 sgl-project#43484 classic-pool slot ledger: RE-ADAPTED. The unified half is
  SUPERSEDED-BY-EQUIVALENT: sgl-project#46977 moved the exact fork ledger onto the budget
  (ChainPrefillBudget.rem_state_slots = mamba_allocator.schedulable +
  mamba_evictable; debit rem -= state_slot_tokens//cost in reserve(); gate via
  budget_state's state_slots_exhausted()) -- factor 1, charge == reserve //
  cost, byte-for-byte identical semantics; the adder-side twin was DROPPED to
  avoid a double ledger. The CLASSIC half SURVIVES as fork delta (the
  base-class budget never sees state): isinstance(HybridReqToTokenPool) gate
  (NOT hasattr -- MagicMock discipline, 266(c) preserved), per-req charge
  1 + mamba_initial_tracking_slots (PR-bug math substitution kept, 266(a)),
  budget_state gate on the FULL charge (< per_req), add_one_req required-slot
  check incl. the defer_staged mamba branch, and slot-unit DEBIT threading at
  all five commit sites + _commit_prefill_admission.
- entry 267: (B4-1) done. entry 268 fix(2): RE-PLANTED -- the
  second-unfinished-chunk guard now applies to ALL policies (the merged
  shortest-prefill-first-only restriction was upstream's own pre-sgl-project#46643 form;
  git log: sgl-project#46643 never merged). sgl-project#45789's policy-reopening term stays the
  recorded PROVEN NO-OP (270(i)); test re-pins ..._is_unconditional.
- entry 269 page-align: RE-PLANTED verbatim at its 3 sites, composed with
  sgl-project#46977's floor_chunked_tokens (DCP grid) as page-align-then-grid-then-fork.
- entry 270 fork-split: RE-PLANTED (gate on get_exec().mamba.enable_mamba_
  extra_buffer + SGLANG_SPLIT_PREFILL_AT_MAMBA_FORK on our env -- the env
  union landed complete at the merge, environ.py untouched), incl. the
  continuation/commit/new-chunk/ignore-eos sites, the larger-host-hit
  re-clamp (270's fork cut lands AFTER page-align, order-safe), the
  truncation_align_size threading from scheduler (270(iii): _align_prefill_chunk
  call KEEPS its default arg deliberately), and the 'no other prefill may
  take its slot' return.
- entry 217 (PrefillAdder closes admission on retraction): the
  finish_storage_prefetch_admission sites VERIFIED PRESENT (retraction/discard
  x2) -- DEDUPED, no edit.
- entry 265: the brp required-slot block's defer/NO_TOKEN shape above; id-set
  half was B4-2.

BEHAVIOR (DEFAULT-ON) reaffirmed for the owed restart-watch: sgl-project#45472's
sync-free planning (B4-2 verified in-tree) + sgl-project#46643's UNCONDITIONAL per-round
admission re-runs (re-planting this cluster) are the two entry-198-class
behavior changes owed TTFT/starvation A/B at the prod restart (still banned;
zero GPU execution this session).

TEST RE-ANCHORS (upstream rewrites of these files silently dropped the
fork's fixture halves -- restored from the 309-tip versions, each pinned by
entry 215/266's own text): held_row's _Adder.add_chunked_req truncation_
align_size kwarg + get_kvcache allocator stub (entry-177 pair, upstream
sgl-project#46980 rewrite dropped them); dcp_logical's pools NS gains state=None
(#46970x _InitializedPools field) and test_scheduler_consumers_receives
_logical_capacity re-adapted to the new seams (pool-stats via the storage
shape, invariant checker's capacity kwarg REMOVED upstream, load_inquirer
direct) -- same anti-double-widening intent, kv_shard_widening=4 fixture
obsolete by design after the B4-1 re-plant.

ACTUALS (damage -> after, CVD=9, prod venv, per-file):
  test_prefill_adder   7F/32subF (39F storm) -> ** 71P/0F/94sub **
  test_dcp_logical_capacity 1F/6subF -> ** 5P/6sub **
  test_scheduler_held_row_admission (regressed by my scheduler wiring, then
  repaired) -> ** 1P/2sub EXACT (215 pin) **
  hybrid_ssm latch+retry family ** 9P ** (entry-198's '8P' + B4-1's case)
  DIR: unit/managers 1048P/48F/9S/439sub -> ** 1055P/3F/9S/474sub **
  (3F = the two order-dependent test_mm_process_config ENV F's [reproduce
  at base] + test_io_struct 1F [diagnosed B4-5, fixture half]).
Lint: ruff format + F821/E9 clean. No GPU; no push.

Co-Authored-By: OpenCode <[email protected]>
detain added a commit to detain/sglang that referenced this pull request Oct 30, 2026
…re-plant) SESSION 2B COMPLETE

Entry 312 records: the 5 cluster commits (9bd9007..5cde7a5) with per-
cluster batteries; THE sgl-project#46977 RECONCILIATION DECISION TABLE (per-hunk
survive-as-is / re-adapt / supersede, incl. the git-log proof that the
spec-mamba four arrived in-range while the admission six NEVER merged --
correcting the briefing's dedupe list, and sgl-project#46643 fix(1)'s reconcile as
already-merged base-PrefillBudget form = the reason prefill_budget.py got
ZERO B4 edits); the entry-200 CAPACITY-PAIR restoration (our configurator's
allocator.size branch survived -> upstream's consumer-side multiplications
double-counted -> model_runner allocator= kwarg + tp_worker/scheduler
subtractive forms re-planted; invariant-checker hunk OBSOLETE by upstream
refactor); the io_struct NEEDS-ATTENTION VERDICT (upstream's own
pointer_head guard vs stale fork stub -- test-side one-field re-anchor,
matching sibling stubs); the -523sub PRUNE-vs-BREAKAGE audit (all three
vanished managers files died to upstream's OWN sgl-project#45672 prune, two byte-
identical to origin/main, the third's fork delta subsumed by sgl-project#46643 --
recorded, not re-homed); the B3 cross-note closures (MambaCowAllocError
CATCHER landed; 216/217 admission interplay VERIFIED absorbed); the 2err
population correction (replayssm_ring_fold pruned by sgl-project#44690, gdn cutedsl
probe lives in the kernels zone, the spec dir's real err was merge damage,
now 0err); the runner-zone finds the damage map missed (_init_model_hooks
BOOT-INTEGRITY loss -- real decode-runner builds AttributeError, and
component_manager's dropped residency half that parallel_executor already
CALLS: both re-planted, 7F+crash-class closed); the true marker census (23
tree-carried, NOT the briefing's 20 -- B3 lesson applied; ALL consumed,
B4=0, B1/B2/B5 diff-audited intact).

GATES: trailing_endpoint ** 17P = 17P ** re-verified post-B4 (DoD-d, B3's
gate unmoved). DoD(e) diff audit: ZERO mem_cache/ files changed, ZERO in
qsa/moe-quant zones (moe_hook diff is marker-removal-only).

NEW PINS: unit/managers 1009P/81F/9S/412sub/2err -> 1056P/2F/9S/474sub (2F
= the two documented order-dependent mm_process_config ENV F's; the dir's
2err never reproduced -- population is the spec row's); unit/spec
363P/20F/21S/238sub/2err -> 388P/0F/21S/238sub/0err EXACT over 7
consecutive full-dir runs. OWED RESTART-WATCH REAFFIRMED: sgl-project#45472's
sync-free planning (verified present, upstream form) + sgl-project#46643's
unconditional per-round admission re-runs (re-planted) ride the entry-201
restart; entry-198's TTFT/starvation measure STILL OWED.

Header: STACK -> qwennext-stack-312+merge5-b4-2026-10-29; +merge5-b4 wave
tag; tip -> 5cde7a5; entries 1-312; INTEGRATION OWED annotated B4
LANDED (boot ban STAYS). wanted_stack: UNTOUCHED (no S-item changed by B4
findings -- recorded here). ENV debts recorded NOT-fixed: pcie_vocab_gather
GPU suite (27F identical at the merge commit), openai 2.6.1<2.8.0
serving_responses import (upstream's own beam.py), imageio (whole diffusion
import chain). NOTHING PUSHED; tree clean; zero GPU execution; zero prod
boots all session.

Co-Authored-By: OpenCode <[email protected]>

@rkarhila-amd rkarhila-amd 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.

This PR has three small changes on scheduling:
(1) bysassing "shortest-prefill-first" check in chunked prefill policy means that all policies lead to same branch
(2) always resetting "batch_is_full" in _get_new_batch_prefill_raw function in the scheduler
(3) changing available_chunk_count calculation in prefill budget, so that available tokens calculation take into account evictable KV tokens among other factors. Also if 0 tokens are available, None is returned, as opposed to old behaviour where full chunk size was returned.

The changes are small but impact all models, and for this reason, I kindly ask for reproduction commands to show the problems that are fixed, and to verify with several other models that the performance with these scheduling changes is not adversely affected.

@aryatsc

aryatsc commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

@rkarhila-amd thanks. Reproductions and the multi-model A/B are below.

Reproduction commands

Each fix has a unit test that fails on the merge base (fbc90a860e) and passes on this branch (ae64753ca5). To reproduce, run the new tests against the old scheduler code:

git worktree add /tmp/sched-base fbc90a860e
cd /tmp/sched-base
git checkout ae64753ca5 -- \
  test/registered/unit/managers/test_prefill_adder.py \
  test/registered/unit/managers/test_scheduler_batch_is_full_latch.py \
  test/registered/unit/mem_cache/test_prefill_memory_budget.py \
  test/registered/unit/models/test_aiter_attention_backend_handler.py
PYTHONPATH=python python -m pytest -q <the four files above>
Fix Commit Test (fails on base, passes on PR) What it reproduces
1. One unfinished chunked request under every policy ba516e7 test_prefill_adder.py::TestPrefillAdder::test_default_policy_rejects_second_unfinished_chunk Under the default (non-SPF) policy, PrefillAdder starts a second chunk while one is already in flight. The scheduler only tracks one chunked_req, so the first one is lost.
2. Re-evaluate batch_is_full each step 274ec4c test_scheduler_batch_is_full_latch.py::TestEmptyBatchFullLatch::{test_latched_empty_batch_still_admits, test_latched_running_batch_still_admits} Once batch_is_full is set, _get_new_batch_prefill_raw returns None until an unrelated request finishes, even if the KV has freed up. Waiting requests stall.
3. Cap a continuing chunk by allocatable KV (incl. evictable), else defer af2910e test_prefill_memory_budget.py::TestContinuingChunkCap::{test_chunk_is_deferred_without_free_kv, test_chunk_leaves_the_page_alloc_extend_over_asks} With no free or evictable KV, the old code returned chunk_limit anyway, so alloc_extend over-asks and fails. Now it returns a size that fits, or None to defer.
(ROCm) keep over-capacity aiter extends chunked 514ee13 test_aiter_attention_backend_handler.py::TestAiterOverCapacityExtend::test_over_capacity_extend_stays_chunked_in_graph_context

Result: 6 failed, 71 passed on base with the PR tests, and 77 passed on the PR branch. CPU only.

Multi-model performance (MI355X, TP1)

Same image for both arms; only python/ differs: base is fbc90a860e, PR is ae64753ca5. Server flags are --tp 1 --chunked-prefill-size 8192. kv-pressure adds --max-total-tokens 40000, which forces chunk continuation, batch_is_full, and eviction on every step. Each arm was run twice in alternating order (base, pr, base, pr) on a fresh server:

python -m sglang.bench_serving --backend sglang --dataset-name random \
  --random-input-len 3000 --random-output-len 300 --random-range-ratio 0.5 \
  --num-prompts 320 --max-concurrency 64 --seed 1
Model Config Arm Completed Output tok/s Mean TTFT (ms) P99 TTFT (ms) Mean TPOT (ms)
Qwen3-8B default base 320 / 320 3386 256 1733 17.1
Qwen3-8B default PR 320 / 320 3397 255 1723 17.1
Qwen3-8B kv-pressure base 320 / 320 2039 4928 6121 7.2
Qwen3-8B kv-pressure PR 320 / 320 2037 4926 6110 7.2
Qwen3-30B-A3B default base 320 / 320 2659 259 1607 22.0
Qwen3-30B-A3B default PR 320 / 320 2612 262 1617 22.4
Qwen3-30B-A3B kv-pressure base 320 / 320 1441 6958 8705 10.2
Qwen3-30B-A3B kv-pressure PR 320 / 320 1435 6978 8692 10.3
DeepSeek-V2-Lite default base 320 / 320 3134 263 1464 18.4
DeepSeek-V2-Lite default PR 320 / 320 3111 264 1449 18.6
DeepSeek-V2-Lite kv-pressure base 320 / 320 1526 6605 8228 9.6
DeepSeek-V2-Lite kv-pressure PR 320 / 320 1522 6619 8246 9.6

Values are means of the two runs. One exception: the first base run of each model in the default config was the container's first server start (cold JIT, for example 980 tok/s on Qwen3-8B), so the base default rows use only the second base run. Raw values for every run:

All runs (output tok/s, mean TTFT ms)
Model Config base r1 PR r1 base r2 PR r2
Qwen3-8B default 980 / 443 (cold) 3402 / 255 3386 / 256 3391 / 255
Qwen3-8B kv-pressure 2037 / 4930 2041 / 4916 2040 / 4926 2033 / 4936
Qwen3-30B-A3B default 2441 / 284 (cold) 2619 / 258 2659 / 259 2605 / 266
Qwen3-30B-A3B kv-pressure 1442 / 6950 1442 / 6945 1439 / 6965 1428 / 7011
DeepSeek-V2-Lite default 2993 / 430 (cold) 3106 / 261 3134 / 263 3116 / 266
DeepSeek-V2-Lite kv-pressure 1522 / 6624 1523 / 6616 1530 / 6586 1521 / 6622

Every request completed in all 24 runs. Differences are within ±1% on every row except Qwen3-30B-A3B default, which is −1.8% against a single warm base run; that is inside the base r1-to-r2 spread on the same row. DeepSeek-V2-Lite server logs had 2–4 lines matching out of memory|Traceback|assert in both arms, while the Qwen logs had none. No run crashed, failed a request, or emitted an OOM.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

# Conflicts:
#	python/sglang/srt/managers/schedule_policy.py
#	test/registered/unit/mem_cache/test_prefill_memory_budget.py
detain added a commit to detain/sglang that referenced this pull request Nov 11, 2026
… survivors

RE-PLANTS (fork-only, no upstream equivalent in-window):
- static_kv_storage.py:392 -- entry-200 sharded-decode rotation_bases arm
  (take_decode): the merged page_interleave.alloc_decode STILL asserts one base
  per request ("sharded alloc_decode needs the rotation base of every
  request"), so sharded-QSA decode dies without it; take_extend's twin
  survived. Adapted self._batch -> the merged batch param.
- prefill_budget.py:228 -- sgl-project#46643 fix(1) (open upstream, never landed): cap the
  continuing chunk at _available_and_evictable minus the one-page over-ask and
  DEFER (None); upstream's forcing tail + the new CP-shard arm folded into the
  same min(). TestContinuingChunkCap 0F (was 2F).
- components/mamba.py:723/907/933 -- the donation-skip recorder
  (_record_skipped_checkpoint, entry 197/sgl-project#37943) at all THREE pinned-pool arms
  (upstream's re-expanded branch form lost them), the entries 197/216
  caller-contract docstring on _try_alloc_mamba_slot, and the region@982
  note (the fresh slot is the merged mamba_value_donated assignment).
- pool_host/group.py:318 -- the entry-90 mirror-fix rationale comment restored
  at the merge_source_transfers call (the call itself survived).
- hybrid_pool_assembler.py:1379/1387/1480 -- the --hicache-mamba-size-gb knob
  override re-plant in the SIMPLE mamba stack builder (it survived only in the
  SWA-group builder; a plain KV+Mamba boot silently ignored the knob); the
  coverage boot line (_log_mamba_host_coverage -- entry-219's "silent paths
  talk" half, a defined-but-never-called orphan after the merge) restored in
  BOTH builders via the _mamba_entry host pool; region@1377's use_mla fraction
  ADOPTED (=_kv_budget_index_bytes generalization, folded note in-tree);
  build_mamba_host_pool + packed-draft mapping ADOPTED (absorbed into
  _mamba_entry 1315/1323).
- pool_host/base.py:357 -- the grafted-back host_memory_budget_bytes in-scope
  branch ADAPTED to upstream's (plain-RAM, hugetlb) tuple snapshot (the int
  arithmetic would TypeError the moment any scoped caller booked; the
  per-pool booking is now HostMemoryPreflight's).

ADOPTED (upstream subsumes; sha cited in-tree):
- storage/fast_file/fast_file_store.py:833 -- whole-module fork port subsumed by
  the merged fast_file family; fork deltas live in the shared base
  (HiCacheFile._build_config_suffix hicache_storage.py:852, batch_exists_v2
  restorable_prefix_pages :296 -- both present).
- pool_host/group.py:17 -- import region survived the PoolName->HostPoolName
  rename; merge_source_transfers still rides the same block.

TEST-SIDE CASCADE (signature/return-shape chase, semantics preserved):
- test_kv_cache_configurator_mamba_budget: stub gains the upstream
  allocate_intermediate_ssm clause read (dataclass default True) -> 5F->0.
- test_hicache_explicit_budget: budget scope asserts retargeted to the tuple
  snapshot ((12345,0)/(1,0)) -> 2F->0.
- test_mamba_donated_alloc_ratio: harness req gains rid= (the skip recorder
  names the request; union merge dropped the field with the fork arm).
- test_hybrid_pool_assembler: declared-indexer test retargeted to the new
  build_hybrid_mamba_stack(root pool) API (decls=/use_mla= kwargs gone).
- test_page_interleave_shard: is_dsv4_model -> is_compressed_kv_model rename
  chase (configurator:2850) -> 1F->0.

Battery actuals (CPU, CVD=9, PYTHONPATH=wt/python):
- mamba_budget 5F->0, explicit_budget 2F->0, page_interleave_shard 1F->0,
  prefill_memory_budget 2F->0, donated new-break 3F->0 (back to baseline).
- Residuals here (all present in the baseline-to-beat, reported): assembler
  TestHybridMambaDeclaredIndexer 5 subfails = the new _prepare_sidecar
  contiguity check vs the test's synthetic (256000,132) meta index buffer
  (b2/qsa harness class); donated TestMambaRatioEnvGate 2 = schedule_batch's
  _alloc_tracking_slots stub gap (b4 zone).
Gates: ruff repo ruleset+format on touched files; registration trio rc=0.
zone=b3 marker census: 0 remaining (18/18).
detain added a commit to detain/sglang that referenced this pull request Nov 11, 2026
…edule_batch grammar-mixed -- 15/39 markers consumed

- grammar_needs_sync RE-PLANTED (entry-122 mixed-tail arm) folded INTO
  upstream's in-window is_none gate (both live inside the predicate now; the
  single scheduler caller is should_process_last_batch_early, C1).
- sgl-project#43484/entry-266 CLASSIC ledger RE-PLANTED onto the renamed helpers:
  _update_prefill_budget gains state_slots_charge (slot-unit debit, the
  unified chain stays byte-for-byte factor-1 on the budget), threaded at all
  5 call sites + _commit_prefill_admission; add_one_req's gate regains the
  required_state_slots > rem_mamba_slots OR-arm (266(c) isinstance/MagicMock
  discipline untouched -- seed block was already consistent).
- sgl-project#46643 fix(2/3) consistency VERIFIED against b3's fix(1) re-plant in
  prefill_budget.available_chunk_tokens (fork cap/defer form intact, zero
  edits; the guards-every-policy comment restored where the fork had it).
- entry-270 gate RE-PLANTED: select-time _mamba_fork_split_len cut (chunk_
  tokens_limit & not has_chunked_req & new_chunked_req is None) in
  _select_prefill_admission, the continuation-path fork split in
  _add_chunked_req, the leaves-budget-behind OTHER return after commit, and
  the truncation_align_size kwarg chain add_chunked_req -> _add_chunked_req
  (entry-177; the scheduler call site had already survived -- TypeError
  class from b3 handoff).
- entry-269/177 composition RE-PLANTED in add_one_req_ignore_eos chunked
  branch: floor -> page-align -> cache-alignment LCM, empty-cut guard.
- _state_slot_reserve_for_req -> upstream _state_slots_for_req rename ADOPTED
  (charge == reserve semantics preserved through the budget's own
  slot*cost conversion; helper note 'renamed upstream' resolved).

Test seams re-pinned (no weakening): mixed_mamba_track -> sgl-project#48328 reserved-
slot-0 untracked padding + GDNAttnBackend.state_pool view binding; prefill_
adder host-hit-select call -> window_host_hit_lengths rename.

Targeted: 98P/0F/118sub (prefill_adder+grammar_sync+mixed_track+boundary).
Gates: ruff repo ruleset + format; registration trio rc=0 (unchanged set).
detain added a commit to detain/sglang that referenced this pull request Nov 11, 2026
…+ re-plant era CLOSED at b86b7c9 (125/125 markers; grep census ZERO verified at this tree): header STACK epoch 321-2026-10-30 -> 329-2026-11-10 (supersession note kept) + +merge6-era-closeout-2026-11-10 trailer line + entries-count 1-329; tip/HEAD re-pinned (era CODE TIP b86b7c9 NAMED with the full wave chain, superseded values dea2641/e9f0ae1838/065fdcdf33/b7c656f69f/5cde7a5ede kept, docs tip recorded as this wave) + a prominent ** LIVE/BOOT STATE ** line (main checkout detached @ 2d87757 = the ONLY boot-validated state, 9b 16:58:52 warm all-needles-hit per prod-health-2026-11-10.txt; era branch CPU-green but NOT BOOTED -- switching prod = operator-chosen checkout + the entry-326 boot-watch). ENTRY 324: imports+bootfix trunk wave -- sgl-project#48781 require_attn_tp_gather->dp_attention relocation invisible to markers, base_runner deletion-only fix unmasking the 145E/32E/31E collection cascade (1dcc2d6); THEN the operator-live crash: maybe_init_router_registration read tokenizer_ipc_name before init_ipc_channels at OUR fork's entry-201 init order, call moved back to upstream's position, RED(2F)/GREEN(2P) test_tokenizer_manager_init_order.py, family scan clean + report-only carry (10a1c08). ENTRY 325: RE-PLANT ERA TABLE b1 12 / b3 18 / b4 39 / b5 17 / b2 23 / b6 16 = 125/125 per-wave dispositions (compressed from the commit bodies, all shas cited) + the NINE ERA CATCHES with FULL CREDIT: _rope_cache_key 10/11-arg universal get_rope crash (15 spec F were its fingerprints), PLE file-backend env registration gap (AttributeError every boot), COW-catcher doubled-staging-arm cascade bug, stat_loggers DI test restored from its corrupted merge hybrid, w13 refined-grid mis-key, the budget-contract decision (fork accounting RESTORED, evidence 106.9GB/100GB = the entry-317 leak shape; INDEXER collective order verified), verify-gate SUBSUME pick (sgl-project#44047 eats sgl-project#42779, both intents preserved), mm_process_config ambient-widths root-cause (validators now state the full 8-way layout), TLFIX twin re-pinned 282/285. ENTRY 326: BATTERY RE-PIN TABLE -- era pins managers 1307P/0F, spec 406P/0F, server_args 496P/0F, sampling 252P/0F, distributed 213P/0F, mem_cache 2965P/24F (the ACCEPTED device-only 24-node list over 8 files), cargo 966P/0F/1-ignored, five registration/wheel gates rc=0 + the PATH-TO-BOOTABLE statement: CPU-proven vs GPU-window debt -- first-boot needles incl. the sampling.cuh-vs-0.7.2 JIT arbitration (if it JIT-fails, wheel-trio-then-pin per S-FI073, never a lone re-pin), autotune caches SHOULD hit warm (no retune owed on 0.7.2), entry-322 verify-at-boot quartet, and the still-riding 321-era watches (sgl-project#45472/sgl-project#46643 TTFT+starvation, first-delta tool-stream latency). ENTRY 327: WHEELS & VENV RECORD -- pairing matrix (FI 0.7.2 HELD, sgl-kernel 0.4.10/0.4.10 era-consistent with the RETIRED-rule cross-ref, torch/cutlass-dsl MATCH), blake3 1.0.11 INSTALLED with ZERO-DRIFT PROOF (0 battery lines vs ~380; matrix re-read unchanged; negative-shim prefix-sim causality) + no-pip/uv-note (operator lane), the two tree-side wheel reverts with reachability + residual-symbol evidence, check_dockerfile_wheel_pins re-green, FI-0.7.3 adoption contract restated with post-era facts (upstream code now expects 0.7.3 in one reported JIT path; tree HELD 0.7.2; first boot arbitrates), dist-name/module-name note sglang_kernel/sgl_kernel. ENTRY 328: INCIDENT RECORD 2026-11-10 ~16:4x-16:58, honest narrative -- re-plant waves landed into the EDITABLE-IMPORT working tree while :30000/:30001 ran; 9b died ~pre-16:50 (cause UNVERIFIABLE from the user acct, /root logs unreadable; worker-respawn-importing-changed-code is the LEADING MECHANISM, stated AS SUCH); the operator restart hit the init-order crash = the era's flagship find; recovery = merge6-era-backup @ b069e6a + detached checkout 2d87757, 9b re-booted WARM 16:58:52 all needles hit, 9d NEVER dropped (Nov 3, HTTP 200); NEW ERA LAW: working tree = prod import path, integration by branch ref-move ONLY; b2's emergency-freeze WIP 7ccf76a (author 16:55:02) kept in range and completed as C1 -- provenance note. ENTRY 329: BACKFILL AUDIT RECORD -- window 2026-08-10..2026-10-27, universe 2714 = 1830 in-tree / 255 already-documented / 628 NEW REJECTS / 1 NEW-INTERESTING; method one-liners; the qwen4-main-squashed side-branch class discovery (REJECT-MERGED-TO-SIDE-BRANCH x44 -- future sweeps MUST filter by base; orchestrator's "206" NOT FOUND in the artifacts, 44 recorded as verified); sgl-project#36043 NVFP4 skinny GEMM SM120 full paragraph (closed-unmerged, absent-tree-verified, W4A4 M<=16 = our exact decode cell, BENCHMARK-BEFORE-PORT -> S-36043-BENCH filed); artifact paths. EVALUATED: the 671-line DOCS-BLOCK.txt inserted VERBATIM as its own dated block (165 dropped list-commas tidied at insertion, noted once at the block head; nothing else reflowed). DATED CORRECTIONS where the waves superseded 322/323-era operational text: the header PROD-BOOT-FORBIDDEN bullet and entry 323's WHEEL DRIFT + STATE lines get [11-10 ERA-CLOSE CORRECTION] annotations (classes closed, wheel landed, ban now purely the operator gate); marker-zone math re-verified against the wave ledgers (121-at-merge vs 125 recount stands correct; planted == consumed per zone). WATCH LIST: era-close block appended (sgl-project#36043 bench-gated; sgl-project#42790/sgl-project#40916 arrived-via-merge6 noted; sgl-project#43703 revert-trap cross-ref from entry 323; sgl-project#45520 STILL-OPEN re-confirmed at era close -- zero in-window refs, b5 verified the fail-safe layer intact; bootfix's report-only get_tokenizer_worker_class/entrypoints wiring carry). Docs-only: NO .py touched; check_registered_tests rc=0 re-run against this tree. NOTHING PUSHED; the live tree was NOT touched by this wave (ref-move integration follows with HEAD/status equality proofs).
@rkarhila-amd

Copy link
Copy Markdown

Thanks, looks ok.

aryatsc and others added 2 commits November 13, 2026 18:17
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

# Conflicts:
#	python/sglang/srt/mem_cache/prefill_budget.py
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@aryatsc

aryatsc commented Nov 13, 2026

Copy link
Copy Markdown
Contributor Author

Merged main. Upstream #44823 now parks a continuation once the budget is spent, so I dropped this PR's free-KV fallback and kept only the cap by allocatable KV (90fed52). Unit tests pass.

aryatsc and others added 2 commits November 17, 2026 06:06
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

# Conflicts:
#	test/registered/unit/mem_cache/test_prefill_memory_budget.py
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

@rkarhila-amd rkarhila-amd 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.

(sorry I forgot to remove my "request changes" earlier)

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@HaiShaw HaiShaw added run-ci CI: run the baseline test suite on this PR run-ci-nv-extra CI: NVIDIA/shared Extra suite (requires run-ci) labels Nov 30, 2026

@HaiShaw HaiShaw left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Findings

  1. Unconditional batch_is_full = False drops the admission latch (high).
  • The latch was meant to stop retrying admission while running work must finish. batch_is_full_after_rejection returns True after a NO_TOKEN rejection precisely for that.
  • With this change, every scheduling step that has waiting requests and a non-empty running batch goes through the whole admission path: calc_priority, the adder loop, prefix matching and _drop_unadmitted_match, and a possible eviction or load-back attempt. It does this on every decode iteration under overload, which is the exact scenario the PR targets.
  • The comment at the "After the early returns, so a full-batch pass does not scan the queue" line is now only true for the slot-limit case. The KV-full case scans every step.
  • There is no CPU-cost measurement. The soak reports 901/901 requests OK and no errors, not per-step scheduler time or TPOT.
  • Suggested alternatives:
    • clear the flag only when KV availability or the running set changed since it was set (for example by tracking available_size + evictable at latch time), or
      rate-limit retries.
    • At minimum, report scheduler time per step before and after.
  1. The batch_is_full check right after the reset is dead code (low). if running_batch.batch_is_full or len(self.waiting_queue) == 0 is evaluated immediately after the flag is forced to False, so the first clause can never be true. It is also misleading, because the flag is still set to True later in the same function. Remove the clause, or keep a real condition and drop the unconditional reset.

  2. The handler change leaks into capture routing (medium).

  • The new early return doesn't test graph context. Outside a graph it duplicates the existing if not _support_mha_one_shot → MHA_CHUNKED_KV a few lines below, so it does nothing there.
  • Inside piecewise or breakable graph context it now overrides the existing MHA route whenever the extend is over capacity. That also applies during capture if the capture-time sequence lengths exceed get_max_chunk_capacity(). The nearby comment in _handle_attention_backend says chunked MHA shapes "vary with kv-len and cannot be captured".
  • Make the condition explicit: apply the early return only when in graph context and not capturing. If capture can't be told apart from replay, say so in a comment.
  • The unit test patches is_in_breakable_cuda_graph=True but doesn't cover capture time or the in-capacity case. Add both.
  1. Only the base budget class is fixed (medium). SWAPrefillBudget.available_chunk_tokens (line 466) still caps by remaining_total only, so the same over-ask can occur on SWA models. ChainPrefillBudget returns chunk_limit and relies on fit_chunk. If the base class covers Kimi-K3's hybrid KDA/MLA, that's fine for this PR, but say so. Otherwise port the cap to the other classes.

  2. The page subtraction and the park have edge cases (low).

− page_size is applied unconditionally. That is right when alloc_extend over-asks a page, but it costs a full page even when the start is page-aligned and over-asks nothing. A comment saying when the over-ask happens would help.

  • A request whose KV need is within about one page of free + evictable capacity (the lone-request case) now parks forever instead of failing. Nothing running will free memory in that case, and there is no abort path. Confirm that intake validation rejects such requests, or abort a continuation that has been parked with nothing running.
  • A unit test with page_size == 1 and with a non-empty current_offset would pin the rounding.
  1. The PR description doesn't match the diff (low).
  • It lists "The one-chunked-request guard applies under every schedule policy" as a modification. The head already has that guard unconditionally (if has_chunked_req: return AddReqResult.OTHER in add_one_req) and the diff has no non-test change for it.
  • That matches "5 of the 6 new cases fail on main": the new adder test (test_default_policy_rejects_second_unfinished_chunk) already passes on main. Update the description to say the guard was already merged and the test only locks it in.
  1. Tests.
  • The new tests are small, targeted, and use the same fixtures as nearby ones. That is good.
  • The batch_is_full tests assert only that calc_priority is reached and the flag is cleared. They don't test that a NO_TOKEN rejection still stops repeated admission attempts, which is finding 1.
  • test_chunk_leaves_the_page_alloc_extend_over_asks uses page_size=16 with 64 free tokens → 48. The tests are CPU unit tests, so none of them exercises the hybrid KDA/MLA path that the Kimi-K3 soak ran on.

CI and merge state

  • mergeable_state is dirty, so the branch has conflicts with main and needs a rebase.

Suggested merge conditions

  • Replace or bound the unconditional batch_is_full reset and show scheduler-step cost under overload (finding 1).
  • Remove the dead clause (finding 2).
  • Scope the handler early return to graph context and add capture and in-capacity tests (finding 3).
  • Decide whether SWA and chain budgets need the same cap (finding 4).
  • Rebase, fix the description, and get CI approved.

aryatsc and others added 2 commits December 1, 2026 01:14
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

# Conflicts:
#	test/registered/unit/mem_cache/test_prefill_memory_budget.py
… and chunk budget

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@aryatsc

aryatsc commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

@HaiShaw thanks for the thorough review. All findings are addressed in 8c8bb5d5b2, with main merged in aec57cc21b:

  1. Conditional batch_is_full latch + scheduler cost (8c8bb5d5b2): Replaced the unconditional running_batch.batch_is_full = False with a latch snapshot (full_avail + full_evictable, mamba_avail + mamba_evictable, allocatable_reqs, running_rids) stored on ScheduleBatch.batch_is_full_latch_state. The latch is cleared only when the running batch is empty, the running set changes, or KV/mamba/slot availability increases past the latched watermark. Also gated the NO_TOKEN latch call through adder.batch_is_full_after_rejection(req). On a CPU micro-benchmark of _get_new_batch_prefill_raw (12 running, 37 waiting, latched after NO_TOKEN), the held latch takes 7.91 us/step vs. 176.32 us/step for the previous unconditional reset ; the old number is a lower bound since the adder was mocked.
  2. Dead batch_is_full check (8c8bb5d5b2): With the unconditional reset removed, if running_batch.batch_is_full or len(self.waiting_queue) == 0: is now live again and short-circuits admission while the latch holds.
  3. Scope handle_attention_aiter early return to graph replay (8c8bb5d5b2): Moved the over-capacity MHA_CHUNKED_KV branch inside if is_in_tc_piecewise_cuda_graph() or is_in_breakable_cuda_graph(): and guarded it with not _is_graph_capturing() (checking is_in_torch_compile_warmup(), get_pcg_capture_stream() is not None, and torch.cuda.is_current_stream_capturing()). Capture and in-capacity replay both stay on MHA. Added capture-time and in-capacity unit tests in test_aiter_attention_backend_handler.py.
  4. SWA and chain budgets (8c8bb5d5b2): Ported the continuing-chunk cap to SWAPrefillBudget.available_chunk_tokens by delegating to super().available_chunk_tokens(chunk_limit) before applying the window cap, with unit tests in test_prefill_memory_budget.py. Left ChainPrefillBudget unchanged: its available_chunk_tokens intentionally returns chunk_limit and whole-request / chunk feasibility is enforced by fit_chunk against live pool demand rather than scalar availability.
  5. Page rounding and lone parked continuation (8c8bb5d5b2): Updated PrefillBudget.available_chunk_tokens to use self.remaining_current - self.page_size with a comment explaining that the one-page margin covers alloc_extend on unaligned prefixes (matching reserve()'s + self.page_size) and conservatively costs one page when aligned. Added page_size=1 and non-empty current_offset tests. For the lone parked continuation case, _get_new_batch_prefill_raw now aborts the parked resumed_req via _abort_unavailable when nothing else is running or in flight (running_batch.is_empty(), no launched/transfer/overlap batch, pp_size == 1), with a unit test covering both running and lone-request cases.
  6. PR description mismatch: Updated the PR description to state that the one-chunked-request guard was already on main and test_default_policy_rejects_second_unfinished_chunk locks it in, and updated the latch/budget/aiter sections to match the new diff.
  7. Tests & merge (aec57cc21b, 8c8bb5d5b2): Added NO_TOKEN latch-retention and state-change tests, lone-parked-abort tests, aiter capture and in-capacity tests, and page_size=1 / non-empty current_offset / SWA budget tests. Merged main (e168174959) cleanly.

The 40-min overload soak in the description ran on the earlier revision; the description now says so.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run-ci CI: run the baseline test suite on this PR run-ci-nv-extra CI: NVIDIA/shared Extra suite (requires run-ci)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants