scheduler: --prefill-interleave auto:SHARE sets the decode-only share of a chunk step's time

auto gave decode-only steps a fixed quarter of a chunk step's time. On the device (8 decoding
sessions beside 64K prefills, MTP on) that left decode at 23 tokens/s a session against 83 alone,
with 0.45 s gaps: two or three decode steps of ~40 ms per 0.45 s chunk. auto:SHARE makes the share a
choice (0 < SHARE <= 4); auto stays 0.25. The cap on decode-only steps rises from 16 to 64 so a
larger share is not cut off. config_test parses it, sched_test checks auto:1.
This commit is contained in:
Code000 committed 2026-11-05 20:20:13 +01:00
1 parent 5a8c5533d1
commit c00b882b96
7 files changed
+43 -12

No files matched your search

+15 -3
View File
@@ -77,7 +77,8 @@ static const Flag g_flags[] = {
"off takes the whole step, N holds the chunk to N tokens" },
{ "--prefill-interleave", "N", "decode-only steps after each prefill chunk while other\n"
"sequences decode, at most 64; auto fits them in a quarter\n"
"of the chunk step's time; 0 (default) lets every step\n"
"of the chunk step's time, auto:SHARE in SHARE of it (0-4];\n"
"0 (default) lets every step\n"
"carry a chunk" },
{ "--preempt-wait-ms", "N", "how long a preempted prefill may wait for the whole-\n"
"recompute gate before reclaiming cache blocks and\n"
@@ -574,7 +575,17 @@ int config_parse(int argc, char** argv, Config* c) {
}
else if (S("--prefill-interleave")) {
if (!(v = need(i))) return RAD_E_INVAL;
if (!std::strcmp(v, "auto")) c->prefill_interleave = -1;
if (!std::strcmp(v, "auto")) { c->prefill_interleave = -1; c->prefill_interleave_share = 0.25; }
else if (!std::strncmp(v, "auto:", 5)) {
/* auto:SHARE -- decode-only steps for up to SHARE x a chunk step's time, 0 < SHARE <= 4 */
char* e = nullptr;
const double sh = std::strtod(v + 5, &e);
if (e == v + 5 || *e || !(sh > 0.0 && sh <= 4.0)) {
RAD_ERR("--prefill-interleave %s: auto:SHARE takes a share in (0, 4]", v);
return RAD_E_INVAL;
}
c->prefill_interleave = -1; c->prefill_interleave_share = sh;
}
else if (!parse_int(a.c_str(), v, 0, 64, &c->prefill_interleave)) return RAD_E_INVAL;
}
else if (S("--preempt-wait-ms")) { if (!num(0, INT64_MAX, &c->preempt_wait_ms)) return RAD_E_INVAL; }
@@ -1352,7 +1363,8 @@ const ShowRow kShow[] = {
: c.busy_prefill_chunk == 0 ? std::string("off") : num(c.busy_prefill_chunk); } },
{ "--prefill-interleave", [](const Config& c) {
return c.prefill_interleave > 0 ? num(c.prefill_interleave)
: c.prefill_interleave < 0 ? std::string("auto") : std::string("off"); } },
: c.prefill_interleave < 0 ? "auto:" + std::to_string(c.prefill_interleave_share)
: std::string("off"); } },
{ "--preempt-wait-ms", [](const Config& c) { return num(c.preempt_wait_ms); } },
{ "--max-num-seqs", [](const Config& c) { return num(c.max_seqs); } },
{ "--max-model-len", [](const Config& c) {
+1
View File
@@ -839,6 +839,7 @@ struct Config {
* prefill stager arms for. 0 = off: the chunk takes every token the step has left. N > 0: cap
* the chunk at N tokens on such a step. See Scheduler::step, docs/GUIDE.md. */
int64_t busy_prefill_chunk = -1;
double prefill_interleave_share = 0.25; /* --prefill-interleave auto[:SHARE] */
int64_t prefill_interleave = 0; /* --prefill-interleave: decode-only steps between chunks;
* -1 auto (Scheduler::interleave_steps) */
/* --preempt-wait-ms: how long a preempted prefill may wait for the whole-recompute gate
+4 -4
View File
@@ -141,8 +141,8 @@ int Scheduler::init(Program& prog, const Config& cfg, IKVManager* kv, IPrefixCac
else if (cfg.prefill_interleave < 0)
RAD_INFO("scheduler: --prefill-interleave auto: after a prefill chunk that leaves its "
"prompt unfinished while other sequences decode, decode-only steps follow for up "
"to a quarter of the chunk step's measured time (at most %lld steps)",
(long long)kInterleaveAutoMax);
"to %.2f of the chunk step's measured time (at most %lld steps)",
cfg.prefill_interleave_share, (long long)kInterleaveAutoMax);
interleave_left_ = 0;
ema_chunk_s_ = 0.0;
ema_decode_s_ = 0.0;
@@ -1279,7 +1279,7 @@ int64_t Scheduler::busy_cap(int64_t n_computed, int64_t n_target, int64_t budget
/* ------------------------------------------------------------------ decode-only steps */
/* How many decode-only steps follow a chunk that ran beside decoding sequences
* (--prefill-interleave). N as given; under auto, as many as fit in kInterleaveShare of a chunk
* (--prefill-interleave). N as given; under auto, as many as fit in Config::prefill_interleave_share of a chunk
* step's measured time at a decode step's, so the prefill gives up at most a fifth of its rate
* (a quarter of a chunk step) however many sequences decode, and the decoders get the steps that
* share buys: several where decode steps are cheap beside the chunk, none where one costs more
@@ -1300,7 +1300,7 @@ void Scheduler::note_step_cost(bool chunk, double seconds) {
int64_t Scheduler::interleave_steps() const {
if (cfg_.prefill_interleave >= 0) return cfg_.prefill_interleave;
if (ema_chunk_s_ <= 0.0 || ema_decode_s_ <= 0.0) return 1;
const double n = kInterleaveShare * ema_chunk_s_ / ema_decode_s_;
const double n = cfg_.prefill_interleave_share * ema_chunk_s_ / ema_decode_s_;
return n >= (double)kInterleaveAutoMax ? kInterleaveAutoMax : (int64_t)n;
}
+1 -2
View File
@@ -783,9 +783,8 @@ private:
/* --prefill-interleave auto: the decode-only steps after a chunk (interleave_steps), sized by
* the running means of a step that carried a chunk and of a decode step, in seconds, fed by
* step_finished. */
static constexpr double kInterleaveShare = 0.25;
static constexpr double kInterleaveEma = 0.25;
static constexpr int64_t kInterleaveAutoMax = 16;
static constexpr int64_t kInterleaveAutoMax = 64;
double ema_chunk_s_ = 0.0, ema_decode_s_ = 0.0;
void step_cost_locked(bool chunk, double seconds);
/* The throughput window (step_finished): each kind's tokens and the wall time the steps
+3 -2
View File
@@ -1157,8 +1157,9 @@ inserted as `steps_held`, `/metrics` as `radiance:engine_steps_held_total`.
`--prefill-interleave auto` sizes the hold from measured step times instead: after each such chunk,
as many decode-only steps as fit in a quarter of a chunk step's time at a decode step's (running
means of both, at most 16 steps; one until a decode step has been timed). The prefill gives up at
most a fifth of its rate however many sequences decode, and the decoders get several steps where a
means of both, at most 64 steps; one until a decode step has been timed). `auto:SHARE` uses SHARE
of the chunk step's time instead of a quarter (0 < SHARE <= 4; `auto:1` gives decode as much time
as prefill). With the quarter the prefill gives up at most a fifth of its rate however many sequences decode, and the decoders get several steps where a
decode step is cheap beside a chunk, none where one costs more than that quarter (they still ride
every chunk). In the scheduler's host simulation of 32 prompts of 128K tokens sent at once, each
then decoding 512 tokens (2048-token chunks, MTP 3, step costs fitted to a lone prefill and to
+9
View File
@@ -465,6 +465,15 @@ TEST(prefill_interleave_takes_a_step_count_up_to_64) {
CHECK_EQ(parse({ "--prefill-interleave", "auto" }, &a), RAD_OK);
CHECK_EQ(a.prefill_interleave, -1);
CHECK_EQ(parse({ "--prefill-interleave", "automatic" }, &c), RAD_E_INVAL);
/* auto:SHARE gives decode-only steps SHARE of a chunk step's time, in (0, 4] */
Config h;
CHECK_EQ(parse({ "--prefill-interleave", "auto:1" }, &h), RAD_OK);
CHECK_EQ(h.prefill_interleave, -1);
CHECK(h.prefill_interleave_share == 1.0);
CHECK(a.prefill_interleave_share == 0.25);
CHECK_EQ(parse({ "--prefill-interleave", "auto:0" }, &c), RAD_E_INVAL);
CHECK_EQ(parse({ "--prefill-interleave", "auto:5" }, &c), RAD_E_INVAL);
CHECK_EQ(parse({ "--prefill-interleave", "auto:x" }, &c), RAD_E_INVAL);
}
/* ================================================================== the table, the parser and the help agree
+10 -1
View File
@@ -3283,7 +3283,16 @@ TEST(interleave_auto_fits_decode_steps_in_a_quarter_of_a_chunk_step) {
CHECK_EQ(steps(0.4, 0.03), 3); /* 0.1 s of 0.03 s steps */
CHECK_EQ(steps(0.4, 0.05), 2);
CHECK_EQ(steps(0.4, 0.2), 0); /* a decode step dearer than the quarter */
CHECK_EQ(steps(1.0, 0.001), 16);
CHECK_EQ(steps(1.0, 0.001), 64); /* capped at kInterleaveAutoMax */
/* auto:SHARE: SHARE of the chunk step's time instead of a quarter. */
Fixture k;
k.build();
k.cfg.prefill_interleave = -1;
k.cfg.prefill_interleave_share = 1.0;
CHECK_OK(k.start());
k.sch.note_step_cost(true, 0.4);
k.sch.note_step_cost(false, 0.04);
CHECK_EQ(k.sch.interleave_steps(), 10); /* 0.4 s of 0.04 s steps */
/* A number is used as given, whatever was measured. */
Fixture g;
g.build();