Repository navigation
cuda: opt-in fused FWHT + q8_1 quantize for PQ2_0 mat-vecs (GGML_CUDA_FWHT_FUSION_PQ2=1), +4-9% decode on H200 - #377
Merged
Merged
Conversation
…_FWHT_FUSION_PQ2=1) The fused Hadamard-transform + q8_1 quantizer (ggml_cuda_try_fwht_q8) only accepted PTQ1_0 consumers, so PQ2_0 models still ran a standalone fwht_cuda_block plus one quantize_q8_1 per consuming mat-vec at every rotated activation. With GGML_CUDA_FWHT_FUSION_PQ2=1 the fusion also accepts PQ2_0 consumers (AoS q8_1 layout; all consumers must share one weight type) and the fused quantizer gains the 4096 transform width. The transform uses the shared ggml_cuda_fwht_block_butterfly and the same per-32 quantization as quantize_q8_1, so the q8_1 rows are bit-identical to the unfused pair. Default behaviour is unchanged: the PQ2_0 consumers and the 4096 width are only taken with the opt-in. Adds ROT_MATVEC to test-backend-ops: [SWIGLU ->] MUL(signs) -> RESHAPE -> Hadamard MUL_MAT -> PQ2_0/PTQ1_0 mat-vec at rotation widths 512 and 4096.
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.
What
GGML_CUDA_FWHT_FUSION_PQ2=1(off by default) lets the existing fused Hadamard transform + q8_1 quantizer (ggml_cuda_try_fwht_q8) feed PQ2_0 mat-vecs, not only PTQ1_0 ones. The fused quantizer also gains the 4096 transform width. A newROT_MATVECtest-backend-ops case covers the pattern for both weight types.Why
On H200, batch-1 decode of our PQ2_0 hybrid (gated-delta-net + attention) models is bound by launch count, not bandwidth. With CUDA graphs and PDL on, an nsys trace (
--cuda-graph-trace=node) of a decode step at 4k depth shows:Hazy Research's "No Bubbles" megakernel work reports 78% at batch 1. Every rotated activation on the PQ2_0 path still ran a standalone
fwht_cuda_blockand then onequantize_q8_1per consuming mat-vec. PTQ1_0 had already folded the two into a single launch. This PR applies the same fusion to PQ2_0. It is a first, small "megakernel-lite" step: it removes launches instead of shortening them.How
ggml_cuda_q8_1_layout_host. Layouts the fused kernel does not write, such as the Ada PQ2_0 multi-column layout, fall through.ggml_cuda_mul_mat_pq2_0_orderedquantizes src1 itself.fwht_quantize_q8_1gainsN = 4096. Fusion at that width is also opt-in, so default behaviour does not change for any type.ggml_cuda_fwht_block_butterflyand the same per-32 quantization asquantize_q8_1, so the q8_1 rows are identical to the unfused pair.Results (H200, sm_90 build, CUDA graphs + PDL on)
Speed: llama-bench tg128 at depth 4096,
-fa 1, r=5. Same binary, env off/on in ABBA order, 2 blocks per model.* That block contains one noisy run (605.9 +- 104 tok/s); the other three "on" runs were 691-693.
Launch counts (nsys). Kernels per decode token fall by 20% (A) and 19% (C). Every standalone
quantize_q8_1and all but onefwht_cuda_blockper token are gone. GPU busy time per token falls by 134 us (A) and 143 us (C).Opt-in off vs base
prism. ABBA ratios are 0.999-1.000 on all four models.Correctness.
prism, with the opt-in both off and on.prism:MUL_MAT: 1630/1630, off and on.MUL_MAT_HADAMARD: 34/34.ROT_MATVEC: 20/20, off and on. nsys confirms the fusedfwht_quantize_q8_1AoS kernels run at widths 512 and 4096.ARCLAB_GLU_ROTandARCLAB_ADD_NORM_ROT: the failing-case sets are identical to base (NaN on CUDA0 at K=17408 and others, 8/15 and 11/15 failing). This is pre-existing and not touched here.Notes