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
@@ -103,6 +103,7 @@ int ref_had_quant_act_i8 (const RadArgs*, RadStream);
|
||||
int ref_quant_act_fp8 (const RadArgs*, RadStream);
|
||||
int ref_quant_cols_fp8 (const RadArgs*, RadStream);
|
||||
int ref_had_quant_act_fp8 (const RadArgs*, RadStream);
|
||||
int ref_had_quant_act_i8g (const RadArgs*, RadStream);
|
||||
int ref_givens_dense_quant(const RadArgs*, RadStream);
|
||||
int ref_givens_rotate(const RadArgs*, RadStream);
|
||||
int ref_rmsnorm_quant_fp8 (const RadArgs*, RadStream);
|
||||
@@ -309,6 +310,7 @@ REF_SHAPE_FN(ref_had_quant_act_i8);
|
||||
REF_SHAPE_FN(ref_quant_act_fp8);
|
||||
REF_SHAPE_FN(ref_quant_cols_fp8);
|
||||
REF_SHAPE_FN(ref_had_quant_act_fp8);
|
||||
REF_SHAPE_FN(ref_had_quant_act_i8g);
|
||||
REF_SHAPE_FN(ref_givens_dense_quant);
|
||||
REF_SHAPE_FN(ref_givens_rotate);
|
||||
REF_SHAPE_FN(ref_rmsnorm_quant_fp8);
|
||||
|
||||
+14
-3
@@ -360,8 +360,11 @@ int ref_quant_cols_fp8(const RadArgs* a, RadStream) {
|
||||
* ~0.2% error per group (a fifth of the int4 grid's own error).
|
||||
*
|
||||
* The output is not interchangeable with quant_act_fp8's: only a weight plane stored as w4a8h
|
||||
* carries the matching rotation and /g. */
|
||||
int ref_had_quant_act_fp8(const RadArgs* a, RadStream) {
|
||||
* carries the matching rotation and /g.
|
||||
*
|
||||
* had_quant_act_i8g is the same at int8 codes (`top` 127), for the i8a8h weight, whose scale
|
||||
* carries the /g the same way. */
|
||||
static int had_quant_act_q8(const RadArgs* a, float top) {
|
||||
if (!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);
|
||||
@@ -383,7 +386,7 @@ int ref_had_quant_act_fp8(const RadArgs* a, RadStream) {
|
||||
const int64_t k0 = gi * g;
|
||||
for (int64_t i = 0; i < g; ++i) buf[i] = ldt(x, xb + (k0 + i) * xs);
|
||||
fwht(buf, g);
|
||||
const float sc = q8_group([&](int64_t i) { return buf[i]; }, g, 448.0f, q,
|
||||
const float sc = q8_group([&](int64_t i) { return buf[i]; }, g, top, q,
|
||||
qb + k0 * qs, qs);
|
||||
stt(s, rowoff(s, r, ngrp) + gi * laststride(s), sc);
|
||||
}
|
||||
@@ -391,6 +394,14 @@ int ref_had_quant_act_fp8(const RadArgs* a, RadStream) {
|
||||
return RAD_OK;
|
||||
}
|
||||
|
||||
int ref_had_quant_act_fp8(const RadArgs* a, RadStream) {
|
||||
return had_quant_act_q8(a, 448.0f);
|
||||
}
|
||||
|
||||
int ref_had_quant_act_i8g(const RadArgs* a, RadStream) {
|
||||
return had_quant_act_q8(a, 127.0f);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------- givens_rotate */
|
||||
/* ParoQuant's activation side: each row divided by its channel factors and rotated by `stages`
|
||||
* rounds of disjoint Givens pairs, written in y's dtype. A weight stored as v = w . D . G_1 ... G_S
|
||||
|
||||
@@ -1062,6 +1062,12 @@ static const RadOpSchema kSchemas[] = {
|
||||
"amax(rotated) / 448, shaped [M, n/group] in f32. n must be a multiple of `group` -- a rotation "
|
||||
"block cannot straddle the end of a row. NOT interchangeable with quant_act_fp8 in either "
|
||||
"direction: the consumer must be a weight that was rotated the same way." },
|
||||
/* Its int8 twin, the activation of the i8a8h GEMMs; the factor of `group` is the weight's here
|
||||
* too. */
|
||||
{ "had_quant_act_i8g", ARR(pQuant), ARR(oQuantFp8),
|
||||
"quant_act_i8g with a Walsh-Hadamard rotation of width `group` along n first: scale = "
|
||||
"amax(rotated) / 127 per group, [M, n/group] in f32, n a multiple of `group`. Pairs with an i8 "
|
||||
"weight rotated the same way, its scale carrying the factor of `group` (dtype i8a8h)." },
|
||||
/* The calibration op, the only one no forward pass issues: it runs under a calibration flag and
|
||||
* its output is read at convert time, in another process, through a file. `dtype` is the input's:
|
||||
* fp8a8 where the tap is a quantiser's output, bf16 without `a_scale` for a plain activation. */
|
||||
@@ -1788,6 +1794,10 @@ SIMPLE("ref_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",
|
||||
ref_had_quant_act_fp8),
|
||||
SIMPLE("ref_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",
|
||||
ref_had_quant_act_i8g),
|
||||
SIMPLE("ref_gram_accum", "gram_accum", "quant",
|
||||
"h += x^T x over a dequantised E4M3 activation, or a plain bf16 one -- the Gram matrix "
|
||||
"GPTQ calibrates on",
|
||||
|
||||
+14
-1
@@ -863,6 +863,18 @@ int ref_had_quant_act_fp8_shape(const RadParam* p, int n_p, int operand, RadOpdD
|
||||
return o.finish("had_quant_act_fp8", operand, out);
|
||||
}
|
||||
|
||||
/* quant_act_i8g's extents: the rotation changes the values, not the shapes. */
|
||||
int ref_had_quant_act_i8g_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out) {
|
||||
const uint32_t D = act_dt(p, n_p);
|
||||
const int64_t M = gi(p, n_p, "M", 0), n = gi(p, n_p, "n", 0);
|
||||
const int64_t ng = scale_groups(n, gi(p, n_p, "group", 0));
|
||||
Opd o;
|
||||
o.t(D, { M, n }); /* x */
|
||||
o.t((uint32_t)RAD_I8, { M, n }); /* q */
|
||||
o.t((uint32_t)RAD_F32, { M, ng }); /* scale (amax / 127) */
|
||||
return o.finish("had_quant_act_i8g", operand, out);
|
||||
}
|
||||
|
||||
/* The int8 rotated forms: `group` is the Walsh-Hadamard rotation width (libr4d's `had`) and the
|
||||
* scale is one per row, carrying the 1/sqrt(group) normalisation (ref_quant.cpp). Describing it as
|
||||
* [M, n/group] would leave the tail of every scale buffer unwritten by both sides, comparing two
|
||||
@@ -960,7 +972,8 @@ static int gemm_q_shape(const RadParam* p, int n_p, int operand, bool bias, RadO
|
||||
const char* q = gs(p, n_p, "dtype");
|
||||
auto is = [&](const char* s) { return q && std::strcmp(q, s) == 0; };
|
||||
const bool a8 = is("fp8a8"), a16 = is("fp8a16"), w4 = is("w4a8"), w8 = is("w8a8");
|
||||
const bool i8 = is("i8a8"), mx = is("mxfp4a8");
|
||||
/* i8a8h is i8a8's operands; its rotation is in the values. */
|
||||
const bool i8 = is("i8a8") || is("i8a8h"), mx = is("mxfp4a8");
|
||||
if ((!a8 && !a16 && !w4 && !w8 && !i8 && !mx) || N <= 0 || K <= 0 || group <= 0)
|
||||
return RAD_E_UNSUPPORTED;
|
||||
/* Neither has a bias form in any architecture. */
|
||||
|
||||
Reference in new issue
Block a user