metrics: count each draft position's acceptances

radiance:draft_position_accepted_total{position}, next to the reach. At a
fixed depth the next position's reach is this position's acceptances, so
reached(j+1) / reached(j) gives the conditional acceptance over a window.
Under the adaptive window a verify can end at j with j taken, and that
ratio drops wherever windows end; accepted(j) / reached(j) does not.
This commit is contained in:
keptn42 authored and StillDeadcode committed 2026-10-07 11:10:19 +02:00
1 parent d579bd7d45
commit 32cdaa5cc7
4 files changed
+40 -2

No files matched your search

+9 -1
View File
@@ -140,6 +140,7 @@ void Metrics::sample(const SchedMetrics& m) {
for (int j = 0; j < seen; ++j) {
const int64_t r = m.draft_pos_reached[j];
g_draft_pos_reached_[j].set((double)r);
g_draft_pos_accepted_[j].set((double)m.draft_pos_accepted[j]);
g_draft_pos_[j].set(r ? (double)m.draft_pos_accepted[j] / (double)r : 0.0);
}
/* Published after the gauges it bounds, so a concurrent render never lists a position whose
@@ -393,7 +394,9 @@ std::string Metrics::render() const {
/* CONDITIONAL, per draft position: of the verifies that reached position j -- every earlier
* one accepted -- the fraction that took j as well. The pooled ratio above cannot tell a
* drafter that decays from one whose later rounds are broken; these can, and the companion
* `_reached_total` says how much evidence each position carries. */
* `_reached_total` says how much evidence each position carries. `_accepted_total` gives the
* same ratio over any window: at a fixed depth the next position's reach would do, but an
* adaptive window can end at j with j taken. */
const int seen = draft_pos_seen_.load(std::memory_order_acquire);
if (seen > 0) {
const std::string base = L.substr(0, L.size() - 1);
@@ -408,6 +411,11 @@ std::string Metrics::render() const {
for (int j = 0; j < seen; ++j)
w.out += "radiance:draft_position_reached_total" + base + ",position=\"" +
std::to_string(j) + "\"} " + num(g_draft_pos_reached_[j].get()) + '\n';
w.help("radiance:draft_position_accepted_total",
"Verifies that accepted each draft position.", "counter");
for (int j = 0; j < seen; ++j)
w.out += "radiance:draft_position_accepted_total" + base + ",position=\"" +
std::to_string(j) + "\"} " + num(g_draft_pos_accepted_[j].get()) + '\n';
}
/* THE ADAPTIVE DRAFT WINDOW, only while RADIANCE_DRAFT_ADAPT is on: where the policy stands --
* at one sequence, that sequence's window -- and where it has been, as verifies by the
+1
View File
@@ -121,6 +121,7 @@ private:
enum { MAX_DRAFT_POS = 64 };
Gauge g_draft_pos_[MAX_DRAFT_POS];
Gauge g_draft_pos_reached_[MAX_DRAFT_POS];
Gauge g_draft_pos_accepted_[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
+1 -1
View File
@@ -1500,7 +1500,7 @@ lists the efforts the chat template takes, or is `null` when it takes any. `serv
| `decode_tokens_total`, `prefill_tokens_total` | |
| `decode_tokens_per_second`, `prefill_tokens_per_second` | |
| `draft_tokens_total`, `draft_accepted_total`, `draft_acceptance_ratio` | |
| `draft_position_reached_total`, `draft_position_acceptance_ratio` | acceptance by position, since start |
| `draft_position_reached_total`, `draft_position_accepted_total`, `draft_position_acceptance_ratio` | acceptance by position: the two counters over any window, the ratio since start |
| `draft_refills_total`, `draft_refill_tokens_total` | prefix hits ended a drafter window early, and the tokens recomputed (§4.6) |
| `decode_rows_unspeculated_total` | rows that never drafted at all |
| `draft_depth_adaptive`, `draft_verify_depth_total{depth}` | the adaptive window's mean over the running sequences, and verifies by the drafts they carried; only with `RADIANCE_DRAFT_ADAPT` (§4.6) |
+29
View File
@@ -2444,6 +2444,35 @@ TEST(concurrent_scrapes_count_each_total_once) {
CHECK_EQ(value("radiance:prefill_tokens_total"), 5000.0);
}
/* EACH DRAFT POSITION'S ACCEPTANCES ARE A COUNTER NEXT TO ITS REACH. At a fixed depth position
* j+1's reach is j's acceptances, but an adaptive window can end at j with j taken, so a ratio
* over a window needs both. Here two verifies end at position 1 with it accepted. */
TEST(each_draft_position_counts_its_acceptances) {
Metrics m("m", 1024);
server::SchedMetrics s;
s.draft_depth_seen = 3;
s.draft_pos_reached[0] = 10; s.draft_pos_accepted[0] = 7;
s.draft_pos_reached[1] = 7; s.draft_pos_accepted[1] = 5;
s.draft_pos_reached[2] = 3; s.draft_pos_accepted[2] = 2;
m.sample(s);
PromDoc d = parse_prom(m.render());
CHECK_EQ((int)d.errors.size(), 0);
CHECK_EQ(d.type["radiance:draft_position_accepted_total"], std::string("counter"));
CHECK_EQ(d.type["radiance:draft_position_reached_total"], std::string("counter"));
auto value = [&d](const std::string& name) {
auto it = d.samples.find(name);
return it == d.samples.end() ? -1.0 : it->second;
};
const std::string L = "{model_name=\"m\",engine=\"0\"";
const std::string A = "radiance:draft_position_accepted_total" + L + ",position=";
CHECK_NEAR(value(A + "\"0\"}"), 7.0, 1e-9);
CHECK_NEAR(value(A + "\"1\"}"), 5.0, 1e-9);
CHECK_NEAR(value(A + "\"2\"}"), 2.0, 1e-9);
CHECK_NEAR(value(A + "\"3\"}"), -1.0, 1e-9);
CHECK_NEAR(value("radiance:draft_position_acceptance_ratio" + L + ",position=\"1\"}"),
5.0 / 7.0, 1e-9);
}
/* THE ADAPTIVE DRAFT WINDOW (RADIANCE_DRAFT_ADAPT) IS EXPOSED ONLY WHILE IT IS ON, so a deployment
* without it scrapes exactly what it always did -- and when it is on, the gauge and the histogram
* are well-formed families with the labels every other sample carries. */