Archived
scheduler: --prefill-interleave auto sizes the decode-only steps from measured step times
Cause: while prompts prefill, a sequence that is already decoding gets one token group per step that carries a chunk. On Qwen3.8-Flash-Next at TP2 such a step takes a 2048-token chunk's time (~0.4 s, more on the device under load), so decoders crawl at a few tokens/s until the queue of prompts drains. --prefill-interleave N inserts N decode-only steps after each chunk, but a fixed N costs the prefill whatever N decode steps cost, which grows with the number of decoders, and is too few where decode steps are cheap. Change: --prefill-interleave auto (default stays 0). After a chunk that ran beside decoding sequences with its prompt continuing, as many decode-only steps follow as fit in a quarter of a chunk step's time at a decode step's (running means of both, fed by step_finished from the step wall times; at most 16; 1 until a decode step has been timed; 0 where a decode step costs more than that quarter). The prefill gives up at most a fifth of its rate however many sequences decode. The hold mechanics (no admission while held, steps issued ahead count, the stager not armed for a held chunk) are --prefill-interleave N's, unchanged. Under auto which steps carry a chunk follows the device's timing; a number keeps a reproducible schedule. A chunk's cut and every row's computation are unchanged. Evidence: sched_test interleave_auto_* (the count from given costs, the step shapes it produces, nothing held for a lone prefill or when decode steps are too dear); config_test parses auto. Host simulation of the scheduler (next commit), 32 x 128K prompts sent at once, 512 tokens each, MTP 3, step costs fitted to a lone 2048-token prefill and to decode alone: decode of the sequences decoding while prompts wait 6.5 -> 31 tokens/s each, last first token 826 -> 875 s (+6 %), TTFT p50 453 -> 480 s; fixed N=2 gives 18 tokens/s at the same cost. Device numbers: the commit that makes auto:1 the served default.
This commit is contained in:
1 parent
f713f449c2
commit
f87d03d304
7 files changed
+144
-9
No files matched your search
+61
-1
@@ -3194,12 +3194,17 @@ struct Interleaved {
|
||||
int64_t steps_held = 0;
|
||||
};
|
||||
|
||||
static Interleaved interleave_run(int64_t n, bool decoder, int steps) {
|
||||
/* `chunk_s` / `decode_s`: step costs fed to --prefill-interleave auto before the run (none when
|
||||
* 0), standing in for step_finished's wall times. */
|
||||
static Interleaved interleave_run(int64_t n, bool decoder, int steps, double chunk_s = 0,
|
||||
double decode_s = 0) {
|
||||
Fixture f;
|
||||
f.build();
|
||||
f.cfg.prefill_interleave = n;
|
||||
CHECK_OK(f.start());
|
||||
f.sch.set_stage_rows(64);
|
||||
if (chunk_s > 0) f.sch.note_step_cost(true, chunk_s);
|
||||
if (decode_s > 0) f.sch.note_step_cost(false, decode_s);
|
||||
if (decoder) {
|
||||
f.submit(100, 512);
|
||||
CHECK(f.sch.step() != nullptr);
|
||||
@@ -3259,6 +3264,61 @@ TEST(interleave_leaves_a_lone_prefill_alone) {
|
||||
CHECK_EQ(r.steps_held, 0);
|
||||
}
|
||||
|
||||
/* auto: as many decode-only steps as fit in a quarter of a chunk step's measured time at a decode
|
||||
* step's (rounded down, at most 16), one until both are measured, none where a decode step costs
|
||||
* more than that quarter. */
|
||||
TEST(interleave_auto_fits_decode_steps_in_a_quarter_of_a_chunk_step) {
|
||||
auto steps = [](double chunk_s, double decode_s) {
|
||||
Fixture f;
|
||||
f.build();
|
||||
f.cfg.prefill_interleave = -1;
|
||||
CHECK_OK(f.start());
|
||||
if (chunk_s > 0) f.sch.note_step_cost(true, chunk_s);
|
||||
if (decode_s > 0) f.sch.note_step_cost(false, decode_s);
|
||||
return f.sch.interleave_steps();
|
||||
};
|
||||
CHECK_EQ(steps(0, 0), 1);
|
||||
CHECK_EQ(steps(0.4, 0), 1);
|
||||
CHECK_EQ(steps(0, 0.03), 1);
|
||||
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);
|
||||
/* A number is used as given, whatever was measured. */
|
||||
Fixture g;
|
||||
g.build();
|
||||
g.cfg.prefill_interleave = 5;
|
||||
CHECK_OK(g.start());
|
||||
g.sch.note_step_cost(true, 1.0);
|
||||
g.sch.note_step_cost(false, 0.001);
|
||||
CHECK_EQ(g.sch.interleave_steps(), 5);
|
||||
/* The costs are running means: a chunk step of 0.4 s, then one of 0.8 s, reads 0.5 s. */
|
||||
Fixture h;
|
||||
h.build();
|
||||
h.cfg.prefill_interleave = -1;
|
||||
CHECK_OK(h.start());
|
||||
h.sch.note_step_cost(true, 0.4);
|
||||
h.sch.note_step_cost(true, 0.8);
|
||||
h.sch.note_step_cost(false, 0.05);
|
||||
CHECK_EQ(h.sch.interleave_steps(), 2); /* 0.125 / 0.05 */
|
||||
}
|
||||
|
||||
/* auto schedules the measured count after every chunk beside a decoder, holds nothing for a lone
|
||||
* prefill, and with decode steps too dear for the quarter puts a chunk in every step. */
|
||||
TEST(interleave_auto_holds_each_chunk_for_the_steps_its_costs_allow) {
|
||||
const Interleaved r = interleave_run(-1, /*decoder=*/true, 10, 0.4, 0.05);
|
||||
CHECK_EQ(r.shape, std::string("CDDCDDCDDC"));
|
||||
CHECK_EQ(r.steps_held, 6);
|
||||
const Interleaved first = interleave_run(-1, /*decoder=*/true, 6); /* nothing measured */
|
||||
CHECK_EQ(first.shape, std::string("CDCDCD"));
|
||||
const Interleaved dear = interleave_run(-1, /*decoder=*/true, 8, 0.4, 0.2);
|
||||
CHECK_EQ(dear.shape, std::string("CCCCCCCC"));
|
||||
CHECK_EQ(dear.steps_held, 0);
|
||||
const Interleaved lone = interleave_run(-1, /*decoder=*/false, 8, 0.4, 0.01);
|
||||
CHECK_EQ(lone.shape, std::string("CCCCCCCC"));
|
||||
CHECK_EQ(lone.steps_held, 0);
|
||||
}
|
||||
|
||||
/* After a prompt's last chunk there is nothing to interleave: the next request is admitted in the
|
||||
* next step. */
|
||||
TEST(interleave_does_not_hold_after_a_prompts_last_chunk) {
|
||||
|
||||
Reference in new issue
Block a user