Skip to content

CUDA: batch-1 Q8_0 mat-vec against F32 activations, without the q8_1 quantize - #448

Open
danielhanchen wants to merge 7 commits into
base/upstream-8f50b1db9from
inkperf5-mmvq-b12681
Open

danielhanchen wants to merge 7 commits into
base/upstream-8f50b1db9from
inkperf5-mmvq-b12681

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

CUDA: batch-1 Q8_0 mat-vec against F32 activations, without the q8_1 quantize

For one src1 column (single-token decode) with Q8_0 weights, MMVQ first quantizes the F32 activations to q8_1 in a separate kernel, then runs the integer dot products. At batch 1 on Blackwell, that extra launch and the round trip through the q8_1 buffer are a visible share of every Q8_0 projection in decode.

This adds a dedicated kernel for that case on NVIDIA cc >= 10.0:

  • The Q8_0 weights are dequantized in registers (int8 to float through a byte permute, no I2F) and dotted with the F32 activations directly, so src1 is never quantized and the q8_1 quantize kernel is not launched.
  • The threads of a block split one row the same way MMVQ does: each thread takes 8 of the 32 quants of a block, with up to 4 such steps per thread (rows of up to 4096 columns). Two rows share a block, and the activation loads, once there are at least 8 rows per SM.
  • When src0 is in a weights buffer (nothing earlier in the graph writes it), its loads are issued before the PDL wait on src1.
  • It is used only when src0 is Q8_0, src1 and dst are F32 and contiguous, there is one column and one matrix (no broadcast), ne00 % 32 == 0, ne00 <= 4096, and the alignments the vector loads need hold. Everything else goes to the existing paths.
  • GGML_CUDA_DISABLE_MMVQ_F32_ACT=1 turns it off.

This is not bit-exact. The activations are no longer rounded to 8 bits before the dot product, so results change slightly against MMVQ. The effect is a small accuracy gain, shown below. Batches larger than one column are unchanged and match bit for bit.

Accuracy

KLD against the BF16 GGUF of the same model, wikitext-2 test, -c 512, 32 chunks, F16 KV, FA on, B200. The BF16 reference has no Q8_0 weights, so this path cannot engage while producing it. "off" is the same binary with GGML_CUDA_DISABLE_MMVQ_F32_ACT=1. Every arm was run twice, and the repeats are bit-identical, so the A/A floor is 0.

model ubatch arm PPL mean KLD 99.9% KLD same top token
UD-Q4_K_XL 1 off 6.430624 0.003406 +/- 0.000140 0.1487 97.708%
UD-Q4_K_XL 1 on 6.419730 0.003016 +/- 0.000103 0.1083 97.929%
UD-Q4_K_XL 512 off 6.418362 0.003278 +/- 0.000134 0.1206 97.941%
UD-Q4_K_XL 512 on 6.418362 0.003278 +/- 0.000134 0.1206 97.941%
UD-IQ3_XXS 1 off 6.545366 0.027801 +/- 0.000883 0.8319 93.223%
UD-IQ3_XXS 1 on 6.539152 0.027478 +/- 0.000788 0.7650 93.051%
UD-IQ3_XXS 512 off 6.543224 0.027816 +/- 0.000878 0.9218 93.174%
UD-IQ3_XXS 512 on 6.543224 0.027816 +/- 0.000878 0.9218 93.174%

The BF16 reference PPL is 6.4174. At ubatch 512 the path is not taken, and every value is identical. At ubatch 1, mean KLD is lower on both quants. Top-1 agreement moves by less than one standard error on IQ3_XXS and improves on Q4_K_XL.

Speed

llama-bench, B200 (exclusive), F16 KV, FA on, -r 3. There were 4 rounds interleaved ABBA, each round a fresh process per arm, and medians are over rounds. The A/A spread is the min-to-max range of the off arm across rounds. Both arms use the same binary and differ only by GGML_CUDA_DISABLE_MMVQ_F32_ACT=1.

model test off (t/s) on (t/s) change A/A spread
UD-Q4_K_XL tg128 113.17 124.13 +9.7% 2.1%
UD-Q4_K_XL tg128 @ d32768 100.73 108.68 +7.9% 0.2%
UD-Q4_K_XL pp512 5061.6 5150.6 within noise 8.9% (one cold round)
UD-Q4_K_XL pp512 @ d32768 3964.7 3957.3 within noise 0.5%
UD-IQ3_XXS tg128 113.51 120.47 +6.1% 0.4%
UD-IQ3_XXS tg128 @ d32768 99.79 107.48 +7.7% 7.0% (one outlier round)
UD-IQ3_XXS pp512 4975.6 5016.7 within noise 18.8% (one cold round)
UD-IQ3_XXS pp512 @ d32768 3886.2 3890.2 within noise 1.5%

Prompt processing does not use this path. Its spread comes from a single cold first round. Without that round the other three are within about 1.5%.

Testing

  • test-backend-ops -o MUL_MAT on CUDA0: 2916/2916. The Q8_0 x F32 one-column subset was also repeated 12 times, each 141/141.
  • New eval cases cover the shapes of the Inkling 2 projections: k = 2304, 3072, 4096 with 7, 384, 1024, 1185, 2304 and 3072 rows, plus a 3072 x 4128 case, which is past the column limit and checks the fallback. 1185 rows leaves a partial block when two rows share one. The perf cases include the LM head shape (201024 rows).
  • The second commit only changes tests. The first version also had cases with a single output row. The CPU reference rounds the activations to 8 bits and this path does not, so with one row the NMSE is the relative error of a single dot product. It exceeds the 5e-4 limit in roughly one random draw in eight (10 to 15% in a NumPy simulation; 3% with two rows, under 1% with three, 0 of 2000 with seven). Those cases now start at 7 rows. The kernel did not change.
  • Merges additively onto the current prebuilt pin set (aged b12676, b12681, b12690 bases) and onto the next pin set on the newer upstream base; every existing pin stays intact.

Not covered

  • Only NVIDIA cc >= 10.0 takes the new path, and only B200 was measured. Older NVIDIA GPUs, HIP, MUSA and other backends are unchanged and were not run.

Update: limit the F32-activation Q8_0 mat-vec to cc 10.x

New head 75c936de1f586ea369a7d828280c42217cdfa991, one commit on top of the current pin 410a1ff30e1. Two files change, +3/-2:

-    if (disabled || !GGML_CUDA_CC_IS_NVIDIA(cc) || cc < 1000) {
+    // only cc 10.x measured faster; consumer Blackwell (cc 12.x) decodes slower with it
+    if (disabled || !GGML_CUDA_CC_IS_NVIDIA(cc) || cc < 1000 || cc >= 1100) {

The header comment changes from cc >= 10.0 to cc 10.x. Nothing else changes. The kernel, the shape checks and the GGML_CUDA_DISABLE_MMVQ_F32_ACT kill switch are untouched.

Why

This pin enabled the path on every NVIDIA cc >= 10.0. Its speed evidence covers B200 (cc 10.0) only. On an RTX 5090 (cc 12.0) the path makes batch-1 decode slower than the existing quantize + MMVQ path. It also changes output against q8_1, so it should run only where it is measured to win. cc 11.x (Thor) was never measured either, so it is excluded too. On cc 12.x the new head is the same as running the old head with GGML_CUDA_DISABLE_MMVQ_F32_ACT=1.

Prebuilt model

The prebuilt is the aged upstream b#### plus the pins in scripts/unsloth/pr-set.json, merged in order. This change stays inside #448's own lines and does not touch any other pin.

Pin set merge

Simulated at b13024 with the next-round pr-set (67 pins) and #448 repinned to 75c936de1f5. Every pin merges, pin_contract reports all 67 pins intact, merge_checks is clean, and the new gate line is present in the merged tree.

RTX 5090 (sm_120a, CUDA 13.0), pin-set tree

Each arm ran 3 rotated rounds. Qwen4-35B-A3B UD-Q2_K_XL is fully on the GPU (UD-Q4_K_XL does not fit in 32 GB), FA on, llama-bench tg128 in t/s.

depth A + A2 median (A/A spread) B Akill
0 215.36 (1.3%) 220.76 (+2.5%) 220.18 (+2.2%)
16384 202.71 (0.7%) 207.52 (+2.4%) 208.56 (+2.9%)
65536 187.49 (1.2%) 191.39 (+2.1%) 191.59 (+2.2%)

An independent repeat on another 5090 used Qwen4 UD-Q4_K_XL, comparing the old head with and without the kill switch. Decode went from 216.8 to 221.6 t/s at depth 0 (+2.2%, A/A 221.6 vs 221.6) and from 194.4 to 198.2 t/s at 64K (+1.9%).

With MTP (draft 2, llama-server), decode is unchanged within noise. The verify batch has more than one column, so it never takes this path.

prompt B vs A A/A spread
chat turn -1.0% 0.5%
~15K tokens +0.1% 2.3%
~42K tokens +1.8% 5.5%

At the chat turn, draft acceptance is 0.644 on A and 0.634 on B. Akill gives the same 0.634 as B.

Greedy output, RTX 5090

llama-completion -no-cnv --temp 0 -s 42 -n 128, md5 of the output.

model A Akill B
Qwen4-35B-A3B UD-Q2_K_XL 7d3491a6 83ecf3a7 83ecf3a7
Qwen3.8-27B UD-Q4_K_XL 9a78f88f 9a78f88f 9a78f88f
Inkling-2-Mini UD-IQ1_S fe1e3574 74e9885e 74e9885e
Qwen3.8-Flash-Next UD-IQ1_S (--cpu-moe) 9f40a5ce 7cca4c97 7cca4c97

B matches the kill-switch output on every model. Where a model has Q8_0 tensors, B differs from A as expected. Qwen3.8-27B does not reach the path and is identical in all three arms.

cc 10.x

On cc 10.x the code path is the same as before, since only cc >= 11.0 is newly excluded. The B200 numbers in this PR's description still apply: +9.7% tg128 and +7.9% at 32K on UD-Q4_K_XL, +6.1% / +7.7% on UD-IQ3_XXS. B200 was not re-run for this change.

Not covered

  • No B200 re-run, since the cc 10.x code path is unchanged.
  • cc 11.x was not run on any hardware.
  • MTP text identity was not checked by md5. The greedy runs above cover output identity.

…quantize

One src1 column of Q8_0 weights on NVIDIA cc >= 10.0: the weights are dequantized in registers and dotted with the
F32 activations, so src1 is not quantized to q8_1 first. Weight loads are issued before the PDL wait when src0 is a
weight. Changes rounding against MMVQ (the activations are no longer rounded to 8 bits).
Kill switch: GGML_CUDA_DISABLE_MMVQ_F32_ACT.
The reference rounds the activations to 8 bits while the CUDA F32 activation path does not, so with one or two
output rows the NMSE of a single dot product goes over 5e-4 in a few percent to one in eight random draws.
Use 7 rows or more, and add 1185 rows for the partial block of the two rows per block launch.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-25T02:44:09.465931Z e148684 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@danielhanchen
danielhanchen changed the base branch from master to base/upstream-d141011c2 November 25, 2026 02:42
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: e148684e17

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

danielhanchen added a commit that referenced this pull request Nov 25, 2026
…, take #414 0cbe311, add #447 and #448, drop #427 and #428 (#451)

Upstream b12696..b12719 changed the Inkling 2 code the pins touch (DSpark
drafter, clip on ggml_l2_norm, depth mix weighted sum order, MMVF int64
offsets), so the old pins no longer merge. Each pin branch merged upstream
33aeb17 (b12720) and keeps upstream's code as is:

- #378: e1b2a33 -> ba3ad42
- #405: b5ed9f2 -> b14ca2b
- #386: a8ca6da -> 7280c5e
- #431: f44881a -> 5373aec

Also:
- #414: 74a0ffc -> 0cbe311 (HIP build of the depth mix fusion)
- add #447 0bc8e1c and #448 e148684, with their feature-checks.json entries
- drop #427 and #428: the base carries both CUDA changes

Every pin moves by fast-forward. Only for a base at or past b12720.
@danielhanchen
danielhanchen changed the base branch from base/upstream-d141011c2 to base/upstream-b671865c7 November 28, 2026 05:07
@danielhanchen
danielhanchen changed the base branch from base/upstream-b671865c7 to base/upstream-a38695013 November 28, 2026 07:04
@danielhanchen
danielhanchen changed the base branch from base/upstream-a38695013 to base/upstream-94f17f659 December 2, 2026 15:08
danielhanchen added a commit that referenced this pull request Dec 2, 2026
#378, #385, #386 and #431 merge upstream aa631e0 (FA bias API cleanup,
b12859); #378 also keeps the Inkling router soft_max off the new short-row
kernels (CUDA b12878, Vulkan b12916). #448 merges b12922 (few-row MMQ for
NVFP4 adds a dst argument to ggml_cuda_should_use_mmq_few).

feature-checks: add inkling2-expert-scales (MUL_MAT_ID with weight scales).
danielhanchen added a commit that referenced this pull request Dec 3, 2026
fix #396, pin #469 #470 (#473)

* pr-set : pin #464, default a missing NVFP4 / FP8 weight scale to 1.0

* pr-set : repin #378 #385 #386 #431 #448 for upstream b12859..b12927

#378, #385, #386 and #431 merge upstream aa631e0 (FA bias API cleanup,
b12859); #378 also keeps the Inkling router soft_max off the new short-row
kernels (CUDA b12878, Vulkan b12916). #448 merges b12922 (few-row MMQ for
NVFP4 adds a dst argument to ggml_cuda_should_use_mmq_few).

feature-checks: add inkling2-expert-scales (MUL_MAT_ID with weight scales).

* pr-set : repin #378 to keep the Inkling router soft_max on the pre-b12878 Metal kernel

* pr-set : repin #378 #386 #431 for b12939 (rpc SUPPORTS_OP, BF16 supports_op), comment-only repins of #241 #243

* pr-set : drop #462, upstream took the same short conv fusion in b12942

* pr-set : pin #469 (greedy argmax of the logits row)

* pr-set : repin #418 for the upstream flat CONCAT kernel in b12957

* pr-set : pin #470 (CPU multi-row MUL_MAT_ID for few-row experts)

* pr-set : repin #396 (the model saver writes a shared host weight once)

* feature-checks : keep cuda-short-conv-in-place with owner null, upstream b12942 carries it

* pr-set : pin upstream's Qwen4 model support until the aged base carries it (b12969)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant