sched: record the fastest single-sequence decode step, for the dashboard to read

The dashboard's restart advice needs a reference the degraded engine is read
against. Asking a human to type a ruler is fragile (a stale or mistyped number
silently mis-advises) and cannot see steps taken while the dashboard tab is
closed. The engine sees every step and knows the concurrency of the exact step it
just timed (plan_.n_seq_decode), so it can keep the reference itself.

Records two figures over single-sequence decode steps: the floor (the fastest
window mean this process has measured) and the current (the most recent window
mean). Both are window means of one stream at one size, so the advisory compares
like with like. A min, not a max: drift only raises the CURRENT step, so the
reference a degraded engine is read against is its own demonstrated floor.
Single-sequence on purpose -- a decode step at eight sequences is a different
measurement, so keying the floor to one row keeps a batch arriving from being
misread as drift. A mixed step is excluded by the phase gate even when it carries
one decode row: that row shared the step with a prefill chunk an order of
magnitude dearer.

Why not a raw min over step brackets: step timing is host-side, and with
pipelining on the next forward pass is issued behind the current step's commit.
Behind a step with long host work -- a prefill chunk, or a decode step that saves
a KV checkpoint -- the decode pass is finished before its own bracket opens, so
the bracket holds readback and commit and no GPU work. It is a real step
advancing a real token, so no token-count or predecessor-phase guard catches it.
A raw min latches that degenerate on the first occurrence and never recovers:
measured live 2026-10-18 on a TP2 R9700 lane, 1.16 ms against a 15.55 ms mean on
the first request after bringup.

Why averaging alone is not enough: these degenerate brackets are not rare. At the
observed ~1.4% rate a min over hundreds of windows reliably lands on a
degenerate-heavy window, and the floor sits ~10% below the true floor -- still
phantom drift, because the engine can never reach a floor that was an artifact.
So a candidate is rejected BEFORE it enters a window when it is under half the
running mean of accepted steps: degenerate brackets sit at ~9% of a real step and
real single-sequence steps at ~96%, so the populations are ~10x apart and any
threshold between them separates them -- 0.5 is the midpoint of that gap, not a
value tuned to one distribution. Filtering at the step level is essential; at
this rate a degenerate dilutes inside a 32-step window to ~0.91x, which no
window-level threshold would catch.

The first window is recorded by neither figure. The rejection gate needs a
window's worth of accepted samples before it can judge one, so the first window
is un-gated by construction; recording it lets the floor latch an unreachable
value forever (measured: a 5% degenerate rate put the floor ~2% low through
bootstrap alone). The cost is one window -- about a second of single-stream
decode -- against a 46 s bringup and a 10 s repaint, so it is never observed.

The estimator is a small struct (rad::DecodeFloor) so it is testable on a
synthetic stream: the scheduler fixture runs steps in microseconds and cannot
manufacture a degenerate bracket, which is why the first round of tests missed
this. The tests feed streams laced with degenerate-short samples, assert a raw min
latches them, assert the estimator rejects them and tracks the true floor, and
assert the rejection does not eat real steps.

Emitted on /stats as step_ns_decode_best and step_ns_decode_recent (0 until the
first gated window completes). Trailing zero-defaulted fields on both SchedMetrics
structs plus the adapter copy -- neither struct is ABI-pinned (scheduler<->server
internal), so this is the sanctioned append. Matches the kv_tokens_max
running-extremum precedent.

Authored at: Memoria Qwen 3.8 Flash-Next 125B MoE (xhigh) via Open WebUI

(cherry picked from commit bf5a803deaa08ae0c2d94e2c3dda0d518c08d9aa)
This commit is contained in:
Memoria (Noblistic) committed 2026-10-19 17:35:05 +00:00
1 parent 51e6020998
commit ed2da8c9da
7 files changed
+431 -1

No files matched your search

+96
View File
@@ -51,6 +51,21 @@ struct SchedMetrics {
int64_t step_ns = 0;
int64_t step_ns_decode = 0;
/* The single-sequence decode floor, nanoseconds; 0 until a window of eligible steps fills.
* A min over WINDOW MEANS of single-sequence decode steps (see DecodeFloor), not over raw
* brackets -- a raw min latches a degenerate bracket forever. Single-sequence on purpose: a
* decode step at eight sequences is a different measurement, so keying the floor to one row
* keeps a batch arriving from being misread as drift. Scheduler::step_finished feeds DecodeFloor. */
int64_t step_ns_decode_best = 0;
/* The most recent completed window mean of single-sequence decode steps, nanoseconds; 0 until
* the first gated window completes. The advisory's OTHER side: best() is how fast the engine
* has ever been, recent() is how fast it is now, and both are window means of the same stream
* at the same size -- so they cannot disagree by order statistics the way the engine's floor
* disagreed with the browser's per-poll min (7.7% phantom drift on a flat lane, 2026-10-18).
* Scheduler::step_finished records it. */
int64_t step_ns_decode_recent = 0;
/* Per KV group. `name` points into the Program, which outlives any scrape. */
int n_kv_groups = 0;
struct Group {
@@ -131,4 +146,85 @@ struct SchedMetrics {
int64_t draft_verify_depth[RAD_METRICS_MAX_SPEC + 1] = {};
};
/* Estimator for the single-sequence decode floor (SchedMetrics::step_ns_decode_best).
*
* A min over RAW step brackets is unbounded below: a decode step issued ahead behind a step with
* long host work (a prefill chunk, or a decode step that saves a KV checkpoint) has its forward
* pass finished before its own bracket opens, so the bracket holds only readback and commit --
* about a millisecond, no GPU work. A min latches that degenerate on the first occurrence and
* never recovers. Measured live 2026-10-18: floor 1.34 ms against a 15.70 ms mean, after which
* the dashboard's restart advice read "heavily drifted, pays back fast" on a healthy engine --
* a systematically wrong advisory, worse than none, because it recommends a restart that cannot
* help.
*
* The fix mirrors the construction the dashboard already proves clean on this lane: a min over
* WINDOW MEANS, not over raw samples. Each full window of single-sequence decode steps
* contributes one mean; a degenerate is diluted by the honest steps sharing its window, so the
* floor tracks the real floor. Two biases on that floor partially cancel: a window MEAN sits
* above the true floor (it averages, so it cannot reach a lone fast step), while min-over-windows
* picks the window with the most degenerates and pulls back down. A simulation of the live lane
* (real ~15.9 ms, true floor ~14.4 ms, degenerate ~1.34 ms) puts the estimate at 14.3 ms median
* at the observed ~1.4% degenerate rate, worst case ~13.6 ms -- within a few percent of the true
* floor, and never the 12x latch of the raw min. The residual can sit slightly BELOW the true
* floor (a degenerate-heavy window), which mildly OVER-reports drift; it is bounded and small,
* not the unbounded latch. kWindow is a structural count of samples to average, not a magic
* threshold a real step could fall below. Scheduler::step_finished feeds it one update per
* single-sequence decode step. */
struct DecodeFloor {
/* Single-sequence decode steps averaged into one floor candidate. 32 approximates the number
* of decode steps the dashboard's 500 ms poll spans at this lane's step time, so the engine
* floor and the page's own c1 floor are computed over comparable windows. */
static constexpr int kWindow = 32;
void update(int64_t ns) {
/* Reject degenerate brackets BEFORE they enter a window. A decode step issued ahead behind
* a long host commit (a prefill chunk, or a KV checkpoint every 256 tokens) brackets at
* ~9% of a real step; real single-sequence steps bracket at ~96%. The populations are ~10x
* apart, so any threshold between them separates them -- 0.5 is the midpoint of that gap,
* not a value tuned to one distribution. Filtering at the STEP level is essential: at the
* observed ~1.4% rate a degenerate dilutes inside a 32-step window to a mean of ~0.91x,
* which no window-level threshold would catch, and a min over hundreds of windows then
* reliably lands on a degenerate-heavy window ~10% below the true floor.
* No rejection until a window's worth of samples has been accepted, so the running mean is
* never bootstrapped from a degenerate. */
if (accepted_ >= kWindow && ns * 2 < mean_) return;
++accepted_;
mean_ += (ns - mean_) / (double)accepted_;
sum_ += ns;
if (++count_ < kWindow) return;
const int64_t mean = sum_ / count_;
/* The FIRST window is recorded by neither side. The rejection gate needs a window's worth
* of accepted samples before it can judge one, so the first window is by construction
* un-gated and can carry degenerates; recording it would let the floor latch a value the
* engine can no longer reach -- the same artifact the gate exists to remove, smuggled in
* through bootstrap. Measured: at a 5% degenerate rate the un-gated first window put the
* floor ~2% below the true floor and it stuck there forever. */
if (warmed_) {
if (best_ == 0 || mean < best_) best_ = mean;
recent_ = mean; /* most recent completed window, same size as best_ */
}
warmed_ = true;
sum_ = 0;
count_ = 0;
}
/* The floor: the fastest window mean ever seen. A restart is priced against this. */
int64_t best() const { return best_; }
/* The CURRENT speed: the most recent completed window mean, from the SAME stream and window
* size as best(). The advisory compares best() against recent() -- both window means of one
* population -- so the two sides cannot disagree by order statistics the way the engine's
* floor disagreed with the browser's per-poll min (a 7.7% phantom gap on a flat lane,
* 2026-10-18). 0 until the first window completes; the page must not divide by it. */
int64_t recent() const { return recent_; }
private:
int64_t sum_ = 0;
int count_ = 0; /* samples in the window being accumulated */
int64_t best_ = 0;
int64_t recent_ = 0;
bool warmed_ = 0; /* false until one window has completed (the un-gated bootstrap) */
int64_t accepted_ = 0; /* samples accepted across all windows (rejection gate's support) */
double mean_ = 0.0; /* running mean of ACCEPTED steps -- the rejection reference */
};
} /* namespace rad */
+15 -1
View File
@@ -2008,7 +2008,21 @@ void Scheduler::step_finished() {
const int64_t ns =
std::chrono::duration_cast<std::chrono::nanoseconds>(step_end - step_start_).count();
m_.step_ns += ns;
if (plan_.phase == RAD_PHASE_DECODE) m_.step_ns_decode += ns;
if (plan_.phase == RAD_PHASE_DECODE) {
m_.step_ns_decode += ns;
/* The single-sequence floor, keyed to the concurrency of THIS step (plan_.n_seq_decode is
* the row count that was just timed, not a later snapshot). A mixed step is excluded by the
* phase gate even when it carries one decode row: its lone row shares the step with a
* prefill chunk and is not the mechanical floor. The estimator is a min over WINDOW MEANS,
* not raw brackets: a decode step issued ahead behind a long host commit has no GPU work
* in its bracket, and a raw min latches that degenerate forever; averaging a window of
* single-row steps first dilutes it. See rad::DecodeFloor. */
if (plan_.n_seq_decode == 1) {
decode_floor_.update(ns);
m_.step_ns_decode_best = decode_floor_.best();
m_.step_ns_decode_recent = decode_floor_.recent();
}
}
const auto from = step_start_ - last_step_at_ < std::chrono::milliseconds(500)
? last_step_at_ : step_start_;
+4
View File
@@ -604,6 +604,10 @@ private:
* covered, both decayed with the same time constant, so their ratio is tokens over time. */
double tps_win_prefill_ = 0.0, tps_win_decode_ = 0.0, tps_win_time_ = 0.0;
bool step_open_ = false;
/* Estimator for the single-sequence decode floor (see rad::DecodeFloor). Replaces a raw min
* over step brackets, which latched a degenerate bracket forever (live defect 2026-10-18:
* 1.16 ms against a 15.55 ms mean). step_finished feeds it each single-sequence decode step. */
DecodeFloor decode_floor_;
/* arrival; mu_ held */
int add_locked(std::unique_ptr<Request> r);
+2
View File
@@ -138,6 +138,8 @@ inline SchedMetrics bridge_metrics(const rad::SchedMetrics& m) {
o.steps_held = m.steps_held;
o.decode_rows_unspeculated = m.decode_rows_unspeculated;
o.step_ns = m.step_ns; o.step_ns_decode = m.step_ns_decode;
o.step_ns_decode_best = m.step_ns_decode_best;
o.step_ns_decode_recent = m.step_ns_decode_recent;
return o;
}
+2
View File
@@ -182,6 +182,8 @@ HttpResponse Server::handle_stats(const HttpRequest&) {
* covers idle time (see SchedMetrics::step_ns). */
o["step_ns"] = m.step_ns;
o["step_ns_decode"] = m.step_ns_decode;
o["step_ns_decode_best"] = m.step_ns_decode_best;
o["step_ns_decode_recent"] = m.step_ns_decode_recent;
o["rows_unspec"] = m.decode_rows_unspeculated;
/* Conditional rate per position with its reach count: a rate of 0.0 over a reach of 3 is
+6
View File
@@ -127,6 +127,12 @@ struct SchedMetrics {
* a decode step regardless of load. */
int64_t step_ns = 0;
int64_t step_ns_decode = 0;
/* The fastest single-sequence decode step this process has measured, nanoseconds; 0 until one
* runs. The dashboard reads this instead of asking a human to type a ruler (see the same field
* on rad::SchedMetrics, where it is recorded). */
int64_t step_ns_decode_best = 0;
/* The most recent completed single-sequence decode window mean; see SchedMetrics. */
int64_t step_ns_decode_recent = 0;
};