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

+7
View File
@@ -122,6 +122,13 @@ private:
Gauge g_draft_pos_[MAX_DRAFT_POS];
Gauge g_draft_pos_reached_[MAX_DRAFT_POS];
std::atomic<int> draft_pos_seen_{0};
/* THE ADAPTIVE DRAFT WINDOW (RADIANCE_DRAFT_ADAPT): the mean window of the running sequences,
* and the verifies by the window they carried, index = drafts. Rendered only while the policy
* is on, so a deployment without it exposes exactly what it always did. */
Gauge g_draft_depth_adapt_;
Gauge g_draft_vdepth_[MAX_DRAFT_POS + 1];
std::atomic<bool> draft_adapt_on_{false};
std::atomic<int> draft_vdepth_top_{0}; /* the deepest window with a verify counted */
/* sample() turns the scheduler's cumulative totals into counter increments by reading each
* counter and adding the difference. Two scrapes doing that at once both read the old value