This repository has been archived on 2026-11-24. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
radiance-sycl/core/mem/vram_budget.h
T
Deadcode 9ed3ef7a7b radiance 1.15.0
New models and formats:
- IQR for Qwen3.8-27B: weights on the int8 grid under GPTQ, a trellis down each GPTQ column
  (IQR-V2), and IQR-V3, a computed trellis code under one scale a row, kept at its codes' width in
  VRAM and decoded in the GEMM; 15 IQR-V3 recipes from ~2 to ~7 bits a weight
  (data/recipes/q38-27b-*-v3.recipe, docs/IQR.md)
- libhalo: a kernel library for Strix Halo (gfx1151), preferred there over libr3d
- Nemotron 3.5 Embed 1B and 8B (nemotron35_embed): text and image embeddings through a Pixtral
  tower, on the card and on the CPU
- Nemotron 3.5 Rerank 8B
- /v1/systemone: Cloudflare's clef and clef-flash, Convai Innovations' Laya and Mica beside
  LiquidAI d1; scored steps read the candidates' logits from the head table with no lm_head pass
- LFM2's 8-bit trunk: block-fp8 or int8 linears with the fused producers, and the d1-3B recipe
- DeepSeek-V4.1's reply format with DSML tool calls and typed argument tags

Weights on the drive:
- The file tier reads only the experts the pass routes rows to; the draft head's weights stay in
  the host pool
- A hot VRAM cache for routed experts read off the drive, reads deposited straight into free host
  pool slots, and copyless evictions; the file tier's counters are now ssd_*
- GLM-5 Next shards its routed experts by expert, not by width, so they can live on the drive
- The stall watch counts drive reads as progress, and the DMA lane's room check reads the lane's
  own completion fence

Quantisation tooling:
- --calib-corpus, --calib-dir and --calib-layers record each linear's input Hessian; beside
  --kld-record the reference's own run records them
- --kld-top N records a sparse KL reference (the N most likely tokens and the tail's mass)
- GPTQ in a third of the time with the same codes, trellis GPTQ on the card, vector codebooks
  with coordinate descent, and rad-convert --reuse repeated, each container supplying what the
  earlier ones lack

Speculation:
- Prompt lookup alone (--spec-ngram K, --spec-ngram-min/-max): each sequence keeps an index of its
  n-grams, and a proposal is verified only when its measured step cost says it pays;
  --draft-window adaptive follows it

Speed:
- IQR decode: the narrow tile splits K for four times the int8 tile's waves and folds each 128-K
  block once; at 8 tokens down and the output projections run in 0.61-0.82x and 0.70-0.92x FP8's
  time (2-6 bits); IQ6R-S-V3 with its DFlash2 drafter steps in 26.3 ms at TP2, against 29.4 ms
  before and FP8's 27.3
- Qwen MXFP4 feed-forward: the gated fold up to 16 rows, not 8
- libr4d: the gated prefill fold, the short-prompt split row, and the rows forms of rmsnorm and
  rope; KLATE again for the head-256 gqa6 paged prefill; gram_accum on the matrix cores

Features:
- /health, /v1/health and /ping answer 503 with "status": "stuck" once the device has advanced
  nothing for a minute or a queue has faulted, so a supervisor can restart a wedged server (#356)
- --image-gen-max-pixels and --image-gen-max-refs size an image generator's buffers (#344)
- The startup report lists only the options not at their default, with a count; -v lists all
  (#250)
- --preempt-wait-ms bounds how long a preempted prefill waits for its whole-recompute room
- --placement layer_offload spills dense layers so one --max-model-len sequence fits
- Startup refuses amdgpu with CWSR off and says how to fix it;
  --proceed-with-incompatible-configuration starts anyway under an UNSUPPORTED banner

Fixes:
- The n-gram read-ahead hands each row to the reader once and reads only as far ahead as the row
  cache holds, and pauses while decode reads: about one drive read a row instead of two (#355)
- A file-tier window reads each of its runs once, not once a run per run
- The decode split law's verify floor is bounded by the batch's workgroups: max_seqs 256 no longer
  declares 64x the scratch (#342)
- A prefetch DMA list's mark stays out of the signal pool until the engine has read it, and a
  prefill stage copies only the blocks its own tables name (#343)
- The split-KV row sum is read with fetch-inactive (#328)
- LFM2 on the host backend: libref and libavx serve the row-form ops it declares (#348)
- The preempted-prefill gate skips a KV group that holds no blocks (#352)
- Every request entry point bounded, gated and sanitised (JSON depth, invalid UTF-8, control bytes
  in the log, the dashboard's CSP, cross-origin browsers on the loopback-only routes); a prompt id
  outside the vocabulary refused at admission; --api-key "" refused at startup
- The telemetry the HTTP thread reads is atomic
- An RMS norm row no longer depends on how many rows its launch carries; prefill attention's
  rescale is decided by live rows only
- A --kld-record prefill chunk that finishes no sequence gets its logits on a tied-head model
- A kernel's lazily made counter block is zeroed outside the lock other ranks take (a TP2 first-step
  hang)

Changes: Plugin ABI 32. Every plugin exports a layout fingerprint of the ABI structs and the loader
refuses a plugin without it or with another (#302), so out-of-tree plugins must be rebuilt.
Appended: RadBuildCtx calib_* and gen_max_*, RadArchProbe gen_max_*, RadBatch score_only and
plugin_words, RadDeviceProps::unified, RadChatFormat arg_json_value_prefix.
2026-10-30 22:01:01 +01:00

155 lines
9.9 KiB
C++

/* vram_budget.h -- how many bytes each VRAM pool gets, decided once and printed in full.
*
* Spec §6 forbids deriving budgets by inference, such as from the free VRAM at startup, which
* moves whenever another process touches the card. This is arithmetic on known, printed, stable
* terms instead:
*
* capacity totalGlobalMem, fixed for the part.
* already held capacity - free VRAM, measured once after every kernel plugin has
* initialised and its code objects are resident: the driver context and
* loaded code. The only observed term, printed on its own line so a
* desktop on the card shows up there instead of shrinking a pool.
* --gpu-headroom-mib what the operator leaves alone (default 96 MiB).
* arena activation arena plus scratch, from arena_plan_bytes() on the buffer
* plan, the same call that later allocates it.
*
* What is left is claimable, spent in two steps:
*
* 1. Static weights come off the top. Every non-expert weight (attention projections, norms,
* embedding, head) must be resident; the one exception is a token embedding that
* --embedding-placement puts in the pinned host pool, which weight_footprint then excludes.
* Under tensor parallelism each rank's share is already divided (declare runs per rank,
* spec §9). They are a floor, not a share, so the cache can never push attention weights to
* host memory. If they do not fit, startup refuses with the shortfall named.
*
* 2. The rest is divided between the expert plane and the KV cache. When the cache lends idle
* blocks to the expert slab, the experts get what the pinned host pool cannot hold and the
* cache gets the rest up to its ceiling, lending back every block no live request holds.
* Without a lender an unused block would sit empty, so experts come first and the cache keeps
* one --max-model-len sequence. The cache never gets less than that sequence.
*
* Both sides are capped at what they can use (the cache at max_seqs x max_ctx tokens,
* KVManager::ceiling; the experts at the whole plane) and one side's excess goes to the other.
*
* No flag states a pool size: unbudgeted VRAM is unusable, and on a model whose experts do not
* fit every unbudgeted GiB costs decode time. Operators move the inputs instead: --gpu-headroom-mib,
* --max-model-len and --max-num-seqs (cache bound), --host-pool-mib (which experts must stay on
* the card).
*
* The host backend uses half the machine's memory as its capacity (host_vram_bytes) and splits it
* like a card; its weights pool holds what a host kernel cannot read where the container stores it
* (mapped_unit in core/place/planner.h). A device reporting no capacity gets what each pool needs:
* the weights the planner copies, and the cache at its ceiling.
*/
#pragma once
#include "../rad_core.h"
#include <string>
#include <vector>
namespace rad {
/* One rank's card and program. Every field is read from the device or computed from the declared
* program; none is policy. */
struct VramFacts {
int64_t capacity = 0; /* RadDeviceProps::vram_bytes -- totalGlobalMem */
int64_t free = 0; /* RadDeviceProps::vram_free, measured now */
int64_t arena = 0; /* arena_plan_bytes() for this rank's program, total incl. scratch */
int64_t staging = 0; /* BatchBuilder::device_bytes(): the step slab and the media staging,
* and TierExec::device_bytes() when a KV tier is configured */
/* Hardware queues this rank creates after `free` was read (compute stream, expert mover, and
* the second compute lane if declared), at `queue_bytes` each. Measured by creating one: the
* driver backs every queue with its own VRAM beside the engine's kernel-argument ring (33 MiB
* per queue on an R9700, 8x the ring). */
int n_queues = 0;
int64_t queue_bytes = 0;
/* The next-layer expert prefetch's ring and buffers (xprefetch.h), when enabled; its stream is
* one of `n_queues`. */
int64_t prefetch = 0;
int64_t kv_ceiling = 0; /* KVManager::ceiling(max_ctx) for this rank's declared groups */
int64_t kv_fixed = 0; /* KVManager::fixed_bytes(): the part of the ceiling that is state */
/* weight_footprint() for this rank; under tensor parallelism already this card's share. */
int64_t statics = 0; /* non-expert weights -- the floor, not a share of anything */
int64_t experts = 0; /* the expert plane: what trades against the KV cache */
int64_t expert_layer_max = 0; /* the most expert bytes one routed layer holds */
/* Experts the pinned host pool cannot hold, plus the slab's spare slots: the expert slab's
* floor when the cache lends (expert_vram_floor, core/place/planner.h). */
int64_t expert_floor = 0;
int64_t kv_one = 0; /* all configured fixed state plus pages for one full-length context */
/* The cache lends idle blocks to the expert slab: a placement that moves units (expert_tiered
* or auto), not --deterministic, on a device with virtual memory management. A lending cache
* can be sized for what live requests could need; a non-lending one would hold it empty. */
bool lends = false;
/* A loaded control vector's direction table: device bytes the engine already holds, which are
* not part of the program or the pools and must not shrink what the plan may claim. It comes
* out of the headroom, as every deployment keeps that unclaimed, so a deployment that only
* offers a vector plans its expert cache against the same card as one that does not. */
int64_t held_out = 0;
/* Integrated graphics: host memory the card must leave to the host, since device memory is
* host memory there. 0 on a discrete card. */
int64_t host_reserve = 0;
/* Unified memory (RadDeviceProps::unified): the pinned host pools are charged against
* the same ledger as the device pools, because both are the same RAM. `unified` says
* the device is one; `host_pinned` is this rank's pinned host pool bytes. Both are 0 /
* false on a discrete card, where the host pool is charged to host RAM the budget does
* not govern. */
bool unified = false;
int64_t host_pinned = 0;
};
/* The resolved split in bytes, with every term it came from. Always filled, including for a
* device that reports no capacity, because the placement and pool reports want the totals. */
struct VramBudget {
int64_t capacity = 0, already_held = 0, headroom = 0, arena = 0, staging = 0;
int64_t drift = 0; /* kDriverDrift: what already_held moves by after it is read */
int64_t queues = 0; /* n_queues * queue_bytes, from the rank that needs most */
int64_t prefetch = 0; /* the expert prefetch's ring and buffers */
int n_queues = 0;
int64_t queue_bytes = 0;
int64_t claimable = 0; /* after the fixed terms above */
int64_t statics = 0; /* off the top, before the split sees anything */
int64_t elastic = 0; /* claimable - statics: what experts and cache share */
int64_t expert_floor = 0; /* the experts the host pool cannot hold */
bool lends = false; /* every rank's cache lends its idle blocks */
int64_t kv_ceiling = 0, expert_ceiling = 0;
int64_t kv_fixed = 0; /* the state part of kv_ceiling, which no context uses */
int64_t experts = 0, kv = 0; /* the two shares, each capped at its ceiling */
int64_t unusable = 0; /* elastic neither side could take -- both were full */
/* Prefill staging region: two buffers, each one layer's share of the experts left off the
* card, funded by cache slack or expert residency above the host-pool floor, appended to the
* top of the activation arena (core/place/stager.h). Zero when every expert is resident or the
* placement cannot move any. */
int64_t stage = 0;
int64_t weights = 0; /* statics + experts: what vram_weights is set to */
bool unified = false; /* a unified-memory device: one RAM ledger */
int64_t host_pinned = 0; /* pinned host pools charged to that ledger */
std::string report; /* the block the engine prints at startup */
};
/* Writes cfg.vram_weights_mib / cfg.vram_kv_mib, the one number every downstream consumer reads
* (an uneven world's cheaper rank re-splits it with vram_budget_rank_split). Takes the smallest
* capacity and free VRAM across ranks and the largest arena, so the split fits every card.
* Refuses, by name and size, when the fixed terms alone exceed the card. */
int vram_budget_resolve(Config& cfg, const std::vector<VramFacts>& per_rank, VramBudget* out);
/* The same split on a copy of `cfg`, without writing or logging anything: for choosing between
* two programs before resolving one (Engine::plan's table placement). */
int vram_budget_trial(const Config& cfg, const std::vector<VramFacts>& per_rank, VramBudget* out);
/* Re-split for an uneven world's cheaper rank. The resolver derives the most expensive rank's
* split, and one block table serves every rank, so a rank whose cache costs less per token (e.g.
* one with no attention cache) would over-reserve KV. Given the common split, the MiB this rank
* needs to page the same tokens, and the bytes of all its weights resident (statics + all experts
* + spare slots), moves the difference to the weights pool up to that cap; the remainder stays
* unclaimed. No change when the need is not below the common pool. */
struct RankSplit {
int64_t weights_mib = 0;
int64_t kv_mib = 0;
int64_t unusable_mib = 0; /* saved from the KV pool but past the weights cap: never allocated */
bool resplit = false;
};
RankSplit vram_budget_rank_split(int64_t common_weights_mib, int64_t common_kv_mib,
int64_t need_kv_mib, int64_t weights_cap_bytes);
} /* namespace rad */