Archived
- Gemma 4 31B (PRs #74, #75, #81, #86; sfjes, keptn42): sliding and global attention with their own kernels, the assistant head as a drafter that reads the trunk's cache, the vision tower, a fused w4a8 decode step, bf16 and compressed-tensors int4 checkpoints, and window snapshots so a prefix hit on a sliding-window model resumes instead of prefilling again. deploy/compose/gemma4-31b-w4a8.yaml serves keptn42's container on two cards - ParoQuant (PRs #65, #66, #67; malic): Qwen3.8-27B checkpoints with learned Givens rotations, as int4, int5 and MXFP4, imported without re-quantising, the prefill's rotations on the matrix cores. deploy/compose/qwen3.8-27b-paro.yaml serves them on one card. A ParoQuant container made with the PR builds is refused: convert it again with --reuse <old container> - Gemma 4 26B-A4B with z-lab's DFlash drafter (PR #88; Perire): arch/gemma4 serves Google's bf16 checkpoint with the routed experts in block fp8 or bf16 (data/recipes/gemma4-26b-a4b-df*.recipe), and libr4d gains its windowed paged attention, the fused sandwich-norm joins, expert_scale and the sharded draft head's pair_argmax. A prefill chunk runs as two slices with its all-reduces beside the compute, bit-exact with the whole step. The 31B's global layers take the windowed attention too: an 11.5K-token prefill on two R9700s in 3.1 s instead of 4.9 - a startup that logs nothing for two minutes says where it waits (#89): the system call (a KFD request by name), the library that made it, and its stack, which addr2line resolves against the binary - the prefix cache is kept in VRAM and host memory only (#70): the disk tier wrote every block and snapshot a prompt produced, and its copies never outlived the process. --prefix-cache-host-mib is renamed --prefix-cache-mib; --prefix-cache-dir and --prefix-cache-disk-mib are removed, and startup refuses all three with what replaced them. The compose files no longer mount /data, and .env no longer needs RADIANCE_STATE - --prefix-cache-ttl S (default 3600, 0 never): a conversation no request has used for that long leaves the cache, whichever tier holds it; radiance:prefix_cache_expired_total counts them. A full host tier now drops its least recently used conversations - --vision-tower-placement vram|ram (#84): ram keeps an encoder tower in pinned host memory and gives its VRAM to the KV cache, read over the link once an image - timings carry ttft_ms and total_ms (#85): the server's own time from the request body's arrival to the first and the last token, queueing and tokenisation included - a KV-cache recall that found a moved expert with nowhere to go stopped halfway and leaked the slots it had already freed: after it every recall failed, the cache stayed short until a restart, and requests failed with HTTP 500. A recall now waits for the slots it is owed and always finishes - a tool result or tool-call arguments that are not JSON are no longer refused as nesting past 1024 levels for their unmatched brackets (#90): only text that parses as JSON is held to the bound, since nothing else is parsed into a tree - the host-pool refusal names the limit that applies to pinned memory (RAM less 1/64 and 1.5 GiB), not ttm.pages_limit - --embedding-placement auto, removed in 1.3.0, is refused with what replaced it - for out-of-tree kernel libraries: gemm_nt_q gains two operands (pb1, pb2, the part bounds), and the loader requires identical op schemas, so a library built against 1.4.0 must be rebuilt. For architecture plugins, rad_op_declared(b, op) asks whether an op is in the loaded vocabulary without declaring it
156 lines
8.6 KiB
C++
156 lines
8.6 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;
|
|
int64_t prefix_expired = 0, prefix_ckpt_expired = 0; /* --prefix-cache-ttl */
|
|
/* 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 */
|