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

+23 -42
View File
@@ -1,16 +1,12 @@
// r4d_quant_act_i8.hip - r4d_quant_act_i8: per-row symmetric int8 quantisation of a bf16 activation,
// written in the order r4d_gemm_w4a8_nt_m64's A fragment wants.
//
// One row per workgroup: absmax over K, then a second pass writing the bytes. K is a few thousand
// and M is a speculative-decode batch, so the whole thing is well under a microsecond -- one launch
// in place of the several an unfused quantiser would cost.
// One row per workgroup: absmax over K, then a second pass writing the bytes.
//
// THE BYTE ORDER. Fragment element e of lane l is A[row][16s + 8*(e>>2) + 4*(l>>4) + (e&3)], so a
// lane's eight bytes are two dwords eight bytes apart in a row-major activation. Writing each k
// step's sixteen bytes as [half 0's eight][half 1's eight] instead makes them contiguous and the
// GEMM reads a fragment with one global_load_b64. Rows are untouched, so every lane of a wave
// stays inside the same sixteen rows it would have read anyway -- laying A out as two separate
// PLANES is the version that loses, see the note in the GEMM.
// Byte order: fragment element e of lane l is A[row][16s + 8*(e>>2) + 4*(l>>4) + (e&3)], two dwords
// eight bytes apart in a row-major activation. Each k step's sixteen bytes are written as
// [half 0's eight][half 1's eight], so the GEMM reads a fragment with one global_load_b64. Rows are
// not permuted; splitting A into two planes is slower (see the note in the GEMM).
#include "r4d.h"
#include "r4d_args.h"
#include "r4d_emit.h"
@@ -18,13 +14,6 @@
#include <hip/hip_bf16.h>
#include <cstdint>
// 0 = choose the workgroup width from M at launch (see r4d_act_threads in r4d_common.h). This
// kernel is not on the W4A8 path -- the rotated sibling is faster -- but it has the same
// one-workgroup-per-row shape, so it gets the same knob rather than being the odd one out.
#ifndef R4D_QAI8_THREADS
#define R4D_QAI8_THREADS 0
#endif
template <int THR>
__global__ __launch_bounds__(THR) void r4d_quant_act_i8_kernel(
const __hip_bfloat16* __restrict__ A, signed char* __restrict__ Q, float* __restrict__ S,
@@ -60,20 +49,15 @@ __global__ __launch_bounds__(THR) void r4d_quant_act_i8_kernel(
}
}
// ---------------------------------------------------------------------------------------------
// Same quantisation, plus the per-row per-group SUM of the int8 codes that an asymmetric weight
// grid needs: sum_k a_k (nibble_k - z_g) = sum_k a_k nibble_k - z_g * sum_k a_k, and the second
// factor depends only on the activation, so it is computed once here rather than N times in the
// GEMM. Output layout is [K/group][Mpad] -- GROUP-MAJOR, Mpad = ceil(M/16)*16 -- because in the
// GEMM a lane's eight accumulator elements are eight CONTIGUOUS output rows at one group, and the
// padding is what lets the GEMM read them as two aligned v4f instead of eight scalars. The caller
// allocates it zeroed; nothing writes the pad rows and the GEMM discards their outputs anyway.
// Same quantisation, plus the per-row per-group sum of the int8 codes for an asymmetric weight
// grid: sum_k a_k (nibble_k - z_g) = sum_k a_k nibble_k - z_g * sum_k a_k, and the second term is
// computed once here instead of N times in the GEMM. Output is [K/group][Mpad], group-major with
// Mpad = ceil(M/16)*16, because a lane's eight accumulator elements are eight contiguous rows at
// one group, read as two aligned v4f. The caller zeroes it; pad rows are never written.
//
// The fragment permutation is a shuffle INSIDE each 16-element step and a group is a whole number
// of steps, so it does not change which elements belong to which group and the sum can be taken on
// either side of it.
// The fragment permutation stays within a 16-element step and a group is whole steps, so group
// membership is unchanged.
#define R4D_QAI8_MAXG 256
template <int THR>
@@ -117,16 +101,14 @@ __global__ __launch_bounds__(THR) void r4d_quant_act_i8_asum_kernel(
Asum[(size_t)g * Mpad + row] = (float)gs[g];
}
// The two launches, as the plugin ABI's RadLaunchFn: `(const RadArgs*, RadStream) -> int`. A
// refused shape is a status code, not a throw; see libr4d/r4d_args.h for why the entry point takes
// the ABI's argument list directly and needs no adapter in front of it.
// The plugin ABI entry point (RadLaunchFn); a refused shape is a status code, not a throw. See
// libr4d/r4d_args.h.
//
// THE THIRD OUTPUT SELECTS THE FORM. Whether the caller wants the per-group row sums that an
// asymmetric weight grid subtracts is a property of the CALL, not of the model, so this is one
// row with a branch rather than two rows a constraint cannot tell apart.
// The optional fourth operand (asum) selects the form: the row sums are a property of the call,
// so this is one row with a branch rather than two rows a constraint cannot tell apart.
enum { QA_X = 0, QA_Q, QA_S, QA_ASUM };
static int rad_quant_act_i8_body(const RadArgs* args, const R4dSink& sk) {
extern "C" int r4d_rad_quant_act_i8(const RadArgs* args, RadStream stream) {
int emit_rc = RAD_OK;
const RadTensor* x = r4d_opt(args, QA_X);
const RadTensor* q = r4d_opt(args, QA_Q);
@@ -141,11 +123,11 @@ static int rad_quant_act_i8_body(const RadArgs* args, const R4dSink& sk) {
if (K % 16) return R4D_NO(RAD_E_SHAPE); // a k step is sixteen bytes of one row
if (r4d_numel(q) != M * K) return R4D_NO(RAD_E_SHAPE);
const int thr = R4D_QAI8_THREADS ? R4D_QAI8_THREADS : r4d_act_threads((int)M, (int)K);
const int thr = r4d_act_threads((int)M, (int)K); // the workgroup width, from M
if (!as) {
#define R4D_QAI8_LAUNCH(T) emit_rc = R4D_EMIT(sk, (r4d_quant_act_i8_kernel<T>), dim3((int)M), \
dim3(T), 0, (const __hip_bfloat16*)r4d_p(x), (signed char*)r4d_wp(q), \
#define R4D_QAI8_LAUNCH(T) emit_rc = R4D_EMIT(stream, (r4d_quant_act_i8_kernel<T>), \
dim3((int)M), dim3(T), 0, (const __hip_bfloat16*)r4d_p(x), (signed char*)r4d_wp(q), \
(float*)r4d_wp(sc), (int)K)
switch (thr) {
case 128: R4D_QAI8_LAUNCH(128); break;
@@ -162,12 +144,12 @@ static int rad_quant_act_i8_body(const RadArgs* args, const R4dSink& sk) {
const long long group = r4d_geti_or(args, "group", R4D_W4_GROUP);
if (group < 1 || K % group) return R4D_NO(RAD_E_SHAPE);
if (K / group > R4D_QAI8_MAXG) return R4D_NO(RAD_E_SHAPE); // the LDS accumulator's bound
// asum is [K/group][Mpad] with Mpad = ceil(M/16)*16 -- GROUP-MAJOR, and padded, because the
// asymmetric GEMM reads it a whole n-tile at a time. Sizing it from M alone overruns.
// asum is [K/group][Mpad], Mpad = ceil(M/16)*16, because the asymmetric GEMM reads whole
// 16-row tiles. Sizing it from M alone overruns.
const long long mpad = ((M + 15) / 16) * 16;
if (r4d_numel(as) < (K / group) * mpad) return R4D_NO(RAD_E_SCRATCH);
#define R4D_QAI8A_LAUNCH(T) emit_rc = R4D_EMIT(sk, (r4d_quant_act_i8_asum_kernel<T>), \
#define R4D_QAI8A_LAUNCH(T) emit_rc = R4D_EMIT(stream, (r4d_quant_act_i8_asum_kernel<T>), \
dim3((int)M), dim3(T), 0, (const __hip_bfloat16*)r4d_p(x), (signed char*)r4d_wp(q), \
(float*)r4d_wp(sc), (float*)r4d_wp(as), (int)K, (int)group, (int)mpad)
switch (thr) {
@@ -180,4 +162,3 @@ static int rad_quant_act_i8_body(const RadArgs* args, const R4dSink& sk) {
#undef R4D_QAI8A_LAUNCH
return emit_rc;
}
R4D_ENTRY(r4d_rad_quant_act_i8, rad_quant_act_i8_body)