sched: a long prefill leaves the rest of the step its room (--busy-prefill-chunk)

A prefill chunk took every token the step had left (plan_chunk(..., budget)). On a step budget of
a few thousand tokens and a prompt of a few hundred thousand, that is every step for a minute or
more, and for all of it a decode row behind the prefill in running_ got nothing (`want > budget`
-> break) and admission never ran (`while (... budget > 0)`). A mostly-cached turn that needed a
few hundred tokens waited for somebody else's whole prompt: on three ranks at
--max-num-batched-tokens 2048, a 94,529-token turn with 94,208 cached took 40.6 s to its first
token, which landed on the instant a 264,725-token cold prefill ahead of it ended (#61).

--busy-prefill-chunk auto (the default) holds a prefill chunk back only when work that would
otherwise get nothing is pending in the step: one row plus the draft window for each decode row
behind it, a share (an eighth of the budget, at least one quantum) for each prefill behind it and
for the next request waiting to start. The chunk never drops under the smallest step the prefill
stager overlaps -- under it every routed layer reads its pooled experts synchronously, the
-65 % prefill measured at a budget one token under the threshold. Where holding it back for a
waiting request or another prefill would leave a remainder under that floor before the checkpoint
boundary, the interval is split into two staged halves instead. Decode rows alone only take their
few tokens: the chunk ends a quantum short of the boundary and the next step finishes the
interval, the same pair of steps a prefill already runs when decode rows are planned ahead of it.
(Halving for decode rows too held a long prompt to half-interval chunks for as long as anything
decoded behind it, the larger cost.) Whatever the reserve was not used for (a refused admission, a
decode row that drafted less than its window) goes back to the chunk before the step is issued.
Admission shares the same way, so a cold prompt admitted with others queued behind it does not
take the whole step either; an embedding input still runs whole or not at all.

A prompt with nothing beside it, and rows already planned ahead of the prefill, are planned
exactly as before, so a lone request's steps -- and every greedy output -- are unchanged. `off`
restores the old loop including its break. `N` holds a chunk that shares the step to N tokens,
rows ahead included (the operator trading prefill speed for every other row's latency); startup
warns when N is under the stager's step.

The engine hands the scheduler the stager's smallest pass after init (PrefillStager::min_rows,
the largest over the ranks). radiance:engine_prefill_chunks_capped_total counts the chunks held
back. sched_test covers admission during a long prefill, a decode row behind one, off reproducing
the old plan, a lone prefill unchanged, an explicit N with rows ahead and behind, the share
handed back when nobody takes it, and the cap's arithmetic at a 2048-token step with the stager
at 1025, with and without a share in the reserve.
This commit is contained in:
baKon committed 2026-10-09 00:28:03 -05:00
1 parent 89cee7ce41
commit 04405089cb
14 files changed
+495 -5

No files matched your search

+19
View File
@@ -719,6 +719,24 @@ step, so a decode step queued behind one waits longer — but the prefill it is
finishes sooner, and that is the larger term. Four decoders with a long prompt landing beside
them finished in 29.5 s at a 2048 chunk against 31.9 s at 512.
**Nor does a long prefill lock out the work behind it** (`--busy-prefill-chunk`, default `auto`).
A chunk used to take every token the step had left, so for the whole of a long prompt's prefill —
a minute or more at 256K — a decode row behind it in the batch got no rows and a request that
arrived was not even admitted: a mostly-cached turn that needed a few hundred tokens waited for
somebody else's prompt to finish. Now, when other work is pending in a step, the chunk leaves it
room: one row plus the draft window for every decode row behind it, and a share of the budget
(an eighth, at least one quantum) for each prefill behind it and for the next request waiting to
start. It never drops under the smallest step the prefill stager overlaps (1025 tokens by
default), because under that every routed layer reads its pooled experts synchronously and the
prefill slows far more than the shared step saves; and where holding a chunk back for a waiting
request or another prefill would leave a short remainder before the checkpoint boundary, the
interval is split into two staged halves instead. Decode rows alone only take their few tokens: the
chunk ends a quantum short of the boundary and the next step finishes it, the same pair of steps a
prefill already runs when decode rows are ahead of it. A prompt with nothing beside it is planned exactly as before. `off` restores the old
behaviour; `--busy-prefill-chunk N` holds a shared chunk to N tokens (the startup line warns when
N is under the stager's step). `radiance:engine_prefill_chunks_capped_total` counts the chunks
held back.
**And check it did not cost you the prefix cache.** The arena it grows is charged before the
split (§4.3), so the KV pool shrinks a little — here 516,864 → 499,920 pool tokens, 3.3% — and
§4.3's cliff is sharp enough that 3% is worth confirming rather than assuming. On this shape it
@@ -1028,6 +1046,7 @@ one line naming each one the command line moved.
| flag | default | |
|---|---|---|
| `--max-num-batched-tokens N` | 8192 | largest token count one step may carry |
| `--busy-prefill-chunk MODE` | auto | a prefill chunk's share of a step that has other work: `auto` leaves decode rows behind it and waiting requests their room (§4.5), `off` takes the whole step, `N` holds it to N tokens |
| `--max-num-seqs N` | 256 | largest number of sequences one step may carry |
| `--max-model-len N` | 0 | context bound; 0 takes the model's training context |
| `--rope-scaling SPEC` | — | `yarn:FACTOR[:ORIG]`: static YaRN over the container's own rotary keys, no reconvert; `none` takes a checkpoint's YaRN off ([YARN.md](YARN.md)) |