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