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

+35 -69
View File
@@ -1,41 +1,23 @@
// The QSA indexer's TAIL: the raw index keys of the tokens that have not yet completed a block.
// The QSA indexer's tail: raw index keys of tokens that have not yet completed a block (a block key
// needs all `ratio` raw keys, and at decode most of them come from earlier steps).
//
// A block key is the mean of `ratio` consecutive raw keys, so a block cannot be built until its
// last token arrives -- and at decode three of the four are from earlier steps. This is where they
// wait.
// The tail is a per-layer linear KV state owned by the sequence (allocated zeroed, kept for the
// sequence's life, checkpointed with the linear state), not a plane indexed by the step-local batch
// row (arch/common/rad_qsa.h's Wire). `state` is one layer's cache, [slots, 1, ring, n]; `sidx`
// names the sequence's slot; position p lands at row p % ring.
//
// IT IS A LINEAR KV STATE AND NOT A PLANE INDEXED BY THE BATCH ROW. A sequence owns one state per
// bound layer, the engine keeps it for that sequence's life, zeroes it when it hands one out and
// checkpoints it with the rest of the linear state; the batch row is step-local and names a
// different sequence from one step to the next. arch/common/rad_qsa.h's Wire is the argument, and
// it is the same one that makes this per LAYER: the keys are `index_qk_proj`'s output.
// The ring is ratio + n_spec, not ratio: the next step restarts at the first rejected position, so
// a step may still owe positions back to p0 - ratio + 1 while writing up to p0 + n_spec. With that
// ring length a row is only overwritten by a position past any step that could still need it.
//
// `state` is the group's cache for ONE layer, `[slots, 1, ring, n]`, and `sidx` names this
// sequence's slot in it. A token at position `p` lands at row `p % ring`.
// A token's sequence comes from cu_seqlens (slot_mapping is a flat KV slot and does not identify
// the sequence); a linear scan suffices for a handful of sequences.
//
// THE RING IS `ratio + n_spec`, NOT `ratio`, AND SPECULATION IS THE WHOLE OF IT. A verify step
// runs 1 + n_spec positions and the next step restarts at the first REJECTED one, so a position
// this step has already overwritten is owed to the next. At ratio 4 depth 3 the step covering
// positions 9..12 writes rows 1,2,3,0 -- and row 0 is the one position 8 is still owed, because
// the block holding 8..11 is rebuilt as soon as the step that follows starts at 10. The widest
// window a step can still owe is [p0 - ratio + 1, p0 + n_spec]; a ring that long means a row is
// only ever overwritten by a position past the end of any step that could ask for it.
// Only the last `ring` tokens of a sequence's chunk write: positions p and p + ring share a row, so
// writing all of a prefill chunk would race. The last `ring` positions hit distinct rows, giving
// what a token-by-token loop would leave; older tokens' blocks are built from the chunk itself.
//
// WHICH SEQUENCE A TOKEN BELONGS TO IS `cu_seqlens`, and that is the whole reason this op takes a
// boundary list. The batch's other per-token index is `slot_mapping`, which is a FLAT KV slot and
// says nothing about the sequence; the boundary list does, and with at most a handful of sequences
// a linear scan of it is free beside the copy it guards.
//
// ONLY THE LAST `ring` TOKENS OF A SEQUENCE'S CHUNK WRITE, AND THAT IS NOT AN OPTIMISATION. A
// prefill chunk carries many tokens per sequence and positions `p` and `p + ring` land on the
// SAME row, so a launch that wrote every token would have two workgroups racing for one row and
// the winner would depend on the schedule. Restricting the write to the last `ring` tokens makes
// every row the target of at most one token -- their positions differ by less than `ring`, so
// their rows differ -- and the result is what a token-by-token loop would have left. The older
// tokens of the chunk are not lost: the blocks they complete are built from the chunk's own keys,
// which are still in the projection's output.
//
// Returns a negative code rather than throwing, for the reason given in r4d_gemm_fp8a8.hip.
// Returns a RAD status rather than throwing, for the reason given in r4d_gemm_fp8a8.hip.
#include "r4d.h"
#include "r4d_args.h"
@@ -57,9 +39,7 @@ __global__ __launch_bounds__(kThreads) void qsa_tail_store_kernel(
const int t = (int)blockIdx.x;
if (t >= T) return;
/* The sequence this token belongs to. A linear scan of at most `seqs + 1` boundaries, done
* redundantly by every thread rather than once into LDS: it is a handful of compares against
* a broadcast load, and a barrier would cost more than it saves. */
/* This token's sequence, by a linear scan in every thread (cheaper than LDS plus a barrier). */
int s = -1;
for (int i = 0; i < seqs; ++i)
if (t >= cu[i] && t < cu[i + 1]) { s = i; break; }
@@ -68,8 +48,7 @@ __global__ __launch_bounds__(kThreads) void qsa_tail_store_kernel(
/* Only the last `ring` tokens of this sequence's chunk -- see the header. */
if (t < cu[s + 1] - ring) return;
/* COLUMN 0 IS THE COMMITTED SLOT. -1 is the pad a sequence with no state carries, and every
* kernel that reads a state row already tests for it. */
/* Column 0 is the committed slot; -1 marks a sequence with no state. */
const int si = sidx[(size_t)s * sidx_ld];
if (si < 0) return;
@@ -85,35 +64,27 @@ __global__ __launch_bounds__(kThreads) void qsa_tail_store_kernel(
// pos [T] i32, each token's position in its sequence
// cu [seqs + 1] i32, cu_seqlens
// sidx [seqs][sidx_ld] i32, the tail group's state row; column 0 is the committed slot
// state [slots][ring][n] bf16, this layer's tail cache -- READ NOWHERE HERE, written in
// place, and rows nothing targets keep what they held
// state [slots][ring][n] bf16, this layer's tail cache; written only, untargeted rows
// keep their contents
static int r4d_qsa_tail_store_bf16_emit(long k, long pos, long cu, long sidx, long state, int T,
int n, int ring, int seqs, int k_ld, int s_slot, int s_row,
int sidx_ld, const R4dSink& sk) {
int emit_rc = RAD_OK;
if (!k || !pos || !cu || !sidx || !state) return -1;
if (T <= 0 || n <= 0 || ring <= 0 || seqs <= 0) return -2;
int sidx_ld, RadStream stream) {
if (!k || !pos || !cu || !sidx || !state) return R4D_NO(RAD_E_INVAL);
if (T <= 0 || n <= 0 || ring <= 0 || seqs <= 0) return R4D_NO(RAD_E_SHAPE);
if (!k_ld) k_ld = n;
if (!s_row) s_row = n;
if (!sidx_ld) sidx_ld = 1;
emit_rc = R4D_EMIT(sk, qsa_tail_store_kernel, dim3((unsigned)T), dim3(kThreads), 0, (const uint16_t*)k, (const int32_t*)pos,
(const int32_t*)cu, (const int32_t*)sidx, (uint16_t*)state, T, n, ring,
seqs, k_ld, s_slot, s_row, sidx_ld);
return emit_rc == RAD_OK && (sk.desc || hipGetLastError() == hipSuccess) ? 0 : -4;
}
extern "C" int r4d_qsa_tail_store_bf16_emit(long k, long pos, long cu, long sidx, long state, int T,
int n, int ring, int seqs, int k_ld, int s_slot, int s_row,
int sidx_ld, long stream) {
R4dSink sk; sk.stream = (RadStream)(uintptr_t)stream;
return r4d_qsa_tail_store_bf16_emit(k, pos, cu, sidx, state, T, n, ring, seqs, k_ld, s_slot, s_row, sidx_ld, sk);
return R4D_EMIT(stream, qsa_tail_store_kernel, dim3((unsigned)T), dim3(kThreads), 0,
(const uint16_t*)k, (const int32_t*)pos, (const int32_t*)cu,
(const int32_t*)sidx, (uint16_t*)state, T, n, ring, seqs, k_ld, s_slot, s_row,
sidx_ld);
}
// ============================================================== the plugin ABI entry point
enum { QT_K = 0, QT_POS = 1, QT_CU = 2, QT_STATE = 3, QT_SIDX = 4 };
static int r4d_rad_qsa_tail_store_body(const RadArgs* a, const R4dSink& sk) {
extern "C" int r4d_rad_qsa_tail_store(const RadArgs* a, RadStream stream) {
const RadTensor* k = r4d_opt(a, QT_K);
const RadTensor* po = r4d_opt(a, QT_POS);
const RadTensor* cu = r4d_opt(a, QT_CU);
@@ -121,10 +92,8 @@ static int r4d_rad_qsa_tail_store_body(const RadArgs* a, const R4dSink& sk) {
const RadTensor* sx = r4d_opt(a, QT_SIDX);
if (!k || !po || !cu || !st || !sx) return R4D_NO(RAD_E_INVAL);
if (k->rank != 2) return R4D_NO(RAD_E_SHAPE);
/* THE STATE ARRIVES AS THE GROUP DECLARED IT: [slots, heads, ring, n], heads 1. The engine
* composes that shape out of the declaration and the manager's slot count
* (core/engine_bringup.cpp), so a different rank here means a different group, not a layout
* this kernel could have coped with. */
/* The state arrives as the group declared it: [slots, heads, ring, n], heads 1
* (core/engine_bringup.cpp). */
if (st->rank != 4 || st->shape[1] != 1) return R4D_NO(RAD_E_SHAPE);
if (st->stride[3] != 1) return R4D_NO(RAD_E_STRIDE);
const long long n = r4d_geti_or(a, "n", 0);
@@ -134,9 +103,8 @@ static int r4d_rad_qsa_tail_store_body(const RadArgs* a, const R4dSink& sk) {
const long long T = k->shape[0];
if (T < 1 || k->shape[1] != n) return R4D_NO(RAD_E_SHAPE);
if (st->shape[2] < ring || st->shape[3] != n) return R4D_NO(RAD_E_SHAPE);
/* `cu_seqlens` IS seqs + 1 LONG AND THAT IS WHERE THE SEQUENCE COUNT COMES FROM. Taking it
* from the state's slot count instead would read the DECLARED max_seqs, and a step with fewer
* sequences than that would scan boundaries the batch never wrote. */
/* The sequence count comes from cu_seqlens, not the state's slot count (the declared
* max_seqs). */
const long long seqs = r4d_numel(cu) - 1;
if (seqs < 1 || r4d_numel(po) < T) return R4D_NO(RAD_E_SHAPE);
const long long sxp = sx->rank >= 2 ? r4d_row_pitch(sx) : 1;
@@ -144,11 +112,9 @@ static int r4d_rad_qsa_tail_store_body(const RadArgs* a, const R4dSink& sk) {
const long long kp = r4d_row_pitch(k);
if (kp < 0) return R4D_NO(RAD_E_STRIDE);
if (k->dtype != RAD_BF16 || st->dtype != RAD_BF16) return R4D_NO(RAD_E_DTYPE);
const int e = r4d_qsa_tail_store_bf16_emit(r4d_addr(k), r4d_addr(po), r4d_addr(cu), r4d_addr(sx),
r4d_addr(st), (int)T, (int)n, (int)ring, (int)seqs,
(int)kp, (int)st->stride[0], (int)st->stride[2],
(int)sxp, sk);
return e == 0 ? RAD_OK : RAD_E_SHAPE;
return r4d_qsa_tail_store_bf16_emit(r4d_addr(k), r4d_addr(po), r4d_addr(cu), r4d_addr(sx),
r4d_addr(st), (int)T, (int)n, (int)ring, (int)seqs,
(int)kp, (int)st->stride[0], (int)st->stride[2],
(int)sxp, stream);
}
R4D_ENTRY(r4d_rad_qsa_tail_store, r4d_rad_qsa_tail_store_body)