Repository navigation
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
Conversation
…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.
bri-prism
force-pushed
the
cuda/norm-fwht-q8
branch
from
October 25, 2026 14:08
d81b858 to
54f7dcb
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rebased onto prism bf8c069 (#391 and #396 merged), base retargeted to
prism.What
#391 fuses
[ADD +] RMS_NORM + MUL(w) + MUL(signs) + Hadamard MUL_MATinto 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.quantize_q8_1<layout>on the same F32 values.ggml_cuda_try_fwht_q8moves into a shared helper,ggml_cuda_fwht_q8_find_uses, with no behaviour change.GGML_CUDA_NORM_FWHT_Q8=0.Results on prism bf8c069 (H200, job 31830; tokens identical)
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)
GDN_FUSION=1(#383)GDN_FUSION=1Job 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.
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 withGGML_CUDA_FWHT_FUSION_PQ2=1, measured −1 to −2% under speculation (job 30882). That opt-in is left as it is.