libr4d: w5a16 / w4a16_asym GEMM (5- and 4-bit asymmetric, any M, parts), givens_rotate kernel, layouts, selftest

This commit is contained in:
Malic Zilyas committed 2026-10-08 23:35:43 +02:00
1 parent ffa235bf0f
commit 9e9fce3aca
9 files changed
+722 -23

No files matched your search

+6 -1
View File
@@ -344,13 +344,14 @@ that points each name at its copy. A name two shards hold that no index entry se
The conversions of record live in `scripts/convfn.sh` and `scripts/convdspark.sh`, with their
recipes in `data/recipes/`.
**A release someone else already quantised is read as it ships.** Three forms are imported weight
**A release someone else already quantised is read as it ships.** Four forms are imported weight
by weight, so their quantised linears need no recipe rule:
| `quantization_config` | read as | |
|---|---|---|
| `quark`, MXFP4 weights (fp4, per_group 32, e8m0) | `fp4_e2m1*e8m0[1x32]` | byte for byte: the same codes and exponents. A checkpoint of this form is also served as it stands (§3.4) |
| `paroquant_mxfp4` (z-lab's ParoQuant on the MXFP4 grid: `format mxfp4`, `mxfp4_block 32`, `group_size 128`) | `fp4_e2m1*e8m0[1x32]/givens` | the codes and exponents byte for byte, plus the learned rotation as the encoding's `givens` tables: per checkpoint tensor the Givens pairs (made whole-row columns), angles and `1 / channel_scales`, a fused gate\|up or qkv\|z carrying one set a part. Convert-time only (the tables are built, not mapped); served by the rotating activation quantiser `givens_quant_act_fp8` and the ordinary MXFP4 GEMM (docs/OPS.md). Its fp8 heads and embedding (one f32 scale a row) are read exactly, for a recipe's `cast`/`rtn` rule |
| `paroquant`, `format int5-bitplane` (bits 5, group 128) and z-lab's plain `paroquant` (bits 4, group 128) | `u5*f16[1x128]-u8[1x128]/givens` and `u4*f16[1x128]-u8[1x128]/givens` | the AWQ-packed low nibbles (plus the fifth-bit plane) re-laid as a code bit stream along K, the f16 scales and the integer zero points transposed to `[N, K/128]`, and the rotation as the `givens` tables above. Convert-time only; served by `givens_rotate` and `gemm_nt_q` at `w5a16` / `w4a16_asym` over an f16 activation (docs/OPS.md) |
| `auto-round` with `packing_format: auto_round:auto_gptq`, and `gptq` (v1) | `i4*bf16[1x128]` or `i8*bf16[1x128]` | the GPTQ-packed codes transposed and made signed, the f16 scales rounded to bf16. Symmetric, group 128 or a multiple of it (per channel included), no act-order. Convert-time only, because the scales are not served as shipped |
The width is read per tensor, so a release mixing int4 experts with int8 projections imports both.
@@ -371,6 +372,10 @@ rad-convert ~/models/amd/Qwen3.8-27B-Quark-AWQ-MXFP4 --draft-model ~/models/z-la
rad-convert ~/models/MisterSnrub/Qwen3.8-27B-PARO-MXFP4-v2 --draft-model ~/models/z-lab/Qwen3.8-27B-DFlash2 \
--recipe data/recipes/q38-27b-paro-mxfp4-df2.recipe -o q38-27b-paro-mxfp4-df2.rad
# ParoQuant int5 (Launch80/Qwen3.8-27B-PARO-int5) and z-lab's int4 (z-lab/Qwen3.8-27B-PARO): same recipe
rad-convert ~/models/Launch80/Qwen3.8-27B-PARO-int5 --draft-model ~/models/z-lab/Qwen3.8-27B-DFlash2 \
--recipe data/recipes/q38-27b-paro-mxfp4-df2.recipe -o q38-27b-paro-int5-df2.rad
# An AutoRound int4 Qwen3.8-Flash-Next: its experts imported, its int4 projections made int8
rad-convert ~/models/ukisai/Swift-1.5-Qwen3.8-Flash-Next-W4A16-AutoRound \
--recipe data/recipes/qwen4exp-autoround-i8-hc8m.recipe -o swift-autoround.rad
+2 -1
View File
@@ -363,6 +363,7 @@ 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_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`? |
@@ -385,7 +386,7 @@ copies of the activation, written side by side -- `q` is `[M, parts * n]`, `scal
`[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. `pb1` absent is one part; `pb2` absent ends the second part at `N`. Only the `mxfp4a8` rows
planes. `givens_rotate` is the same rotation with no quantiser, `y` in its own dtype (f16), for the 16-bit-activation weights `w5a16` (ParoQuant int5: u5 codes, an f16 scale and a u8 zero point a 128 of K) and `w4a16_asym` (z-lab's int4, the same at 4 bits); their GEMM serves any `M` (rows past 64 run as chunks of 64). `pb1` absent is one part; `pb2` absent ends the second part at `N`. Only the `mxfp4a8` rows
read them, and the host rows that do not (`libavx`) refuse a call that names one rather than
contract against the wrong copy.