Repository navigation
cuda: PQ2_0 multi-column mat-vec on Hopper + its missing PDL wait (+10-14% MTP, +14-16% DFlash2 decode on H200) - #381
Merged
Merged
Conversation
Collaborator
Author
|
Final check on this branch as pushed (H200, job 29566): |
3 tasks done
…PDL wait mul_mat_vec_pq2_0_mc (3-8 columns, plain 2D) was Ada-only. On Hopper the generic mmvq handles those widths at a fraction of DRAM bandwidth; the dedicated kernel is 24-50% faster there (H200, 9B shapes: 12288x4096 n=4 19.3 -> 10.2 us, vocab head 248320x4096 n=4 332 -> 167 us). The kernel is launched through ggml_cuda_kernel_launch, which uses PDL on sm_90+, but never waited for the kernel that wrote its activations. On Ada there is no PDL so this never showed; on Hopper it read stale q8 data and the model produced garbage from the first token while test-backend-ops (small graphs) passed. Wait before reading vy and trigger launch completion after the K loop, as mul_mat_vec_q does; restrict-qualified locals instead of parameters, as in mul_mat_vec_q. H200, Ternary-Bonsai-2-9B PQ2_0-MTP, llama-server, 4 prompts x 128 greedy: MTP depth 3 +9.5..+13.2% decode, DFlash2 depth 7 +17..+20%, depth 15 -1..+5%, no speculation +-0. Not bit-exact vs the generic kernel (same as on Ada); greedy output is deterministic and diverges late on 2/4 prompts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PRQc3TQpn72qBxrUn5vKqo
bri-prism
force-pushed
the
cuda/pq2-mc-hopper
branch
from
October 24, 2026 16:55
1c904ac to
a4f9789
Compare
# Conflicts: # tests/test-backend-ops.cpp
This was referenced Oct 24, 2026
bri-prism
added a commit
that referenced
this pull request
Oct 25, 2026
… bias and gate+GLU fusion The 3-8 column PQ2_0 kernel (#381) needs no per-weight decode: the activation layout is permuted so the raw 2-bit codes pair with it. On H200 it is also the faster 1-column kernel for the larger projections (2.3-2.9 TB/s against 1.7-2.2 for the generic tall-row path). Plain decode calls the 1-column mat-vec with fused bias (residual) and fused gate+up+GLU, so the kernel gets the same epilogue as mul_mat_vec_q: x_bias added to the result, and with a gate a second weight matrix dotted against the same activations, gate_bias added, then the GLU op. Hopper takes 1-8 columns; elsewhere it stays at 3-8. GGML_CUDA_PQ2_MC_MIN overrides the lower bound.
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.
Overview
mul_mat_vec_pq2_0_mc(mmvq-pq2_0.cuh) is the dedicated PQ2_0 mat-vec for 3–8 columns in plain 2D. Until now it was gated to Ada (cc == 890). On Hopper those widths, which cover MTP verify and DFlash verify at depth 7, fell back to the generic mmvq at a fraction of DRAM bandwidth. Under MTP depth 3, nsys on an H200 put the 4-column PQ2_0 mat-vec at 32% of GPU time. This PR enables the kernel on Hopper (cc == 900).Enabling it required a fix. The kernel is launched through
ggml_cuda_kernel_launch, which uses PDL on sm_90+, but the kernel never waited for the kernel that writes its q8 activations. Ada has no PDL, so the bug never showed there. On Hopper it read stale activations:test-backend-opsstill passed (small graphs);llama-eval-callback, which synchronizes after every node, was correct, which is what pointed to the race.The kernel now waits before reading
vyand triggers launch completion after the K loop, the same asmul_mat_vec_q. The restrict qualifiers move to locals, also as inmul_mat_vec_q.Validation
All runs are on an H200 with CUDA 12.8 and a Release sm_90 build, at prism
73bfe6ccplus this patch.Kernel (
test-backend-ops perf):Across n = 3–8 the kernel is 24–50% faster. n = 1, 2, 12 and 16 are unchanged.
End to end: Ternary-Bonsai-2-9B PQ2_0-MTP-Q8_0 on llama-server, 4 prompts × 128 greedy tokens, 2 rounds. Decode tok/s, stock prism → this PR:
No speculation and DFlash2 depth 15 (16-column verify) are flat to slightly positive.
Combined with #380 (thin F32 mat-muls) and #379 (batched snapshot copies), MTP depth 3 reaches +17.6% to +22.8% and DFlash2 depth 7 +22% to +26% over stock prism.
Correctness
Blackwell (sm_100/120) and GB10 are left as they are because I didn't measure them.
Requirements
🤖 Generated with Claude Code
https://claude.ai/code/session_01PRQc3TQpn72qBxrUn5vKqo