Repository navigation
Conversation
bri-prism
force-pushed
the
cuda/pq2-j128-d1
branch
from
October 24, 2026 16:14
b51de6d to
05086fb
Compare
…prefill GGML_CUDA_PQ2_D1=1 quantizes the activations of PQ2_0 mat-muls with at least 128 columns with one scale per 128 values instead of one per 32 (the four D4 scale fields of a block_q8_1_mmq hold the same value), and the J=128 PQ2_0 kernel then sums the four 32-value integer products of a block in int32 and scales once. This is the D1 consumer of the Yukon cuda.fast Bonsai engine. Not bit-exact and off by default. It needs the J=128 kernel (it is ignored when GGML_CUDA_PQ2_J128 is off) and only applies when the mat-mul quantizes its own activations; a consumer of a shared quantized buffer still reads all four scales, which is correct for both layouts. Decode and small verify batches (fewer than 128 columns) are unchanged.
bri-prism
force-pushed
the
cuda/pq2-j128-d1
branch
from
October 24, 2026 16:46
05086fb to
5a792f5
Compare
Resolve the mmq_args conflicts by keeping prism's J_best and fusion fields and adding d1_y after them; the args initializer passes d1 after fusion_device, and the type switch takes prism's prec_src1 argument.
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.
The bit-exact J=128 PQ2_0 kernel from #374 is in
prism. This PR adds the opt-in D1 path.What
GGML_CUDA_PQ2_D1=1(opt-in, off by default, not bit-exact). PQ2_0 mat-muls with at least 128 columns quantize their activations with one scale per 128 values instead of one per 32. The four D4 scale fields of eachblock_q8_1_mmqthen hold the same value.Why
This is the remaining large prefill item in the Yukon cuda.fast Bonsai engine (MIT,
licenses/yukon-cudafast), measured on H200 on top of the bit-exact J=128 port.How
quantize.cu:quantize_mmq_q8_1gets ad1template flag (D4 layout only). It widens the amax shuffle from 8 lanes (32 values) to the whole warp (128 values). Rounding and the stored scale expression are unchanged, so the four D4 fields are equal. The plain, fused RMS-norm and fused SwiGLU entry points take a trailingd1 = falseargument.mmq.cu:d1is set only when all of these hold:ne11 >= 128, NVIDIA sm_90+, andGGML_CUDA_PQ2_D1=1with the J=128 kernel enabled;It is passed to the quantizer and in
mmq_args::d1_y. A consumer of a sharedexternal_q8keepsd1_y = falseand reads all four (equal) scales, which is correct for both layouts. The same holds for any shape that ends up on the generic kernel.mmq-pq2-j128.cuh:ggml_cuda_pq2_j128_d1_computeis the source's D1 consumer. It uses the accumulatingmma.syncand reads only scale 0 of each column record. The two D1 call sites in the segment loop are restored, and the launcher picksmul_mat_q_pq2_j128<..., D1=true>whenargs.d1_y.Quality gate
Threshold, set from existing anchors:
-ub 256instead of-ub 512, which changes MMQ tile shapes and stream-k partitions.Setup:
llama-perplexityon wiki.test.raw, with base logits from the exact J=128 build with D1 off (bit-identical toprism, per #374). There are 24 chunks × 512 for 9B and 4B, and one 16384-token chunk for the 9B long-context spot check.Verdict: passes.
Speed
llama-bench -fa 1 -ub 512 -b 2048 -r 5. ABBA, 3 pairs per size, exact J=128 (A) vs J=128 + D1 (B), H200.Test plan
mul_mat_q_pq2_j128<1,0,0,1,1>(D1) has 181 launches and 42.5% of GPU time;quantize_mmq_q8_1<D4,0,0,0,1>(D1 quantizer) has 197 launches;-lv 4, the J=128 log line appears in the D1 perplexity run.GGML_CUDA_PQ2_D1unset, MUL_MAT outputs on 25 PQ2_0 shapes are bitwise identical toprism.-o MUL_MATpasses 1630/1630 withGGML_CUDA_PQ2_D1=1, within the suite tolerance vs CPU.cc, as cuda: PQ2_0 J=128 prefill kernel numerically identical to MMQ, +5-16% prefill on H200, default on for Hopper #374's default does.