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

+73 -55
View File
@@ -1,29 +1,24 @@
/* geometry.cpp -- reconciling the linear-state chunk geometry with the attention block size.
* See geometry.h for why this is computed and not configured.
/* geometry.cpp -- reconciles the linear-state chunk length with the attention block size.
* See geometry.h.
*/
#include "geometry.h"
#include <algorithm>
#include <cstring>
#include <numeric>
namespace rad {
static int64_t gcd64(int64_t a, int64_t b) {
while (b) { int64_t t = a % b; a = b; b = t; }
return a < 0 ? -a : a;
}
/* lcm, with a non-positive side meaning "no constraint yet". */
static int64_t lcm64(int64_t a, int64_t b) {
if (a <= 0) return b;
if (b <= 0) return a;
return a / gcd64(a, b) * b;
return std::lcm(a, b);
}
/* WHICH PARAMETER OF THIS OP IS ITS SEQUENCE-CHUNK LENGTH, asked of the op's own schema. The
* scheduler must cut its steps on a multiple of it or a linear-state chunk straddles a sequence
* boundary, so this is the one parameter the core reads by MEANING rather than carrying opaquely.
*
* The schema names it (RAD_PROLE_SEQ_CHUNK), so the core holds no vocabulary of its own. Matching
* a list of likely parameter spellings here instead would silently miss any op that spells it
* differently, and a missed contributor is a quantum that does not divide the kernel's tile. */
/* The op's sequence-chunk parameter, found by role (RAD_PROLE_SEQ_CHUNK) in its schema. Steps
* must be cut on a multiple of it or a linear-state chunk straddles a step boundary. Matching
* parameter names instead would silently miss an op that spells it differently. */
static const char* chunk_key_of(const RadOpSchema* s) {
if (!s) return nullptr;
for (int i = 0; i < s->n_params; ++i)
@@ -31,22 +26,25 @@ static const char* chunk_key_of(const RadOpSchema* s) {
return nullptr;
}
/* One contributor, appended to the explanation. Kept to a line each so the refusal prints as a
* short list and not a wall. */
/* Appends one contributor to the explanation. */
static void note(std::string& why, const char* what, int64_t v, const char* from) {
if (!why.empty()) why += "; ";
why += fmt("%s=%lld from %s", what, (long long)v, from);
}
int64_t prefill_shared_tok(const Config& cfg) {
if (cfg.prefill_span <= 1 || cfg.checkpoint_interval <= 0) return cfg.max_tok;
const int64_t I = cfg.checkpoint_interval;
return std::max(std::min(cfg.max_tok, I), cfg.max_tok - (cfg.prefill_span - 1) * I);
}
int chunk_geometry_resolve(const Program& prog, const Config& cfg, ChunkGeometry* out) {
if (!out) return RAD_E_INVAL;
ChunkGeometry g;
/* ---------------------------------------------------------------- attention block size */
/* One lcm across every paged group. In practice every paged group on a given kernel set has
* the same block size -- libr4d's is 16 for all of them -- but a hybrid model with a
* sliding-window group served by a different kernel is exactly the case §7.2 is written for,
* and lcm is the answer that is right for both. */
/* lcm across every paged group. libr4d uses 16 for all of them, but a sliding-window group
* served by a different kernel may differ (§7.2). */
bool has_linear = false, has_window = false;
for (const KVGroupInfo& kg : prog.kv_groups) {
if (kg.decl.kind == RAD_KV_FULL || kg.decl.kind == RAD_KV_WINDOW) {
@@ -64,9 +62,8 @@ int chunk_geometry_resolve(const Program& prog, const Config& cfg, ChunkGeometry
}
/* ---------------------------------------------------------------- linear-state chunk */
/* Two sources, both already resolved: what the plugin declared the op with, and what the
* kernel that won selection constrains. The first is the model's statement, the second is the
* kernel's, and a chunk that is a multiple of both satisfies both. */
/* Two sources: the geometry the plugin declared the op with, and the constraints of the
* kernel selected for it. The lcm satisfies both. */
for (const OpInfo& op : prog.ops) {
const char* ckey = chunk_key_of(op.schema);
if (!ckey) continue;
@@ -87,9 +84,8 @@ int chunk_geometry_resolve(const Program& prog, const Config& cfg, ChunkGeometry
const RadConstraint& c = ki->constraints[i];
if (!c.key || std::strcmp(c.key, ckey) != 0 || c.ival <= 0) continue;
switch (c.op) {
/* DIV and EQ are both "a legal chunk is a multiple of this". GE is folded
* in the same way rather than as a separate floor: a multiple of N is
* >= N, so one number carries both facts and the arithmetic stays lcm. */
/* DIV and EQ mean "a legal chunk is a multiple of this". GE folds in the
* same way, since a multiple of N is >= N. */
case RAD_C_DIV:
case RAD_C_EQ:
case RAD_C_GE:
@@ -97,8 +93,7 @@ int chunk_geometry_resolve(const Program& prog, const Config& cfg, ChunkGeometry
note(g.why, c.key, c.ival, ki->name);
break;
case RAD_C_LE:
g.max_chunk = g.max_chunk ? (g.max_chunk < c.ival ? g.max_chunk
: (int64_t)c.ival)
g.max_chunk = g.max_chunk ? std::min<int64_t>(g.max_chunk, c.ival)
: (int64_t)c.ival;
break;
default: break;
@@ -113,8 +108,8 @@ int chunk_geometry_resolve(const Program& prog, const Config& cfg, ChunkGeometry
if (g.quantum < 1) g.quantum = 1;
if (g.max_chunk > 0 && g.quantum > g.max_chunk) {
/* Two kernels that cannot both be fed. Naming it is the whole value: the alternative is a
* chunk that is legal for one of them and silently wrong for the other. */
/* No chunk length satisfies both kernels; report it instead of serving a chunk that is
* wrong for one of them. */
out->why = fmt("chunk quantum %lld exceeds the %lld a resolved kernel accepts (%s)",
(long long)g.quantum, (long long)g.max_chunk, g.why.c_str());
out->quantum = g.quantum;
@@ -122,51 +117,74 @@ int chunk_geometry_resolve(const Program& prog, const Config& cfg, ChunkGeometry
return RAD_E_SHAPE;
}
/* The checkpoint interval is the operator's number rounded up to a legal chunk length, so that
* "split at the interval" is always also "split at a quantum". Rounding UP rather than down
* because down can reach zero and because a longer interval costs retention, not correctness.
/* Round the operator's interval up to a multiple of the quantum, so a split at the interval
* is a legal chunk split. Up, not down: down can reach zero, and a longer interval costs only
* retention.
*
* No linear state means no checkpoints: the interval is a property of a state kind that this
* model does not have, and pretending otherwise would split chunks for nothing. The one
* exception is a trunk window under a prefix cache, which snapshots the window behind a
* prompt's tail (window_ckpt) and does not split chunks for it. */
* Without linear state there are no checkpoints, except for a trunk window under a prefix
* cache, which snapshots the window behind a prompt's tail (window_ckpt) without splitting
* chunks. */
if ((has_linear || (has_window && cfg.prefix_cache)) && cfg.checkpoint_interval > 0)
g.checkpoint_interval = align_up(cfg.checkpoint_interval, g.quantum);
else
g.checkpoint_interval = 0;
g.window_ckpt = !has_linear && g.checkpoint_interval > 0;
/* A window snapshot splits no chunk (plan_chunk), so there is no interval grid to span. */
g.span = (g.checkpoint_interval > 0 && !g.window_ckpt && cfg.prefill_span > 1)
? cfg.prefill_span : 1;
g.shared_tok = prefill_shared_tok(cfg);
/* One full quantum has to fit in one step. Below that, every chunk is short, no chunk ever
* ends on a boundary, and the checkpoint lands wherever the step happened to end -- which is
* precisely the vLLM failure §7.3 exists to remove. Refusing is the honest response. */
/* One full quantum must fit in one step; otherwise no chunk ends on a boundary and
* checkpoints land wherever a step ends (§7.3). */
g.min_max_tok = g.quantum;
*out = g;
if (cfg.max_tok < g.min_max_tok) {
RAD_ERR("--max-num-batched-tokens is %lld but this model's chunk geometry needs at least "
"%lld: %s", (long long)cfg.max_tok, (long long)g.min_max_tok, g.why.c_str());
RAD_ERR("a smaller budget cannot end a chunk on a linear-state boundary, so every "
"checkpoint would land in request-unique tokens and the linear prefix hit rate "
"would be zero. Refusing rather than serving that.");
"%lld, so a chunk can end on a linear-state boundary: %s",
(long long)cfg.max_tok, (long long)g.min_max_tok, g.why.c_str());
return RAD_E_INVAL;
}
/* AND THE CHUNK AN OPERATOR ACTUALLY GETS, which is not --max-num-batched-tokens whenever the
* checkpoint interval is smaller: `plan_chunk` splits at the interval so a checkpoint is
* always written, and that clamp comes FIRST. Printing only the budget would hide it -- every
* budget above the interval runs the same chunk length, so a sweep over them reads as
* "prefill is flat against the chunk" when nothing about the chunk changed. The clamp itself
* is correct; a budget that silently does nothing is what has to be visible. A window
* snapshot is taken at the prompt's tail and splits nothing. */
const int64_t eff = (g.checkpoint_interval > 0 && !g.window_ckpt &&
g.checkpoint_interval < cfg.max_tok)
? g.checkpoint_interval : cfg.max_tok;
/* Log the effective chunk length. `plan_chunk` splits at the checkpoint interval first, so
* when the interval is below --max-num-batched-tokens, raising the budget does not change the
* chunk; the log line makes that visible. A window snapshot splits nothing. */
const int64_t span_tok = g.checkpoint_interval * g.span;
const int64_t eff = (g.checkpoint_interval > 0 && !g.window_ckpt && span_tok < cfg.max_tok)
? span_tok : cfg.max_tok;
RAD_INFO("chunk geometry: quantum %lld (attn block %lld, state chunk %lld), checkpoint "
"interval %lld, max_tok %lld -> prefill chunks of at most %lld%s",
(long long)g.quantum, (long long)g.attn_block, (long long)g.state_chunk,
(long long)g.checkpoint_interval, (long long)cfg.max_tok, (long long)eff,
eff < cfg.max_tok ? " (the checkpoint interval, not the budget)" : "");
eff >= cfg.max_tok ? ""
: g.span > 1 ? " (the checkpoint interval times the span, not the budget)"
: " (the checkpoint interval, not the budget)");
if (cfg.prefill_span > 1) {
/* What the span does here, said once: the intervals the budget holds can be fewer than
* the flag asks for, and a model without an interval grid spans nothing. */
const int64_t held = g.span > 1 ? std::min(g.span, cfg.max_tok / g.checkpoint_interval) : 0;
if (g.span <= 1)
RAD_WARN("--prefill-span %lld: this model has no checkpoint interval grid (%s), so no "
"chunk spans; a prefill alone in its step may still take the whole budget, "
"and every other step is planned at %lld tokens", (long long)cfg.prefill_span,
g.checkpoint_interval > 0 ? "its snapshots are taken at a prompt's end"
: "it keeps no linear state",
(long long)g.shared_tok);
else if (held < 2)
RAD_WARN("--prefill-span %lld does nothing: --max-num-batched-tokens %lld holds one "
"checkpoint interval of %lld tokens, and a span of %lld needs %lld",
(long long)cfg.prefill_span, (long long)cfg.max_tok,
(long long)g.checkpoint_interval, (long long)cfg.prefill_span,
(long long)(cfg.prefill_span * g.checkpoint_interval));
else
RAD_INFO("chunk geometry: a prefill alone in its step spans up to %lld intervals%s "
"from its second interval on; every other step is planned at %lld tokens",
(long long)held,
held < g.span ? fmt(" (all the budget holds of the %lld asked)",
(long long)g.span).c_str() : "",
(long long)g.shared_tok);
}
return RAD_OK;
}