Repository navigation
CUDA: quantize a MUL_MAT src1 once for the MUL_MATs that read it - #416
Open
danielhanchen wants to merge 1 commit into
Open
danielhanchen wants to merge 1 commit into
danielhanchen wants to merge 1 commit into
Conversation
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.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
This was referenced Nov 23, 2026
erokhins
pushed a commit
to JetBrains-Hardware/llama.cpp
that referenced
this pull request
Nov 24, 2026
This branch has not been deployed
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.
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)
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)