Skip to content

cuda: PQ2_0 multi-column mat-vec for 1-2 columns on Hopper, with bias and gate+GLU fusion: +4.1% decode, +1.4-3.1% MTP3 on H200 - #397

Merged
bri-prism merged 1 commit into
prismfrom
cuda/pq2-mc-1col
Oct 25, 2026
Merged

bri-prism merged 1 commit into
prismfrom
cuda/pq2-mc-1col

Conversation

@bri-prism

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

Copy link
Copy Markdown
Collaborator

What

The PQ2_0 multi-column mat-vec from #381 needs no per-weight decode: the activation layout is permuted so the raw 2-bit codes pair with the activation bytes.

On H200 it is also the faster 1-column kernel for the larger projections. Kernel times, including the activation quantize:

shape generic (tall rows) this PR change
10240×5120 8.2 µs 6.1 µs −26%
12288×4096 8.0 µs 6.0 µs −25%
17408×5120 11.8 µs 9.6 µs −19%
5120×17408 11.2 µs 10.1 µs −10%
248320×4096 (vocab) 120 µs 92 µs −23%

Plain decode calls the 1-column mat-vec with fused bias (the residual) and fused gate+up+GLU. The kernel therefore gets the same epilogue as mul_mat_vec_q:

  • x_bias is added to the result;
  • with a gate, a second weight matrix is dotted against the same activations, then gate_bias is added and the GLU op is applied.

Fusion is a template parameter. The unfused instantiation, used by every 3–8 column verify call, compiles to the same code as before. An earlier runtime bias check cost mc<8> 12–14% (27.2 → 31.0 µs) and DFlash7 −5%.

Scope:

  • Hopper: 1–8 columns go to the multi-column kernel.
  • Elsewhere: unchanged (3–8 columns), since 1–2 columns were not measured there.
  • Override: GGML_CUDA_PQ2_MC_MIN sets the lower bound; 3 gives the old behaviour.

Results on prism bf8c069 (H200, 9B PQ2_0, job 31830)

mode prism this PR with #395
no spec 367.2–369.0 +5.8 to +6.4% +7.9 to +8.5%
MTP3 420–678 +1.5 to +2.9% +2.5 to +4.0%
DFlash7 304–744 +0.1 to +0.4% −0.1 to +1.0%

27B unaffected (−0.1 to +0.3%). 2B PQ2_0 with #395: +7.5 to +7.8%. Tests: MUL_MAT_VEC_FUSION 538/538, MUL_MAT 1669/1669, Hadamard fusion suites pass.

Earlier results (H200, 9B PQ2_0, prism 97ea5ae, job 31406)

mode prism this PR GGML_CUDA_PQ2_MC_MIN=3
no spec 316.7–317.1 +4.1% −0.3 to −0.1%
MTP3 367–594 +1.4 to +3.1% −0.4 to +0.9%
DFlash7 268–662 +0.2 to +1.1% −0.3 to +0.5%

Exactness: not bit-identical to the generic 1-column kernel. The integer dot products are exact, but the float accumulation order differs. Greedy tokens are identical on 3 of 4 prompts; one near-tie flips (gen-lru, no spec). This is the same class as #381.

Stacked: on #395 + #396 with GGML_CUDA_GDN_FUSION=1, no-spec decode is +5.3 to +5.8% (370 → 390 tok/s, job 31362).

27B (PTQ1_0): not affected, since it uses a different weight type. No spec −0.1 to 0%, MTP2 −0.5 to +0.2%, tokens identical.

Tests

  • MUL_MAT_VEC_FUSION 525/525, including new PQ2_0 gate / bias / gate+bias cases at 1, 2, 4 and 8 tokens, K=4096.
  • MUL_MAT 1666/1666.
  • New perf cases: PQ2_0 at 1 column, 9B decode shapes.

… 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.
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