Archived
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:
1 parent
51e6020998
commit
ed2da8c9da
7 files changed
+431
-1
No files matched your search
@@ -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 */
|
||||
@@ -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_;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -2546,6 +2546,312 @@ TEST(the_adaptive_window_times_its_steps_and_the_next_cycle_reads_them) {
|
||||
}
|
||||
|
||||
/* ================================================================== the step path */
|
||||
/* The single-sequence decode floor the dashboard reads instead of a typed ruler. Timing is real
|
||||
* wall clock, so the assertions are the ones that hold whatever the machine measured: a step of a
|
||||
* shape that must not sample leaves the floor at zero (a min only ever goes down, so a wrongly
|
||||
* sampled step could never be told apart later -- it has to be caught while the floor is still
|
||||
* unset), and a single-sequence step sets it. */
|
||||
TEST(the_decode_floor_estimator_does_not_latch_a_degenerate_bracket) {
|
||||
/* The estimator is tested on a SYNTHETIC stream because the defect is a property of the
|
||||
* estimator, not of the scheduler's ability to produce a degenerate bracket: the fixture runs
|
||||
* steps in microseconds and cannot manufacture a 1.34 ms bracket behind a 15 ms one. What the
|
||||
* live lane showed -- floor 1.34 ms against a 15.70 ms mean -- is reproduced here directly. */
|
||||
using Est = rad::DecodeFloor;
|
||||
|
||||
/* First, the OLD construction, shown to fail. A min over raw brackets latches the single
|
||||
* degenerate sample and never recovers, no matter how many honest steps follow. This is the
|
||||
* defect, encoded as a test so the fix is measured against it rather than asserted. */
|
||||
{
|
||||
int64_t best = 0;
|
||||
const int64_t real = 15'000'000, degenerate = 1'340'000;
|
||||
auto old_min = [&](int64_t ns) { if (best == 0 || ns < best) best = ns; };
|
||||
old_min(degenerate); /* one degenerate, early */
|
||||
for (int i = 0; i < 500; ++i) old_min(real);
|
||||
CHECK_EQ(best, degenerate); /* latched -- this is the bug */
|
||||
}
|
||||
|
||||
/* The NEW construction: a min over WINDOW MEANS. The same single degenerate is diluted by
|
||||
* the honest steps sharing its window, so the floor tracks the real floor instead. */
|
||||
{
|
||||
Est est;
|
||||
const int64_t real = 15'000'000, degenerate = 1'340'000;
|
||||
est.update(degenerate); /* same degenerate, same position */
|
||||
for (int i = 0; i < 500; ++i) est.update(real);
|
||||
const int64_t floor = est.best();
|
||||
CHECK(floor > 0);
|
||||
CHECK(floor > degenerate); /* did NOT latch the degenerate */
|
||||
/* Within 25% of the real floor: the window mean is a faithful estimator. */
|
||||
CHECK(floor >= real * 3 / 4 && floor <= real);
|
||||
}
|
||||
|
||||
/* Robust to a HIGH rate of degenerates: the live lane's checkpoint interval (256 tokens)
|
||||
* implies they recur. One in four here. The assertion is that the floor tracks the REAL step
|
||||
* time, not merely that it beats the degenerate -- with the rejection gate in place the latter
|
||||
* would be trivially true and prove nothing. */
|
||||
{
|
||||
Est est;
|
||||
const int64_t real = 15'000'000, degenerate = 1'340'000;
|
||||
for (int i = 0; i < 400; ++i) est.update((i % 4 == 0) ? degenerate : real);
|
||||
const int64_t floor = est.best();
|
||||
CHECK(floor >= real * 90 / 100); /* tracks the real step, not the poison */
|
||||
CHECK(floor <= real);
|
||||
}
|
||||
|
||||
/* A steady stream with no degenerates: the floor equals the true floor. */
|
||||
{
|
||||
Est est;
|
||||
const int64_t real = 14'500'000;
|
||||
for (int i = 0; i < 200; ++i) est.update(real);
|
||||
CHECK_EQ(est.best(), real);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(the_decode_floor_rejects_degenerate_brackets_so_the_floor_is_the_true_floor) {
|
||||
/* Window-averaging dilutes a LONE degenerate but not a RECURRENT one. At the live lane's
|
||||
* observed ~1.4% degenerate rate (a decode step issued ahead behind a long host commit --
|
||||
* prefill, or a KV checkpoint every 256 tokens), a min over hundreds of windows reliably
|
||||
* catches a window holding two or three degenerates, and the floor lands ~10% below the true
|
||||
* floor. That residual is phantom drift: a healthy engine reads "restart pays back" against a
|
||||
* floor it can no longer reach because the floor was never reachable -- it was an artifact.
|
||||
* So a candidate far below the running mean of accepted steps is rejected outright: the
|
||||
* degenerates sit at ~9% of the mean, real single-sequence steps at ~96%, so the two
|
||||
* populations are ~10x apart and any threshold between them separates them. 0.5 is the
|
||||
* midpoint of that gap, not a value tuned to a single distribution. */
|
||||
using Est = rad::DecodeFloor;
|
||||
const int64_t true_floor = 14'400'000, typical = 15'000'000, degen = 1'340'000;
|
||||
|
||||
/* A realistic stream: ~1.4% degenerates, the rest jittered around the typical step, with the
|
||||
* true floor occasionally reached. The floor must land near the TRUE floor, not near the
|
||||
* degenerate-contaminated window mean. */
|
||||
Est est;
|
||||
uint32_t rng = 12345;
|
||||
for (int i = 0; i < 400 * Est::kWindow; ++i) {
|
||||
rng = rng * 1664525u + 1013904223u;
|
||||
const bool d = ((rng >> 16) % 1000u) < 14u; /* ~1.4% */
|
||||
int64_t ns;
|
||||
if (d) ns = degen;
|
||||
else {
|
||||
rng = rng * 1664525u + 1013904223u;
|
||||
ns = true_floor + (int64_t)((rng >> 8) % (typical - true_floor + 1)); /* floor..typical */
|
||||
}
|
||||
est.update(ns);
|
||||
}
|
||||
const int64_t floor = est.best();
|
||||
/* Within 5% of the true floor. The un-rejected estimator lands ~10% low here, so this fails
|
||||
* without the rejection gate. */
|
||||
CHECK(floor >= true_floor * 95 / 100);
|
||||
CHECK(floor <= true_floor * 115 / 100);
|
||||
|
||||
/* The bootstrap hole: the gate needs a window of accepted samples before it can judge one, so
|
||||
* the first window is un-gated. A degenerate-heavy FIRST window must therefore be recorded by
|
||||
* neither side, or the floor latches an unreachable value forever. */
|
||||
{
|
||||
Est est;
|
||||
for (int i = 0; i < Est::kWindow; ++i) est.update(degen); /* whole first window poisoned */
|
||||
CHECK_EQ(est.best(), (int64_t)0);
|
||||
CHECK_EQ(est.recent(), (int64_t)0);
|
||||
for (int i = 0; i < 40 * Est::kWindow; ++i) est.update(typical);
|
||||
CHECK(est.best() >= typical * 95 / 100); /* floor came from a gated window, not bootstrap */
|
||||
}
|
||||
|
||||
/* And the rejection must NOT eat real steps: a stream of only real steps (no degenerates)
|
||||
* still records a floor equal to the true floor. */
|
||||
Est clean;
|
||||
for (int i = 0; i < 100 * Est::kWindow; ++i) clean.update(true_floor);
|
||||
CHECK_EQ(clean.best(), true_floor);
|
||||
}
|
||||
|
||||
TEST(the_decode_floor_reports_a_recent_window_for_like_for_like_drift) {
|
||||
/* The advisory compares "how fast is it now" against "how fast has it ever been". If those two
|
||||
* numbers come from different instruments -- the engine's floor versus the browser's per-poll
|
||||
* mean -- they disagree by pure order statistics: a min over hundreds of windows sits below a
|
||||
* min over the last sixty samples even on a perfectly flat engine. Measured live 2026-10-18:
|
||||
* a 7.7% phantom gap on a lane that had not changed. So the engine reports BOTH sides of the
|
||||
* comparison, from the same stream and the same window size. */
|
||||
using Est = rad::DecodeFloor;
|
||||
const int64_t base = 15'000'000;
|
||||
|
||||
/* A steady engine with realistic run-to-run jitter: the recent window and the floor are both
|
||||
* window means of the same population, so they must agree closely. */
|
||||
{
|
||||
Est est;
|
||||
for (int i = 0; i < 400 * Est::kWindow; ++i) {
|
||||
const int64_t jitter = ((i % 7) - 3) * 200'000; /* +/- 0.6 ms, deterministic */
|
||||
est.update(base + jitter);
|
||||
}
|
||||
const int64_t floor = est.best(), recent = est.recent();
|
||||
CHECK(floor > 0);
|
||||
CHECK(recent > 0);
|
||||
/* The phantom gap must be small: this is the number the deadband is sized against. */
|
||||
const int64_t gap_pct = 100 * (recent - floor) / floor;
|
||||
CHECK(gap_pct >= 0);
|
||||
CHECK(gap_pct < 3);
|
||||
}
|
||||
|
||||
/* A degraded engine: the recent window rises, the floor remembers the old best. The verdict
|
||||
* must separate -- that is the whole point of the advisory. */
|
||||
{
|
||||
Est est;
|
||||
for (int i = 0; i < 200 * Est::kWindow; ++i) est.update(base);
|
||||
const int64_t floor = est.best();
|
||||
for (int i = 0; i < 20 * Est::kWindow; ++i) est.update(base * 6 / 5); /* 20% slower */
|
||||
const int64_t recent = est.recent();
|
||||
CHECK(recent > floor * 115 / 100);
|
||||
/* The floor does not chase the degradation: a restart is exactly what would restore it. */
|
||||
CHECK_EQ(est.best(), floor);
|
||||
}
|
||||
|
||||
/* Before any window completes there is no recent reading -- the page must not divide by it. */
|
||||
{
|
||||
Est est;
|
||||
for (int i = 0; i < Est::kWindow - 1; ++i) est.update(base);
|
||||
CHECK_EQ(est.recent(), (int64_t)0);
|
||||
est.update(base); /* completes window 1: the un-gated warmup */
|
||||
CHECK_EQ(est.recent(), (int64_t)0); /* warmup is recorded by neither side */
|
||||
for (int i = 0; i < Est::kWindow; ++i) est.update(base);
|
||||
CHECK(est.recent() > 0);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(the_decode_floor_records_only_single_sequence_decode_steps) {
|
||||
Fixture f;
|
||||
f.build(/*blocks=*/4096, /*states=*/64);
|
||||
CHECK_OK(f.start());
|
||||
|
||||
/* A prefill step samples nothing. Budget 128 tokens: this test walks 1 prefill +
|
||||
* (kWindow-1) + 1 + kWindow = 65 steps, so 64 would run dry one step short. */
|
||||
uint64_t a = f.submit(160, 128, /*priority=*/0, /*ignore_eos=*/true);
|
||||
REQUIRE(f.sch.step() != nullptr);
|
||||
f.commit_plain(11);
|
||||
f.sch.step_finished();
|
||||
CHECK_EQ(f.sch.metrics().step_ns_decode_best, (int64_t)0);
|
||||
|
||||
/* The floor is a min over WINDOW MEANS of single-sequence decode steps, so it stays 0 until a
|
||||
* full window (DecodeFloor::kWindow) has run -- unlike the old raw min, which latched the very
|
||||
* first bracket. One short of a window and the floor is still unset. */
|
||||
for (int i = 1; i < rad::DecodeFloor::kWindow; ++i) {
|
||||
REQUIRE(f.sch.step() != nullptr);
|
||||
CHECK_EQ(f.sch.plan().n_seq_decode, 1);
|
||||
CHECK_EQ(f.sch.plan().phase, RAD_PHASE_DECODE);
|
||||
f.commit_plain(12);
|
||||
f.sch.step_finished();
|
||||
}
|
||||
CHECK_EQ(f.sch.metrics().step_ns_decode_best, (int64_t)0);
|
||||
|
||||
/* The step that completes the FIRST window leaves the floor unset: window 1 is the un-gated
|
||||
* warmup (the rejection gate needs a window of accepted samples before it can judge one), so
|
||||
* it is recorded by neither side. */
|
||||
REQUIRE(f.sch.step() != nullptr);
|
||||
f.commit_plain(13);
|
||||
f.sch.step_finished();
|
||||
CHECK_EQ(f.sch.metrics().step_ns_decode_best, (int64_t)0);
|
||||
|
||||
/* The SECOND window is the first gated one and sets the floor: positive, and no larger than
|
||||
* the cumulative decode time it was drawn from. */
|
||||
for (int i = 0; i < rad::DecodeFloor::kWindow; ++i) {
|
||||
REQUIRE(f.sch.step() != nullptr);
|
||||
f.commit_plain(14);
|
||||
f.sch.step_finished();
|
||||
}
|
||||
const int64_t floor1 = f.sch.metrics().step_ns_decode_best;
|
||||
CHECK(floor1 > 0);
|
||||
CHECK(floor1 <= f.sch.metrics().step_ns_decode);
|
||||
|
||||
/* A further full window can only lower the floor or leave it: it is a min over windows. */
|
||||
for (int i = 0; i < rad::DecodeFloor::kWindow; ++i) {
|
||||
REQUIRE(f.sch.step() != nullptr);
|
||||
f.commit_plain(15);
|
||||
f.sch.step_finished();
|
||||
}
|
||||
const int64_t floor2 = f.sch.metrics().step_ns_decode_best;
|
||||
CHECK(floor2 > 0);
|
||||
CHECK(floor2 <= floor1);
|
||||
(void)a;
|
||||
}
|
||||
|
||||
TEST(the_decode_floor_ignores_a_decode_step_issued_behind_a_prefill) {
|
||||
/* The live defect was a raw min latching the first decode step, which is issued ahead behind
|
||||
* the prefill's host-side staging and whose bracket holds no GPU work. The fix does NOT
|
||||
* exclude that step -- it is a real single-sequence decode step and belongs in the floor. It
|
||||
* is made harmless by averaging: the floor is a min over window means, so the one degenerate
|
||||
* bracket is diluted by the honest steps sharing its window. This pins that the
|
||||
* prefill-following decode step IS eligible: a full window of decode steps that BEGINS with it
|
||||
* produces a floor. Under the old predecessor-phase gate the first step was dropped, so a
|
||||
* window of exactly kWindow decode steps fed only kWindow-1 samples and left the floor unset
|
||||
* -- this test would have failed on that design. */
|
||||
Fixture f;
|
||||
f.build(/*blocks=*/4096, /*states=*/64);
|
||||
CHECK_OK(f.start());
|
||||
|
||||
uint64_t a = f.submit(160, 128, /*priority=*/0, /*ignore_eos=*/true);
|
||||
REQUIRE(f.sch.step() != nullptr); /* prefill */
|
||||
f.commit_plain(21);
|
||||
f.sch.step_finished();
|
||||
|
||||
/* Two windows: window 1 (holding the prefill-following step) is the un-gated warmup, so the
|
||||
* floor only appears once a second, gated window completes. */
|
||||
for (int i = 0; i < 2 * rad::DecodeFloor::kWindow; ++i) {
|
||||
REQUIRE(f.sch.step() != nullptr);
|
||||
CHECK_EQ(f.sch.plan().phase, RAD_PHASE_DECODE);
|
||||
CHECK_EQ(f.sch.plan().n_seq_decode, 1);
|
||||
CHECK(f.sch.plan().n_tok_decode >= 1); /* a token DID advance; token count is not the guard */
|
||||
f.commit_plain(22);
|
||||
f.sch.step_finished();
|
||||
}
|
||||
/* The window filled, counting the prefill-following step: the floor is set. */
|
||||
CHECK(f.sch.metrics().step_ns_decode_best > 0);
|
||||
(void)a;
|
||||
}
|
||||
|
||||
TEST(the_decode_floor_ignores_batched_and_mixed_steps) {
|
||||
Fixture f;
|
||||
f.build(/*blocks=*/4096, /*states=*/64);
|
||||
CHECK_OK(f.start());
|
||||
|
||||
/* Two requests prefilled, then decoding TOGETHER: every decode step here carries two rows, so
|
||||
* the floor must still be unset at the end -- a batched step is a different measurement and
|
||||
* keying the floor to it would report the batch arriving as drift. */
|
||||
uint64_t a = f.submit(160, 64);
|
||||
uint64_t b = f.submit(160, 64);
|
||||
REQUIRE(f.sch.step() != nullptr); /* both prompts */
|
||||
f.commit_plain(11);
|
||||
f.sch.step_finished();
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
REQUIRE(f.sch.step() != nullptr);
|
||||
CHECK_EQ(f.sch.plan().n_seq_decode, 2);
|
||||
CHECK_EQ(f.sch.plan().phase, RAD_PHASE_DECODE);
|
||||
f.commit_plain(12);
|
||||
f.sch.step_finished();
|
||||
}
|
||||
CHECK(f.sch.metrics().steps_decode > 0); /* decode steps really ran ... */
|
||||
CHECK_EQ(f.sch.metrics().step_ns_decode_best, (int64_t)0); /* ... and none of them sampled */
|
||||
(void)a; (void)b;
|
||||
}
|
||||
|
||||
TEST(the_decode_floor_ignores_a_lone_decode_row_inside_a_mixed_step) {
|
||||
Fixture f;
|
||||
f.build(/*blocks=*/4096, /*states=*/64);
|
||||
CHECK_OK(f.start());
|
||||
|
||||
/* The subtle case: a mixed step carrying exactly ONE decode row alongside a prefill chunk.
|
||||
* n_seq_decode is 1, so a check on the row count alone would sample it -- but that row shared
|
||||
* the step with a chunk an order of magnitude dearer, and its time is not the mechanical floor.
|
||||
* The phase gate is what excludes it. */
|
||||
uint64_t b = f.submit(1000, 64, /*priority=*/1); /* several chunks */
|
||||
uint64_t a = f.submit(160, 64, /*priority=*/0); /* one chunk, then decodes */
|
||||
REQUIRE(f.sch.step() != nullptr); /* both prompts */
|
||||
f.commit_plain(11);
|
||||
f.sch.step_finished();
|
||||
|
||||
REQUIRE(f.sch.step() != nullptr); /* a decodes, b still chunking */
|
||||
CHECK_EQ(f.sch.plan().n_seq_decode, 1);
|
||||
CHECK_EQ(f.sch.plan().phase, RAD_PHASE_MIXED);
|
||||
f.commit_plain(12);
|
||||
f.sch.step_finished();
|
||||
CHECK_EQ(f.sch.metrics().step_ns_decode_best, (int64_t)0);
|
||||
(void)a; (void)b;
|
||||
}
|
||||
|
||||
TEST(the_step_path_does_not_allocate) {
|
||||
Fixture f;
|
||||
f.build(/*blocks=*/4096, /*states=*/64);
|
||||
|
||||
Reference in new issue
Block a user