diff --git a/core/engine.cpp b/core/engine.cpp index 10ffd81e..832fbc75 100644 --- a/core/engine.cpp +++ b/core/engine.cpp @@ -410,6 +410,8 @@ int Engine::step_loop() { * collected, and a pass issued ahead would have overwritten them by then. */ pipelining_ = !cfg_.kld() && drafter_.kind != RAD_DRAFT_BLOCK && (serial_drafting() || cfg_.n_spec <= 0); + /* The adaptive draft window prices serial rounds; a block drafter keeps its depth (scheduler.h). */ + if (drafter_.kind == RAD_DRAFT_BLOCK) sched_.draft_adapt_off("a block drafter"); const bool t_on = (int)log_level() >= (int)Log::Debug; /* Read once. See the block in the idle branch below for what it is for. */ /* "kv" | "arena" | "all" | "kv:," -- the last narrows the KV scrub to named groups, diff --git a/core/sched/scheduler.cpp b/core/sched/scheduler.cpp index c1e6e0c9..7f83ef3f 100644 --- a/core/sched/scheduler.cpp +++ b/core/sched/scheduler.cpp @@ -1356,6 +1356,17 @@ void Scheduler::take_encodes(std::vector>* out) { } /* ------------------------------------------------------------------ the load cap */ +void Scheduler::draft_adapt_off(const char* why) { + std::lock_guard lk(mu_); + if (!draft_.adaptive()) return; + DraftController::Params p = draft_.params(); + p.adapt = false; + if (draft_.configure(p) == RAD_OK) + RAD_WARN("RADIANCE_DRAFT_ADAPT is set and the drafter is %s: the adaptive window is the serial " + "drafter's policy, so this run keeps the configured depth %d", why, p.max_depth); + draft_busy_cap_ = 0; +} + void Scheduler::draft_cycle() { const int32_t cap = (int32_t)draft_.busy_cap((int)running_.size()); if (cap != draft_busy_cap_) diff --git a/core/sched/scheduler.h b/core/sched/scheduler.h index a4f6ade8..8fa1330b 100644 --- a/core/sched/scheduler.h +++ b/core/sched/scheduler.h @@ -290,6 +290,13 @@ public: * (draft_cap): the controller's depth, or what the adaptive policy gives the sequence. */ int set_draft(uint64_t id, const int32_t* tokens, int n); + /* RADIANCE_DRAFT_ADAPT is the SERIAL drafter's policy: every draft there is one more round of + * the head, which is what its cost table prices. A block drafter proposes its whole block in + * one pass, so a shorter window only saves verify rows -- a different trade with a policy of its + * own. The engine calls this once, before the first step, when the drafter is a block drafter; + * the switch then changes nothing about that run. Says so when it was on. */ + void draft_adapt_off(const char* why); + /* ---------------------------------------------------------- media the encoder owes * A REQUEST CARRYING MEDIA IS ADMITTED ONLY ONCE EVERY ITEM IS ENCODED. Until then it keeps * its place in the queue, the requests behind it are admitted around it, and its items wait diff --git a/tests/sched_test.cpp b/tests/sched_test.cpp index a420ec83..6fb07045 100644 --- a/tests/sched_test.cpp +++ b/tests/sched_test.cpp @@ -1819,6 +1819,34 @@ TEST(the_adaptive_window_caps_the_proposal_and_the_rounds) { CHECK_EQ(m.draft_depth, 4); /* the ceiling, as before */ } +/* A BLOCK DRAFTER KEEPS ITS DEPTH. The engine turns the policy off before the first step when the + * drafter proposes its block in one pass; the proposal then reaches the step uncut, as without the + * switch. */ +TEST(the_adaptive_window_turns_off_for_a_block_drafter) { + Fixture f; + f.build(/*blocks=*/4096, /*states=*/64); + f.cfg.n_spec = 4; + CHECK_OK(f.start()); + DraftController::Params p; + p.max_depth = 4; + p.adapt = true; + p.prior = 0.3f; /* on the default cost: two */ + CHECK_OK(f.sch.draft().configure(p)); + f.sch.draft_adapt_off("a block drafter"); + CHECK(!f.sch.draft().adaptive()); + + const uint64_t a = f.submit(160, 64); + 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); + const SchedMetrics m = f.sch.metrics(); + CHECK(!m.draft_adaptive); + f.sch.draft_adapt_off("again"); /* a second call is a no-op */ + CHECK(!f.sch.draft().adaptive()); +} + /* EACH SEQUENCE ITS OWN WINDOW, AND THE ROUNDS FOLLOW THE DEEPEST. The step issued ahead of a * commit verifies, for each sequence, the first of those rounds up to its own window -- and the * drafter's longer proposal is taken cut to that count rather than refused as a mismatch. */