UPSTREAM PR #21089: ggml : add CPU TurboQuant KV cache types (TBQ3_0 / TBQ4_0)#1311
Open
loci-dev wants to merge 2 commits into
Open
UPSTREAM PR #21089: ggml : add CPU TurboQuant KV cache types (TBQ3_0 / TBQ4_0)#1311loci-dev wants to merge 2 commits into
loci-dev wants to merge 2 commits into
Conversation
loci-dev
had a problem deploying
to
PROD__AL_DEMO
March 28, 2026 03:07 — with
GitHub Actions
Failure
loci-dev
force-pushed
the
main
branch
9 times, most recently
from
April 4, 2026 02:17
a67a372 to
6ef937b
Compare
loci-dev
force-pushed
the
main
branch
8 times, most recently
from
April 11, 2026 02:17
34734bc to
55afbee
Compare
loci-dev
force-pushed
the
main
branch
9 times, most recently
from
April 18, 2026 02:17
d101579 to
63ab8d1
Compare
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.
Note
Source pull request: ggml-org/llama.cpp#21089
Summary
This PR adds CPU-only TurboQuant KV-cache support for two new cache types:
tbq3_0tbq4_0The scope is intentionally narrow for the first PR:
TBQonly (TBQP/ Q-prod is left for follow-up work)That keeps the initial landing aligned with the contributor guidance for new features and new
ggml_typeadditions: start with CPU support first, keep the PR reviewable, and add backend support in follow-up PRs.What changed
GGML_TYPE_TBQ3_0andGGML_TYPE_TBQ4_0vec_dotsupport so CPU flash attention can consume the new KV typesggmltype traits and quantization entry pointstbq3_0/tbq4_0in CLI KV-cache argumentsllama-benchandquantizesupport for the new typestest-quantize-fnsGET_ROWS,SET_ROWS,CPY, andFLASH_ATTN_EXTWhy this scope
I started from a broader TurboQuant implementation, but for the first upstream PR I cut the surface down to the part that is strongest on the current CPU-only evaluation:
tbq4_0is the best-balanced TurboQuant point heretbq3_0is the memory-first optionTBQP/ split-outlier path is better handled as follow-up work after the plainTBQCPU base landsBlock layout
tbq3_0: 98 bytes / 256 elements = 3.0625 bits / elementtbq4_0: 130 bytes / 256 elements = 4.0625 bits / elementCPU results
Model:
Qwen3.5-4B-Q4_K_M.ggufSettings:
flash_attn=onllama-benchwithpp32/tg8llama-perplexityonwikitext-2-raw/wiki.test.rawctx=256,chunks=4f16q8_0q4_0tbq3_0tbq4_0Key takeaways:
tbq4_0is the best-balanced TurboQuant point in this CPU-only sweep.tbq4_0reduces KV cache below stockq4_0while keeping similar KLD and slightly better perplexity in this run.tbq3_0pushes KV memory lower again, with the expected quality tradeoff.Plots
KV cache memory usage
Throughput
Compression vs speed
Ablation: KV size vs KLD
Validation
Built locally:
cmake -S . -B build-cpu-pr -DCMAKE_BUILD_TYPE=Releasecmake --build build-cpu-pr --target test-quantize-fns test-backend-ops llama-bench llama-cli llama-perplexity -j4Checks run:
./build-cpu-pr/bin/test-quantize-fns./build-cpu-pr/bin/test-backend-ops test -b CPU -o GET_ROWS,SET_ROWS,CPY,FLASH_ATTN_EXT -p 'tbq'llama-benchCPU comparison vsf16,q8_0,q4_0llama-perplexity+ KL divergence comparison vsf16Follow-up work
Planned follow-ups after this CPU base:
TBQP/ Q-prod variantsAcknowledgements
This work was informed by:
mudler/llama.cppfeat/turbo-quantAaryan-Kapoor/llama.cppturboquant-tq3_0TheTom/turboquant_plustonbistudio/turboquant-pytorchAI usage disclosure
AI tools were used in an assistive capacity for exploration, mechanical refactoring, test/benchmark scripting, and draft review text. The code and measurements in this PR were manually reviewed locally, the relevant checks were run manually, and I can explain the submitted changes and benchmark setup in detail.