draft: an adaptive draft window per sequence (RADIANCE_DRAFT_ADAPT)

One depth for every request is too shallow for code and JSON and too deep
for prose. With RADIANCE_DRAFT_ADAPT=1, --num-speculative-tokens becomes
the ceiling and each sequence drafts into the window d that maximises
E(d)/T(d): the tokens a step is expected to emit from the sequence's own
smoothed acceptance at each position, over the step's cost
(RADIANCE_DRAFT_COST, depth:ms pairs). The serial head runs as many rounds
as the deepest window in the step. A window moves only past a hysteresis
and a hold, since a new window is a new pass shape. Acceptance is
unchanged. /metrics gains radiance:draft_depth_adaptive and
radiance:draft_verify_depth_total{depth} while it is on. Unset, nothing
changes. Greedy at up to 6 against fixed 3: code +7.7 %, JSON +16.3 %.
This commit is contained in:
keptn42 authored and StillDeadcode committed 2026-10-07 11:10:19 +02:00
1 parent 73691a1189
commit 82da8eab69
11 files changed
+830 -10

No files matched your search

+19 -2
View File
@@ -109,6 +109,12 @@ struct SchedReq {
draft_hi = 0;
}
/* THE ADAPTIVE DRAFT WINDOW'S ESTIMATE FOR THIS REQUEST (RADIANCE_DRAFT_ADAPT, draft.h), and
* deliberately NOT in drafter_reset(): it describes the text the request is writing, which a
* preemption does not change, rather than any cache the request holds. A recycled slot starts
* it over in add_locked. Untouched while the policy is off. */
DraftAdapt adapt;
int32_t sched_tokens = 0; /* tokens given to this request in the current step */
int32_t entry = -1; /* its index in the current StepPlan, or -1 */
/* Its index in the NEXT step, already issued while this one runs (step_next), or -1; and the
@@ -280,7 +286,8 @@ public:
* the one that is stuck. Returns how many were written. */
int requests(ReqStat* out, int max) const;
/* The drafter's proposal for a request's next step. n is clamped to the controller's depth. */
/* The drafter's proposal for a request's next step. n is clamped to the sequence's window
* (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);
/* ---------------------------------------------------------- media the encoder owes
@@ -318,7 +325,8 @@ public:
* from one to the other.
*
* expect_draft after the drafter is issued: how many drafts it proposes for a sequence,
* which is how many the next step verifies.
* which is how many the next step verifies -- capped at the sequence's window,
* which under the adaptive policy can be fewer than the rounds that ran.
* step_next plans and builds that step: every row of this one, as a device row, at
* the furthest context it can reach. Null -- and the engine plans with step()
* after this one commits -- whenever the step needs a decision only a
@@ -491,6 +499,15 @@ private:
return hit_holes_draft_ ? ctx_len : 0;
}
/* THE WINDOW A SEQUENCE MAY DRAFT INTO: the configured depth, or under RADIANCE_DRAFT_ADAPT
* the one its own acceptance pays for (DraftController::depth_for, which starts the estimate
* on the first ask). It is the rule every site that caps a proposal applies -- step(),
* set_draft(), expect_draft() and the rounds in serial_begin() -- and with the policy off it
* is next_depth(), exactly as before. */
int draft_cap(SchedReq& s) const {
return draft_.adaptive() ? draft_.depth_for(s.adapt) : draft_.next_depth();
}
/* The built-in prompt-lookup drafter (scheduler.cpp). Fills s.draft and returns how many
* tokens it proposed; 0 when the sequence has no repeated pattern to extend. The pattern
* lengths it tries, longest first. */