Skip to content

cuda: quantize to q8_1 inside the fused norm + Hadamard kernel for PQ2_0 consumers, bit-identical, +2% decode on H200 (stacked on #391) - #395

Merged
bri-prism merged 1 commit into
prismfrom
cuda/norm-fwht-q8
Oct 25, 2026
Merged

bri-prism merged 1 commit into
prismfrom
cuda/norm-fwht-q8

Conversation

@bri-prism

@bri-prism bri-prism commented Oct 24, 2026 •

Copy link
Copy Markdown
Collaborator

Rebased onto prism bf8c069 (#391 and #396 merged), base retargeted to prism.

What

#391 fuses [ADD +] RMS_NORM + MUL(w) + MUL(signs) + Hadamard MUL_MAT into one kernel at both norm sites of every Bonsai 2 layer. Its F32 output is then quantized to q8_1 separately by each consuming mat-vec: qkv and z at the layer start, gate and up at the FFN input.

With this PR, the fused kernel writes the q8_1 rows itself when every use of the transform output is a PQ2_0 mat-vec on the mmvq path:

The mat-vecs find the rows through ctx.fwht_q8(), the same handoff as #377, and skip their quantize launch.

Results on prism bf8c069 (H200, job 31830; tokens identical)

model / mode prism + this PR + this PR + #397
9B no spec, 4 prompts 367.2–369.0 +2.2 to +2.6% +7.9 to +8.5%
9B MTP3 420–678 +0.1 to +0.9% +2.5 to +4.0%
9B DFlash7 304–744 −0.1 to +0.6% −0.1 to +1.0%
27B PTQ1_0 (no spec / MTP2) −0.1 to +0.3% (unaffected)
2B PQ2_0 no spec 662–664 +7.5 to +7.8%

Tests on this tip: ADD_RMS_NORM_HADAMARD 22/22, RMS_NORM_HADAMARD_LOOKAHEAD 18/18, MUL_MAT_HADAMARD 34/34, ROT_MATVEC 20/20, MUL_MAT_VEC_FUSION 522/522, MUL_MAT 1669/1669, GDN_CONV_CHAIN 34/34.

Earlier results (H200, 9B PQ2_0, prism 97ea5ae + #391; tokens identical in every cell)

#391 + this PR #391 + GDN_FUSION=1 (#383) + this PR + GDN_FUSION=1
no spec, 4 prompts 333.5–333.6 340.2–340.7 (+2.0 to +2.1%) +7.0 to +7.2% +9.2 to +9.4%
MTP3 — −0.6 to +0.2% −0.3 to +0.1% −0.3 to +0.1%
DFlash7 — −0.7 to +0.8% −0.4 to +0.1% −0.4 to +0.4%

Job 31055. The earlier base gave the same picture: no spec +0.9 to +2.3% (job 30880).

Tests

New PQ2_0-consumer variants of ADD_RMS_NORM_HADAMARD and RMS_NORM_HADAMARD_LOOKAHEAD (n 1024/4096 × 1, 2, 4, 8, 9 tokens): AoS, PQ2 and fallback paths.

Test Result
ADD_RMS_NORM_HADAMARD 22/22
RMS_NORM_HADAMARD_LOOKAHEAD 18/18
MUL_MAT_HADAMARD 34/34
ROT_MATVEC 20/20
GDN_CONV_CHAIN 6/6
MUL_MAT 1666/1666

nsys shows the q8 variants firing: layout 0 (AoS) and layout 3 (PQ2).

Tried and not included

Adding the PQ2 layout to fwht_quantize_q8_1, so that the o_proj and ffn_down transforms also quantize at verify widths with GGML_CUDA_FWHT_FUSION_PQ2=1, measured −1 to −2% under speculation (job 30882). That opt-in is left as it is.

…2_0 consumers

When every use of the transform output from #391's fused ADD+RMS_NORM+MUL+FWHT kernel
(either site) is a PQ2_0 mat-vec on the mmvq path, the kernel writes the q8_1 rows
directly: AoS at 1 column, the PQ2 layout at the multi-column widths. The qkv/z/gate/up
mat-vecs then find them through ctx.fwht_q8() and skip their quantize launch. Same
per-32 arithmetic and stores as quantize_q8_1<layout>, so the q8_1 rows are
bit-identical. The consumer scan of ggml_cuda_try_fwht_q8 moves into a shared helper
(ggml_cuda_fwht_q8_find_uses) with no change in behaviour. GGML_CUDA_NORM_FWHT_Q8=0
disables it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant