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

+21 -38
View File
@@ -1,10 +1,8 @@
/* r4d_fp8_args.h -- the block-scaled fp8 family's operand list, read once for five kernels.
/* r4d_fp8_args.h -- operand list of the block-scaled fp8 GEMM family.
*
* Every kernel that reads `<linear>.weight` as the checkpoint stores it -- F8_E4M3 [N][K] with a
* BF16 scale on a [ceil(N/128)][ceil(K/128)] grid -- takes the same five operands in the same
* order, because they implement the same op at different M. The reader belongs to the family, so
* it is a header beside them rather than an adapter between them and the core. See
* libr4d/r4d_args.h.
* Every kernel that reads `<linear>.weight` as the checkpoint stores it (F8_E4M3 [N][K] with a
* BF16 scale on a [ceil(N/128)][ceil(K/128)] grid) implements the same op at a different M and
* takes the same five operands in the same order. See libr4d/r4d_args.h.
*/
#ifndef R4D_FP8_ARGS_H
#define R4D_FP8_ARGS_H
@@ -15,38 +13,29 @@
enum { F_A = 0, F_ASCALE = 1, F_B = 2, F_BSCALE = 3, F_Y = 4 };
/* ...and for `quant_act_fp8` and `sample_chain`. */
enum { QF_X = 0, QF_Q = 1, QF_S = 2 };
/* The two fused forms. Shaped on their int8 siblings (`rmsnorm_had_quant_i8`,
* `gated_had_quant_i8`) minus the operands the rotation needs, so an architecture that switches
* activation format changes op names and not operand order. */
/* The fused forms follow their int8 siblings (`rmsnorm_had_quant_i8`, `gated_had_quant_i8`)
* minus the rotation's operands, so switching activation format changes op names only. */
enum { RQ_X = 0, RQ_RES = 1, RQ_W = 2, RQ_Q = 3, RQ_S = 4, RQ_Y = 5 };
enum { GQ_GU = 0, GQ_Q = 1, GQ_S = 2, GQ_Y = 3 };
enum { TQ_G = 0, TQ_X = 1, TQ_Q = 2, TQ_S = 3, TQ_Y = 4 };
enum { SC_LOGITS = 0, SC_QUERY = 1, SC_U = 2, SC_DRAW = 3 };
/* A required integer parameter, or 0. Distinct from r4d_geti_or's defaulting because these three
* have no sensible default: a geometry without M, N and K is not a geometry. */
static inline long long aff_or(const RadArgs* a, const char* k) { return r4d_geti_or(a, k, 0); }
struct Fp8Ops {
const RadTensor *a, *ascale, *b, *bscale, *y;
long long M, N, K, nkb;
long a_ld, sa_ld, w_ld, sw_ld; /* a_ld / w_ld in ELEMENTS here; see the note at each use */
long a_ld, sa_ld, w_ld, sw_ld; /* a_ld / w_ld in elements here; see the note at each use */
};
/* Pitches, and the one place this family's two operand pitches are read.
*
* libr4d takes the WEIGHT pitch in BYTES and the SCALE pitch in ELEMENTS, which is not an
* inconsistency: an E4M3 row is bytes and a bf16 scale row is not, and giving both the same unit
* would make one of the two conversions invisible at the call site. Restated here so the shim
* cannot get it wrong quietly. */
/* The weight's scale plane: per 128x128 tile (block E4M3), or per ROW per 128 K (the int8 twins). */
/* Reads this family's operands and pitches. libr4d takes the weight pitch in bytes and the scale
* pitch in elements: an E4M3 row is bytes, a bf16 scale row is not. */
/* The weight's scale plane: per 128x128 tile (block E4M3), or per row per 128 K (the int8 twins). */
enum { FP8_OPS_BLOCK_SCALE = 0, FP8_OPS_ROW_SCALE = 1 };
static inline int fp8_ops(const RadArgs* a, Fp8Ops* g, int want_ascale,
int wscale = FP8_OPS_BLOCK_SCALE) {
std::memset(g, 0, sizeof(*g));
/* No fp8 or int8 block GEMM reads a partitioned weight's `pb1`/`pb2`; refused, not ignored (see
* gemm_ops). */
/* No fp8 or int8 block GEMM reads a partitioned weight's `pb1`/`pb2`; refuse rather than
* ignore (see gemm_ops). */
if (r4d_geti_or(a, "pb1", 0) > 0 || r4d_geti_or(a, "pb2", 0) > 0) return R4D_NO(RAD_E_UNSUPPORTED);
g->a = r4d_opt(a, F_A);
g->ascale = r4d_opt(a, F_ASCALE);
@@ -57,27 +46,23 @@ static inline int fp8_ops(const RadArgs* a, Fp8Ops* g, int want_ascale,
if (want_ascale && !g->ascale) return R4D_NO(RAD_E_INVAL);
if (g->b->rank != 2 || g->bscale->rank != 2) return R4D_NO(RAD_E_SHAPE);
/* ROWS ARE DIM 0 AND EVERYTHING AFTER IT IS THE ROW -- the same reading r4d_rad_quant_act_fp8
* takes of its input, and for the same reason. A gated attention block's q|gate projection is
* declared [tokens, heads, 2*head_dim] because the de-interleaving that follows needs the head
* axis; its N is heads*2*head_dim and the GEMM neither knows nor cares. Demanding rank 2 here
* would refuse that projection, which is the first thing a gated attention layer does. */
/* Rows are dim 0 and everything after it is the row, as in r4d_rad_quant_act_fp8. A gated
* attention q|gate projection is declared [tokens, heads, 2*head_dim] for the de-interleave
* that follows; to the GEMM its N is heads*2*head_dim, so rank > 2 must be accepted. */
if (g->y->rank < 2) return R4D_NO(RAD_E_SHAPE);
g->M = g->y->shape[0];
if (g->M < 1 || r4d_numel(g->y) % g->M) return R4D_NO(RAD_E_SHAPE);
g->N = r4d_numel(g->y) / g->M;
g->K = g->b->shape[1];
if (g->b->shape[0] != g->N) return R4D_NO(RAD_E_SHAPE);
if (g->M < 1 || g->N < 1 || g->K < 1) return R4D_NO(RAD_E_SHAPE);
if (g->N < 1 || g->K < 1) return R4D_NO(RAD_E_SHAPE);
/* The layout hook and the .rad it wrote are built against R4D_FP8_BLOCK; libr4d compiles its
* own copy in. A scalar compare against a constant costs nothing and the alternative is a
* silently wrong scale grid. */
/* The layout hook and the .rad it wrote use R4D_FP8_BLOCK and libr4d compiles its own copy;
* a mismatch would be a silently wrong scale grid. */
const long long blk = r4d_gemm_fp8a8_block();
if (blk != R4D_FP8_BLOCK) return R4D_NO(RAD_E_SHAPE);
g->nkb = (g->K + blk - 1) / blk;
/* The scale plane's own extents, checked rather than assumed: this is the operand a converter
* is most likely to hand over at the wrong grid, and a wrong grid reads a plausible number. */
/* Check the scale plane's extents: a wrong grid still reads plausible numbers. */
if (g->bscale->shape[0] != (wscale == FP8_OPS_ROW_SCALE ? g->N : (g->N + blk - 1) / blk))
return R4D_NO(RAD_E_SHAPE);
if (g->bscale->shape[1] != g->nkb) return R4D_NO(RAD_E_SHAPE);
@@ -102,10 +87,8 @@ static inline int fp8_ops(const RadArgs* a, Fp8Ops* g, int want_ascale,
if (asp < 0) return R4D_NO(RAD_E_STRIDE);
g->sa_ld = asp;
}
/* 16, not 128. The widest weight load in the family is a uint4 in the matvec and a 32-byte
* staged pair in the GEMM, both at a 16-byte offset from the row base. A 128-byte demand would
* be a claim about the cacheline, which is 256 on this part and is not an alignment rule of any
* load here. */
/* 16 bytes: the widest weight load in the family is a uint4 (matvec) or a 32-byte staged pair
* (GEMM), both at a 16-byte offset from the row base. */
if (!r4d_aligned(g->a->data, 16) || !r4d_aligned(g->b->data, 16)) return R4D_NO(RAD_E_ALIGN);
return RAD_OK;
}