Archived
ParoQuant: dense per-group rotation (givens_dense_quant): composed 128x128 f16 matrices built at convert time, WMMA kernel with int8/fp8 epilogue; LinearFP8 uses it for the quantising rotation
This commit is contained in:
1 parent
a19cbcae85
commit
c17f5fdc89
13 files changed
+493
-30
No files matched your search
@@ -1079,6 +1079,26 @@ static const RadOperandSpec oGivensQuantAct[] = {
|
||||
{ "scale", RAD_OPD_OUT, 0 },
|
||||
};
|
||||
|
||||
/* `givens_dense_quant` is givens_quant_act_fp8 with the rotation done by a dense per-group matrix on the
|
||||
* matrix cores (r4d_givens_dense.hip). The matrices are the weight -- rad-convert composes them from the
|
||||
* givens tables (r4d_rad_layout_gdense) -- so its tables are `tdense` and the channel scale `rscale`.
|
||||
* `out` is the quantiser: "i8" (scale amax / 127) or "fp8" (E4M3, amax / 448), as q's dtype says. */
|
||||
static const RadParamSpec pGivensDense[] = {
|
||||
{ "M", RAD_P_INT, RAD_REQUIRED },
|
||||
{ "n", RAD_P_INT, RAD_REQUIRED },
|
||||
{ "group", RAD_P_INT, RAD_REQUIRED },
|
||||
{ "dtype", RAD_P_STR, RAD_REQUIRED },
|
||||
{ "parts", RAD_P_INT, RAD_REQUIRED },
|
||||
{ "out", RAD_P_STR, RAD_REQUIRED },
|
||||
};
|
||||
static const RadOperandSpec oGivensDense[] = {
|
||||
{ "x", RAD_OPD_IN, 0 },
|
||||
{ "tdense", RAD_OPD_WEIGHT, 0 },
|
||||
{ "rscale", RAD_OPD_WEIGHT, 0 },
|
||||
{ "q", RAD_OPD_OUT, 0 },
|
||||
{ "scale", RAD_OPD_OUT, 0 },
|
||||
};
|
||||
|
||||
/* `gram_accum` is a NEW OP and this plugin fixes its schema. It is the calibration half of GPTQ:
|
||||
* `h += x^T x` over an E4M3 activation, accumulated across every launch of a corpus.
|
||||
*
|
||||
@@ -2346,6 +2366,13 @@ static const RadOpSchema kSchemas[] = {
|
||||
"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."),
|
||||
SCHEMA("givens_dense_quant", pGivensDense, oGivensDense,
|
||||
"ParoQuant's activation quantiser with the rotation as a dense per-group matrix: y = T (x / "
|
||||
"rscale) for each of `parts` rotated copies, T the [128, 128] f16 matrix a (part, 128-column "
|
||||
"group) that its Givens stages compose to, then the block-scaled quantiser `out` names "
|
||||
"(\"i8\": scale amax / 127, round to nearest; \"fp8\": E4M3, amax / 448). q is [M, parts * n] "
|
||||
"and scale [M, parts * n / group]; tdense is [parts * n, 128]. The same activation as "
|
||||
"givens_quant_act_i8g / _fp8 up to the f16 rounding of T."),
|
||||
SCHEMA("givens_quant_act_i8g", pGivensQuantAct, oGivensQuantAct,
|
||||
"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 "
|
||||
@@ -3015,6 +3042,9 @@ static const RadConstraint cQuantActFp8[] = {
|
||||
* straddle the end of a row: the ragged tail the unrotated kernel writes zero-padded would mix
|
||||
* real values with padding inside one butterfly, and there is no weight block on the other side
|
||||
* that was rotated the same way. */
|
||||
static const RadConstraint cGivensDense[] = {
|
||||
C_DIV("n", R4D_FP8_BLOCK), C_EQ("group", R4D_FP8_BLOCK), C_IN("dtype", "bf16"), C_IN("out", "i8 fp8"),
|
||||
};
|
||||
static const RadConstraint cHadQuantActFp8[] = {
|
||||
C_DIV("n", R4D_FP8_BLOCK), C_EQ("group", R4D_FP8_BLOCK), C_IN("dtype", "bf16"),
|
||||
};
|
||||
@@ -5258,6 +5288,18 @@ static const RadKernelInfo kKernels[] = {
|
||||
r4d_rad_relayout_givens_pairs, nullptr, r4d_rad_unrelayout_givens_pairs, nullptr,
|
||||
r4d_rad_givens_quant_act_i8g_describe },
|
||||
|
||||
{ "givens_dense_quant", "givens_dense_quant", "quant",
|
||||
"ParoQuant's rotation as a dense 128 x 128 f16 matrix a (part, group) on the matrix cores, then "
|
||||
"per-(row, 128-column) symmetric quantisation to int8 or E4M3, once for each rotated part",
|
||||
"n a multiple of 128 and group 128; the matrices are the weight, composed from the givens tables at "
|
||||
"convert time",
|
||||
"bf16 in, int8 or E4M3 out in PLAIN ROW-MAJOR order, parts side by side, with an f32 scale (amax/127 "
|
||||
"or amax/448) per (row, part, 128 columns); f16 matrices and f32 channel scales",
|
||||
RAD_DOMAIN_DEVICE, R4D_PRIO_ONLY,
|
||||
ROW(cGivensDense), NOTUNE,
|
||||
nullptr, nullptr, r4d_rad_givens_dense_quant, nullptr, r4d_rad_layout_gdense, r4d_rad_relayout_gdense,
|
||||
nullptr, nullptr, nullptr, r4d_rad_givens_dense_quant_describe },
|
||||
|
||||
{ "givens_rotate", "givens_rotate", "quant",
|
||||
"the channel scale and ParoQuant's Givens rotations, once for each rotated part, to f16",
|
||||
"n a multiple of 128 and group 128: a rotation group cannot straddle the end of a row",
|
||||
|
||||
Reference in new issue
Block a user