Skip to content

Pascal (sm_61) PQ2_0 mat-vec for 1-4 columns: +17% on Ternary-Bonsai-2-9B with MTP, bit-identical output - #368

Merged
bri-prism merged 1 commit into
PrismML-Eng:prismfrom
ArtyomITA:pascal-pq2_0-matvec
Oct 19, 2026
Merged

bri-prism merged 1 commit into
PrismML-Eng:prismfrom
ArtyomITA:pascal-pq2_0-matvec

Conversation

@ArtyomITA

Copy link
Copy Markdown

Overview

This adds a PQ2_0 mat-vec for 1-4 columns on Pascal (sm_61) in ggml/src/ggml-cuda/ggml-cuda.cu (+112 lines), used by single-token decode and by the MTP verify step. On sm_61 these went to the generic vec_dot, since the multi-column PQ2_0 kernel is only enabled on Ada. It keeps the exact summation order of the generic mmvq (warp per 4 rows, no shared memory or barriers, activations read in the PQ2 layout without per-weight decode), so the output is bit-identical.

GTX 1080, driver 581.57, CUDA 12.4, MSVC 14.38, Windows, PrismML fork commit 0082ac2 (branch prism)

Ternary-Bonsai-2-9B PQ2_0 + MTP Q8_0, llama-server, draft-mtp n-max 2, 1 slot, fa on, ~5k token context then 3 greedy answers of 384 tokens:
from 55.7 to 65.3 tok/s (+17.3%), all 5 pairs faster (+13.6% to +19.5%)
prefill 518 to 512 tok/s (-1.2%, noise)

With llama-bench (PQ2_0, no MTP, -r 3, average of 2 runs per build A-B-B-A):

build pp512 tg128
stock 629.7 47.4
patched 635.7 51.2

tg128 +8.1%, pp512 +1% (noise). Without MTP every step is 1 column, with MTP the verify step runs 3 columns and that is where the generic path was slowest.

How i measured: median of 5 runs per build, alternating A-B-A-B for thermal drift, first run with the GPU at 55 C. Anything under 3% i call it noise.

Correctness. Against logits saved from the stock build (llama-perplexity --kl-divergence):

ubatch mean KLD same top token
512 (prefill) 0 100%
3 (MTP verify) 0 100%
1 (decode) 1e-6 99.902%

The 99.902% at ubatch 1 is not from the patch: the stock build against its own saved logits gives the same 99.902%. A different summation order (correct on paper) moved the KL divergence to 7e-4, that's why the kernel copies the generic order. test-backend-ops on the patched build: 15873/15873 tests passed.

Additional information

This is the safest piece of a larger set of changes for the same model and card, tested together in one build: +51% in total (55.9 to 84.4 tok/s), same KLD floor, greedy text on 11k tokens identical, same texts as the stock build with --parallel 4. The other pieces are not part of this PR; this is what each one is worth in the full build (full build vs full build without that piece):

change worth in the full build
this mat-vec +36.9%
CUDA graphs on Pascal only for small batches (same idea as ggml-org#27721) +17.1%
fusions with identical output (add+rms_norm, rms_norm+mul+swiglu, F32 copies, ssm alpha+beta, conv state) +8.0%
fwht4096 + q8_1 quantize in the PQ2 layout in one kernel +4.5%
top-k for k <= 32 without argsort/cub, GDN concat +3.3%

If there is interest i can open them as separate PRs.

Requirements

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: YES - AI was used to produce the patch (an overnight multi-agent research run with a sealed evaluator, https://github.com/Partido-De-What/claude-plugins/blob/main/docs/research-mode.md), to run the benchmarks, and to translate this description from italian. Some of the explanation paragraphs were drafted by it too and then reviewed by me. I have reviewed the change and the benchmarks myself and can explain them, and i am responsible for everything submitted here.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ArtyomITA
ArtyomITA force-pushed the pascal-pq2_0-matvec branch from 533257f to e687f81 Compare October 17, 2026 18:05
@bri-prism
bri-prism merged commit 483bdab into PrismML-Eng:prism Oct 19, 2026
1 check passed
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.

2 participants