Skip to content

CUDA: quantize a MUL_MAT src1 once for the MUL_MATs that read it - #416

Open
danielhanchen wants to merge 1 commit into
base/upstream-418fe97b5from
inkperf4-up-q8reuse
Open

danielhanchen wants to merge 1 commit into
base/upstream-418fe97b5from
inkperf4-up-q8reuse

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Pin for the prebuilt: upstream b12602 (418fe97) plus this one commit. Base branch base/upstream-418fe97b5.

What it changes

MUL_MAT nodes of a graph that read the same src1 tensor (the projections of one layer input) share its q8_1 quantization for MMVQ and for MMQ (per q8_1 layout). The quantized buffer is a pool allocation kept between nodes and dropped at the start and end of a graph, after any node whose output overlaps src1 (including the inner nodes of fused groups), and in concurrent stream regions. Only MUL_MAT nodes without ids use it. The native FP4 activation path (cc 12.x NVFP4 / MXFP4 W4A4) and MUL_MAT_ID are not touched.

The same bytes are reused, so the results are unchanged. GGML_CUDA_DISABLE_Q8_1_REUSE=1 turns it off; GGML_CUDA_Q8_1_REUSE_STATS=1 prints the hit count when the backend is freed. test-backend-ops gets MUL_MAT_SHARED_SRC1 (30 cases, with another src1 in between and with src1 overwritten in place between its readers; with the invalidation disabled 9 of the 10 in-place cases fail).

Evidence (B200, one exclusive card, load-gated runs)

  • Inkling-2-Mini UD-Q4_K_XL decode: quantize_q8_1 385 -> 249 per token. UD-Q8_K_XL has BF16 dense weights, so nothing changes there.
  • Share of the decode set: tg128 -1.5% on UD-Q8_K_XL, -6% on UD-Q4_K_XL (wider spread).
  • KLD against the pin set (UD-IQ1_S, UD-Q4_K_XL, Mainline_Support UD-IQ1_S; prefill, -ub 1/4, two GPUs): PPL string equal, mean KLD 0, top-1 100%.

Other NVIDIA GPUs (Colab T4, L4, A100-40GB, RTX PRO 6000 Blackwell Server; one card each, built from b12628 plus #399 plus the decode pins)

GPU (cc) file pp512 with it off tg128 with it off
T4 (7.5) UD-IQ1_S +1.6% +0.1%
L4 (8.9) UD-IQ1_S -0.6% -0.8%
L4 (8.9) UD-Q4_K_XL -0.4% -0.8%
A100 (8.0) UD-IQ1_S -0.3% -1.6%
A100 (8.0) UD-Q4_K_XL -0.4% -1.6%
A100 (8.0) UD-Q8_K_XL +0.2% +0.1%
RTX PRO 6000 (12.0) UD-IQ1_S -1.0% -2.1%
RTX PRO 6000 (12.0) UD-Q4_K_XL -0.5% -1.3%
RTX PRO 6000 (12.0) UD-Q8_K_XL +0.0% +0.0%
  • UD-Q8_K_XL has BF16 dense weights, so there is nothing to share (1.000). The T4 pp512 row (+1.6% with the reuse off) is inside T4's 3% spread for that metric.

MUL_MAT nodes of a graph that read the same src1 tensor (the projections of one
layer input) now share its q8_1 quantization for MMVQ and for MMQ (per q8_1
layout). The quantized buffer is a pool allocation kept between nodes and
dropped at the start and end of a graph, after any node whose output overlaps
src1, and in concurrent stream regions. Only MUL_MAT nodes without ids use it,
so no caller allocation can be live below it.

The same bytes are reused, so the results are unchanged. Set
GGML_CUDA_DISABLE_Q8_1_REUSE=1 to turn it off, GGML_CUDA_Q8_1_REUSE_STATS=1
prints the hit count when the backend is freed.

tests: MUL_MAT_SHARED_SRC1 with another src1 in between and with src1
overwritten in place between its readers.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 23, 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-23T02:26:50.062177Z d72c6be PR opened
ℹ️ 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.

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