Archived
libref, libavx: had_quant_act_i8g, the activation of the i8a8h GEMMs
had_quant_act_fp8 at int8 codes (top 127), one body shared by both in each library, so a rotated int8 trunk runs on the host kernels too. gemm_nt_q needs no change: both libraries pick the int8 product from the operands' dtypes, and i8a8h's rotation is in the values. libref's operand description takes i8a8h, and rad-avx-check gains cases for the op and the dtype. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
037427e67e
commit
61afe50b96
10 files changed
+84
-11
No files matched your search
+1
-1
@@ -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`, `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_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`) |
|
||||
| `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 |
|
||||
|
||||
@@ -153,6 +153,8 @@ std::vector<Case> build_cases() {
|
||||
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),
|
||||
HS("dtype", "bf16") });
|
||||
add("dequant", { HI("M", 5), HI("n", 256), HI("group", group),
|
||||
@@ -221,11 +223,14 @@ std::vector<Case> build_cases() {
|
||||
add("gemm_nt_q_bias", { HI("M", M), HI("N", 96), HI("K", 256), HI("group", 128),
|
||||
HS("dtype", dt) }, 0, fl);
|
||||
}
|
||||
/* The int8 trunk (row-major codes, a scale per row per 128 of K on both sides) and OCP-MXFP4
|
||||
* (e2m1 codes with an E8M0 exponent per 32 of K against the E4M3 activation). */
|
||||
/* The int8 trunk (row-major codes, a scale per row per 128 of K on both sides; i8a8h is the
|
||||
* same operands over a rotated weight) and OCP-MXFP4 (e2m1 codes with an E8M0 exponent per 32
|
||||
* of K against the E4M3 activation). */
|
||||
for (int M : { 1, 65 }) {
|
||||
add("gemm_nt_q", { HI("M", M), HI("N", 96), HI("K", 256), HI("group", 128),
|
||||
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);
|
||||
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);
|
||||
}
|
||||
@@ -961,6 +966,8 @@ std::vector<Case> build_cases() {
|
||||
HS("dtype", "bf16") }, (double)M * 2048 * 3, 0);
|
||||
speed("quant_act_i8g", { HI("M", M), HI("n", 2048), HI("group", 128),
|
||||
HS("dtype", "bf16") }, (double)M * 2048 * 3, 0);
|
||||
speed("had_quant_act_i8g", { HI("M", M), HI("n", 2048), HI("group", 128),
|
||||
HS("dtype", "bf16") }, (double)M * 2048 * 3, 0);
|
||||
speed("had_quant_act_i8", { HI("M", M), HI("n", 2048), HI("group", 128),
|
||||
HS("dtype", "bf16") }, (double)M * 2048 * 3, 0);
|
||||
}
|
||||
|
||||
+1
-1
@@ -83,7 +83,7 @@ int avx_par_force(int threads);
|
||||
/* ---- 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(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) \
|
||||
/* ---- gemm and the vocabulary edges */ \
|
||||
X(gemm_nt) X(gemm_nt_bias) X(gemm_nt_q) X(gemm_nt_q_bias) \
|
||||
|
||||
+13
-3
@@ -537,8 +537,10 @@ AVX_KERNEL(gated_quant_fp8) {
|
||||
* is scaled by.
|
||||
*
|
||||
* 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. */
|
||||
AVX_KERNEL(had_quant_act_fp8) {
|
||||
* 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) {
|
||||
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);
|
||||
@@ -561,7 +563,7 @@ AVX_KERNEL(had_quant_act_fp8) {
|
||||
fwht_row(buf, n, g);
|
||||
for (int64_t gi = 0; gi < ngrp; ++gi) {
|
||||
float sc;
|
||||
fp8_group(buf, out, gi * g, gi * g + g, &sc);
|
||||
fp8_group(buf, out, gi * g, gi * g + g, &sc, top);
|
||||
stt(s, rowoff(s, r, ngrp) + gi * laststride(s), sc);
|
||||
}
|
||||
out_row(q, rowoff(q, r, n), n, out);
|
||||
@@ -569,6 +571,14 @@ AVX_KERNEL(had_quant_act_fp8) {
|
||||
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);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------- givens_rotate */
|
||||
/* ParoQuant's activation side for a 16-bit GEMM: each row is divided by its channel scales and
|
||||
* rotated by `stages` rounds of disjoint Givens pairs, once per part, parts side by side in y.
|
||||
|
||||
@@ -772,6 +772,9 @@ static const RadOpSchema kSchemas[] = {
|
||||
{ "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(pQuant), ARR(oGram),
|
||||
"h += x^T x over a dequantised E4M3 activation. `h` is [n, n] and INOUT." },
|
||||
{ "givens_dense_quant", ARR(pGivensDense), ARR(oGivensDense),
|
||||
@@ -1244,6 +1247,10 @@ 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)),
|
||||
|
||||
Reference in new issue
Block a user