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

+1
View File
@@ -294,6 +294,7 @@ public:
o.steps_prefill = m.steps_prefill; o.steps_mixed = m.steps_mixed;
o.steps_decode = m.steps_decode;
o.steps_ahead = m.steps_ahead;
o.prefill_chunks_capped = m.prefill_chunks_capped;
o.decode_rows_unspeculated = m.decode_rows_unspeculated;
o.step_ns = m.step_ns; o.step_ns_decode = m.step_ns_decode;
return o;
+1
View File
@@ -192,6 +192,7 @@ HttpResponse Server::handle_stats(const HttpRequest&) {
o["steps"] = m.steps;
o["steps_prefill"] = m.steps_prefill;
o["steps_mixed"] = m.steps_mixed;
o["prefill_chunks_capped"] = m.prefill_chunks_capped;
o["steps_decode"] = m.steps_decode;
/* WHAT THE STEPS COST, so the page does not have to divide wall clock by a step count.
* That is the derivation this handler's header calls the page's job, and it is the one
+1
View File
@@ -132,6 +132,7 @@ struct SchedMetrics {
int64_t steps_mixed = 0;
int64_t steps_decode = 0;
int64_t steps_ahead = 0; /* issued behind the step before, ahead of its commit */
int64_t prefill_chunks_capped = 0; /* held back for other work in the step (--busy-prefill-chunk) */
int64_t decode_rows_unspeculated = 0;
/* WHAT THE STEPS COST: cumulative nanoseconds spent inside a step, and the decode half of it
* separately. A step time is not wall clock over a step count -- the engine idles between an
+5
View File
@@ -163,6 +163,7 @@ void Metrics::sample(const SchedMetrics& m) {
c_steps_mixed_.inc(std::max(0.0, (double)m.steps_mixed - c_steps_mixed_.get()));
c_steps_decode_.inc(std::max(0.0, (double)m.steps_decode - c_steps_decode_.get()));
c_steps_ahead_.inc(std::max(0.0, (double)m.steps_ahead - c_steps_ahead_.get()));
c_prefill_capped_.inc(std::max(0.0, (double)m.prefill_chunks_capped - c_prefill_capped_.get()));
c_rows_unspec_.inc(std::max(0.0,
(double)m.decode_rows_unspeculated - c_rows_unspec_.get()));
c_step_secs_.inc(std::max(0.0, (double)m.step_ns * 1e-9 - c_step_secs_.get()));
@@ -332,6 +333,10 @@ std::string Metrics::render() const {
w.counter("radiance:engine_steps_ahead_total",
"Steps whose forward pass was issued behind the step before, ahead of its commit.",
L, c_steps_ahead_.get());
w.counter("radiance:engine_prefill_chunks_capped_total",
"Prefill chunks held back so decode rows and waiting requests got into the step "
"(--busy-prefill-chunk).",
L, c_prefill_capped_.get());
w.counter("radiance:decode_rows_unspeculated_total",
"Decode rows that took no draft, for any reason.",
L, c_rows_unspec_.get());
+1
View File
@@ -144,6 +144,7 @@ private:
/* STEPS BY SHAPE, and the decode rows a mixed step cost speculation. Exposed as counters so
* two scrapes give the rate over a window rather than a number dominated by startup. */
Counter c_steps_prefill_, c_steps_mixed_, c_steps_decode_, c_rows_unspec_, c_steps_ahead_;
Counter c_prefill_capped_;
/* SECONDS SPENT INSIDE A STEP, and the decode half of it. A step time is not wall clock over
* a step count -- SchedMetrics::step_ns says why -- and without these every scraper has to
* assume a saturated window and no prefill in it. */