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:
Malic Zilyas committed 2026-10-08 23:35:43 +02:00
1 parent c17f5fdc89
commit ec65b8cbeb
18 files changed
+318 -486

No files matched your search

+12 -10
View File
@@ -365,33 +365,35 @@ spelling of `act`, not the vocabulary's.
|---|---|---|
| `quant_act_fp8` | `M` `n` `group` `dtype` | `x` → `q`, `scale` |
| `had_quant_act_fp8` | `M` `n` `group` `dtype` | `x` → `q`, `scale` |
| `givens_quant_act_fp8` | `M` `n` `group` `dtype` `stages` `parts` | `x`, `pairs`w, `angle`w, `rscale`w → `q`, `scale` |
| `givens_quant_act_i8g` | `M` `n` `group` `dtype` `stages` `parts` | `x`, `pairs`w, `angle`w, `rscale`w → `q`, `scale` |
| `givens_dense_quant` | `M` `n` `group` `dtype` `parts` `out`:str | `x`, `tdense`w, `rscale`w → `q`, `scale` |
| `givens_rotate` | `M` `n` `group` `dtype` `stages` `parts` | `x`, `pairs`w, `angle`w, `rscale`w → `y` |
| `rmsnorm_quant_fp8` | `M` `n` `eps`:f64 `group` `dtype` `wadd`:f64/opt | `x`, `residual`:inout?, `w`w → `q`, `scale`, `out_bf16`? |
| `gated_quant_fp8` | `M` `n` `group` `dtype` `act`:str/opt | `gate_up` → `q`, `scale`, `out_bf16`? |
| `gemm_nt_q_gated` | `M` `N` `K` `group` `dtype` `act` | `a`, `a_scale`, `b`w, `b_scale`w → `q`, `scale`, `out_bf16`? |
### `givens_quant_act_fp8`: ParoQuant's rotated activation
### `givens_dense_quant`: ParoQuant's rotated activation
A weight stored with the `givens` transform (`abi/rad_encoding.h`) is `v = w . D . G_1 ... G_S`: the
channel scale `D` and `S` stages of disjoint pairwise rotations were applied to each row BEFORE it
was quantised (ParoQuant, z-lab), so the product the GEMM contracts is `<v, x'>` with
`x' = x . D^-1 . G_1 ... G_S` -- the activation takes the same rotation, forward, once a token.
`givens_quant_act_fp8` is that: `x / rscale`, then for each stage `a' = a cos t + b sin t,
b' = b cos t - a sin t` over its pairs, then `quant_act_fp8`'s quantiser (scale `amax / 448` per
`group` columns). The pairs are column indices of the row and each pair lies inside ONE scale group
(ParoQuant's are within groups of 128), so the kernel rotates a group at a time and the quantiser
sees the rotated group. The consumer is the plain `gemm_nt_q` at `mxfp4a8`; nothing in the weight's
codes or exponents changed.
`givens_dense_quant` is that: `x / rscale`, then the rotation, then a block-scaled quantiser (`out`
names it: `fp8` is `quant_act_fp8`'s, scale `amax / 448`; `i8` is `quant_act_i8g`'s, scale
`amax / 127`, round to nearest) per `group` columns. The rotation is applied as ONE dense 128 x 128
f16 matrix a (part, group) -- `tdense`, `[parts * n, 128]` -- the composition of the group's `stages`
rounds `a' = a cos t + b sin t, b' = b cos t - a sin t` over its pairs. A weight's `pairs` and `angle`
tables are column indices and angles of the row and each pair lies inside ONE scale group (ParoQuant's
are within groups of 128), so the matrices are the weight's own: rad-convert's layout hook for this op
composes them from the tables (`r4d_rad_layout_gdense`). The consumers are `gemm_nt_q` at `mxfp4a8`
(`out` fp8) and at `w4a8i8_asym` / `w5a8i8` (`out` i8); nothing in the weight's codes or exponents
changed.
A fused projection (gate|up, qkv|z) was rotated PER CHECKPOINT TENSOR, so it has `parts` rotated
copies of the activation, written side by side -- `q` is `[M, parts * n]`, `scale`
`[M, parts * n / group]` -- and `pairs` and `angle` stack the parts' `stages` rows each, `rscale`
one row a part. `gemm_nt_q` then takes `pb1` and `pb2`, the row bounds of the weight's parts: its
rows `[0, pb1)`, `[pb1, pb2)` and `[pb2, N)` meet copy 0, 1 and 2, and `a`/`a_scale` are the wide
planes. `givens_rotate` is the same rotation with no quantiser, `y` in its own dtype (f16), for the 16-bit-activation weights `w5a16` and `w4a16_asym`; their GEMM serves any `M` (rows past 64 run as chunks of 64). `givens_quant_act_i8g` is the rotation with `quant_act_i8g`'s quantiser (scale `amax / 127` per `group`), for `w5a8i8` / `w4a8i8_asym`. `pb1` absent is one part; `pb2` absent ends the second part at `N`. The `mxfp4a8` rows and the
planes. `givens_rotate` is the same rotation done stage by stage, with no quantiser, `y` in its own dtype (f16), for the 16-bit-activation weights `w5a16` and `w4a16_asym`; their GEMM serves any `M` (rows past 64 run as chunks of 64). The int8 activation of `w5a8i8` / `w4a8i8_asym` is `givens_dense_quant`'s at `out` `i8`. `pb1` absent is one part; `pb2` absent ends the second part at `N`. The `mxfp4a8` rows and the
asymmetric 4- and 5-bit rows (`w5a16`, `w4a16_asym`, `w5a8i8`, `w4a8i8_asym`) read them, and the
host rows that do not (`libavx`) refuse a call that names one rather than contract against the
wrong copy.