Archived
libr4d: int8 prefill band for ParoQuant int4/int5 (gemm_w4a8i8/w5a8i8 tiled, givens_quant_act_i8g); LinearFP8 uses it above 64 rows
This commit is contained in:
1 parent
cfe03f8ad8
commit
6091039926
16 files changed
+709
-64
No files matched your search
@@ -101,6 +101,7 @@ int ref_had_quant_act_i8 (const RadArgs*, RadStream);
|
||||
int ref_quant_act_fp8 (const RadArgs*, RadStream);
|
||||
int ref_had_quant_act_fp8 (const RadArgs*, RadStream);
|
||||
int ref_givens_quant_act_fp8(const RadArgs*, RadStream);
|
||||
int ref_givens_quant_act_i8g(const RadArgs*, RadStream);
|
||||
int ref_givens_rotate(const RadArgs*, RadStream);
|
||||
int ref_rmsnorm_quant_fp8 (const RadArgs*, RadStream);
|
||||
int ref_gated_quant_fp8 (const RadArgs*, RadStream);
|
||||
@@ -231,6 +232,7 @@ REF_SHAPE_FN(ref_had_quant_act_i8);
|
||||
REF_SHAPE_FN(ref_quant_act_fp8);
|
||||
REF_SHAPE_FN(ref_had_quant_act_fp8);
|
||||
REF_SHAPE_FN(ref_givens_quant_act_fp8);
|
||||
REF_SHAPE_FN(ref_givens_quant_act_i8g);
|
||||
REF_SHAPE_FN(ref_givens_rotate);
|
||||
REF_SHAPE_FN(ref_rmsnorm_quant_fp8);
|
||||
REF_SHAPE_FN(ref_gated_quant_fp8);
|
||||
|
||||
@@ -427,7 +427,7 @@ int ref_had_quant_act_fp8(const RadArgs* a, RadStream) {
|
||||
* stage a' = a cos t + b sin t, b' = b cos t - a sin t in f32, then amax/448 per group. Not
|
||||
* bit-identical to the device on the angle: cos and sin of an f32 differ by an ulp between libm
|
||||
* and the GPU's. */
|
||||
static int givens_body(const RadArgs* a, bool quant) {
|
||||
static int givens_body(const RadArgs* a, bool quant, bool i8 = false) {
|
||||
if (!have(a, quant ? 6 : 5)) return RAD_E_INVAL;
|
||||
const RadTensor *x = &a->t[0], *pr = &a->t[1], *an = &a->t[2], *sc = &a->t[3];
|
||||
const RadTensor *q = &a->t[4], *s = quant ? &a->t[5] : nullptr;
|
||||
@@ -475,12 +475,14 @@ static int givens_body(const RadArgs* a, bool quant) {
|
||||
const float m = std::fabs(buf[(size_t)(k0 + i)]);
|
||||
if (m > amax) amax = m;
|
||||
}
|
||||
const float scl = amax > 0.0f ? amax * (1.0f / 448.0f) : 1.0f;
|
||||
const float qmax = i8 ? 127.0f : 448.0f;
|
||||
const float scl = amax > 0.0f ? amax * (1.0f / qmax) : 1.0f;
|
||||
const float inv = 1.0f / scl;
|
||||
for (int64_t i = 0; i < g; ++i) {
|
||||
float v = buf[(size_t)(k0 + i)] * inv;
|
||||
if (v > 448.0f) v = 448.0f;
|
||||
if (v < -448.0f) v = -448.0f;
|
||||
if (v > qmax) v = qmax;
|
||||
if (v < -qmax) v = -qmax;
|
||||
if (i8) v = std::nearbyint(v);
|
||||
st_dt(q->dtype, q->data, qb + (p * n + k0 + i) * qs, v);
|
||||
}
|
||||
stt(s, rowoff(s, r, P * ngrp) + (p * ngrp + gi) * laststride(s), scl);
|
||||
@@ -491,6 +493,7 @@ static int givens_body(const RadArgs* a, bool quant) {
|
||||
}
|
||||
|
||||
int ref_givens_quant_act_fp8(const RadArgs* a, RadStream) { return givens_body(a, true); }
|
||||
int ref_givens_quant_act_i8g(const RadArgs* a, RadStream) { return givens_body(a, true, true); }
|
||||
|
||||
/* The same channel scale and rotations with NO quantiser: y = the rotated row in y's dtype, `parts`
|
||||
* copies side by side. For a weight whose GEMM reads a 16-bit activation (w5a16). */
|
||||
|
||||
@@ -811,6 +811,10 @@ static const RadOpSchema kSchemas[] = {
|
||||
"stages) of `pairs` and `angle` and row p of `rscale`: a fused projection's pieces were each "
|
||||
"rotated on their own. Only a weight stored with the \"givens\" transform reads the result; "
|
||||
"it is NOT quant_act_fp8's output in either direction." },
|
||||
{ "givens_quant_act_i8g", ARR(pGivensQuant), ARR(oGivensQuant),
|
||||
"givens_quant_act_fp8 with an int8 output: the same channel scale and rotations, then "
|
||||
"quant_act_i8g's quantiser (scale = amax / 127 per `group`, round to nearest). For the int8 "
|
||||
"prefill GEMMs of a weight stored with the \"givens\" transform." },
|
||||
{ "givens_rotate", ARR(pGivensQuant), ARR(oGivensRotate),
|
||||
"givens_quant_act_fp8 without the quantiser: y = x / rscale rotated by `stages` rounds of Givens "
|
||||
"pairs, `parts` copies side by side ([M, parts * n]) in y's own dtype. For a weight whose GEMM "
|
||||
@@ -1184,6 +1188,10 @@ SIMPLE("ref_givens_quant_act_fp8", "givens_quant_act_fp8", "quant",
|
||||
"channel scale and Givens rotations per part, then the block-scaled E4M3 quantiser",
|
||||
"float in, fp8_e4m3 out, f32 scale per group; int32 pairs, f32 angles and channel scales",
|
||||
ref_givens_quant_act_fp8),
|
||||
SIMPLE("ref_givens_quant_act_i8g", "givens_quant_act_i8g", "quant",
|
||||
"channel scale and Givens rotations per part, then the block-scaled int8 quantiser",
|
||||
"float in, int8 out, f32 scale per group; int32 pairs, f32 angles and channel scales",
|
||||
ref_givens_quant_act_i8g),
|
||||
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",
|
||||
|
||||
@@ -836,6 +836,10 @@ int ref_givens_quant_act_fp8_shape(const RadParam*, int, int, RadOpdDesc*) {
|
||||
return RAD_E_UNSUPPORTED;
|
||||
}
|
||||
|
||||
int ref_givens_quant_act_i8g_shape(const RadParam*, int, int, RadOpdDesc*) {
|
||||
return RAD_E_UNSUPPORTED; /* a pairing cannot be drawn: see givens_quant_act_fp8 */
|
||||
}
|
||||
|
||||
int ref_givens_rotate_shape(const RadParam*, int, int, RadOpdDesc*) {
|
||||
return RAD_E_UNSUPPORTED; /* a pairing cannot be drawn: see givens_quant_act_fp8 */
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user