Archived
radiance 2.0.0
Radiance becomes a multi-model engine: one process serves several models behind one port, loads each when a request names it, parks it in host memory or restores it from its container, and shares the cards between them (docs/MULTIMODEL.md). The configuration is one YAML file; the command line flags are gone (`radiance --config FILE`, hot reload on SIGHUP). Formats. IQ8R (rotated int8) and IQR-V4 replace FP8 and MXFP4 as whole-model formats, with an int8 KV cache (`kv-cache-dtype: i8`) in place of the fp8 one. Containers whose weights are block FP8, MXFP4, M2XFP4, NVFP4 or ParoQuant are refused at startup by the name of the first such weight. Not served until they have int8 containers: GLM-5.3-Flash, Ornith-1.5, Sage-A1.5, Nemotron-3.5-Bolt-74B, Ling-3.0-flash, drama-3 and Anima's FP8 container; Nemotron-3.5-Bolt-E4B, the Gemma 4 31B DFlash containers and MiniCPM5-2B bf16 serve without their drafter. 1.17.0 serves all of them. Speed. Chained launches for Qwen3.8-27B, Gemma 4, Gemma 3 and the small bf16 models, a new Qwen3.8-Flash-Next container (IQR-V4 experts, int8 trunk) with its decode step and prefill reworked, and a reworked adaptive draft window. Deployment. deploy/compose has two fleet files, tp1.yaml and tp2.yaml, each with its configuration beside it, in place of the per-model files. `host-pool-mib` is a model's host pool in all, split among its ranks. The dashboard is rebuilt: an hour of history kept by the server, each accelerator's memory by model, model states over time. Merged since 1.17.0: Nemotron-3.5-Bolt-74B-A9B by keptn42 (#339); GLM-5.3-Flash on four cards by AnimusNull (#397); chained launches for Flash-Next's decode step (#396) and preempted requests keeping their prefix and place (#405) by mici81; --prefill-interleave auto by Code000 (#410); eight more libr3d kernels and the w4a4 reference by RikshaDriver (#403, #407, #408); libr3d large-BAR and E4M3 decode fixes by neuromanMD (#438, #439); int4/int5 decode tiles by Kezi (#426); attention for Nanbeige 4.3 33B by everplays (#417); expert_stats_report.py by baKon (#431). Fixed: #398, #402, #419, #437 (dschmitz's patch); added the metrics of #392, and multi-model serving as asked for in #367 and #109. Plugin ABI 39: out-of-tree plugins need to be rebuilt. Thanks to @keptn42, @AnimusNull, @mici81, @Code000, @RikshaDriver, @neuromanMD, @Kezi, @everplays, @baKon and @dschmitz.
This commit is contained in:
1 parent
b4c04b6042
commit
ddcb9c69bb
696 files changed
+120770
-56596
No files matched your search
+91
-30
@@ -87,6 +87,33 @@ static inline const float* head_f32(const RadTensor* t, int64_t base, int64_t ds
|
||||
return scr;
|
||||
}
|
||||
|
||||
/* The int8 cache (abi/rad_builder.h), as libref reads and writes it (ref_attn.cpp): a token's row
|
||||
* in a head is head_dim K codes, head_dim V codes and their two f16 scales. `row` is the row's
|
||||
* byte offset; `half` 0 is K, 1 V. */
|
||||
static inline float kv_i8_scale(const void* cache, int64_t row, int64_t head_dim, int half) {
|
||||
uint16_t h;
|
||||
std::memcpy(&h, (const uint8_t*)cache + row + 2 * head_dim + 2 * half, sizeof h);
|
||||
return rad_f16_to_f32(h);
|
||||
}
|
||||
/* One head's K or V into its row: the scale is the head's absmax / 127 as an f16 (clamped at 515),
|
||||
* the codes round(x / scale) against the rounded scale, clamped to +-127. `x` is the head widened
|
||||
* to f32. */
|
||||
static inline void kv_i8_put(void* cache, int64_t row, int64_t head_dim, int half, const float* x) {
|
||||
float am = 0.0f;
|
||||
for (int64_t d = 0; d < head_dim; ++d) am = std::fmax(am, std::fabs(x[d]));
|
||||
const uint16_t h = rad_f32_to_f16(std::fmin(am / 127.0f, 515.0f));
|
||||
const float sc = rad_f16_to_f32(h);
|
||||
int8_t* const c = (int8_t*)cache + row + half * head_dim;
|
||||
for (int64_t d = 0; d < head_dim; ++d) {
|
||||
const float r = sc > 0.0f ? std::nearbyint(x[d] / sc) : 0.0f;
|
||||
c[d] = (int8_t)std::fmin(std::fmax(r, -127.0f), 127.0f);
|
||||
}
|
||||
std::memcpy((uint8_t*)cache + row + 2 * head_dim + 2 * half, &h, sizeof h);
|
||||
}
|
||||
static inline bool kv_i8_shape(const RadTensor* kv, int64_t head_dim) {
|
||||
return kv->rank == 4 && kv->shape[3] == 2 * head_dim + 4 && kv->stride[3] == 1;
|
||||
}
|
||||
|
||||
static inline void axpy(float* acc, const float* v, float w, int64_t n) {
|
||||
const vf vw = vf_set1(w);
|
||||
int64_t i = 0;
|
||||
@@ -149,6 +176,8 @@ static int attn_paged_prefill(const RadArgs* a, [[maybe_unused]] RadStream strea
|
||||
const int64_t o_hs = o->rank >= 3 ? o->stride[o->rank - 2] : head_dim * o_ds;
|
||||
const int64_t o_rs = row_stride(o, q_heads * head_dim);
|
||||
const float scale = p_f32(a, "scale", 1.0f / std::sqrt((float)head_dim));
|
||||
/* The int8 cache: a key's own K and V scales stand where the descales do. */
|
||||
const bool i8 = kv->dtype == RAD_I8;
|
||||
|
||||
enum { QB = 64 };
|
||||
const int64_t nqb = (q_len + QB - 1) / QB;
|
||||
@@ -181,10 +210,12 @@ static int attn_paged_prefill(const RadArgs* a, [[maybe_unused]] RadStream strea
|
||||
continue;
|
||||
}
|
||||
kbv[j] = blk * kvv.sb + kh * kvv.sh + (j % block_size) * kvv.so;
|
||||
const float* kr = head_f32(kv, kbv[j], kvv.sd, head_dim, kds, kbuf);
|
||||
const float km = i8 ? kv_i8_scale(kv->data, kbv[j], head_dim, 0) : kds;
|
||||
const float vm = i8 ? kv_i8_scale(kv->data, kbv[j], head_dim, 1) : vds;
|
||||
const float* kr = head_f32(kv, kbv[j], kvv.sd, head_dim, km, kbuf);
|
||||
for (int64_t d = 0; d < head_dim; ++d) Kp[(size_t)j * head_dim + d] = kr[d];
|
||||
const float* vr = head_f32(kv, kbv[j] + head_dim * kvv.sd, kvv.sd, head_dim,
|
||||
vds, kbuf);
|
||||
vm, kbuf);
|
||||
for (int64_t d = 0; d < head_dim; ++d) Vp[(size_t)j * head_dim + d] = vr[d];
|
||||
nkeys = j + 1;
|
||||
}
|
||||
@@ -307,6 +338,9 @@ static int attn_paged_rows(const RadArgs* a, RadStream stream, const RadTensor*
|
||||
if (numel(o) < rows * q_heads * head_dim) return RAD_E_SHAPE;
|
||||
if (kv->rank == 4 && kv->shape[2] != block_size) return RAD_E_SHAPE;
|
||||
if (kv->rank == 4 && kv->shape[3] < 2 * head_dim) return RAD_E_SHAPE;
|
||||
/* The int8 cache: dense rows of 2 * head_dim + 4 bytes, each key's scales in its own row. */
|
||||
const bool i8 = kv->dtype == RAD_I8;
|
||||
if (i8 && !kv_i8_shape(kv, head_dim)) return RAD_E_SHAPE;
|
||||
|
||||
const int64_t max_blocks = bt->rank >= 2 ? bt->shape[bt->rank - 1] : numel(bt) / n_seq;
|
||||
const int64_t bt_rs = bt->rank >= 2 ? bt->stride[bt->rank - 2] : max_blocks;
|
||||
@@ -430,8 +464,9 @@ static int attn_paged_rows(const RadArgs* a, RadStream stream, const RadTensor*
|
||||
}
|
||||
for (int t = 0; t < ntile; ++t) {
|
||||
/* One widening per key, then gqa axpys. */
|
||||
const float vm = i8 ? kv_i8_scale(kv->data, kbase[t], head_dim, 1) : vds;
|
||||
const float* vv = head_f32(kv, kbase[t] + head_dim * kvv.sd, kvv.sd, head_dim,
|
||||
vds, vrow);
|
||||
vm, vrow);
|
||||
for (int64_t g = 0; g < gqa; ++g) {
|
||||
const float w = sbufs[g * AVX_KV_TILE + t];
|
||||
ll[g] += w;
|
||||
@@ -455,7 +490,8 @@ static int attn_paged_rows(const RadArgs* a, RadStream stream, const RadTensor*
|
||||
if (blk < 0) continue;
|
||||
const int64_t kb = blk * kvv.sb + kh * kvv.sh + (j % block_size) * kvv.so;
|
||||
/* One widening per key, then gqa dots. */
|
||||
const float* kvrow = head_f32(kv, kb, kvv.sd, head_dim, kds, krow);
|
||||
const float km = i8 ? kv_i8_scale(kv->data, kb, head_dim, 0) : kds;
|
||||
const float* kvrow = head_f32(kv, kb, kvv.sd, head_dim, km, krow);
|
||||
for (int64_t g = 0; g < gqa; ++g)
|
||||
sbufs[g * AVX_KV_TILE + ntile] =
|
||||
dotf(qpan + g * head_dim, kvrow, head_dim) * scale;
|
||||
@@ -1045,15 +1081,17 @@ AVX_KERNEL(attn_local_rel) {
|
||||
* A negative slot is skipped; that is how a padded batch row says it has no cache slot. libr4d
|
||||
* treats slot <= 0 as null because vLLM reserves block 0, but slot 0 is valid in general, so only
|
||||
* negative slots are skipped (libref's rule). */
|
||||
/* The scatter: token t's k and v rows into its slot of every KV head. SCALED multiplies them by
|
||||
* the fp8 cache's inverse descales `ks` and `vs`; the unscaled form is a separate instantiation so
|
||||
* the common path carries no scale. */
|
||||
template <bool SCALED>
|
||||
/* The scatter: token t's k and v rows into its slot of every KV head. MODE 2 writes the int8
|
||||
* cache's codes and scales (kv_i8_put); MODE 1 multiplies the rows by the fp8 cache's inverse
|
||||
* descales `ks` and `vs`; MODE 0 stores the values themselves, a separate instantiation so the
|
||||
* common path carries no scale. */
|
||||
template <int MODE>
|
||||
static void kv_scatter(const RadTensor* k, const RadTensor* v, const RadTensor* sm,
|
||||
const RadTensor* kv, const KVView& kvv, int64_t M, int64_t kv_heads,
|
||||
int64_t head_dim, int64_t block_size, int64_t k_rs, int64_t k_hs,
|
||||
int64_t k_ds, int64_t v_rs, int64_t v_hs, int64_t v_ds, float ks,
|
||||
float vs) {
|
||||
constexpr bool I8 = MODE == 2, SCALED = MODE == 1;
|
||||
AVX_PARALLEL_FOR_IF(M * kv_heads * head_dim >= AVX_PAR_MIN)
|
||||
for (int64_t t = 0; t < M; ++t) {
|
||||
const int64_t slot = ldi(sm, offlin(sm, t));
|
||||
@@ -1062,6 +1100,13 @@ static void kv_scatter(const RadTensor* k, const RadTensor* v, const RadTensor*
|
||||
float* buf = scratch_f32((size_t)head_dim);
|
||||
for (int64_t h = 0; h < kv_heads; ++h) {
|
||||
const int64_t cb = blk * kvv.sb + h * kvv.sh + off * kvv.so;
|
||||
if constexpr (I8) {
|
||||
for (int64_t d = 0; d < head_dim; ++d) buf[d] = ldt(k, t * k_rs + h * k_hs + d * k_ds);
|
||||
kv_i8_put(kv->data, cb, head_dim, 0, buf);
|
||||
for (int64_t d = 0; d < head_dim; ++d) buf[d] = ldt(v, t * v_rs + h * v_hs + d * v_ds);
|
||||
kv_i8_put(kv->data, cb, head_dim, 1, buf);
|
||||
continue;
|
||||
}
|
||||
/* A whole head at a time through the row converter; strided operands go per
|
||||
* element. */
|
||||
if (k_ds == 1 && kvv.sd == 1) {
|
||||
@@ -1115,8 +1160,10 @@ AVX_KERNEL(kv_store) {
|
||||
const int64_t v_hs = v->rank >= 3 ? v->stride[v->rank - 2] : head_dim * v_ds;
|
||||
const int64_t v_rs = row_stride(v, kv_heads * head_dim);
|
||||
const KVView kvv = kv_view(kv, head_dim, block_size, kv_heads);
|
||||
/* An fp8 cache stores k / k_scale and v / v_scale, the scales being the reader's descales
|
||||
* (default 1.0), as libref and libr4d store it. A wider cache stores the value itself. */
|
||||
const bool i8 = kv->dtype == RAD_I8;
|
||||
if (i8 && !kv_i8_shape(kv, head_dim)) return RAD_E_SHAPE;
|
||||
/* An fp8 cache (GLM-5.3's latent attention) stores k / k_scale and v / v_scale, the scales
|
||||
* being the reader's descales (default 1.0), as libref and libr4d store it. */
|
||||
const bool fp8 = kv->dtype == RAD_F8E4M3 || kv->dtype == RAD_F8E5M2;
|
||||
const float ks = fp8 ? 1.0f / p_f32(a, "k_scale", 1.0f) : 1.0f;
|
||||
const float vs = fp8 ? 1.0f / p_f32(a, "v_scale", 1.0f) : 1.0f;
|
||||
@@ -1127,20 +1174,23 @@ AVX_KERNEL(kv_store) {
|
||||
if (slot >= 0 && n_blocks > 0 && slot / block_size >= n_blocks) return RAD_E_SHAPE;
|
||||
}
|
||||
|
||||
if (ks != 1.0f || vs != 1.0f)
|
||||
kv_scatter<true>(k, v, sm, kv, kvv, M, kv_heads, head_dim, block_size, k_rs, k_hs, k_ds,
|
||||
v_rs, v_hs, v_ds, ks, vs);
|
||||
if (i8)
|
||||
kv_scatter<2>(k, v, sm, kv, kvv, M, kv_heads, head_dim, block_size, k_rs, k_hs, k_ds,
|
||||
v_rs, v_hs, v_ds, ks, vs);
|
||||
else if (ks != 1.0f || vs != 1.0f)
|
||||
kv_scatter<1>(k, v, sm, kv, kvv, M, kv_heads, head_dim, block_size, k_rs, k_hs, k_ds,
|
||||
v_rs, v_hs, v_ds, ks, vs);
|
||||
else
|
||||
kv_scatter<false>(k, v, sm, kv, kvv, M, kv_heads, head_dim, block_size, k_rs, k_hs, k_ds,
|
||||
v_rs, v_hs, v_ds, ks, vs);
|
||||
kv_scatter<0>(k, v, sm, kv, kvv, M, kv_heads, head_dim, block_size, k_rs, k_hs, k_ds,
|
||||
v_rs, v_hs, v_ds, ks, vs);
|
||||
return RAD_OK;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ kv_store_streamed */
|
||||
/* kv_store for a streamed group (libref/ref_attn.cpp, ref_kv_store_streamed): `host` written
|
||||
* always, `kv_cache[res[block]]` only where the block is resident. Both planes are the same paged
|
||||
* layout seen as the cache's dtype, so one conversion writes both: E4M3 as kv_store_fp8, bf16 the
|
||||
* value itself. `res` is read, never written. */
|
||||
* layout seen as the cache's dtype, so one conversion writes both: the int8 cache's codes and
|
||||
* scales, E4M3 as kv_store_fp8, or bf16 the value itself. `res` is read, never written. */
|
||||
AVX_KERNEL(kv_store_streamed) {
|
||||
if (!rad_args_have(a, 6)) return RAD_E_INVAL;
|
||||
const RadTensor *k = &a->t[0], *v = &a->t[1], *sm = &a->t[2], *kv = &a->t[3];
|
||||
@@ -1153,16 +1203,17 @@ AVX_KERNEL(kv_store_streamed) {
|
||||
if (k->dtype != RAD_BF16 || v->dtype != RAD_BF16) return RAD_E_DTYPE;
|
||||
if (sm->dtype != RAD_I32 || res->dtype != RAD_I32) return RAD_E_DTYPE;
|
||||
if (host->dtype != RAD_U8) return RAD_E_DTYPE;
|
||||
/* E4M3 or bf16; a packed fp8_v4/k6_v4 group has no streamed row. */
|
||||
const bool fp8 = kv->dtype == RAD_F8E4M3;
|
||||
if (!fp8 && kv->dtype != RAD_BF16) return RAD_E_UNSUPPORTED;
|
||||
const bool i8 = kv->dtype == RAD_I8, fp8 = kv->dtype == RAD_F8E4M3;
|
||||
if (!i8 && !fp8 && kv->dtype != RAD_BF16) return RAD_E_UNSUPPORTED;
|
||||
const float ks = fp8 ? 1.0f / p_f32(a, "k_scale", 1.0f) : 1.0f;
|
||||
const float vs = fp8 ? 1.0f / p_f32(a, "v_scale", 1.0f) : 1.0f;
|
||||
const int64_t rowe = i8 ? 2 * head_dim + 4 : 2 * head_dim; /* a token's row in a head */
|
||||
if (kv->rank != 4 || kv->shape[1] != kv_heads || kv->shape[2] != block_size ||
|
||||
kv->shape[3] != 2 * head_dim) return RAD_E_SHAPE;
|
||||
kv->shape[3] != rowe || kv->stride[3] != 1) return RAD_E_SHAPE;
|
||||
if (host->rank != 2) return RAD_E_SHAPE;
|
||||
|
||||
/* Both planes are dense rows of one block of one layer, so one offset addresses both. */
|
||||
const int64_t EB = fp8 ? 1 : 2;
|
||||
const int64_t row = kv_heads * block_size * 2 * head_dim * EB;
|
||||
const int64_t row = kv_heads * block_size * rowe * (kv->dtype == RAD_BF16 ? 2 : 1);
|
||||
const int64_t slots = kv->shape[0], blocks = host->shape[0];
|
||||
if (host->shape[1] != row ||
|
||||
host->stride[0] * rad_dtype_bytes(host->dtype, 1) != row) return RAD_E_STRIDE;
|
||||
@@ -1180,9 +1231,6 @@ AVX_KERNEL(kv_store_streamed) {
|
||||
const int64_t v_ds = v->rank >= 2 ? v->stride[v->rank - 1] : 1;
|
||||
const int64_t v_hs = v->rank >= 3 ? v->stride[v->rank - 2] : head_dim * v_ds;
|
||||
const int64_t v_rs = row_stride(v, kv_heads * head_dim);
|
||||
const float ks = fp8 ? 1.0f / p_f32(a, "k_scale", 1.0f) : 1.0f;
|
||||
const float vs = fp8 ? 1.0f / p_f32(a, "v_scale", 1.0f) : 1.0f;
|
||||
|
||||
/* Refused before the first write, as libref refuses it (the device row, which cannot return a
|
||||
* status from its kernel, guards these instead). */
|
||||
const int32_t* const R = (const int32_t*)res->data;
|
||||
@@ -1194,8 +1242,10 @@ AVX_KERNEL(kv_store_streamed) {
|
||||
if (R[blk] < -1 || R[blk] >= slots) return RAD_E_INVAL;
|
||||
}
|
||||
|
||||
RadTensor hkv = *host;
|
||||
hkv.dtype = kv->dtype; /* the same bytes, seen as the cache's dtype */
|
||||
/* The mirror seen as the plane it holds: the ring's layout over the mirror's bytes. */
|
||||
RadTensor hkv = *kv;
|
||||
hkv.data = host->data;
|
||||
hkv.shape[0] = blocks;
|
||||
const KVView kvv = kv_view(kv, head_dim, block_size, kv_heads);
|
||||
const KVView hv = kv_view(&hkv, head_dim, block_size, kv_heads);
|
||||
|
||||
@@ -1206,10 +1256,21 @@ AVX_KERNEL(kv_store_streamed) {
|
||||
const int64_t blk = slot / block_size, off = slot % block_size;
|
||||
const int64_t hb = blk * hv.sb + off * hv.so;
|
||||
const int64_t cb = R[blk] >= 0 ? R[blk] * kvv.sb + off * kvv.so : -1;
|
||||
float* buf = i8 ? scratch_f32((size_t)head_dim) : nullptr;
|
||||
for (int64_t h = 0; h < kv_heads; ++h) {
|
||||
const int64_t kx = t * k_rs + h * k_hs, vx = t * v_rs + h * v_hs;
|
||||
if (i8) {
|
||||
for (int64_t d = 0; d < head_dim; ++d) buf[d] = ldt(k, kx + d * k_ds);
|
||||
kv_i8_put(hkv.data, hb + h * hv.sh, head_dim, 0, buf);
|
||||
if (cb >= 0) kv_i8_put(kv->data, cb + h * kvv.sh, head_dim, 0, buf);
|
||||
for (int64_t d = 0; d < head_dim; ++d) buf[d] = ldt(v, vx + d * v_ds);
|
||||
kv_i8_put(hkv.data, hb + h * hv.sh, head_dim, 1, buf);
|
||||
if (cb >= 0) kv_i8_put(kv->data, cb + h * kvv.sh, head_dim, 1, buf);
|
||||
continue;
|
||||
}
|
||||
for (int64_t d = 0; d < head_dim; ++d) {
|
||||
const float xk = ldt(k, t * k_rs + h * k_hs + d * k_ds) * ks;
|
||||
const float xv = ldt(v, t * v_rs + h * v_hs + d * v_ds) * vs;
|
||||
const float xk = ldt(k, kx + d * k_ds) * ks;
|
||||
const float xv = ldt(v, vx + d * v_ds) * vs;
|
||||
stt(&hkv, hb + h * hv.sh + d * hv.sd, xk);
|
||||
stt(&hkv, hb + h * hv.sh + (head_dim + d) * hv.sd, xv);
|
||||
if (cb >= 0) {
|
||||
|
||||
Reference in new issue
Block a user