sched: --draft-window adaptive applies to block drafters

The adaptive window priced only a serial head's rounds and was refused for a
block drafter, on the grounds that the block is proposed in one pass. But
every verified draft is still a verify row, and on a MoE whose verify reads
the experts each row routes to, rows are not free (16 rows read ~10x the
experts one does). A block drafter now takes the same policy with its rounds
fixed: each sequence verifies the first min(D, its stop) of the block, its
stop from its own measured acceptance and D from the measured step times.
Prompt lookup alone keeps the fixed window and says so.

Speculation stays lossless: what is verified is a prefix of the proposal.

Measured on gemma-4-26B-A4B-it + z-lab DFlash (block 15), 4x R9700, TP4,
together with gemma4k's split-KV merge rewrite (landed in the same build, so
the two are not separated): story at T=1 95 -> 177 tok/s, greedy thinking
~360 -> 572 tok/s; code at T=0 319-334 tok/s (it verifies deep either way).

tests/sched_test.cpp: the block-drafter case now expects the policy on
(4 drafts verified while the estimate is the prior, 1 after 64 rejected
steps, draft_verify_depth[4] and [1] both counted); the prompt-lookup-only
and no-speculation cases are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
AshlynandClaude Opus 5.5 committed 2026-10-12 14:40:04 -05:00
1 parent fb716830c2
commit 29bfe8f00c
2 files changed
+63 -22

No files matched your search

+22 -13
View File
@@ -112,25 +112,34 @@ int Scheduler::init(Program& prog, const Config& cfg, IKVManager* kv, IPrefixCac
DraftController::Params dp;
dp.max_depth = cfg.n_spec;
/* THE ADAPTIVE WINDOW IS THE SERIAL DRAFTER'S POLICY (draft.h): it prices a draft as one more
* round of the head. A block drafter proposes its block in one pass and prompt lookup runs no
* pass at all, so for either the window stays fixed -- decided here, once, before any step
* has counted an acceptance, and said, because a flag that changes nothing reads exactly
* like a flag that made no difference. */
/* THE ADAPTIVE WINDOW (draft.h) prices a draft by what the step it adds to costs, measured.
* For a serial head that is a round of the head and a verify row. For a BLOCK drafter the
* block is proposed in one pass whatever is verified, but each verified draft is still a
* verify row -- and on a model whose verify streams weights per row, a MoE that reads the
* experts every row routes to, a row is not free: sixteen rows read ten times the experts one
* does. So a block drafter takes the same policy with its rounds fixed: each sequence verifies
* the first min(D, its stop) of the block, its stop from its own measured acceptance, and D
* from the measured step times. Deep where the text is predictable (code, JSON, greedy), a few
* drafts where it is not (prose at temperature 1, where a point-mass draft survives a position
* with probability p(x) and a fifteen-token chain dies after one or two). Prompt lookup runs
* no pass and keeps the fixed window, decided here, once, and said, because a flag that
* changes nothing reads exactly like a flag that made no difference. */
if (cfg.draft_window == DraftWindow::Adaptive) {
const RadDrafterDecl& dd = prog.drafter;
if (cfg.n_spec <= 0)
RAD_WARN("--draft-window adaptive: this deployment does not speculate "
"(--num-speculative-tokens %d), so there is no window to adapt", cfg.n_spec);
else if (dd.kind != RAD_DRAFT_SERIAL || dd.depth <= 0)
RAD_WARN("--draft-window adaptive: the window is fixed at %d with %s -- the adaptive "
"window prices the rounds of a serial draft head, which this deployment does "
"not run", cfg.n_spec,
dd.kind == RAD_DRAFT_BLOCK ? "a block drafter, which proposes its block in one "
"pass"
: "prompt lookup only");
else
else if ((dd.kind != RAD_DRAFT_SERIAL && dd.kind != RAD_DRAFT_BLOCK) || dd.depth <= 0)
RAD_WARN("--draft-window adaptive: the window is fixed at %d with prompt lookup only "
"-- the adaptive window prices draft passes and verify rows, and prompt "
"lookup runs no pass", cfg.n_spec);
else {
dp.adapt = true;
if (dd.kind == RAD_DRAFT_BLOCK)
RAD_INFO("--draft-window adaptive with a block drafter: the block of %d is "
"proposed whole, and each sequence verifies the first min(D, its stop) "
"of it", dd.depth);
}
}
RAD_TRY(draft_.configure(dp));
draft_est_.clear();
+41 -9
View File
@@ -2170,10 +2170,10 @@ TEST(the_adaptive_window_chooses_the_head_depth_over_the_whole_batch) {
CHECK_EQ(h.plan_step(hone, 0, 3), 2);
}
/* THE FLAG, AND ONLY FOR A SERIAL HEAD. --draft-window adaptive with a block drafter, with prompt
* lookup alone, or with no speculation keeps the configured depth and says so at startup; the
* proposal then reaches the step uncut. The default is the fixed window. */
TEST(the_adaptive_window_is_a_flag_for_a_serial_drafter_and_said_when_it_is_not) {
/* THE FLAG, FOR A DRAFTING HEAD -- SERIAL OR BLOCK. --draft-window adaptive with prompt lookup
* alone, or with no speculation, keeps the configured depth and says so at startup; the proposal
* then reaches the step uncut. The default is the fixed window. */
TEST(the_adaptive_window_is_a_flag_for_a_drafting_head_and_said_when_there_is_none) {
{
Fixture f;
adaptive_fixture(f, 4);
@@ -2192,18 +2192,50 @@ TEST(the_adaptive_window_is_a_flag_for_a_serial_drafter_and_said_when_it_is_not)
Config d;
CHECK(d.draft_window == kDraftWindowDefault); /* the default */
}
for (int kind : { (int)RAD_DRAFT_BLOCK, (int)RAD_DRAFT_NONE }) {
/* A BLOCK DRAFTER TAKES THE POLICY WITH ITS ROUNDS FIXED. It proposes its whole block in one
* pass, and each sequence verifies the first of it up to its own window: the whole block while
* its estimate is the prior, one draft once its drafts stop being taken. Startup says so. */
{
Fixture f;
adaptive_fixture(f, 4);
f.prog.drafter.kind = (decltype(f.prog.drafter.kind))kind;
if (kind == RAD_DRAFT_NONE) f.prog.drafter.depth = 0;
f.prog.drafter.kind = RAD_DRAFT_BLOCK;
int st = RAD_E_STATE;
const std::string log = stderr_of([&] { st = f.start(); });
CHECK_OK(st);
CHECK(f.sch.draft().adaptive());
CHECK(log.find("ADAPTIVE") != std::string::npos);
CHECK(log.find("with a block drafter") != std::string::npos);
CHECK(log.find("the window is fixed") == std::string::npos);
const uint64_t a = f.submit(160, 2000);
CHECK(f.sch.step() != nullptr);
f.commit_plain(11);
int32_t draft[4] = { 21, 22, 23, 24 };
CHECK_OK(f.sch.set_draft(a, draft, 4));
CHECK_EQ(f.sch.find(a)->n_draft, 4);
for (int t = 0; t < 64; ++t) { /* no draft is ever taken */
REQUIRE(f.sch.step() != nullptr);
f.commit_plain(9);
CHECK_OK(f.sch.set_draft(a, draft, 4));
}
CHECK_EQ(f.sch.find(a)->n_draft, 1);
REQUIRE(f.sch.step() != nullptr);
for (const StepEntry& e : f.sch.plan().e) CHECK_EQ(e.n_spec, 1);
CHECK(f.sch.metrics().draft_adaptive);
CHECK(f.sch.metrics().draft_verify_depth[4] > 0);
CHECK(f.sch.metrics().draft_verify_depth[1] > 0);
}
{
Fixture f;
adaptive_fixture(f, 4);
f.prog.drafter.kind = RAD_DRAFT_NONE;
f.prog.drafter.depth = 0;
int st = RAD_E_STATE;
const std::string log = stderr_of([&] { st = f.start(); });
CHECK_OK(st);
CHECK(!f.sch.draft().adaptive());
CHECK(log.find("--draft-window adaptive: the window is fixed at 4") != std::string::npos);
CHECK(log.find(kind == RAD_DRAFT_BLOCK ? "a block drafter" : "prompt lookup only") !=
std::string::npos);
CHECK(log.find("prompt lookup only") != std::string::npos);
const uint64_t a = f.submit(160, 64);
CHECK(f.sch.step() != nullptr);