Archived
ParoQuant: drop the sequential rotate-and-quantise ops (givens_quant_act_fp8 / givens_quant_act_i8g): givens_dense_quant replaces them; the rotate-only f16 kernel keeps its own file
This commit is contained in:
1 parent
c17f5fdc89
commit
ec65b8cbeb
18 files changed
+318
-486
No files matched your search
+8
-61
@@ -1052,10 +1052,10 @@ static const RadOperandSpec oQuantActFp8[] = {
|
||||
{ "scale", RAD_OPD_OUT, 0 },
|
||||
};
|
||||
|
||||
/* `givens_quant_act_fp8` is ParoQuant's activation side, and libref declared this schema first
|
||||
* (the loader refuses two that differ). The tables are the "givens" encoding's, as WEIGHT operands;
|
||||
* see libref/ref_quant.cpp for the contract and r4d_givens_quant_act_fp8.hip for the kernel. */
|
||||
static const RadParamSpec pGivensQuantAct[] = {
|
||||
/* `givens_rotate` is ParoQuant's activation side for the 16-bit GEMMs, and libref declared this schema
|
||||
* first (the loader refuses two that differ). The tables are the "givens" encoding's, as WEIGHT
|
||||
* operands; see libref/ref_quant.cpp for the contract and r4d_givens_rotate.hip for the kernel. */
|
||||
static const RadParamSpec pGivensRotate[] = {
|
||||
{ "M", RAD_P_INT, RAD_REQUIRED },
|
||||
{ "n", RAD_P_INT, RAD_REQUIRED },
|
||||
{ "group", RAD_P_INT, RAD_REQUIRED },
|
||||
@@ -1070,16 +1070,8 @@ static const RadOperandSpec oGivensRotate[] = {
|
||||
{ "rscale", RAD_OPD_WEIGHT, 0 },
|
||||
{ "y", RAD_OPD_OUT, 0 },
|
||||
};
|
||||
static const RadOperandSpec oGivensQuantAct[] = {
|
||||
{ "x", RAD_OPD_IN, 0 },
|
||||
{ "pairs", RAD_OPD_WEIGHT, 0 },
|
||||
{ "angle", RAD_OPD_WEIGHT, 0 },
|
||||
{ "rscale", RAD_OPD_WEIGHT, 0 },
|
||||
{ "q", RAD_OPD_OUT, 0 },
|
||||
{ "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
|
||||
/* `givens_dense_quant` is ParoQuant's activation quantiser, 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. */
|
||||
@@ -2352,31 +2344,17 @@ static const RadOpSchema kSchemas[] = {
|
||||
SCHEMA("had_quant_act_i8g", pQuantActFp8, oQuantActFp8,
|
||||
"quant_act_i8g with a `group`-wide Hadamard along K first; pairs with an i8 weight stored "
|
||||
"rotated, its scale carrying the residual factor of `group`."),
|
||||
SCHEMA("givens_rotate", pGivensQuantAct, oGivensRotate,
|
||||
"givens_quant_act_fp8 without the quantiser: y = x / rscale rotated by `stages` rounds of "
|
||||
SCHEMA("givens_rotate", pGivensRotate, oGivensRotate,
|
||||
"ParoQuant's rotation without a 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 reads a 16-bit activation. `group` is the width a pair stays inside."),
|
||||
SCHEMA("givens_quant_act_fp8", pGivensQuantAct, oGivensQuantAct,
|
||||
"ParoQuant's activation quantiser: x is divided by the channel scale `rscale`, rotated by "
|
||||
"`stages` rounds of disjoint Givens pairs (a' = a cos t + b sin t, b' = b cos t - a sin t, "
|
||||
"pairs as column indices of the row, each inside one scale group), then quantised as "
|
||||
"quant_act_fp8 does: scale = amax / 448 per `group`. `parts` rotated copies are written "
|
||||
"side by side -- q is [M, parts * n], scale [M, parts * n / group] -- part p from table "
|
||||
"rows [p * stages, (p + 1) * 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."),
|
||||
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 "
|
||||
"prefill GEMMs of a weight stored with the \"givens\" transform."),
|
||||
"the sequential rotation, up to the f16 rounding of T."),
|
||||
SCHEMA("had_quant_act_fp8", pQuantActFp8, oQuantActFp8,
|
||||
"the same, with a `group`-wide Hadamard along K applied BEFORE the absmax. Pairs with "
|
||||
"an expert weight stored at dtype w4a8h, which carries the matching rotation and the "
|
||||
@@ -5257,37 +5235,6 @@ static const RadKernelInfo kKernels[] = {
|
||||
nullptr, nullptr, r4d_rad_had_quant_act_fp8, nullptr, nullptr, nullptr,
|
||||
r4d_shape_quant_act_fp8, nullptr, nullptr, r4d_rad_had_quant_act_fp8_describe },
|
||||
|
||||
/* ParoQuant's rotation and the quantiser in one pass, because the rotation changes the maximum the
|
||||
* scale is taken over and so cannot be a separate launch ahead of quant_act_fp8 without writing
|
||||
* and re-reading the rotated row. It exists for the MXFP4 weight stored rotated and for nothing
|
||||
* else. */
|
||||
{ "givens_quant_act_fp8", "givens_quant_act_fp8", "quant",
|
||||
"the channel scale, ParoQuant's Givens rotations, then per-(row, 128-column) symmetric E4M3 "
|
||||
"quantisation, once for each rotated part of a fused projection",
|
||||
"n a multiple of 128 -- a rotation group cannot straddle the end of a row -- and group 128, "
|
||||
"which is both the rotation group and the weight scale's activation block",
|
||||
"bf16 in, E4M3 out in PLAIN ROW-MAJOR order, parts side by side, with an f32 scale per (row, part, "
|
||||
"128 columns); the tables are the weight's int32 pairs (checked at load to pair each group's own "
|
||||
"columns), f32 angles and f32 channel scales",
|
||||
RAD_DOMAIN_DEVICE, R4D_PRIO_ONLY,
|
||||
ROW(cHadQuantActFp8), NOTUNE,
|
||||
nullptr, nullptr, r4d_rad_givens_quant_act_fp8, nullptr, r4d_rad_layout_givens_pairs,
|
||||
r4d_rad_relayout_givens_pairs, nullptr, r4d_rad_unrelayout_givens_pairs, nullptr,
|
||||
r4d_rad_givens_quant_act_fp8_describe },
|
||||
|
||||
{ "givens_quant_act_i8g", "givens_quant_act_i8g", "quant",
|
||||
"the channel scale, ParoQuant's Givens rotations, then per-(row, 128-column) symmetric int8 "
|
||||
"quantisation, once for each rotated part of a fused projection",
|
||||
"n a multiple of 128 and group 128, as givens_quant_act_fp8's",
|
||||
"bf16 in, int8 out in PLAIN ROW-MAJOR order, parts side by side, with an f32 scale of amax/127 per "
|
||||
"(row, part, 128 columns); the tables are the weight's int32 pairs, f32 angles and f32 channel "
|
||||
"scales",
|
||||
RAD_DOMAIN_DEVICE, R4D_PRIO_ONLY,
|
||||
ROW(cHadQuantActFp8), NOTUNE,
|
||||
nullptr, nullptr, r4d_rad_givens_quant_act_i8g, nullptr, r4d_rad_layout_givens_pairs,
|
||||
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",
|
||||
|
||||
Reference in new issue
Block a user