Archived
A prefill chunk took every token the step had left (plan_chunk(..., budget)). On a step budget of a few thousand tokens and a prompt of a few hundred thousand, that is every step for a minute or more, and for all of it a decode row behind the prefill in running_ got nothing (`want > budget` -> break) and admission never ran (`while (... budget > 0)`). A mostly-cached turn that needed a few hundred tokens waited for somebody else's whole prompt: on three ranks at --max-num-batched-tokens 2048, a 94,529-token turn with 94,208 cached took 40.6 s to its first token, which landed on the instant a 264,725-token cold prefill ahead of it ended (#61). --busy-prefill-chunk auto (the default) holds a prefill chunk back only when work that would otherwise get nothing is pending in the step: one row plus the draft window for each decode row behind it, a share (an eighth of the budget, at least one quantum) for each prefill behind it and for the next request waiting to start. The chunk never drops under the smallest step the prefill stager overlaps -- under it every routed layer reads its pooled experts synchronously, the -65 % prefill measured at a budget one token under the threshold. Where holding it back for a waiting request or another prefill would leave a remainder under that floor before the checkpoint boundary, the interval is split into two staged halves instead. Decode rows alone only take their few tokens: the chunk ends a quantum short of the boundary and the next step finishes the interval, the same pair of steps a prefill already runs when decode rows are planned ahead of it. (Halving for decode rows too held a long prompt to half-interval chunks for as long as anything decoded behind it, the larger cost.) Whatever the reserve was not used for (a refused admission, a decode row that drafted less than its window) goes back to the chunk before the step is issued. Admission shares the same way, so a cold prompt admitted with others queued behind it does not take the whole step either; an embedding input still runs whole or not at all. A prompt with nothing beside it, and rows already planned ahead of the prefill, are planned exactly as before, so a lone request's steps -- and every greedy output -- are unchanged. `off` restores the old loop including its break. `N` holds a chunk that shares the step to N tokens, rows ahead included (the operator trading prefill speed for every other row's latency); startup warns when N is under the stager's step. The engine hands the scheduler the stager's smallest pass after init (PrefillStager::min_rows, the largest over the ranks). radiance:engine_prefill_chunks_capped_total counts the chunks held back. sched_test covers admission during a long prefill, a decode row behind one, off reproducing the old plan, a lone prefill unchanged, an explicit N with rows ahead and behind, the share handed back when nobody takes it, and the cap's arithmetic at a 2048-token step with the stager at 1025, with and without a share in the reserve.
155 lines
8.5 KiB
C++
155 lines
8.5 KiB
C++
/* metrics.h -- the scheduler's snapshot, for the server's /metrics endpoint (spec §14).
|
|
*
|
|
* A plain struct of numbers with no strings built and nothing formatted. Formatting belongs to
|
|
* whoever is exporting -- Prometheus wants vLLM-compatible names, the live view wants a terminal
|
|
* line, and a scheduler that rendered either would have to be edited to add the other. Fixed
|
|
* arrays, so a scrape allocates nothing and cannot contend with the step path for the allocator.
|
|
*/
|
|
#pragma once
|
|
#include "rad_core.h"
|
|
|
|
namespace rad {
|
|
|
|
enum { RAD_SCHED_MAX_KV_GROUPS = 16 };
|
|
|
|
struct SchedMetrics {
|
|
int64_t step = 0;
|
|
|
|
/* Queue state, instantaneous. */
|
|
int64_t queue_depth = 0; /* requests waiting, including preempted ones */
|
|
int64_t running = 0;
|
|
int64_t preempted_waiting = 0; /* of queue_depth, how many are awaiting recompute */
|
|
|
|
/* Cumulative counters. Monotonic, so a scraper can rate() them. */
|
|
int64_t admitted = 0;
|
|
int64_t finished = 0;
|
|
int64_t failed = 0;
|
|
int64_t cancelled = 0;
|
|
int64_t preemptions = 0;
|
|
int64_t steps = 0;
|
|
|
|
/* STEPS BY SHAPE, AND WHAT SPECULATION DID NOT REACH. `steps_mixed` over `steps` says how
|
|
* often the load produces a step carrying both a prefill chunk and decode rows; an agentic
|
|
* load produces them often enough to be worth measuring.
|
|
*
|
|
* `decode_rows_unspeculated` counts every decode row that took no draft, whatever the reason
|
|
* -- depth 0, a request that may not speculate, a drafter with nothing to propose. Counting
|
|
* ROWS rather than any one reason keeps it the answer to "how much of my decode is running
|
|
* unspeculated" as the set of reasons changes. Without it the loss is invisible: throughput
|
|
* falls and every explanation fits. */
|
|
int64_t steps_prefill = 0;
|
|
int64_t steps_mixed = 0;
|
|
int64_t steps_decode = 0;
|
|
int64_t decode_rows_unspeculated = 0;
|
|
/* STEPS ISSUED AHEAD: a step whose forward pass went onto the card behind the step before it,
|
|
* before that step committed (Scheduler::step_next). Every other step waits for the host's
|
|
* commit and staging with the card idle, so steps_ahead against steps is how much of the run
|
|
* kept the card fed through the host's part of it. */
|
|
int64_t steps_ahead = 0;
|
|
/* PREFILL CHUNKS HELD BACK for other work in the same step (--busy-prefill-chunk): each is a
|
|
* chunk that would have taken more of the step and left decode rows behind it, or a request
|
|
* waiting to be admitted, with nothing. Zero under `off`, and on a load that never overlaps a
|
|
* prefill with anything else. */
|
|
int64_t prefill_chunks_capped = 0;
|
|
|
|
/* HOW LONG THE ENGINE SPENT INSIDE A STEP, cumulative nanoseconds, and the decode half of it
|
|
* separately. Neither is a derived rate -- they are counters, and that is the point.
|
|
*
|
|
* A STEP TIME IS NOT WALL TIME OVER A STEP COUNT, and a gauge that computes it that way is
|
|
* wrong in two directions at once. An engine that idles between requests -- which is every
|
|
* agent, every chat client, every tool loop -- charges the idle gap to the steps around it,
|
|
* inflating the step time by however long nothing was running. And a prefill chunk costs an
|
|
* order of magnitude more than a decode step, so a load that mixes them averages two
|
|
* populations and calls the result the step time. Both faults are invisible without an
|
|
* instrument: the number is plausible, it moves with load, and nothing contradicts it.
|
|
*
|
|
* With these, `step_ns_decode / steps_decode` is a decode step time that needs no window, no
|
|
* saturation assumption and no second endpoint. Charged from the scheduler's own
|
|
* `step_start_`, which is the same clock `decode_tps` already uses -- so this adds no
|
|
* synchronisation and no timing mode (spec §16). */
|
|
int64_t step_ns = 0;
|
|
int64_t step_ns_decode = 0;
|
|
|
|
/* Per KV group. `name` points into the Program, which outlives any scrape. */
|
|
int n_kv_groups = 0;
|
|
struct Group {
|
|
const char* name = "";
|
|
int64_t blocks_total = 0;
|
|
int64_t blocks_free = 0;
|
|
float utilisation = 0.0f; /* 1 - free/total */
|
|
/* Tokens one block covers, 0 for a stateful group. A pool measured in blocks cannot be
|
|
* compared with a request measured in tokens, and every reader wants that comparison. */
|
|
int64_t block_tokens = 0;
|
|
/* A WINDOWED GROUP recycles its blocks below the window, so its carve says how far back a
|
|
* sequence keeps context and nothing about how much context fits. */
|
|
bool window = false;
|
|
/* AND THE SAME GROUP IN BYTES, which is the measure that survives being added to the next
|
|
* group's. Neither blocks nor tokens does: a stateful group has no token axis, and two
|
|
* paged groups share one, so a token of context takes a slot in both and summing them
|
|
* reports a pool the card does not have. */
|
|
int64_t bytes_total = 0;
|
|
int64_t bytes_used = 0;
|
|
/* WHAT IT WAS CARVED TO ADDRESS, as against bytes_total, which is what the card is
|
|
* actually holding for it. The two differ by what the elastic pool has released: the
|
|
* cache releases the VRAM behind blocks nothing holds, and the difference between these
|
|
* two numbers is exactly what it gave back. Equal otherwise. */
|
|
int64_t bytes_carved = 0;
|
|
} kv[RAD_SCHED_MAX_KV_GROUPS];
|
|
|
|
/* Prefix caching (§7.3). Attention and linear are reported separately because they hit at
|
|
* different granularities and a single number would hide exactly the effect the decoupling
|
|
* was for. */
|
|
int64_t prompt_tokens = 0;
|
|
int64_t attn_cached_tokens = 0;
|
|
int64_t linear_cached_tokens = 0;
|
|
float attn_hit_rate = 0.0f;
|
|
/* Cumulative, from the prefix cache itself. Rising evictions under a steady workload
|
|
* mean the pool cannot hold the working set and turn-2 latency is about to collapse. */
|
|
int64_t prefix_evictions = 0;
|
|
int64_t prefix_ckpt_evictions = 0;
|
|
/* WHAT THE CACHE IS HOLDING ON ITS OWN NOW, in tokens of context: the part of the pool that
|
|
* an eviction would actually free, because no live sequence is reading it. The pool figure
|
|
* above counts a held block whoever holds it, and on a server serving conversations most of
|
|
* it is this rather than the running requests -- so without it a working cache and a leak are
|
|
* the same picture. Blocks shared with a running sequence are NOT in it; counting them would
|
|
* make one long request read as a cache that would not release its context. Same token axis
|
|
* as the paged groups, so it is comparable with kv_tokens_used. */
|
|
int64_t prefix_held_tokens = 0;
|
|
float linear_hit_rate = 0.0f;
|
|
int64_t checkpoints_written = 0;
|
|
|
|
/* Throughput: tokens over wall time in a 1-second decaying window (Scheduler::step_finished);
|
|
* the counters beside them are exact. */
|
|
int64_t prefill_tokens = 0;
|
|
int64_t decode_tokens = 0;
|
|
float prefill_tps = 0.0f;
|
|
float decode_tps = 0.0f;
|
|
|
|
/* Speculation (§10). */
|
|
int64_t draft_tokens = 0;
|
|
int64_t draft_accepted = 0;
|
|
/* Prefix hits ended early so a windowed block drafter has context (Scheduler::draft_refill_),
|
|
* and the reusable tokens they gave back to be recomputed. */
|
|
int64_t draft_refills = 0;
|
|
int64_t draft_refill_tokens = 0;
|
|
float draft_acceptance = 0.0f;
|
|
int draft_depth = 0; /* what the controller would choose right now */
|
|
/* Per draft POSITION, so a cliff can be told from a decay: `reached` is how often every
|
|
* earlier position was accepted and this one was therefore evaluated, `accepted` how often it
|
|
* was then taken. Their ratio is the conditional hazard, which is the number that says what a
|
|
* deeper draft would actually buy. `draft_depth_seen` bounds how much of the arrays is real. */
|
|
enum { RAD_METRICS_MAX_SPEC = 64 };
|
|
int draft_depth_seen = 0;
|
|
int64_t draft_pos_reached [RAD_METRICS_MAX_SPEC] = {};
|
|
int64_t draft_pos_accepted[RAD_METRICS_MAX_SPEC] = {};
|
|
/* THE ADAPTIVE WINDOW (--draft-window adaptive, draft.h), all zero while it is off. The mean
|
|
* window it gives the sequences running now -- at one sequence, that sequence's window -- and
|
|
* the verifies by the window they carried, index = drafts verified, cumulative: the gauge says
|
|
* where the policy stands, the histogram where it has been. */
|
|
bool draft_adaptive = false;
|
|
float draft_depth_adaptive = 0.0f;
|
|
int64_t draft_verify_depth[RAD_METRICS_MAX_SPEC + 1] = {};
|
|
};
|
|
|
|
} /* namespace rad */
|