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

+24 -38
View File
@@ -3,17 +3,14 @@
//
// out[r][d] = x[r][d] . rsqrt(mean_d(x[r][:]^2) + eps) . w[d] . act(z[r][d])
//
// one row per (token, head), 128 wide. It replaces FLA's `rmsnorm_fn` (mamba/ops/layernorm_gated),
// which is the last Triton kernel in the layer.
// one row per (token, head), 128 wide. Replaces FLA's `rmsnorm_fn` (mamba/ops/layernorm_gated).
//
// It exists as its own kernel only because the chunked scan cannot host it: that kernel's
// workgroup owns 64 of the 128 v channels of a row (BV=64, and widening it to 128 leaves 24
// workgroups on 64 CUs), while an RMS needs the whole row. The DECODE kernel does own the whole
// row, so there the same arithmetic is fused into the epilogue and this kernel is not launched at
// all -- see r4d_gdn_recurrent_update_k128_v128_bf16_fp32state.hip.
// A separate kernel because the chunked scan's workgroup owns only 64 of a row's 128 v channels
// (BV=64; 128 would leave 24 workgroups on 64 CUs). The decode recurrent update owns whole rows and
// fuses this into its epilogue (r4d_gdn_recurrent_update_k128_v128_bf16_fp32state.hip).
//
// One wave per row, four channels per lane: the reduction is five shuffles with no LDS and no
// barrier, and both loads and the store are one 8-byte access per lane.
// One wave per row, four channels per lane: a barrier-free five-shuffle reduction, and one 8-byte
// access per lane for each load and the store.
#include <hip/hip_runtime.h>
#include "r4d.h"
#include "r4d_gdn_args.h"
@@ -42,10 +39,8 @@ void r4d_gdn_gated_rmsnorm_kernel(const unsigned short* __restrict__ x,
const long r = (long)blockIdx.x * GN_NW + warp;
if (r >= rows) return;
const int d0 = lane * GN_DPL;
// THE GATE CAN BE A COLUMN VIEW, and then its rows are not evenly spaced: the fp8 delta net
// projects [q|k|v|z] in one GEMM, so within a token the `zheads` gate rows are `zrow` apart and
// the next token is `ztok` away, which is wider. zheads <= 0 is the flat case and the one every
// other caller passes.
// The gate may be a column view of a fused [q|k|v|z] projection: within a token the `zheads`
// gate rows are `zrow` apart and the next token is `ztok` away. zheads <= 0 is the flat case.
const long zoff = zheads > 0 ? (r / zheads) * ztok + (r % zheads) * zrow : r * zrow;
const ushort4 xv = *(const ushort4*)(x + r * xrow + d0);
@@ -88,9 +83,7 @@ extern "C" int r4d_gdn_gated_rmsnorm_h128_bf16(const void* x, const void* z, con
}
// ============================================================== the plugin ABI entry points
//
// The shared operand helpers are r4d_gdn_args.h. See libr4d/r4d_args.h for why there is no
// adapter directory between the core and these launches.
// Shared operand helpers: r4d_gdn_args.h.
/* ------------------------------------------------------------------ gated rms norm */
enum { GN_X = 0, GN_Z, GN_W, GN_O };
@@ -100,22 +93,17 @@ extern "C" int r4d_rad_gdn_gated_rmsnorm(const RadArgs* a, RadStream s) {
const RadTensor* z = r4d_opt(a, GN_Z);
const RadTensor* w = r4d_opt(a, GN_W);
const RadTensor* o = r4d_opt(a, GN_O);
/* "bf16 x / z / out, fp32 weight". */
/* bf16 x, z, out; fp32 weight. */
R4D_DT(x, RAD_BF16); R4D_DT(z, RAD_BF16); R4D_DT(o, RAD_BF16); R4D_DT(w, RAD_F32);
if (!x || !z || !w || !o) return R4D_NO(RAD_E_INVAL);
if (x->rank < 2 || z->rank < 2 || o->rank < 2) return R4D_NO(RAD_E_SHAPE);
if (!r4d_contig(w)) return R4D_NO(RAD_E_STRIDE);
/* ONE ROW IS ONE (token, head), and the three operands do not agree on how that is spelled.
* The norm's input and output are [tokens, heads, channels] -- rank 3, because the chunk scan
* before them requires it -- while the gate arrives as the [tokens, heads*channels] projection
* it was produced by. Both are the same rows in the same order; only the rank differs, and
* taking the last axis as the width would refuse the gate for having 6144 columns instead of
* 128. So the WIDTH comes from the op's `channels` (or x's last axis, which agrees), the row
* COUNT comes from x's extent, and each operand's pitch is read according to which of the two
* shapes it has. libr4d wants a pitch between consecutive (token, head) rows, which for a
* flattened projection is the width itself and not the token stride. */
/* One row is one (token, head). x and out are [tokens, heads, channels] (rank 3, as the chunk
* scan requires) while the gate may be the flat [tokens, heads*channels] projection. So the
* width comes from `channels` (or x's last axis), the row count from x, and each operand's
* pitch between consecutive (token, head) rows is read per its shape. */
const long long width = r4d_geti_or(a, "channels", x->shape[x->rank - 1]);
if (width <= 0 || r4d_numel(x) % width) return R4D_NO(RAD_E_SHAPE);
const long long rows = r4d_numel(x) / width;
@@ -125,31 +113,29 @@ extern "C" int r4d_rad_gdn_gated_rmsnorm(const RadArgs* a, RadStream s) {
const long long orow = gn_row_pitch(o, width);
if (xrow < 0 || orow < 0) return R4D_NO(RAD_E_STRIDE);
/* AND THE GATE HAS A THIRD SPELLING: a COLUMN SLICE of a wider projection row, which the fp8
* delta net hands it because [q|k|v|z] is one GEMM there. Its (token, head) rows are then not
* evenly spaced -- heads are `width` apart inside a token and tokens are the slice's own
* stride apart -- so one pitch cannot describe it and the kernel takes the head count too.
* `zheads` is 0 for the two flat spellings, which is every other caller. */
/* The gate may also be a column slice of a wider [q|k|v|z] row (fp8 delta net): heads are
* `width` apart within a token and tokens are the slice's stride apart, so the kernel also
* takes the head count. zheads stays 0 for the flat layouts. */
long long zrow = gn_row_pitch(z, width), zheads = 0, ztok = 0;
if (zrow < 0 && z->rank == 2 && z->stride[1] == 1 && z->shape[1] % width == 0) {
zheads = z->shape[1] / width;
ztok = z->stride[0];
zrow = width;
/* The gate's head count has to divide the row count, and where x spells its own it has to
* agree: two operands disagreeing about how many heads a token carries would interleave
* silently rather than run off the end. */
/* The gate's head count must divide the row count and match x's head axis if it has one;
* a mismatch would silently interleave rows. */
if (zheads <= 0 || rows % zheads) return R4D_NO(RAD_E_SHAPE);
if (x->rank >= 3 && x->shape[x->rank - 2] != zheads) return R4D_NO(RAD_E_SHAPE);
}
if (zrow < 0) return R4D_NO(RAD_E_STRIDE);
const float eps = (float)r4d_getf(a, "eps", 1e-6);
/* "silu" or "sigmoid". The integer libr4d wants is produced here and nowhere else. */
/* "silu" (0) or "sigmoid" (1). */
const int act = r4d_act_code(a, "act", nullptr, -1);
if (act != 0 && act != 1) return R4D_NO(RAD_E_INVAL);
return r4d_gdn_gated_rmsnorm_h128_bf16(x->data, z->data, w->data, o->data,
(long)rows, (long)xrow, (long)zrow, (long)orow,
(long)zheads, (long)ztok, (int)width, eps, act, s);
return R4D_RAW(r4d_gdn_gated_rmsnorm_h128_bf16(x->data, z->data, w->data, o->data,
(long)rows, (long)xrow, (long)zrow,
(long)orow, (long)zheads, (long)ztok,
(int)width, eps, act, s));
}