Archived
Rotated Qwen3.8-27B checkpoints: ParoQuant MXFP4, int5 bit-plane and z-lab's int4 import (the givens
transform with parts, per-row scales, zero points), the w5a16/w4a16_asym decode GEMMs, the
w4a8i8/w5a8i8 prefill band, the givens_rotate kernel, and the dense per-group rotation
(givens_dense_quant: one 128x128 f16 matrix a part and group on the matrix cores) for the quantising
rotation in prefill. gemm_nt_q gains part bounds (pb1/pb2), an op-schema change an out-of-tree
kernel library has to follow.
Fixes on top: the dense matrices are a container table ("t.dense") that rad-convert composes in f64
from the pairs and angles, and the loader only moves its bits. A container converted before this is
refused at load, naming the re-convert (--reuse copies every unchanged weight). A gemm_nt_q row that
does not read part bounds refuses them instead of ignoring them. libavx implements givens_rotate and
givens_dense_quant.
This commit is contained in:
commit
f6a9467cb5
40 files changed
+4206
-143
No files matched your search
@@ -706,12 +706,19 @@ static const RadOperandSpec oGemmNt[] = {
|
||||
{ "y", RAD_OPD_OUT, 0 },
|
||||
};
|
||||
|
||||
/* `pb1` and `pb2` are ParoQuant's, and the mxfp4a8 rows and the 4- and 5-bit asymmetric rows (w5a16,
|
||||
* w4a16_asym, w4a8i8_asym, w5a8i8) read them: the weight's rows
|
||||
* [0, pb1), [pb1, pb2) and [pb2, N) each meet their own copy of the activation, side by side in a
|
||||
* row of `a` (so `a` is [M, parts * K]). 0 leaves a bound out. Optional, and absent from every
|
||||
* other grid: a fused projection whose pieces were not rotated apart has one activation. */
|
||||
static const RadParamSpec pGemmNtQ[] = {
|
||||
{ "M", RAD_P_INT, RAD_REQUIRED },
|
||||
{ "N", RAD_P_INT, RAD_REQUIRED },
|
||||
{ "K", RAD_P_INT, RAD_REQUIRED },
|
||||
{ "group", RAD_P_INT, RAD_REQUIRED },
|
||||
{ "dtype", RAD_P_STR, RAD_REQUIRED },
|
||||
{ "pb1", RAD_P_INT, RAD_OPTIONAL },
|
||||
{ "pb2", RAD_P_INT, RAD_OPTIONAL },
|
||||
};
|
||||
/* docs/OPS.md's `gemm_nt_q` is `a`, `a_scale`, `b`w, `b_scale`w -> `y`. Two of libr4d's six
|
||||
* quantised GEMMs need a seventh operand each and neither is expressible as a weight aux stream,
|
||||
@@ -1047,6 +1054,45 @@ static const RadOperandSpec oQuantActFp8[] = {
|
||||
{ "scale", RAD_OPD_OUT, 0 },
|
||||
};
|
||||
|
||||
/* `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 },
|
||||
{ "dtype", RAD_P_STR, RAD_REQUIRED },
|
||||
{ "stages", RAD_P_INT, RAD_REQUIRED },
|
||||
{ "parts", RAD_P_INT, RAD_REQUIRED },
|
||||
};
|
||||
static const RadOperandSpec oGivensRotate[] = {
|
||||
{ "x", RAD_OPD_IN, 0 },
|
||||
{ "pairs", RAD_OPD_WEIGHT, 0 },
|
||||
{ "angle", RAD_OPD_WEIGHT, 0 },
|
||||
{ "rscale", RAD_OPD_WEIGHT, 0 },
|
||||
{ "y", RAD_OPD_OUT, 0 },
|
||||
};
|
||||
|
||||
/* `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 -- the givens encoding's "t.dense" table,
|
||||
* which rad-convert composes -- 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.
|
||||
*
|
||||
@@ -2461,6 +2507,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", 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_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 "
|
||||
"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 "
|
||||
@@ -3109,6 +3166,19 @@ static const RadConstraint cGemmNtTiled[] = {
|
||||
static const RadConstraint cGemmNtW4[] = {
|
||||
C_LE("M", 64), C_DIV("K", 128), C_DIV("N", 16), C_IN("dtype", "w4a16"),
|
||||
};
|
||||
/* w5a16 serves any M: the dispatcher takes rows past 64 as chunks of 64. */
|
||||
static const RadConstraint cGemmNtW5[] = {
|
||||
C_GE("M", 1), C_DIV("K", 128), C_DIV("N", 16), C_IN("dtype", "w5a16"),
|
||||
};
|
||||
static const RadConstraint cGemmNtW4Asym[] = {
|
||||
C_GE("M", 1), C_DIV("K", 128), C_DIV("N", 16), C_IN("dtype", "w4a16_asym"),
|
||||
};
|
||||
static const RadConstraint cGemmNtW4A8I8[] = {
|
||||
C_GE("M", 1), C_DIV("K", 128), C_DIV("N", 16), C_IN("dtype", "w4a8i8_asym"),
|
||||
};
|
||||
static const RadConstraint cGemmNtW5A8I8[] = {
|
||||
C_GE("M", 1), C_DIV("K", 128), C_DIV("N", 16), C_IN("dtype", "w5a8i8"),
|
||||
};
|
||||
static const RadConstraint cGemmNtW2A8[] = {
|
||||
C_DIV("K", 128), C_DIV("N", 16), C_IN("dtype", "w2a8"),
|
||||
};
|
||||
@@ -3172,6 +3242,11 @@ static const RadConstraint cQuantActFp8[] = {
|
||||
static const RadConstraint cHadQuantActFp8[] = {
|
||||
C_DIV("n", R4D_FP8_BLOCK), C_EQ("group", R4D_FP8_BLOCK), C_IN("dtype", "bf16"),
|
||||
};
|
||||
/* ParoQuant's dense rotation: the same whole-group rule (a rotation group cannot straddle a row's end),
|
||||
* and `out` one of the two quantisers its epilogue has. */
|
||||
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"),
|
||||
};
|
||||
|
||||
/* The dtype is the INPUT's, and the input is already quantised -- so it is `fp8a8` and not `bf16`
|
||||
* the way every other row in this family reads it. A four-multiple `n` is the staging slot (one
|
||||
@@ -5039,6 +5114,53 @@ static const RadKernelInfo kKernels[] = {
|
||||
nullptr, nullptr, r4d_rad_gemm_w4a16_m64, nullptr, r4d_rad_layout_w4, r4d_rad_relayout_w4,
|
||||
nullptr, r4d_rad_unrelayout_w4 },
|
||||
|
||||
{ "gemm_w5a16_nt_m64", "gemm_nt_q", "gemm",
|
||||
"skinny GEMM with a 5-bit asymmetric weight (ParoQuant int5), 16x16x16 f16 WMMA, split-K reduced "
|
||||
"in LDS; rows past 64 in chunks of 64, a partitioned weight (pb1/pb2) one launch a part",
|
||||
"N a multiple of 16; K divisible by SK*128; weight pre-permuted into fragment order, a nibble "
|
||||
"plane then a fifth-bit plane",
|
||||
"f16 A (parts side by side), 5-bit W with an f16 scale and integer zero per 128 K, bf16 C, fp32 "
|
||||
"accumulate",
|
||||
RAD_DOMAIN_DEVICE, R4D_PRIO_GEMM_SKINNY,
|
||||
ROW(cGemmNtW5), ROW(tGemmSkinny), r4d_tune_valid_gemm,
|
||||
nullptr, nullptr, r4d_rad_gemm_w5a16_m64, nullptr, r4d_rad_layout_w5, r4d_rad_relayout_w5,
|
||||
nullptr, r4d_rad_unrelayout_w5 },
|
||||
|
||||
{ "gemm_w4a16_asym_nt_m64", "gemm_nt_q", "gemm",
|
||||
"skinny GEMM with a 4-bit ASYMMETRIC weight (z-lab's ParoQuant int4), the 5-bit row's kernel with "
|
||||
"no fifth-bit plane; rows past 64 in chunks of 64, a partitioned weight (pb1/pb2) one launch a part",
|
||||
"N a multiple of 16; K divisible by SK*128; weight pre-permuted into fragment order, unsigned nibbles",
|
||||
"f16 A (parts side by side), 4-bit W with an f16 scale and integer zero per 128 K, bf16 C, fp32 "
|
||||
"accumulate",
|
||||
RAD_DOMAIN_DEVICE, R4D_PRIO_GEMM_SKINNY,
|
||||
ROW(cGemmNtW4Asym), ROW(tGemmSkinny), r4d_tune_valid_gemm,
|
||||
nullptr, nullptr, r4d_rad_gemm_w4a16asym_m64, nullptr, r4d_rad_layout_w4, r4d_rad_relayout_w4,
|
||||
nullptr, r4d_rad_unrelayout_w4 },
|
||||
|
||||
{ "gemm_w4a8i8_tiled", "gemm_nt_q", "gemm",
|
||||
"the 4-bit ASYMMETRIC weight x int8 activation GEMM for prefill row counts (z-lab's ParoQuant int4): "
|
||||
"int8 WMMA over (code - zero), the weight and activation scales folded per 128 of K",
|
||||
"N a multiple of 16; K a multiple of 128; the activation scale per (row, 128 of K); weight in the "
|
||||
"f16 kernel's fragment order; a partitioned weight (pb1/pb2) one launch a part",
|
||||
"I8 A (parts side by side) with an f32 scale per (row, part, 128), 4-bit W with an f16 scale and "
|
||||
"integer zero per 128 K, bf16 C, int32 accumulate per 128 of K",
|
||||
RAD_DOMAIN_DEVICE, R4D_PRIO_GEMM_SKINNY,
|
||||
ROW(cGemmNtW4A8I8), NOTUNE,
|
||||
nullptr, nullptr, r4d_rad_gemm_w4a8i8_tiled, r4d_rad_gemm_mxfp4a8_tiled_scratch,
|
||||
r4d_rad_layout_w4, r4d_rad_relayout_w4, nullptr, r4d_rad_unrelayout_w4 },
|
||||
|
||||
{ "gemm_w5a8i8_tiled", "gemm_nt_q", "gemm",
|
||||
"the 5-bit ASYMMETRIC weight x int8 activation GEMM for prefill row counts (ParoQuant int5): int8 "
|
||||
"WMMA over (code - zero), the weight and activation scales folded per 128 of K",
|
||||
"N a multiple of 16; K a multiple of 128; the activation scale per (row, 128 of K); weight in the "
|
||||
"int5 kernel's two planes (nibbles, then fifth bits); a partitioned weight (pb1/pb2) one launch a part",
|
||||
"I8 A (parts side by side) with an f32 scale per (row, part, 128), 5-bit W with an f16 scale and "
|
||||
"integer zero per 128 K, bf16 C, int32 accumulate per 128 of K",
|
||||
RAD_DOMAIN_DEVICE, R4D_PRIO_GEMM_SKINNY,
|
||||
ROW(cGemmNtW5A8I8), NOTUNE,
|
||||
nullptr, nullptr, r4d_rad_gemm_w5a8i8_tiled, r4d_rad_gemm_mxfp4a8_tiled_scratch,
|
||||
r4d_rad_layout_w5, r4d_rad_relayout_w5, nullptr, r4d_rad_unrelayout_w5 },
|
||||
|
||||
{ "gemm_w8a16_nt_m64", "gemm_nt_q", "gemm",
|
||||
"skinny GEMM with an 8-bit weight, 16x16x16 WMMA, split-K reduced in LDS",
|
||||
"M <= 64; N a multiple of 16; K divisible by SK*128; weight pre-permuted into fragment order, "
|
||||
@@ -5518,6 +5640,29 @@ 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 },
|
||||
|
||||
{ "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",
|
||||
"bf16 in, f16 out, parts side by side; 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_rotate, nullptr, r4d_rad_layout_givens_pairs,
|
||||
r4d_rad_relayout_givens_pairs, nullptr, r4d_rad_unrelayout_givens_pairs, nullptr,
|
||||
r4d_rad_givens_rotate_describe },
|
||||
|
||||
{ "quant_act_i8g", "quant_act_i8g", "quant",
|
||||
"per-(row, 128-column) symmetric int8 quantisation of a bf16 activation",
|
||||
"quant_act_fp8's: n a multiple of 4, group 128, a ragged last group written zero-padded",
|
||||
|
||||
Reference in new issue
Block a user