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:
Deadcode committed 2026-11-14 22:32:28 +01:00
1 parent b4c04b6042
commit ddcb9c69bb
696 files changed
+120770 -56596

No files matched your search

+4 -5
View File
@@ -20,7 +20,7 @@ every step) needs this plugin.
## The embedding gather
`embed_lookup_q` over an E4M3 table into bf16 is the one host op a GPU deployment runs, wherever
`--ngram-placement` leaves the n-gram table for the host gather: read from the container file
`ngram-placement` leaves the n-gram table for the host gather: read from the container file
(`disk`), or a locked copy in RAM when no device kernel for the op is loaded (`ram`). Where libr4d
is loaded, `ram` is a pinned copy its kernel reads over the link, and this one does not run.
@@ -78,7 +78,7 @@ Every `RAD_E_UNSUPPORTED` a libavx kernel returns, beside libref's answer to the
| `rope` | YaRN with `axial` or a position scale | the same |
| `rope` | Llama 3 scaling beside YaRN, with `axial`, or over multi-component positions | the same |
| `rope` | a rotary half-width over 1024 | the same |
| `had_quant_act_i8`, `had_quant_act_fp8`, `had_quant_act_i8g`, `rmsnorm_had_quant_i8`, `gated_had_quant_i8`, `hc_read` | a Hadamard group over 4096 | the same (`REF_HAD_MAX`) |
| `had_quant_act_i8`, `had_quant_act_i8g`, `rmsnorm_had_quant_i8`, `gated_had_quant_i8`, `hc_read` | a Hadamard group over 4096 | the same (`REF_HAD_MAX`) |
| `gdn_conv_prep`, `gdn_conv_update` | a convolution history over 16 | the same |
| `gdn_recurrent_update` | a `state_form` other than `per_candidate` or `anchor` | the same |
| `ple_conv`, `causal_conv1d` | a history over 64 | the same |
@@ -471,7 +471,7 @@ On a busy machine each figure moves by up to 2x between runs; repeat before comp
## Image generation
Qwen-Image 2.1 (`arch/qwenimage21`) generates on the host backend with `--kernels libavx` alone,
Qwen-Image 2.1 (`arch/qwenimage21`) generates on the host backend with `server.kernels: libavx` alone,
no reference library loaded: engine_e2e_test's `qwen_image_generates_on_libavx_alone_as_on_libref`
serves a tiny synthetic pipeline converted to a bf16 and a block-fp8 container, with and without
guidance. A seed repeats its PNG byte for byte, and the picture agrees with libref's at 51-53 dB
@@ -517,7 +517,6 @@ core at AVX-512:
| attn_prefix_self | 4096 rows + 256, 4 x 128, bf16 | - | 1243625 | 287250 | 282482 | **80237** | 455 GFLOP/s |
| ln_mod | 1024 x 4096 | 53696 | 3490 | 1909 | 1347 | **879** | 19.1 GB/s |
| gate_add | 1024 x 4096 | 48096 | 2974 | 2105 | 1444 | **991** | 25.4 GB/s |
| ln_mod_quant_fp8 | 1024 x 4096, gated | 120492 | 28441 | 23452 | 5227 | **3267** | 9.0 GB/s |
| qk_norm_rope | gptj_blocks, 1024 x 64 heads of 128 | 83241 | 9851 | 4963 | 3851 | **3078** | 10.9 GB/s |
| l2norm_chan | 262144 px x 144, silu | 534042 | 100513 | 50344 | 34219 | **23405** | 6.5 GB/s |
| d2s_add | 576 -> 288, 512 x 512 out | 174944 | 47387 | 42418 | 34430 | **29654** | 12.7 GB/s |
@@ -544,7 +543,7 @@ so these vary by about 15%):
| gemm_nt | the DiT's gate_up, bf16, M 1024 | 5.2 TFLOP/s | 0.64 TFLOP/s |
| gemm_nt_q | the same, fp8a8 (block fp8) | 0.31-0.42 TFLOP/s | 0.26 TFLOP/s |
| ln_mod, gate_add | 1024 x 4096 | 92-101 GB/s | |
| ln_mod_quant_fp8, qk_norm_rope | 1024 x 4096 | 33-35 GB/s | |
| qk_norm_rope | 1024 x 4096 | 33-35 GB/s | |
At AVX2 the convolution and the bf16 GEMM run on the generic driver, which at large M forks one
parallel region per 6- to 16-row block of A: it is a decode-shaped loop, and why their 16-thread
+91 -30
View File
@@ -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) {
+22 -49
View File
@@ -219,6 +219,15 @@ std::vector<Case> build_cases() {
add("quant_cols_fp8", { HI("M", 5), HI("n", 256), HS("dtype", "bf16") }, EB(5, 256, 2, 1.5));
add("quant_cols_fp8", { HI("M", 7), HI("n", 96), HS("dtype", "f32") }, EB(7, 96, 4, 1.25));
/* IQ8R's activation: one scale per 256 columns, each 128-wide half rotated on its own. */
add("had_quant_act_i8g", { HI("M", 5), HI("n", 512), HI("group", 256), HS("dtype", "bf16") });
/* The packed four-bit weight read back: two's complement at a group of 64, a zero point at
* 128, one fragment tile of rows each. */
add("dequant_w4", { HI("N", 16), HI("K", 64), HI("group", 64), HI("twos", 1),
HS("dtype", "w4a8") });
add("dequant_w4", { HI("N", 16), HI("K", 128), HI("group", 128), HI("twos", 0),
HS("dtype", "w4a8") });
/* Quantisation. 128 is the real grid; 64 tests a second block edge. n = 256 is divisible by
* both, which the had_* forms require (a rotation block may not straddle the row end). */
for (int group : { 64, 128 }) {
@@ -232,8 +241,6 @@ std::vector<Case> build_cases() {
HS("dtype", "f32") }, EB(5, 256, 4, 1.25));
add("quant_act_fp8", { HI("M", 5), HI("n", 256), HI("group", group),
HS("dtype", "bf16") }, EB(5, 256, 2, 1.5));
add("had_quant_act_fp8", { HI("M", 5), HI("n", 256), HI("group", group),
HS("dtype", "bf16") });
add("had_quant_act_i8g", { HI("M", 5), HI("n", 256), HI("group", group),
HS("dtype", "bf16") });
add("had_quant_act_i8", { HI("M", 5), HI("n", 256), HI("group", group),
@@ -312,6 +319,9 @@ std::vector<Case> build_cases() {
HS("dtype", "i8a8") }, 0, 2.0 * M * 96 * 256);
add("gemm_nt_q", { HI("M", M), HI("N", 96), HI("K", 256), HI("group", 128),
HS("dtype", "i8a8h") }, 0, 2.0 * M * 96 * 256);
/* IQ8R's grid: one scale per 256 of K on both sides. */
add("gemm_nt_q", { HI("M", M), HI("N", 96), HI("K", 512), HI("group", 256),
HS("dtype", "i8a8h") }, 0, 2.0 * M * 96 * 512);
add("gemm_nt_q", { HI("M", M), HI("N", 96), HI("K", 256), HI("group", 32),
HS("dtype", "mxfp4a8") }, 0, 2.0 * M * 96 * 256);
}
@@ -477,39 +487,19 @@ std::vector<Case> build_cases() {
add("attn_local_rel", { HI("M", 40), HI("head_dim", 32), HI("n_head", 3),
HI("left", 12), HI("right", 0), HF("softcap", 50.0),
HI("cu_div", cd), HS("dtype", dt) });
/* An fp8 cache under bf16 queries, as --kv-cache-dtype fp8 serves: decode and a ragged verify
* window, unbounded and sliding. */
for (int qlen : { 1, 17 })
for (int window : { 0, 8 })
add("attn_paged", { HI("q_len", qlen), HI("head_dim", 64), HI("gqa", 4),
HI("block_size", 16), HI("causal", 1), HI("window", window),
HS("q_dtype", "bf16"), HS("kv_dtype", "fp8_e4m3"),
HF("scale", 0.125), HI("max_ctx", 128), HI("n_head", 8),
HI("max_seqs", 2) });
for (const char* dt : { "f32", "bf16" })
/* The store into each cache: the values themselves, the int8 cache's codes and scales, or
* E4M3 (GLM-5.3's latent attention). */
for (const char* dt : { "f32", "bf16", "i8", "fp8_e4m3" })
add("kv_store", { HI("M", 12), HI("head_dim", 64), HI("n_head_kv", 2),
HI("block_size", 16), HS("kv_dtype", dt), HF("k_scale", 1.0),
HF("v_scale", 1.0) });
/* The fp8 store divides by the reader's descales; one below 1 and one above. */
for (double ks : { 0.5, 2.0 })
add("kv_store", { HI("M", 12), HI("head_dim", 64), HI("n_head_kv", 2),
HI("block_size", 16), HS("kv_dtype", "fp8_e4m3"), HF("k_scale", ks),
HF("v_scale", 1.0 / ks) });
HI("block_size", 16), HS("kv_dtype", dt) });
/* The streamed store, on one block and one ring slot (ref_shapes.cpp says why); the resident and
* mirror-only split is built by hand in avx_check_hand.cpp. */
for (double ks : { 1.0, 0.5 })
for (const char* dt : { "i8", "bf16", "fp8_e4m3" }) {
add("kv_store_streamed", { HI("M", 12), HI("head_dim", 64), HI("n_head_kv", 2),
HI("block_size", 32), HS("kv_dtype", "fp8_e4m3"),
HF("k_scale", ks), HF("v_scale", 1.0 / ks) });
add("kv_store_streamed", { HI("M", 3), HI("head_dim", 32), HI("n_head_kv", 1),
HI("block_size", 4), HS("kv_dtype", "fp8_e4m3") });
/* The same store into a bf16 cache: both planes are the values themselves, two bytes wide. */
for (double ks : { 1.0, 0.5 })
add("kv_store_streamed", { HI("M", 12), HI("head_dim", 64), HI("n_head_kv", 2),
HI("block_size", 32), HS("kv_dtype", "bf16"),
HF("k_scale", ks), HF("v_scale", 1.0 / ks) });
add("kv_store_streamed", { HI("M", 3), HI("head_dim", 32), HI("n_head_kv", 1),
HI("block_size", 4), HS("kv_dtype", "bf16") });
HI("block_size", 32), HS("kv_dtype", dt) });
add("kv_store_streamed", { HI("M", 3), HI("head_dim", 32), HI("n_head_kv", 1),
HI("block_size", 4), HS("kv_dtype", dt) });
}
for (const char* mode : { "neox", "gptj" }) {
add("rope", { HI("M", 12), HI("head_dim", 64), HI("n_head", 4), HI("n_head_kv", 2),
HF("theta", 10000.0), HF("scale", 1.0), HS("mode", mode),
@@ -881,9 +871,6 @@ std::vector<Case> build_cases() {
for (int var : { 0, 1 })
add("chan_stats", { HI("M", 7), HI("n", 645), HS("mode", mode), HI("var", var),
HF("eps", 1e-4), HS("dtype", dt) });
for (int gated : { 1, 0 })
add("ln_mod_quant_fp8", { HI("M", 5), HI("n", 256), HF("eps", 1e-6), HI("group", 128),
HI("gated", gated), HS("dtype", dt) });
for (int round : { 3, 2, 1, 0 })
add("timestep_embed", { HI("M", 3), HI("n", 256), HF("scale", 1000.0),
HF("max_period", 10000.0), HI("round", round),
@@ -975,19 +962,12 @@ std::vector<Case> build_cases() {
for (int gated : { 1, 0 }) {
add("rms_mod", { HI("M", 7), HI("n", 645), HF("eps", 1e-5), HI("gated", gated),
HS("dtype", dt) });
add("rms_mod_quant_fp8", { HI("M", 5), HI("n", 256), HF("eps", 1e-5), HI("group", 128),
HI("gated", gated), HS("dtype", dt) });
/* A zero-centred gain (1 + w), the norm and gain rounded once (Krea 2's). */
add("rms_mod", { HI("M", 7), HI("n", 645), HF("eps", 1e-5), HI("gated", gated),
HS("dtype", dt), HF("wadd", 1.0), HI("norm_once", 1) });
add("rms_mod_quant_fp8", { HI("M", 5), HI("n", 256), HF("eps", 1e-5), HI("group", 128),
HI("gated", gated), HS("dtype", dt), HF("wadd", 1.0),
HI("norm_once", 1) });
/* A LayerNorm without a gain (FLUX's). */
add("rms_mod", { HI("M", 7), HI("n", 645), HF("eps", 1e-6), HI("gated", gated),
HS("dtype", dt), HS("norm", "layer") });
add("rms_mod_quant_fp8", { HI("M", 5), HI("n", 256), HF("eps", 1e-6), HI("group", 128),
HI("gated", gated), HS("dtype", dt), HS("norm", "layer") });
}
add("flow_x0_step", { HI("M", 9), HI("n", 645), HS("dtype", dt) });
for (int pt : { 1, 4 })
@@ -1280,9 +1260,7 @@ std::vector<Case> build_cases() {
/* The row-form names: every case of the base op again under the name. */
{
const char* const forms[][2] = { { "rmsnorm", "rmsnorm_rows" }, { "rope", "rope_rows" },
{ "gemm_nt_q", "gemm_nt_q_short" },
{ "gemm_nt_q_gated", "gemm_nt_q_gated_wide" } };
const char* const forms[][2] = { { "rmsnorm", "rmsnorm_rows" }, { "rope", "rope_rows" } };
const size_t n = c.size();
for (size_t i = 0; i < n; ++i)
for (const auto& f : forms)
@@ -1326,8 +1304,6 @@ std::vector<Case> build_cases() {
(double)M * 2048 * 4 * 2, 0);
speed("quant_act_fp8", { HI("M", M), HI("n", 2048), HI("group", 128),
HS("dtype", "bf16") }, (double)M * 2048 * 3, 0);
speed("had_quant_act_fp8", { HI("M", M), HI("n", 2048), HI("group", 128),
HS("dtype", "bf16") }, (double)M * 2048 * 3, 0);
speed("quant_act_i8", { HI("M", M), HI("n", 2048), HI("group", 128),
HS("dtype", "bf16") }, (double)M * 2048 * 3, 0);
speed("quant_act_i8g", { HI("M", M), HI("n", 2048), HI("group", 128),
@@ -1473,9 +1449,6 @@ std::vector<Case> build_cases() {
1024.0 * 4096 * 2 * 2, 0);
speed("gate_add", { HI("M", 1024), HI("n", 4096), HS("dtype", "bf16") },
1024.0 * 4096 * 2 * 3, 0);
speed("ln_mod_quant_fp8", { HI("M", 1024), HI("n", 4096), HF("eps", 1e-6), HI("group", 128),
HI("gated", 1), HS("dtype", "bf16") },
1024.0 * 4096 * (2 * 3 + 1), 0);
speed("qk_norm_rope", { HI("M", 1024), HI("head_dim", 128), HI("n_head", 32),
HI("n_head_kv", 32), HF("theta", 10000.0), HF("eps", 1e-6),
HS("mode", "gptj_blocks"), HS("sections", "64"),
+44 -139
View File
@@ -947,55 +947,6 @@ void shape_cases(std::vector<Hand>& hs) {
.pi("M", 4).pi("n", 33).ps("dtype", "i4");
hs.push_back(std::move(g));
}
/* ---- ParoQuant's rotation over real pairings: each stage of each group is a permutation of
* its 128 columns read as pairs; two parts of three stages. The dense form uses a drawn matrix
* per (part, group). ------------------------------------------------------------------------ */
{
const int64_t M = 5, K = 256, S = 3, P = 2, G = 128;
std::vector<int32_t> pr((size_t)(P * S * K));
for (int64_t ps = 0; ps < P * S; ++ps)
for (int64_t g = 0; g < K / G; ++g) {
std::vector<int32_t> perm((size_t)G);
for (int64_t i = 0; i < G; ++i) perm[(size_t)i] = (int32_t)i;
uint64_t x = 0x9E3779B97F4A7C15ull * (uint64_t)(ps * 31 + g + 1);
for (int64_t i = G - 1; i > 0; --i) {
x ^= x >> 31; x *= 0xBF58476D1CE4E5B9ull; x ^= x >> 29;
std::swap(perm[(size_t)i], perm[(size_t)(x % (uint64_t)(i + 1))]);
}
for (int64_t i = 0; i < G; ++i)
pr[(size_t)(ps * K + g * G + i)] = (int32_t)(g * G + perm[(size_t)i]);
}
const auto h63 = hfill(63);
const auto scl = [h63](int64_t i) { return 1.25f + 0.75f * h63(i); }; /* (0.5, 2) */
const auto zero = [](int64_t) { return 0.0f; };
for (uint32_t ydt : { (uint32_t)RAD_F16, (uint32_t)RAD_F32 }) {
Hand h(ydt == RAD_F16 ? "two parts of three stages, y f16" : "two parts of three stages, y f32",
"givens_rotate", 1e-5);
h.dense(RAD_BF16, { M, K }, hfill(61))
.dense(RAD_I32, { P * S, K }, [pr](int64_t i) { return (float)pr[(size_t)i]; })
.dense(RAD_F32, { P * S, K / 2 }, hfill(62, 3.0f))
.dense(RAD_F32, { P, K }, scl)
.dense(ydt, { M, P * K }, zero, true)
.pi("M", M).pi("n", K).pi("group", G).ps("dtype", "bf16").pi("stages", S)
.pi("parts", P);
hs.push_back(std::move(h));
}
/* libref sums in f64 and libavx in f32, so a code on a rounding edge can differ by one
* grid step; the tolerance allows a few such codes in 2560. */
for (const char* outq : { "fp8", "i8" }) {
const bool i8 = outq[0] == 'i';
Hand h(i8 ? "two parts, i8" : "two parts, fp8", "givens_dense_quant", 5e-3);
h.dense(RAD_BF16, { M, K }, hfill(64))
.dense(RAD_F16, { P * K, G }, hfill(65, 0.1f))
.dense(RAD_F32, { P, K }, scl)
.dense(i8 ? RAD_I8 : RAD_F8E4M3, { M, P * K }, zero, true)
.dense(RAD_F32, { M, P * K / G }, zero, true)
.pi("M", M).pi("n", K).pi("group", G).ps("dtype", "bf16").pi("parts", P)
.ps("out", outq);
hs.push_back(std::move(h));
}
}
}
/* ================================================================== bit patterns and formats */
@@ -1067,23 +1018,31 @@ void format_cases(std::vector<Hand>& hs) {
hs.push_back(std::move(h));
}
/* ---- an fp8 cache read with per-(sequence, head) descales ------------------------------- *
* Decode and a uniform verify of 5 over two sequences, both descales present and different per
* KV head, which libref's description always leaves absent. */
/* ---- the int8 cache: each key's codes against its own K and V scales -------------------- *
* Decode and a uniform verify of 5 over two sequences. The cache is laid out by hand, a row
* of head_dim K codes, head_dim V codes and two f16 scales (a power of two times 1, 1.5 or
* 1.25, so every key's differ), which libref's description does not draw. */
for (int64_t ql : { 1, 5 }) {
const int64_t S = 2, KVH = 2, G = 2, HD = 64, BS = 16, NB = 4;
Hand h(ql == 1 ? "fp8 cache, k_descale and v_descale, decode"
: "fp8 cache, k_descale and v_descale, verify of 5", "attn_paged", 2e-2);
const int64_t S = 2, KVH = 2, G = 2, HD = 64, BS = 16, NB = 4, ROW = 2 * HD + 4;
Hand h(ql == 1 ? "int8 cache, a scale of K and of V per key, decode"
: "int8 cache, a scale of K and of V per key, verify of 5", "attn_paged",
2e-2);
h.dense(RAD_BF16, { S * ql, KVH * G, HD }, hfill(80))
.dense(RAD_F8E4M3, { NB, KVH, BS, 2 * HD }, hfill(81, 2.0f))
.dense(RAD_I8, { NB, KVH, BS, ROW }, [=](int64_t i) {
const int64_t r = i / ROW, c = i % ROW;
if (c < 2 * HD) return (float)((int)((i * 37 + r * 11) % 255) - 127);
/* the f16's low byte 0, its high byte: 0x2C00 = 2^-4, 0x2E00 = 1.5 * 2^-4,
* 0x2D00 = 1.25 * 2^-4, K's and V's from different residues */
static const int hi[3] = { 0x2C, 0x2E, 0x2D };
const int half = (int)((c - 2 * HD) / 2);
return (c & 1) ? (float)hi[(r + half) % 3] : 0.0f;
})
.dense(RAD_I32, { S, 2 }, [](int64_t i) { return (float)((i * 3 + 2) % 4); })
.idx({ 20, 9 })
.dense(RAD_F32, { S, KVH }, [](int64_t i) { return (float)(0.25 * (1 + (i * 5) % 7)); })
.dense(RAD_F32, { S, KVH }, [](int64_t i) { return (float)(0.5 * (1 + (i * 3) % 5)); })
.none()
.none().none().none()
.dense(RAD_BF16, { S * ql, KVH * G, HD }, zero, true)
.pi("q_len", ql).pi("head_dim", HD).pi("gqa", G).pi("block_size", BS).pi("causal", 1)
.pi("window", 0).ps("q_dtype", "bf16").ps("kv_dtype", "fp8_e4m3").pf("scale", 0.125);
.pi("window", 0).ps("q_dtype", "bf16").ps("kv_dtype", "i8").pf("scale", 0.125);
hs.push_back(std::move(h));
}
@@ -2019,26 +1978,6 @@ void gen_cases(std::vector<Hand>& hs) {
.dense(dt, { R, D }, hfill(214), true)
.pi("M", R).pi("n", D).ps("dtype", dn);
hs.push_back(std::move(g));
for (const bool gated : { true, false }) {
Hand q((std::string(gated ? "gated" : "the first block's, no branch") +
", three entries, 4D pitch" + sfx).c_str(), "ln_mod_quant_fp8", 1e-2);
if (gated) {
q.dense(dt, { R, D }, hfill(215))
.view(dt, { 3, D }, { W, 1 }, 3 * W, hfill(216));
} else {
q.none().none();
}
q.view(dt, { 3, D }, { W, 1 }, 3 * W, hfill(217, 0.5f))
.idx({ 0, 4, 4, R })
.dense(dt, { R, D }, hfill(218, 2.0f), true)
.dense(RAD_F8E4M3, { R, D }, zero, true)
.dense(RAD_F32, { R, D / 32 }, zero, true)
.dense(RAD_BF16, { R, D }, zero, true)
.pi("M", R).pi("n", D).pf("eps", 1e-6).pi("group", 32)
.pi("gated", gated ? 1 : 0).ps("dtype", dn);
hs.push_back(std::move(q));
}
}
/* ---- the sampler's state: seeds, flags, pairs and lanes ----------------------------- */
@@ -2335,26 +2274,6 @@ void gen_cases(std::vector<Hand>& hs) {
}
}
/* ---- an fp8 cache read with per-(entry, kv head) descales ------------------------------ */
{
const int64_t T = 20, kvh = 2, gqa = 1, hd = 64, BS = 16;
Hand h("fp8 cache, k and v descales, bf16 rows", "attn_prefix_self", 2e-2);
h.dense(RAD_BF16, { T, kvh * gqa * hd }, hfill(270))
.dense(RAD_BF16, { T, kvh * hd }, hfill(271))
.dense(RAD_BF16, { T, kvh * hd }, hfill(272))
.dense(RAD_F8E4M3, { 4, kvh, BS, 2 * hd }, hfill(273, 8.0f))
.dense(RAD_I32, { 2, 2 }, [](int64_t i) { return (float)i; })
.idx({ 30, 17 })
.idx({ 0, 12, T })
.dense(RAD_F32, { 4 }, [](int64_t i) { return 0.1f + 0.05f * (float)i; })
.dense(RAD_F32, { 4 }, [](int64_t i) { return 0.2f - 0.03f * (float)i; })
.none().none()
.dense(RAD_BF16, { T, kvh * gqa * hd }, zero, true)
.pi("q_len", T).pi("head_dim", hd).pi("gqa", gqa).pi("block_size", BS).pi("causal", 0)
.ps("q_dtype", "bf16").ps("kv_dtype", "fp8_e4m3").pf("scale", 0.125);
hs.push_back(std::move(h));
}
/* ---- scatter_add_rows: a repeated destination adds in index order ----------------------- */
{
Hand h("a destination three times, one skip", "scatter_add_rows", 0.0);
@@ -2449,25 +2368,6 @@ void video_cases(std::vector<Hand>& hs) {
.pi("M", R).pi("n", D).pf("eps", 1e-5).pi("gated", gated ? 1 : 0)
.ps("dtype", dn);
hs.push_back(std::move(h));
Hand q((std::string(gated ? "gated" : "ungated") + ", quantised, three entries" +
sfx).c_str(), "rms_mod_quant_fp8", 1e-2);
if (gated) {
q.dense(dt, { R, D }, hfill(414))
.view(dt, { 3, D }, { W6, 1 }, 3 * W6, hfill(415, 0.5f));
} else {
q.none().none();
}
q.view(dt, { 3, 2 * D }, { W6, 1 }, 3 * W6, hfill(416, 0.5f))
.dense(dt, { D }, [](int64_t i) { return 0.8f + 0.003f * (float)i; })
.idx({ 0, 4, 4, R })
.dense(dt, { R, D }, hfill(417, 2.0f), true)
.dense(RAD_F8E4M3, { R, D }, zero, true)
.dense(RAD_F32, { R, D / 32 }, zero, true)
.dense(RAD_BF16, { R, D }, zero, true)
.pi("M", R).pi("n", D).pf("eps", 1e-5).pi("group", 32)
.pi("gated", gated ? 1 : 0).ps("dtype", dn);
hs.push_back(std::move(q));
}
}
@@ -3654,7 +3554,7 @@ Hand store(const char* name, int64_t blocks, int64_t slots, int64_t bs, int64_t
std::vector<int64_t> sm, std::vector<int64_t> res) {
const int64_t M = (int64_t)sm.size();
const int64_t lane = kvh * hd;
const int64_t row = kvh * bs * 2 * hd;
const int64_t row = kvh * bs * (2 * hd + 4);
const int64_t span = M * 2 * lane;
Hand h(name, "kv_store_streamed", 0.0);
h.view(RAD_BF16, { M, lane }, { 2 * lane, 1 }, span,
@@ -3662,13 +3562,13 @@ Hand store(const char* name, int64_t blocks, int64_t slots, int64_t bs, int64_t
.view(RAD_BF16, { M, lane }, { 2 * lane, 1 }, span,
[](int64_t i) { return (float)((int)(i % 13) - 6) * 0.25f; }) /* v */
.idx(sm)
.dense(RAD_F8E4M3, { slots, kvh, bs, 2 * hd },
.dense(RAD_I8, { slots, kvh, bs, 2 * hd + 4 },
[](int64_t i) { return (float)((int)(i % 5) + 1); }, true) /* the ring */
.idx(res)
.dense(RAD_U8, { blocks, row },
[](int64_t i) { return (float)(int)((i * 37) % 251); }, true) /* the mirror */
.pi("M", M).pi("head_dim", hd).pi("n_head_kv", kvh).pi("block_size", bs)
.ps("kv_dtype", "fp8_e4m3");
.ps("kv_dtype", "i8");
return h;
}
@@ -3701,33 +3601,38 @@ void kvstream_cases(std::vector<Hand>& hs) {
hs.push_back(std::move(h));
}
/* The mirror's exact bytes, laid out by hand: four tokens fill both blocks at both offsets
* with constants, so the paged layout [kv_heads][block_size][2 * head_dim] and the E4M3
* with constants, so the paged layout [kv_heads][block_size][2 * head_dim + 4] and the int8
* encoding are pinned against an answer no library computes: agreement alone cannot catch a
* store that writes the right values to the wrong address or at the wrong scale. */
* store that writes the right values to the wrong address or at the wrong scale. Each head's
* larger element is 127 times a power of two, so its scale is that power exactly and the
* codes are the elements over it. */
{
const int64_t blocks = 2, slots = 2, bs = 2, kvh = 1, hd = 2, M = 4;
const int64_t lane = kvh * hd, row = kvh * bs * 2 * hd, span = M * 2 * lane;
const float kd[M][2] = { { 1, 2 }, { 3, 4 }, { 5, 6 }, { 7, 8 } };
const float vd[M][2] = { { -1, -2 }, { -3, -4 }, { -5, -6 }, { -7, -8 } };
Hand h("the mirror's bytes, block-id addressing and E4M3", "kv_store_streamed", 0.0);
const int64_t blocks = 2, slots = 2, bs = 2, kvh = 1, hd = 2, M = 4, rowe = 2 * hd + 4;
const int64_t lane = kvh * hd, row = kvh * bs * rowe, span = M * 2 * lane;
const float kd[M][2] = { { 63.5f, 127 }, { -254, 64 }, { 31.75f, 5 }, { 508, -100 } };
const float vd[M][2] = { { -127, 1 }, { 2, 254 }, { -63.5f, -8 }, { 15.875f, 3 } };
/* scale (a power of two, as an f16's high byte with a zero low byte) and codes */
const uint8_t ksh[M] = { 0x3C, 0x40, 0x34, 0x44 }, vsh[M] = { 0x3C, 0x40, 0x38, 0x30 };
const int8_t kc[M][2] = { { 64, 127 }, { -127, 32 }, { 127, 20 }, { 127, -25 } };
const int8_t vc[M][2] = { { -127, 1 }, { 1, 127 }, { -127, -16 }, { 127, 24 } };
Hand h("the mirror's bytes, block-id addressing and the int8 rows", "kv_store_streamed", 0.0);
h.view(RAD_BF16, { M, lane }, { 2 * lane, 1 }, span,
[&](int64_t i) { return i % 4 < 2 ? kd[i / 4][i % 4] : 0.0f; })
.view(RAD_BF16, { M, lane }, { 2 * lane, 1 }, span,
[&](int64_t i) { return i % 4 < 2 ? vd[i / 4][i % 4] : 0.0f; })
.idx({ 0, 1, 2, 3 })
.dense(RAD_F8E4M3, { slots, kvh, bs, 2 * hd }, [](int64_t) { return 0.0f; }, true)
.dense(RAD_I8, { slots, kvh, bs, rowe }, [](int64_t) { return 0.0f; }, true)
.idx({ 0, 1 })
.dense(RAD_U8, { blocks, row }, [](int64_t) { return 0.0f; }, true) /* the mirror */
.pi("M", M).pi("head_dim", hd).pi("n_head_kv", kvh).pi("block_size", bs)
.ps("kv_dtype", "fp8_e4m3");
.ps("kv_dtype", "i8");
std::vector<uint8_t> want((size_t)(blocks * row), 0);
for (int64_t t = 0; t < M; ++t) {
const float pair[2 * hd] = { kd[t][0], kd[t][1], vd[t][0], vd[t][1] };
uint8_t enc[2 * hd] = {};
h_narrow(pair, RAD_F8E4M3, 2 * hd, enc);
const int64_t blk = t / bs, off = t % bs;
for (int64_t j = 0; j < 2 * hd; ++j)
want[(size_t)(blk * row + off * 2 * hd + j)] = enc[j];
uint8_t* w = &want[(size_t)(blk * row + off * rowe)];
w[0] = (uint8_t)kc[t][0]; w[1] = (uint8_t)kc[t][1];
w[2] = (uint8_t)vc[t][0]; w[3] = (uint8_t)vc[t][1];
w[4] = 0; w[5] = ksh[t]; w[6] = 0; w[7] = vsh[t];
}
h.expect_bytes(5, want);
hs.push_back(std::move(h));
@@ -3769,19 +3674,19 @@ void kvstream_cases(std::vector<Hand>& hs) {
}
/* A mirror row that is not the block's pitch: a write would spill into the next block. */
{
const int64_t blocks = 2, slots = 1, bs = 2, kvh = 1, hd = 2, row = 8;
const int64_t blocks = 2, slots = 1, bs = 2, kvh = 1, hd = 2, row = 16;
Hand h("a padded mirror row is refused", "kv_store_streamed", 0.0);
h.view(RAD_BF16, { 2, 2 }, { 4, 1 }, 8,
[](int64_t i) { return (float)((int)(i % 7) - 3); })
.view(RAD_BF16, { 2, 2 }, { 4, 1 }, 8,
[](int64_t i) { return (float)((int)(i % 5) - 2); })
.idx({ 0, 1 })
.dense(RAD_F8E4M3, { slots, kvh, bs, 2 * hd }, [](int64_t) { return 1.0f; }, true)
.dense(RAD_I8, { slots, kvh, bs, 2 * hd + 4 }, [](int64_t) { return 1.0f; }, true)
.idx({ -1, -1 })
.view(RAD_U8, { blocks, row }, { row + 4, 1 }, blocks * (row + 4),
[](int64_t i) { return (float)(int)(i % 251); }, true)
.pi("M", 2).pi("head_dim", hd).pi("n_head_kv", kvh).pi("block_size", bs)
.ps("kv_dtype", "fp8_e4m3")
.ps("kv_dtype", "i8")
.refuses(RAD_E_STRIDE);
hs.push_back(std::move(h));
}
+20
View File
@@ -1038,6 +1038,26 @@ static int gemm_ntq_impl(const RadArgs* a, bool bias_operand) {
if (zg)
return gemm_zp(*zg, A, as_, B, bs_, rad_arg_in(a, 5), Y, M, N, K, p_int(a, "group", 0),
pb1, pb2);
/* A scale in two levels, joined (avx_layout_gemm_q): an integer per (row, group) under a float
* a row. Their product in f32 is the scale the loop below reads, as libref forms it. */
std::vector<float> two_level;
RadTensor bs_two;
if (avxp::is_joined(bs_)) {
const avxp::JPlane s1 = avxp::jplane(bs_, "scale"), s2 = avxp::jplane(bs_, "scale.1");
if (!s1 || !s2 || s1.dt != RAD_U8 || !avxp::float_scale_dt(s2.dt)) return RAD_E_DTYPE;
if (s1.rows != N || s1.cols <= 0 || s2.rows != N || s2.cols != 1) return RAD_E_SHAPE;
two_level.resize((size_t)(N * s1.cols));
for (int64_t n = 0; n < N; ++n)
for (int64_t g = 0; g < s1.cols; ++g)
two_level[(size_t)(n * s1.cols + g)] = s1.at(n, g) * s2.at(n, 0);
std::memset(&bs_two, 0, sizeof(bs_two));
bs_two.data = two_level.data();
bs_two.dtype = RAD_F32;
bs_two.rank = 2;
bs_two.shape[0] = N; bs_two.shape[1] = s1.cols;
bs_two.stride[0] = s1.cols; bs_two.stride[1] = 1;
bs_ = &bs_two;
}
if (pb1 > 0 || pb2 > 0) {
if (bias_operand) return RAD_E_UNSUPPORTED;
return gemm_ntq_parts(A, as_, B, bs_, Y, pb1, pb2, M, N, K);
-62
View File
@@ -261,66 +261,6 @@ AVX_KERNEL(gate_add) {
/* gate_add (with `gated` 1), ln_mod and quant_act_fp8 in one pass over each row: the residual
* rounded to x's dtype and stored, the norm to bf16, the codes as quant_act_fp8 writes them over
* that bf16 row (avx_had.h: fp8_emit), and the bf16 row into `z` when bound. */
AVX_KERNEL(ln_mod_quant_fp8) {
if (a->n_t < 8) return RAD_E_INVAL;
const RadTensor *Yv = rad_arg_in(a, 0), *G = rad_arg_in(a, 1), *S = &a->t[2], *cu = &a->t[3];
const RadTensor *X = &a->t[4], *Q = &a->t[5], *SC = &a->t[6], *Z = rad_arg_in(a, 7);
const int64_t n = p_int(a, "n", 0), grp = p_int(a, "group", 0);
const bool gated = p_int(a, "gated", 0) != 0;
const float eps = p_f32(a, "eps", 1e-6f);
if (n <= 0 || grp <= 0 || n % grp || (gated && (!Yv || !G))) return RAD_E_SHAPE;
const int64_t rows = rows_of(Q, n), n_seq = numel(cu) - 1, ngrp = n / grp;
if (rows <= 0 || n_seq <= 0 || rows_of(X, n) < rows || numel(SC) < rows * ngrp)
return RAD_E_SHAPE;
if (!S->data) return RAD_E_INVAL;
/* Both tables from one scratch_raw call: a second may reallocate the first. */
float* tabs = (float*)scratch_raw((size_t)(2 * n_seq * n + 32) * sizeof(float));
{
const int64_t s_rs = row_stride(S, n), s_cs = laststride(S);
const int64_t g_rs = gated ? row_stride(G, n) : 0, g_cs = gated ? laststride(G) : 0;
for (int64_t e = 0; e < n_seq; ++e)
for (int64_t i = 0; i < n; ++i) {
tabs[e * n + i] = narrow1(RAD_BF16, 1.0f + ldt(S, e * s_rs + i * s_cs));
if (gated)
tabs[(n_seq + e) * n + i] =
narrow1(X->dtype, sc_tanh(ldt(G, e * g_rs + i * g_cs)));
}
}
const float* gain = tabs;
const float* gate = tabs + n_seq * n;
AVX_PARALLEL_FOR_IF(rows * n >= AVX_PAR_MIN)
for (int64_t r = 0; r < rows; ++r) {
float* buf = scratch_f32((size_t)(5 * n + 80));
float *xs = buf, *v = buf + n + 16, *o = v + n + 16, *codes = o + n + 16;
float* tmp = codes + n + 16;
const int64_t e = seq_of(cu, n_seq, r);
const float* xv = in_row(X, rowoff(X, r, n), n, xs);
if (gated) {
const float* yv = in_row(Yv, rowoff(Yv, r, n), n, codes);
const float* t = gate + e * n;
int64_t i = 0;
for (; i + VF_N <= n; i += VF_N)
vf_storeu(v + i, vf_mul(vf_loadu(t + i), vf_loadu(yv + i)));
for (; i < n; ++i) v[i] = t[i] * yv[i];
narrow_row(X->dtype, v, n, tmp);
add_rows(v, xv, n);
narrow_row(X->dtype, v, n, tmp);
out_row(X, rowoff(X, r, n), n, v);
} else {
std::memcpy(v, xv, (size_t)n * sizeof(float));
}
const float mean = row_sum(v, n) / (float)n;
const float rs = 1.0f / std::sqrt(dev_sumsq(v, mean, n) / (float)n + eps);
center_scale(v, mean, rs, o, n);
narrow_row(RAD_BF16, o, n, tmp);
mul_rows(o, gain + e * n, n);
narrow_row(RAD_BF16, o, n, tmp);
fp8_emit(o, codes, n, grp, Q, SC, Z, r);
}
return RAD_OK;
}
/* ------------------------------------------------------------------ rms_mod / rms_mod_quant_fp8 */
/* Both forms: with `gated` the branch added through the gate row (no tanh) and the residual stored
* in x's dtype; then n1 = rd(x rsqrt(mean(x^2) + eps)), n2 = rd(n1 w), m = rd(n2 rd(1 + scale)),
@@ -426,8 +366,6 @@ static int rms_mod_run(const RadArgs* a, bool quant) {
}
AVX_KERNEL(rms_mod) { return rms_mod_run(a, false); }
AVX_KERNEL(rms_mod_quant_fp8) { return rms_mod_run(a, true); }
/* ------------------------------------------------------------------ timestep_embed */
/* y[m] = [cos(t' f_0) .. cos(t' f_{h-1}) | sin(t' f_0) .. sin(t' f_{h-1})] with libref's libm
* calls: a pass embeds one row per entry, so this is a few thousand transcendentals. With
+10 -7
View File
@@ -107,7 +107,7 @@ AVX_KERNEL(hc_read) {
const RadTensor* inj = rad_arg_in(a, 6);
const RadTensor* q = rad_arg_in(a, 7);
const RadTensor* s = rad_arg_in(a, 8);
const RadTensor* rq = rad_arg_in(a, 9); /* rotated fp8 form, for a w4a8h consumer */
const RadTensor* rq = rad_arg_in(a, 9); /* rotated form, for a w4a8h consumer */
const RadTensor* rs = rad_arg_in(a, 10);
const int64_t n = p_int(a, "n", 0);
@@ -146,8 +146,9 @@ AVX_KERNEL(hc_read) {
ngrp = (n + g - 1) / g;
if (numel(q) < rows * n || !s || !s->data || numel(s) < rows * ngrp) return RAD_E_SHAPE;
}
/* The rotated form is had_quant_act_fp8 of the stored `x`: each scale group is rotated whole,
* so the group must be a power of two that tiles the row. */
/* The rotated form is had_quant_act_fp8 of the stored `x`, or had_quant_act_i8g into an int8
* buffer: each scale group is rotated whole, so the group must be a power of two that tiles
* the row. */
int64_t rg = 0;
if (rq && rq->data) {
rg = p_int(a, "group", 0);
@@ -251,7 +252,7 @@ AVX_KERNEL(hc_read) {
}
}
/* ---- optional fp8 form of x, taken from the stored (narrowed) value rather than the
/* ---- optional code form of x, taken from the stored (narrowed) value rather than the
* accumulator, as a fused kernel must, so the two agree bit for bit. */
if (((q && q->data) || rg) && x->dtype != RAD_F32) {
row_from_f32(x->dtype, xv, tmp, n);
@@ -262,13 +263,14 @@ AVX_KERNEL(hc_read) {
for (int64_t gi = 0; gi < ngrp; ++gi) {
const int64_t k0 = gi * g, k1 = (k0 + g < n) ? k0 + g : n;
float sc;
fp8_group(xv, qv, k0, k1, &sc);
fp8_group(xv, qv, k0, k1, &sc, q->dtype == RAD_I8 ? 127.0f : 448.0f);
stt(s, rowoff(s, r, ngrp) + gi * laststride(s), sc);
}
out_row(q, rowoff(q, r, n), n, qv);
}
/* ---- optional rotated fp8 form of x, from the same stored values. */
/* ---- optional rotated form of x, from the same stored values: E4M3 codes, or int8
* (had_quant_act_i8g's) where the buffer is. */
if (rg) {
float* rv = N; /* N and tmp are dead once the plain codes are stored. */
float* rc = tmp;
@@ -277,7 +279,8 @@ AVX_KERNEL(hc_read) {
const int64_t rgrp = n / rg;
for (int64_t gi = 0; gi < rgrp; ++gi) {
float sc;
fp8_group(rv, rc, gi * rg, gi * rg + rg, &sc);
fp8_group(rv, rc, gi * rg, gi * rg + rg, &sc,
rq->dtype == RAD_I8 ? 127.0f : 448.0f);
stt(rs, rowoff(rs, r, rgrp) + gi * laststride(rs), sc);
}
out_row(rq, rowoff(rq, r, n), n, rc);
+5 -5
View File
@@ -102,9 +102,9 @@ int avx_par_force(int threads);
X(embed_attn) X(ministral_rope) X(pixtral_rope) X(pixtral_merge) \
/* ---- quantisation and rotation */ \
X(quant_act_i8) X(quant_act_i8g) X(had_quant_act_i8) X(quant_act_fp8) \
X(had_quant_act_fp8) X(gram_accum) X(rmsnorm_had_quant_i8) X(gated_had_quant_i8) \
X(dequant) X(quant_cols_fp8) X(had_quant_act_i8g) \
X(rmsnorm_quant_fp8) X(gated_quant_fp8) X(givens_rotate) X(givens_dense_quant) \
X(gram_accum) X(rmsnorm_had_quant_i8) X(gated_had_quant_i8) \
X(dequant) X(quant_cols_fp8) X(had_quant_act_i8g) X(dequant_w4) \
X(rmsnorm_quant_fp8) X(gated_quant_fp8) \
/* ---- gemm and the vocabulary edges */ \
X(gemm_nt) X(gemm_nt_bias) X(gemm_nt_q) X(gemm_nt_q_bias) \
X(gemm_nt_q_gated) X(embed_lookup) X(embed_lookup_q) X(logits_gemm) \
@@ -125,14 +125,14 @@ int avx_par_force(int threads);
/* ---- collectives */ \
X(all_reduce) X(all_gather) \
/* ---- image generation */ \
X(ln_mod) X(gate_add) X(ln_mod_quant_fp8) X(timestep_embed) \
X(ln_mod) X(gate_add) X(timestep_embed) \
X(gather_rows2) X(lane_gather) X(lane_store) X(randn_lanes) \
X(flow_euler) X(chan_affine) X(conv2d_nhwc) X(l2norm_chan) \
X(d2s_add) X(s2d_avg_add) X(to_rgba8) X(gelu_tanh) \
X(scatter_add_rows) X(attn_prefix_self) X(kd_input) X(kd_step) \
X(gelu_quick) X(im2col_nhwc) \
/* ---- video generation */ \
X(rms_mod) X(rms_mod_quant_fp8) X(flow_x0_step) X(patch_unfold) \
X(rms_mod) X(flow_x0_step) X(patch_unfold) \
X(vtile_gather) X(vtile_stitch) X(grid_pos3) X(vsa_select) \
X(attn_vsa) X(conv3d_ndhwc) X(group_norm) X(tconv_dw) \
X(resize_bilinear) X(patch_fold) X(flow_renoise) X(flow_res_multistep) \
+3 -1
View File
@@ -1033,7 +1033,9 @@ static int moe_gemm_impl(const RadArgs* a, bool quant, int ncls = 2) {
const Mat ma = as_mat(A, K);
const Scales SA = make_scales(as_, AR, K, false);
const int64_t gp = p_int(a, "group", 0);
/* The activation's scales are per `a_group` of K where the caller states one (an int8
* activation at one scale per 256 against experts scaled per 128), else per `group`. */
const int64_t gp = p_int(a, "a_group", p_int(a, "group", 0));
if (quant && gp > 0 && SA.p && SA.group != gp) return RAD_E_SHAPE;
const int64_t y_rs = row_stride(Y, N);
+60 -23
View File
@@ -80,6 +80,7 @@ struct Gather {
std::vector<uint8_t> kind; /* per row: a RowCache::Found, or PAD / DONE below */
std::vector<SpanRead> reads; /* the rows this thread reads */
std::vector<long long> waits; /* rows another thread is reading */
std::vector<long long> later; /* the other ranks' share of a decode gather, unclaimed so far */
std::vector<long long> again; /* rows whose slot changed under the decode */
/* One decode batch: each row's source and destination and, for cached rows, its call index
* and the slot word it was read under. */
@@ -618,12 +619,13 @@ int read_and_publish(const TableFile& tf, RowCache& rc, ReadRing& rr, Gather& g,
return RAD_OK;
}
/* The decode regime: a step wants a hundred-odd rows now, and never waits on another thread's read.
* Rows READY in the cache decode from it; a missing row whose slot is free to take is claimed and
* read into the cache, so the ranks' gathers and the later steps that meet the same trigram find it
* READY instead of reading the file again (Flash-Next decode at c4 lost 2.5% when these reads were
* never cached); a row another thread is reading, or one with no slot, is read straight into its
* output row. */
/* The decode regime: a step wants a hundred-odd rows now, and never waits on the reader thread's
* read. Rows READY in the cache decode from it; a missing row whose slot is free to take is claimed
* and read into the cache, so the ranks' gathers and the later steps that meet the same trigram
* find it READY instead of reading the file again (Flash-Next decode at c4 lost 2.5% when these
* reads were never cached); a row the reader thread holds, or one with no slot, is read straight
* into its output row, and one another rank's gather is reading is waited for. The ranks split a
* step's missing rows between them (gather_ondemand). */
constexpr long long kOnDemandMaxRows = 4096;
/* Decode-sized gathers reading now. The reader thread starts no batch while any is (see the reader
@@ -660,31 +662,66 @@ int gather_ondemand(const TableFile& tf, RowCache& rc, ReadRing& rr, const avx::
g.reads.clear();
g.again.clear();
g.waits.clear();
g.later.clear();
const uint64_t reader = g_reader_tag.load(std::memory_order_acquire);
for (long long m = 0; m < M; ++m) {
uint16_t* dst = q.out + m * x_ld;
if (pad(row_of(m))) { std::memset(dst, 0, (size_t)ne * sizeof(uint16_t)); continue; }
auto hit = [&](long long m, int64_t s, uint64_t key) {
g.src.push_back(rc.data + (size_t)s * (size_t)n);
g.dst.push_back(q.out + m * x_ld);
g.dm.push_back(m);
g.dw.push_back(RowCache::ready(key));
};
auto theirs_waits = [&](int64_t s) {
return s >= 0 && ((rc.word[s].load(std::memory_order_acquire) >> 2) & 255) != reader;
};
/* Finds or claims row m: READY decodes from the cache, a row another rank thread is reading is
* waited for below instead of read a second time (both ranks gather the same rows, so reading
* it again doubled decode's reads), and the reader's THEIRS, MINE (a row twice in one call)
* and NONE are read directly. */
auto claim = [&](long long m) {
const uint64_t key = key_of(m);
int64_t s = -1;
const RowCache::Found f = rc.find_or_claim(key, me, &s);
g.slot[m] = s;
if (f == RowCache::HIT) hit(m, s, key);
else if (f == RowCache::THEIRS && theirs_waits(s)) g.waits.push_back(m);
else g.reads.push_back({m, key, f == RowCache::CLAIMED ? s : -1});
};
/* A direct read costs its thread a few microseconds to submit and to complete, and the ranks'
* threads gather the same rows at the same moment: whichever scanned first used to claim every
* missing row and read them all alone while the other waited (47 rows, 380 us, on Flash-Next
* at one sequence under the draft head, longer than the first layer runs: the card idled). So
* a rank first claims only its share, the rows m with m % world_size == rank, and leaves the
* rest, which it takes up after its own reads: by then the other ranks have claimed theirs and
* it waits for those, and whatever nobody claimed (a rank that is not there) it reads itself. */
const long long share = q.world_size > 1 ? q.world_size : 1;
for (long long m = 0; m < M; ++m) {
if (pad(row_of(m))) {
std::memset(q.out + m * x_ld, 0, (size_t)ne * sizeof(uint16_t));
continue;
}
if (m % share == q.rank % share) { claim(m); continue; }
const uint64_t key = key_of(m);
int64_t s = -1;
const RowCache::Found f = rc.lookup(key, &s);
g.slot[m] = s;
if (f == RowCache::HIT) {
g.src.push_back(rc.data + (size_t)s * (size_t)n);
g.dst.push_back(dst);
g.dm.push_back(m);
g.dw.push_back(RowCache::ready(key));
} else if (f == RowCache::THEIRS && s >= 0 &&
((rc.word[s].load(std::memory_order_acquire) >> 2) & 255) != reader) {
/* Another rank thread is reading it: wait below instead of reading it a second time
* (both ranks gather the same rows, so reading it again doubled decode's reads). */
rc.ref[s].store(1, std::memory_order_relaxed);
hit(m, s, key);
} else if (f == RowCache::THEIRS && theirs_waits(s)) {
g.waits.push_back(m);
} else {
/* The reader's THEIRS, MINE (a row twice in one call) and NONE are read directly. */
g.reads.push_back({m, key, f == RowCache::CLAIMED ? s : -1});
g.later.push_back(m);
}
}
const UrgentReads urgent;
if (!g.reads.empty()) {
/* This rank's share, then what is left of the others' (see above): each batch is read and
* published before the next is claimed. */
for (int pass = 0; pass < 2; ++pass) {
if (pass == 1) {
g.reads.clear();
for (long long m : g.later) claim(m);
}
if (g.reads.empty()) continue;
const int rs = read_and_publish(tf, rc, rr, g, g.reads.data(), g.reads.size(), n, ne,
decode, lut, q.out, x_ld);
if (rs != RAD_OK) return rs;
@@ -697,9 +734,9 @@ int gather_ondemand(const TableFile& tf, RowCache& rc, ReadRing& rr, const avx::
g.dw.push_back(RowCache::ready(r.key));
}
}
/* Wait for the other rank's reads, as gather_rows does. This thread's own reads are done, so no cycle: the other rank reads its claims before it
* waits. A row that turns READY decodes from the cache; one released or taken over is read
* directly below. */
/* Wait for the other ranks' reads, as gather_rows does. This thread's own reads are done, so
* no cycle: every rank reads its claims before it waits. A row that turns READY decodes from
* the cache; one released or taken over is read directly below. */
while (!g.waits.empty()) {
const uint32_t e = rc.published.load(std::memory_order_acquire);
size_t keep = 0;
+17 -1
View File
@@ -159,7 +159,9 @@ static inline int avx_layout_mtp(const RadParam*, int, int operand, const RadEnc
return layout_scaled(operand, 4, 5, enc, sel, planes, n, out);
}
/* gemm_nt_q: `b_scale` (operand 3) as the scale and zero of the grid `dtype` names. */
/* gemm_nt_q: `b_scale` (operand 3) as the scale and zero of the grid `dtype` names, or a symmetric
* int8 grid's scale in two levels, an unsigned integer per (row, `group` of K) under a float a row
* (IQ8R), whose product is the scale: libref's two forms (ref_planes.h). */
static inline int avx_layout_gemm_q(const RadParam* p, int n_p, int operand,
const RadEncoding* enc, const int* sel,
const RadTensor* planes, int n, RadLayout* out) {
@@ -168,6 +170,20 @@ static inline int avx_layout_gemm_q(const RadParam* p, int n_p, int operand,
if (n < 2 || operand != 3) return RAD_E_UNSUPPORTED;
const ZpGrid* zg = zp_grid(rad_param_gets(p, n_p, "dtype", nullptr));
const long long group = rad_param_geti(p, n_p, "group", 0);
if (!zg && sel_roles(enc, sel, n, "scale", "scale.1")) {
if (group <= 0 || !rad_enc_is(enc, "affine") || enc->n_planes != 3) return RAD_E_DTYPE;
const RadEncPlane& c = enc->plane[0];
const RadEncPlane& s = enc->plane[sel[0]];
const RadEncPlane& s2 = enc->plane[sel[1]];
if (std::strncmp(c.role, "codes", RAD_ENC_STR) != 0 || c.dtype != RAD_I8 ||
c.block[0] != 1 || c.block[1] != 1)
return RAD_E_DTYPE;
if (s.kind != RAD_PLANE_TILED || s.dtype != RAD_U8 || s.block[0] != 1 ||
s.block[1] != group || s2.kind != RAD_PLANE_TILED || !float_scale_dt(s2.dtype) ||
s2.block[0] != 1 || s2.block[1] != 0)
return RAD_E_DTYPE;
return rad_planes_layout(enc, sel, planes, n, out);
}
if (!zg || group <= 0 || !rad_enc_is(enc, "affine")) return RAD_E_DTYPE;
if (enc->transform[0] && std::strncmp(enc->transform, "givens", RAD_ENC_STR) != 0)
return RAD_E_DTYPE;
+43 -114
View File
@@ -313,6 +313,43 @@ AVX_KERNEL(gated_had_quant_i8) {
return RAD_OK;
}
/* ------------------------------------------------------------------ dequant_w4 */
/* The packed 4-bit weight back to row-major bf16 [N, K], as libref reads it (ref_quant.cpp): eight
* nibbles a dword in fragment order [t][kb][lh][r][s], t = n / 16, r = n % 16, kb = k / 64,
* s = (k % 64) / 16, the k inside a step 4 * lh + {0, 8, 1, 9, 2, 10, 3, 11}[i]; the scale dword at
* [t][g][r] holds the f16 scale low and -(1024 + zero) high. `twos` reads the nibble as two's
* complement with no zero point. A table's inverse, run where weights are checked, so scalar. */
AVX_KERNEL(dequant_w4) {
if (!rad_args_have(a, 3)) return RAD_E_INVAL;
const RadTensor *wq = &a->t[0], *ws = &a->t[1], *y = &a->t[2];
if (y->rank < 2) return RAD_E_SHAPE;
const int64_t N = y->shape[0], K = y->shape[1];
const int64_t group = p_int(a, "group", 128);
const int64_t twos = p_int(a, "twos", 1);
if (N <= 0 || K <= 0 || N % 16 || K % 64 || group < 1 || K % group) return RAD_E_SHAPE;
static const int kOff[8] = { 0, 8, 1, 9, 2, 10, 3, 11 };
const uint32_t* Wq = (const uint32_t*)wq->data;
const uint32_t* Ws = (const uint32_t*)ws->data;
const int64_t nkb = K / 64, ng = K / group;
AVX_PARALLEL_FOR_IF(N * K >= AVX_PAR_MIN)
for (int64_t idx = 0; idx < N * K / 8; ++idx) {
const int64_t s = idx & 3, r = (idx >> 2) & 15, lh = (idx >> 6) & 1;
const int64_t kb = (idx >> 7) % nkb, t = (idx >> 7) / nkb;
const int64_t row = t * 16 + r, kbase = kb * 64 + s * 16 + 4 * lh;
const uint32_t w = Wq[idx];
const uint32_t sz = Ws[(size_t)(t * ng + kbase / group) * 16 + (size_t)r];
const float sc = rad_f16_to_f32((uint16_t)(sz & 0xFFFFu));
const float zero = -rad_f16_to_f32((uint16_t)(sz >> 16)) - 1024.f;
for (int i = 0; i < 8; ++i) {
const int n = (int)((w >> (4 * i)) & 0xF);
const float q = twos ? (float)((n ^ 8) - 8) : (float)n;
stt(y, row * K + kbase + kOff[i], (q - (twos ? 0.f : zero)) * sc);
}
}
return RAD_OK;
}
/* ------------------------------------------------------------------ dequant */
/* q * scale, with the scale tensor's extent giving the group count. The inverse of quant_act_i8
* only; it does not undo a rotation. */
@@ -539,8 +576,10 @@ AVX_KERNEL(gated_quant_fp8) {
* Unlike had_quant_act_i8, 1/sqrt(g) is not applied here. <Hw, Ha> = g <w, a>, and the whole g is
* divided out of the weight scale instead, where dividing a bf16 by a power of two is exact.
*
* had_quant_act_i8g is the same at int8 codes (`top` 127), for the i8a8h weight. */
static int had_quant_q8(const RadArgs* a, float top) {
* had_quant_act_i8g is the same at int8 codes (`top` 127), for the i8a8h weight. Its rotation is
* at most `rot_cap` (128) wide: a wider group (IQ8R's 256) is whole 128-wide rotations under one
* scale, as libref's. */
static int had_quant_q8(const RadArgs* a, float top, int64_t rot_cap = 0) {
if (!rad_args_have(a, 3)) return RAD_E_INVAL;
const RadTensor *x = &a->t[0], *q = &a->t[1], *s = &a->t[2];
const int64_t n = p_int(a, "n", 0);
@@ -560,7 +599,7 @@ static int had_quant_q8(const RadArgs* a, float top) {
float* out = scratch_f32_b((size_t)n);
const float* v = in_row(x, rowoff(x, r, n), n, buf);
if (v != buf) std::memcpy(buf, v, (size_t)n * sizeof(float));
fwht_row(buf, n, g);
fwht_row(buf, n, rot_cap > 0 && g > rot_cap ? rot_cap : g);
for (int64_t gi = 0; gi < ngrp; ++gi) {
float sc;
fp8_group(buf, out, gi * g, gi * g + g, &sc, top);
@@ -571,12 +610,8 @@ static int had_quant_q8(const RadArgs* a, float top) {
return RAD_OK;
}
AVX_KERNEL(had_quant_act_fp8) {
return had_quant_q8(a, 448.0f);
}
AVX_KERNEL(had_quant_act_i8g) {
return had_quant_q8(a, 127.0f);
return had_quant_q8(a, 127.0f, 128);
}
/* ------------------------------------------------------------- givens_rotate */
@@ -585,59 +620,6 @@ AVX_KERNEL(had_quant_act_i8g) {
* libref's arithmetic and order (ref_quant.cpp): the divide, then a' = a cos t + b sin t,
* b' = b cos t - a sin t in f32, stage by stage. The pair walk is a gather/scatter and stays
* scalar; the cos and sin of each angle are computed once per call. */
AVX_KERNEL(givens_rotate) {
if (!rad_args_have(a, 5)) return RAD_E_INVAL;
const RadTensor *x = &a->t[0], *pr = &a->t[1], *an = &a->t[2], *sc = &a->t[3], *y = &a->t[4];
const int64_t n = p_int(a, "n", 0), S = p_int(a, "stages", 0), P = p_int(a, "parts", 1);
const int64_t g = p_int(a, "group", 0);
if (n <= 0 || S <= 0 || P <= 0 || (n & 1)) return RAD_E_SHAPE;
if (g <= 0 || g > n || n % g != 0) return RAD_E_SHAPE;
const int64_t NP = P * S * (n / 2);
if (numel(pr) < P * S * n || numel(an) < NP || numel(sc) < P * n) return RAD_E_SHAPE;
const int64_t rows = numel(x) / n;
if (rows <= 0 || numel(y) < rows * P * n) return RAD_E_SHAPE;
int32_t* idx = (int32_t*)scratch_raw((size_t)(P * S * n) * sizeof(int32_t) +
(size_t)(2 * NP + P * n) * sizeof(float) + 64);
float* cs = (float*)(idx + P * S * n);
float* sn = cs + NP;
float* rs = sn + NP;
for (int64_t i = 0; i < P * S * n; ++i) {
const int64_t c = ldi(pr, i);
if (c < 0 || c >= n) return RAD_E_INVAL;
idx[i] = (int32_t)c;
}
for (int64_t j = 0; j < NP; ++j) {
const float th = ldt(an, j);
cs[j] = sc_cos(th);
sn[j] = sc_sin(th);
}
for (int64_t k = 0; k < P * n; ++k) rs[k] = ldt(sc, k);
AVX_PARALLEL_FOR_IF(rows * P * n * S >= AVX_PAR_MIN)
for (int64_t r = 0; r < rows; ++r) {
float* buf = scratch_f32((size_t)n);
float* out = scratch_f32_b((size_t)(P * n));
const float* v = in_row(x, rowoff(x, r, n), n, buf);
for (int64_t p = 0; p < P; ++p) {
float* w = out + p * n;
for (int64_t k = 0; k < n; ++k) w[k] = v[k] / rs[p * n + k];
for (int64_t st = 0; st < S; ++st) {
const int32_t* ip = idx + (p * S + st) * n;
const int64_t a0 = (p * S + st) * (n / 2);
for (int64_t j = 0; j < n / 2; ++j) {
const float c = cs[a0 + j], s1 = sn[a0 + j];
const float va = w[ip[2 * j]], vb = w[ip[2 * j + 1]];
w[ip[2 * j]] = va * c + vb * s1;
w[ip[2 * j + 1]] = vb * c - va * s1;
}
}
}
out_row(y, rowoff(y, r, P * n), P * n, out);
}
return RAD_OK;
}
/* --------------------------------------------------------- givens_dense_quant */
/* Quantising form: the rotation as one dense 128 x 128 f16 matrix per (part, group) (`tdense`,
* which rad-convert composes from the pairs and angles as the weight's "t.dense" table), then the
@@ -645,59 +627,6 @@ AVX_KERNEL(givens_rotate) {
* amax / 127, rounded to nearest; scale 1 for an all-zero group, as libref. The matrices are widened
* to f32 once per call. Each group is a matrix-vector product summed in f32 (libref uses f64), so a
* code on a rounding edge can differ from libref's. */
AVX_KERNEL(givens_dense_quant) {
if (!rad_args_have(a, 5)) return RAD_E_INVAL;
const RadTensor *x = &a->t[0], *tm = &a->t[1], *sc = &a->t[2], *q = &a->t[3], *s = &a->t[4];
const int64_t n = p_int(a, "n", 0), P = p_int(a, "parts", 1), g = p_int(a, "group", 0);
if (n <= 0 || P <= 0 || g != 128 || n % g != 0) return RAD_E_SHAPE;
const bool i8 = q->dtype == RAD_I8;
if (!i8 && q->dtype != RAD_F8E4M3) return RAD_E_DTYPE;
const char* outs = p_str(a, "out", "");
if (std::strcmp(outs, i8 ? "i8" : "fp8") != 0) return RAD_E_DTYPE; // `out` names q's dtype
const int64_t rows = numel(x) / n, ngrp = n / g;
if (rows <= 0 || numel(tm) < P * n * g || numel(sc) < P * n || numel(q) < rows * P * n ||
numel(s) < rows * P * ngrp) return RAD_E_SHAPE;
const float qmax = i8 ? 127.0f : 448.0f;
float* T = (float*)scratch_raw((size_t)(P * n * g + P * n) * sizeof(float) + 64);
float* rs = T + P * n * g;
for (int64_t i = 0; i < P * n; ++i) {
row_to_f32(tm->dtype, byte_at(tm->data, tm->dtype, rowoff(tm, i, g)), T + i * g, g);
rs[i] = ldt(sc, i);
}
AVX_PARALLEL_FOR_IF(rows * P * n * g >= AVX_PAR_MIN)
for (int64_t r = 0; r < rows; ++r) {
float* buf = scratch_f32((size_t)n);
float* out = scratch_f32_b((size_t)(P * n));
float* in = scratch_f32_c((size_t)g);
const float* v = in_row(x, rowoff(x, r, n), n, buf);
for (int64_t p = 0; p < P; ++p)
for (int64_t gi = 0; gi < ngrp; ++gi) {
for (int64_t i = 0; i < g; ++i) in[i] = v[gi * g + i] / rs[p * n + gi * g + i];
float* yv = out + p * n + gi * g;
const float* Tg = T + (p * n + gi * g) * g;
for (int64_t j = 0; j < g; ++j) {
vf acc = vf_zero();
for (int64_t i = 0; i < g; i += VF_N)
acc = vf_fma(vf_loadu(Tg + j * g + i), vf_loadu(in + i), acc);
yv[j] = vf_hsum(acc);
}
const float amax = row_amax(yv, g);
const float scl = amax > 0.0f ? amax * (1.0f / qmax) : 1.0f;
const float inv = 1.0f / scl;
for (int64_t j = 0; j < g; ++j) {
float t = yv[j] * inv;
t = t > qmax ? qmax : (t < -qmax ? -qmax : t);
yv[j] = i8 ? std::nearbyint(t) : t;
}
stt(s, rowoff(s, r, P * ngrp) + (p * ngrp + gi) * laststride(s), scl);
}
out_row(q, rowoff(q, r, P * n), P * n, out);
}
return RAD_OK;
}
/* ---------------------------------------------------------------- the Gram accumulator
*
* h[k1][k2] += sum over rows of x[m][k1] * x[m][k2], where x is the dequantised E4M3 input, or a
+16 -45
View File
@@ -293,6 +293,9 @@ static const RadOperandSpec oGram[] = { OPD("a"), OPD_O("a_scale"), INOUT("h") }
static const RadParamSpec pDequant[] = { P_INT("M"), P_INT("n"), P_INT("group"),
P_STR("dtype") };
static const RadOperandSpec oDequant[] = { OPD("q"), OPD("scale"), OUT("y") };
static const RadParamSpec pDequantW4[] = { P_INT("N"), P_INT("K"), P_INT("group"), P_STR("dtype"),
P_INT("twos") };
static const RadOperandSpec oDequantW4[] = { WGT("wq"), WGT("ws"), OUT("y") };
/* ---- gemm --------------------------------------------------------------------------------- */
static const RadParamSpec pGemm[] = { P_INT("M"), P_INT("N"), P_INT("K"), P_STR("dtype") };
@@ -522,7 +525,7 @@ static const RadOperandSpec oMoeGemm[] = { OPD("a"), WTAB("w"), OPD("sorted_tok"
static const RadParamSpec pMoeGemmQ[] = { P_INT("M"), P_INT("N"), P_INT("K"), P_INT("n_expert"),
P_INT("top_k"), P_INT("group"), P_STR("a_order"),
P_STR("dtype"), P_INTO("N_odd"), P_INTO("K_odd"),
P_INTO("parts") };
P_INTO("parts"), P_INTO("a_group") };
static const RadOperandSpec oMoeGemmQ[] = { OPD("a"), OPD_O("a_scale"), WTAB("w"), WTAB("w_scale"),
OPD("sorted_tok"), OPD("expert_offset"),
WTAB("w_odd"), WTAB("w_odd_scale"), OUT("y") };
@@ -532,7 +535,8 @@ static const RadParamSpec pMoeGemmQMod4[] = { P_INT("M"), P_INT("N"), P_INT("K
P_INT("n_expert"), P_INT("top_k"), P_INT("group"),
P_STR("a_order"), P_STR("dtype"), P_INTO("N_1"),
P_INTO("K_1"), P_INTO("N_2"), P_INTO("K_2"),
P_INTO("N_3"), P_INTO("K_3"), P_INTO("parts") };
P_INTO("N_3"), P_INTO("K_3"), P_INTO("parts"),
P_INTO("a_group") };
static const RadOperandSpec oMoeGemmQMod4[] = { OPD("a"), OPD_O("a_scale"), WTAB("w"),
WTAB("w_scale"), OPD("sorted_tok"),
OPD("expert_offset"), WTAB("w_1"),
@@ -994,7 +998,8 @@ static const RadOpSchema kSchemas[] = {
{ "ssd_update", ARR(pSsdUpdate), ARR(oSsdUpdate), "Mamba-2 scalar-decay state update with candidate-state rollback, per_candidate or anchor." },
{ "hc_read", ARR(pHcRead), ARR(oHcRead),
"The read half of a gated residual: grouped norm, low-rank gate, stream mix, and optionally the "
"block-scaled fp8 form of x and its Hadamard-rotated twin. See docs/OPS.md for the three facts "
"block-scaled fp8 form of x and its Hadamard-rotated twin, each int8 into an int8 buffer. See "
"docs/OPS.md for the three facts "
"a second implementation has to match (the mix is a MEAN, there is a separate / hc inside each "
"gate argument, and hc_write adds into the UNNORMED h). `mix` names the matrices' stored "
"format; a host kernel reads them as the dense tensors it is handed." },
@@ -1116,21 +1121,11 @@ static const RadOpSchema kSchemas[] = {
"symmetric int8, one f32 scale per `group` contiguous elements, row-major." },
{ "quant_act_fp8", ARR(pQuant), ARR(oQuantFp8), "symmetric block-scaled E4M3 quantiser." },
{ "quant_cols_fp8", ARR(pQuantCols), ARR(oQuantCols), "E4M3 with one scale per column." },
{ "had_quant_act_fp8", ARR(pQuant), ARR(oQuantFp8),
"width-`group` Hadamard, then the same symmetric block-scaled E4M3 quantiser. No normalisation: "
"the 1/group is folded into the stored weight scale at convert (docs/OPS.md)." },
{ "had_quant_act_i8g", ARR(pQuant), ARR(oQuantFp8),
"width-`group` Hadamard, then quant_act_i8g's symmetric int8 per group. No normalisation: the "
"1/group is the i8a8h weight's stored scale (docs/OPS.md)." },
{ "gram_accum", ARR(pGram), ARR(oGram),
"h += x^T x over a dequantised E4M3 activation. `h` is [n, n] and INOUT." },
{ "givens_dense_quant", ARR(pGivensDense), ARR(oGivensDense),
"ParoQuant's activation quantiser with the rotation as a dense per-group matrix: y = T (x / "
"rscale) for each of `parts` rotated copies, then the block-scaled quantiser `out` names "
"(\"i8\": amax / 127, round to nearest; \"fp8\": E4M3, amax / 448)." },
{ "givens_rotate", ARR(pGivensRotate), ARR(oGivensRotate),
"ParoQuant's rotation without a quantiser: x / rscale rotated by `stages` rounds of Givens "
"pairs, `parts` copies side by side, in y's own dtype." },
{ "had_quant_act_i8", ARR(pQuant), ARR(oHadQuant),
"Walsh-Hadamard rotation at width `group`, then symmetric int8 with ONE scale per row carrying "
"the 1/sqrt(group)." },
@@ -1139,6 +1134,9 @@ static const RadOpSchema kSchemas[] = {
{ "gated_had_quant_i8", ARR(pGatedQuant), ARR(oGatedQuant),
"gated product, rotation and int8 in one pass." },
{ "dequant", ARR(pDequant), ARR(oDequant), "group-scaled dequantisation." },
{ "dequant_w4", ARR(pDequantW4), ARR(oDequantW4),
"Packed int4 weight to row-major bf16. Each 32-bit word holds 8 codes; the scale is "
"f16 in the low 16 bits, the zero point -(1024+zero) as f16 in the high 16 bits." },
{ "rmsnorm_quant_fp8", ARR(pRmsQuantFp8), ARR(oRmsQuantFp8),
"RMS norm with an optional residual add, then the E4M3 quantiser, in one pass. The add is "
"stored before the variance reads it, and the codes are taken over the bf16-narrowed row that "
@@ -1287,9 +1285,6 @@ static const RadOpSchema kSchemas[] = {
{ "all_reduce", ARR(pAllReduce), ARR(oAllReduce),
"sum across ranks, f32, ascending rank order." },
{ "all_gather", ARR(pAllGather), ARR(oAllGather), "gather every rank's shard." },
{ "ln_mod_quant_fp8", ARR(pLnModQ), ARR(oLnModQ),
"gate_add (with `gated` 1), ln_mod and quant_act_fp8 in one pass, each value rounded as its own "
"store would round it; z written when bound." },
{ "ln_mod", ARR(pLnMod), ARR(oLnMod),
"y = bf16(bf16(LN(x)) * bf16(1 + s[seq])): a gainless layer norm and the row's entry's "
"modulation row of `s` ([n_seq, >= n] at its own pitch)." },
@@ -1354,8 +1349,6 @@ static const RadOpSchema kSchemas[] = {
{ "rms_mod", ARR(pRmsMod), ARR(oRmsMod),
"the gated residual (no tanh), then an RMS norm with a gain times bf16(1 + scale row) plus the "
"shift row, `s` holding [shift | scale]; libref's roundings." },
{ "rms_mod_quant_fp8", ARR(pRmsModQ), ARR(oRmsModQ),
"rms_mod with its norm chain in bf16, then the E4M3 codes and scales of that row." },
{ "flow_x0_step", ARR(pMnD), ARR(oFlowX0),
"x = r x + (1 - r)(x + (1 - t) v), r = sigma_next / sigma, each step one f32 rounding, bit for "
"bit libref's." },
@@ -1543,10 +1536,6 @@ static const RadOpSchema kSchemas[] = {
"rmsnorm, for rows a model declares in thousands (the head norms over head_dim)." },
{ "rope_rows", ARR(pRope), ARR(oRope),
"rope, for a model that wants the per-(token, pair) angles form at prefill row counts." },
{ "gemm_nt_q_short", ARR(pGemmQ), ARR(oGemmQ),
"gemm_nt_q, for the short-prompt split rule's rows." },
{ "gemm_nt_q_gated_wide", ARR(pGemmQGated), ARR(oGemmQGated),
"gemm_nt_q_gated at any M." },
};
/* ================================================================== the kernel table
@@ -1581,6 +1570,9 @@ static CbForm cb_form(const RadParam* p, int n_p) {
if (s && !std::strcmp(s, "w4nl64a8h")) return CbForm{ 4, 64, RAD_F8E4M3, true };
if (s && !std::strcmp(s, "w4nl32a8h")) return CbForm{ 4, 32, RAD_F8E4M3, true };
if (s && !std::strcmp(s, "w5nl64a8h")) return CbForm{ 5, 64, RAD_F8E4M3, true };
/* The same stored experts under their names against an int8 activation. */
if (s && !std::strcmp(s, "w4nl64a8i8h")) return CbForm{ 4, 64, RAD_F8E4M3, true };
if (s && !std::strcmp(s, "w4nl32a8i8h")) return CbForm{ 4, 32, RAD_F8E4M3, true };
return CbForm{ 0, 0, 0, false };
}
static int cb_check(const RadParam* p, int n_p, int operand, const RadEncoding* enc,
@@ -1796,21 +1788,10 @@ SIMPLE("avx_quant_act_fp8", "quant_act_fp8", "quant", "symmetric block-scaled E4
"float in, fp8_e4m3 out, f32 scale", L(quant_act_fp8)),
SIMPLE("avx_quant_cols_fp8", "quant_cols_fp8", "quant", "E4M3 with one scale per column",
"float in, fp8_e4m3 out, f32 scale", L(quant_cols_fp8)),
SIMPLE("avx_had_quant_act_fp8", "had_quant_act_fp8", "quant",
"width-`group` Hadamard, then the same symmetric block-scaled E4M3 quantiser",
"float in, fp8_e4m3 out, f32 scale per group; n a multiple of group",
L(had_quant_act_fp8)),
SIMPLE("avx_had_quant_act_i8g", "had_quant_act_i8g", "quant",
"width-`group` Hadamard, then the symmetric int8 quantiser, one scale per group",
"float in, i8 out, f32 scale per group; n a multiple of group",
L(had_quant_act_i8g)),
SIMPLE("avx_givens_rotate", "givens_rotate", "quant",
"channel scale and Givens rotations per part, in the output's dtype",
"float in, float out; int32 pairs, f32 angles and channel scales", L(givens_rotate)),
SIMPLE("avx_givens_dense_quant", "givens_dense_quant", "quant",
"the rotation as a dense per-group matrix, then the block-scaled int8 or E4M3 quantiser",
"float in, int8 or fp8_e4m3 out, f32 scale per group; f16 matrices and f32 channel scales",
L(givens_dense_quant)),
SIMPLE("avx_gram_accum", "gram_accum", "quant",
"h += x^T x over a dequantised E4M3 activation, or a plain bf16 one",
"fp8_e4m3 plus an f32 scale per group, or bf16 with no scale, in; an f32 [n][n] "
@@ -1823,6 +1804,8 @@ SIMPLE("avx_gated_had_quant_i8", "gated_had_quant_i8", "quant",
"gated product, rotation and int8 in one pass", "float in, i8 out, f32 scale",
L(gated_had_quant_i8)),
SIMPLE("avx_dequant", "dequant", "quant", "group-scaled dequantisation", DT_ANY, L(dequant)),
SIMPLE("avx_dequant_w4", "dequant_w4", "quant", "packed int4 weight to row-major bf16", DT_ANY,
L(dequant_w4)),
SIMPLE("avx_rmsnorm_quant_fp8", "rmsnorm_quant_fp8", "quant",
"RMS norm, optional residual add, and the E4M3 quantiser in one pass",
"float in, fp8_e4m3 out, f32 scale, bf16 out_bf16", L(rmsnorm_quant_fp8)),
@@ -1980,9 +1963,6 @@ SIMPLE("avx_mix_rows", "mix_rows", "elem", "a weighted sum of k consecutive rows
L(mix_rows)),
SIMPLE("avx_chan_stats", "chan_stats", "elem", "per-channel statistics held as weights",
DT_FLOAT, L(chan_stats)),
SIMPLE("avx_ln_mod_quant_fp8", "ln_mod_quant_fp8", "norm",
"gated residual, adaptive norm and the E4M3 quantiser in one pass",
"float in, fp8_e4m3 out, f32 scale, bf16 z", L(ln_mod_quant_fp8)),
SIMPLE("avx_timestep_embed", "timestep_embed", "elem", "sinusoidal timestep embedding", DT_FLOAT,
L(timestep_embed)),
SIMPLE("avx_gather_rows2", "gather_rows2", "elem", "rows from two sources by a signed index",
@@ -2022,9 +2002,6 @@ SIMPLE("avx_attn_prefix_self", "attn_prefix_self", "attn",
SIMPLE("avx_rms_mod", "rms_mod", "norm",
"gated residual, RMS norm with a gain times (1 + scale row) plus a shift row", DT_FLOAT,
L(rms_mod)),
SIMPLE("avx_rms_mod_quant_fp8", "rms_mod_quant_fp8", "norm",
"gated residual, modulated RMS norm and the E4M3 quantiser in one pass", DT_FLOAT,
L(rms_mod_quant_fp8)),
SIMPLE("avx_flow_x0_step", "flow_x0_step", "elem", "a sampler step toward the clean estimate",
DT_FLOAT, L(flow_x0_step)),
SIMPLE("avx_flow_res_multistep", "flow_res_multistep", "elem",
@@ -2191,12 +2168,6 @@ SIMPLE("avx_dflash_tree", "dflash_tree", "draft",
SIMPLE("avx_rmsnorm_rows", "rmsnorm_rows", "norm", "rmsnorm under its row-form name", DT_FLOAT,
L(rmsnorm)),
SIMPLE("avx_rope_rows", "rope_rows", "attn", "rope under its row-form name", DT_FLOAT, L(rope)),
ROWL("avx_gemm_nt_q_short", "gemm_nt_q_short", "gemm", "gemm_nt_q under its row-form name",
"as avx_gemm_nt_q", L(gemm_nt_q), avx_layout_gemm_q),
SIMPLE("avx_gemm_nt_q_gated_wide", "gemm_nt_q_gated_wide", "gemm",
"gemm_nt_q_gated under its row-form name",
"i8 / fp8 / float A; w4, w2, mxfp4, i8 or float B; fp8_e4m3 out, f32 scale",
L(gemm_nt_q_gated)),
};
/* ================================================================== plugin exports */