radiance 1.7.0

- every model serves without a GPU: libavx covers every op, so `--kernels libavx` alone serves
  every shipped container
- Qwen3-ASR (zivius): speech to text on /v1/audio/transcriptions and live over /v1/realtime
- /v1/messages works with Claude Code as it ships (gearwave00001)
- a long agent conversation keeps its cached history when the client rewrites its last turn
  (manueloverride)
- a stream's first event goes out with the first token, so llama-benchy measures prefill right
- opt-in --prefill-interleave (Smellyyyy, baKon) and --prefill-span (keptn42)
- four-rank TP releases the link early; four-rank selftests and docs/TP4.md (goodman-b)
- NVFP4 and FP8 compressed-tensors imports (devmilan); tools/rad-export for finetunes and LoRA
  adapters (baKon)
- many fixes, among them lost tokens on stop strings under concurrency, keep-alive, MiniCPM5 tool
  arguments and the CPU's vision and audio encoders
- plugin ABI 17 and changed op schemas: out-of-tree plugins must be rebuilt
This commit is contained in:
Deadcode committed 2026-10-16 18:25:18 +02:00
1 parent b068190326
commit 1e968f6e1d
739 files changed
+128447 -84632

No files matched your search

+48 -79
View File
@@ -1,22 +1,17 @@
/* pools.h -- explicit pool budgets (spec §6).
*
* Every pool is budgeted EXPLICITLY. No profiling pass, no utilisation fraction, no inference
* about what the workload will be. The trade between KV blocks and resident weights is real and
* workload-dependent -- a long-context low-concurrency server and a short-context high-concurrency
* one want opposite splits -- but it is the operator's to make. An engine that quietly
* re-optimises the split is an engine whose benchmarks do not reproduce.
* Every pool is budgeted explicitly: no profiling pass, no utilisation fraction. The KV vs
* weights split depends on the workload, and an engine that re-optimises it on its own does not
* produce reproducible benchmarks.
*
* Two properties this file exists to make STRUCTURAL rather than conventional:
* Two structural properties:
*
* 1. A Pool holds a base, a size and a cursor, and has no pointer to any other Pool. There is
* no allocate-from-wherever call anywhere in this header. Therefore no code path exists
* along which the mover's expert promotion (spec §5.4) can reach a KV block: the mover is
* handed Pools::weights() and it is not possible to reach Pools::kv() from it. That is the
* whole reason the weight slab is a fixed budget.
* 1. A Pool holds a base, a size and a cursor, and no pointer to any other Pool. The mover is
* handed Pools::weights() only, so expert promotion (spec §5.4) cannot reach a KV block.
*
* 2. A reservation that does not fit returns null and RECORDS the shortfall by name and by how
* much. It never falls through to another pool, never shrinks an earlier reservation, and
* never silently rounds the request down. The engine refuses to start instead.
* 2. A reservation that does not fit returns null and records the shortfall by name and size.
* It never falls through to another pool, shrinks an earlier reservation or rounds down;
* the engine refuses to start instead.
*/
#pragma once
#include "rad_core.h"
@@ -30,11 +25,9 @@
namespace rad {
/* ------------------------------------------------------------------ the allocator seam */
/* Everything here goes through an allocator object rather than calling rad_dev_alloc directly.
* The host backend is the primary development target and not a fallback
* (docs/IMPLEMENTATION.md), and a pool test that cannot run without ROCm is a pool test that does
* not run. The device allocator is the default; the malloc one is what the no-device build and
* the tests use. */
/* Pools allocate through this interface rather than rad_dev_alloc so they run without ROCm: the
* host backend is a primary target (docs/IMPLEMENTATION.md). The device allocator is the default;
* the malloc one serves the no-device build and the tests. */
class MemAllocator {
public:
virtual ~MemAllocator() = default;
@@ -47,28 +40,22 @@ MemAllocator& rad_device_allocator(); /* rad_dev_alloc / rad_dev_free */
MemAllocator& rad_malloc_allocator(); /* aligned_alloc; host-only builds and tests */
/* ------------------------------------------------------------------ shortfalls */
/* What did not fit, by name and by how much. Every refusal in this component produces one of
* these rather than a bare RAD_E_NOMEM, because "it returned -6" is not a diagnosis. */
/* What did not fit, by name and by how much. Every refusal here produces one, not just a bare
* RAD_E_NOMEM. */
struct Shortfall {
std::string pool; /* which budget: "vram_weights", "vram_kv", ... */
std::string what; /* what was being reserved when it ran out */
int64_t wanted = 0;
int64_t available = 0;
/* A backing allocation the allocator refused: there is no "available" to report, only the
* allocator's own sentence for why, which is what tells an out-of-memory card from a pinned-
* memory limit from a driver that would not map the range. */
/* Set when the allocator refused a backing allocation: its reason (out of memory, pinned
* limit, mapping failure). `available` is meaningless then. */
std::string refused;
int64_t missing() const { return wanted - available; }
std::string str() const;
};
/* ------------------------------------------------------------------ Pool */
/* One reservation, made once, that never grows, never shrinks and never borrows.
*
* `accounting_only` pools hold no memory: the headroom budget is memory we promise NOT to touch,
* for activations and the arena (spec §6). The arena owner still reserves against it, so an arena
* that would exceed the headroom refuses at startup by name instead of succeeding here and
* failing the first prefill on the device. */
/* One reservation, made once, that never grows, never shrinks and never borrows. */
class Pool {
public:
Pool() = default;
@@ -82,70 +69,55 @@ public:
int64_t avail() const { return bytes_ - used_; }
void* base() const { return base_; }
int kind() const { return kind_; }
bool accounting_only() const { return accounting_; }
/* Carve `bytes` at `align`. Returns the pointer (null for an accounting-only pool, which
* still tracks the cursor), or null with a recorded shortfall if it does not fit.
* `off_out`, when given, receives the byte offset from base -- which is what a slab of
* fixed-stride slots actually wants, since the offset survives a base that is a device
* pointer nobody may dereference on the host. */
/* Carve `bytes` at `align`. Returns the pointer, or null with a recorded shortfall if it does
* not fit.
* `off_out` receives the byte offset from base, which fixed-stride slabs use because the base
* may be a device pointer the host cannot dereference. */
void* reserve(std::string_view what, int64_t bytes, int64_t align, int64_t* off_out = nullptr);
/* True when nothing was refused. Checked once, at the end of startup, so the report names
* every failure rather than the first one at the top (spec §3.1's rule, applied here). */
/* True when nothing was refused. Checked once at the end of startup so the report names every
* failure, not only the first (spec §3.1). */
bool ok() const { return shortfalls_.empty(); }
/* ---- elastic pools ----------------------------------------------------------------------
*
* An elastic pool reserves its ADDRESS RANGE whole and backs only the part somebody has asked
* for. Every offset reserve() hands out is final from the first call, so a slab stride or a
* layer stride computed against the full range stays correct while the physical memory behind
* the unused part goes back to the card for another pool to take. That is the only way two
* pools on one card can trade: the addresses cannot move, so the pages have to.
* An elastic pool reserves its whole address range and backs only the parts that are
* committed. Offsets from reserve() are final, so strides computed against the full range
* stay valid while unused pages go back to the card for another pool. Addresses cannot move
* between pools; pages can.
*
* The two pools this exists for are the KV cache and the expert slab, and the trade is not
* symmetric. A KV block holds a sequence's state and can only be given back once nothing
* holds it; an expert slot holds a COPY of a weight that also lives in the host pool or the
* container, so it can be given back whenever the mover can spare it. That asymmetry is the
* policy's, not this file's -- what is here is the mechanism and the refusal.
* Used by the KV cache and the expert slab. A KV block can be released only once nothing
* holds it; an expert slot is a copy of a weight that also lives in host memory or the
* container, so the mover can release it at will. That policy lives with the callers.
*
* A pool is elastic only where the device layer has virtual memory management (VMem in
* core/device/device.h). Where it does not, init_elastic() allocates the whole range exactly
* as init() does and commit()/decommit() are no-ops that succeed: a caller written for an
* elastic pool runs unchanged against a fixed one, holding the maximum it was reserved. That
* is the degradation spec §6 allows, because the pool is still one explicit budget -- it is
* simply one that cannot give anything back. */
* Without virtual memory management (VMem in core/device/device.h), init_elastic() allocates
* the whole range like init() and commit()/decommit() succeed as no-ops, so callers run
* unchanged against a fixed pool that holds its maximum (allowed by spec §6). */
bool elastic() const { return elastic_; }
int64_t committed() const { return elastic_ ? vm_.committed() : bytes_; }
/* Back [off, off+bytes) so a kernel may touch it. Rounds OUTWARD to the commit granule, so
* what was asked for is certainly backed, and is idempotent: a pool growing to n asks for
* [0, n) every time n changes and pays only for the part that is new. */
/* Back [off, off+bytes) so a kernel may touch it. Rounds outward to the commit granule and is
* idempotent: a pool growing to n may commit [0, n) each time and pays only for the new part. */
int commit(int64_t off, int64_t bytes);
/* Hand the pages back. Rounds INWARD, so a granule holding one byte the caller still wants
* stays -- a caller that shrinks to exactly the boundary it is holding is therefore safe, and
* one that shrinks between boundaries simply keeps a granule it will use next time. */
/* Release the pages. Rounds inward, so a granule with any byte still in use stays backed. */
int decommit(int64_t off, int64_t bytes);
bool is_committed(int64_t off, int64_t bytes) const;
/* The commit quantum, so a caller can pick grow steps that do not strand a fraction of one in
* every stripe. 0 when the pool is not elastic. */
static int64_t granule();
const std::vector<Shortfall>& shortfalls() const { return shortfalls_; }
std::string report() const;
private:
/* Reserve the address range and back nothing. `bytes` is the MAXIMUM the pool may ever hold
* and is what reserve() carves against; what it costs the card is committed(). Falls back to
* a whole allocation where the device layer has no virtual memory management. */
/* Reserve the address range and back nothing. `bytes` is the maximum the pool may ever hold
* and what reserve() carves against; committed() is what it costs the card. Falls back to a
* whole allocation without virtual memory management. */
int init_elastic(std::string_view nm, int64_t bytes, int kind, MemAllocator* a);
friend class Pools;
int init(std::string_view nm, int64_t bytes, int kind, MemAllocator* a, bool accounting);
int init(std::string_view nm, int64_t bytes, int kind, MemAllocator* a);
/* release(), then name the pool and set its budget with nothing reserved. */
void reset(std::string_view nm, int64_t bytes, int kind, MemAllocator* a);
void release();
std::string name_;
@@ -153,7 +125,6 @@ private:
int64_t used_ = 0;
void* base_ = nullptr;
int kind_ = RAD_MEM_DEVICE;
bool accounting_ = false;
bool elastic_ = false;
VMem vm_;
MemAllocator* alloc_ = nullptr;
@@ -165,12 +136,11 @@ private:
/* ------------------------------------------------------------------ Pools */
class Pools {
public:
/* `vram_capacity` is what the device reports free. Pass 0 to skip the capacity check, which
* is what the host backend wants -- it has no meaningful answer and inventing one would be
* exactly the inference §6 forbids.
/* `vram_capacity` is what the device reports free; 0 skips the capacity check (the host
* backend has no meaningful answer).
*
* Refuses, by name and by how much, rather than shrinking anything:
* - if the operator did not state the weight and KV budgets at all;
* Refuses, by name and size, rather than shrinking anything:
* - if the weight or KV budget is zero (the resolver did not run);
* - if weights + kv exceeds the card;
* - if a pool's backing allocation fails.
*/
@@ -187,11 +157,10 @@ public:
bool configured() const { return configured_; }
/* The line the engine prints at startup and the reason it refuses. Always populated, even on
* success, because the placement report wants the pool totals (spec §16). */
/* Printed at startup and on refusal. Populated on success too, for the placement report's
* pool totals (spec §16). */
const std::string& fit_report() const { return fit_report_; }
/* Every shortfall from every pool, gathered. */
std::vector<Shortfall> shortfalls() const;
private: