Repository navigation
Slow prefill on small KV quants fixed - #27140
Cybertiron wants to merge 1 commit into
Conversation
|
Hi @Cybertiron, thanks for your contribution! Per our contribution guidelines, the automated PR checker found the following issue(s) that need your attention:
Please note that maintainers reserve the right to make final decisions on PRs. If you believe there is a mistake, please comment below. |
428ae50 to
665dac0
Compare
|
seems to work on a 3090 cool stuff |
|
I think you got a bit slow token generation. Maybe you did not get out of error? |
here's a bit of a cleaner experiment same exact model, same exact settings, just different executables; your branch is much faster. |
|
Thank you for sharing your settings! Here what I use - but not this is with my fix build from my repo https://github.com/Cybertiron/llama.cpp/releases/tag/b27109-quant-kv-fix not mainline llama.cpp build. On not yet fixed mainline llama.cpp you should use only -ctk q8_0 -ctv q8_0 (mixed/small quant KV falls back to CPU there and gets slow). My setup on a single RTX 3090:
Right now it's generating a 3D chess game in Python at ~31 t/s (GPU 97%, 220W). Your ngram-mod tip actually helped — about +27% t/s on code/math generation for me (single GPU only; on 2-GPU split it didn't help). Thanks again! |
|
Lowered KV cache to q3_K quants github.com/Cybertiron/llama.cpp-rtx3090-prefill-fix/releases/tag/ampere-kv-v0.1 |
|
the commit with the new q3_k quant and updated README from your repo bled into this PR; i don't think that's what you intended to do |
|
I will fix that |
|
Please remove the extra quant code and mark it as ready when you're done. |
6239571 to
665dac0
Compare
…l-org#27140) Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
I removed the extra quant code, it is original code. |
|
/bot review |
Automated code reviewI have enough context. Let me write the review. Code Review: PR #27140 - Slow prefill on small KV quants fixedReviewed the diff in I verified the dequant math and output layout of all four kernels against the reference helpers in Blocking(point 1) HIP/ROCm build portability of Will slow the review(point 2) Comments reference the issue/PR. Every new block is prefixed (point 3) Comment verbosity / restating code. The (point 4) Duplicated near-identical kernels. q4_0/q4_1 differ only in scale/min ( Nits(point 5) The kernel parameters are (point 6) Style: the new kernels use Notes for the contributor
This review was generated automatically by pi coding agent using |
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
|
+1 I hope maintainers get to review this sometime soon |
|
According to the llama.cpp AI usage policy:
|
JohannesGaessler
left a comment
There was a problem hiding this comment.
- There is a lot of code duplication between the kernels. If at all possible, please consolidate them into a single template.
- The existing dequantization kernels should be removed and the new ones should be used unconditionally. The check on
fp16_availableis only needed for cases where FP16 arithmetic is used (which these kernels don't). Type conversions are always fine.
Overview
I found an issue with quants, that they become very slow on prefill. Later I googled the exact issue. Found out that q_8 is working perfectly fine, but it did not compress enough memory for single gpu to use newest qwen 3.8 model. Tested each quant individually to get results, which were unsatisfactory:
All "after" numbers measured at the same ~9000 token prompt for a fair comparison. Before the fix the small quants collapse and time out at long prompts, so those are at shorter prompts:
At equal prompt length all quant KV types now run within ~2% of each other, so the fix makes them all as fast as q8_0.
Than tried reverse engineer to find the problem with opus 4.8. Because it is working on q_8 i decided that the fix will be easy, as AI can find patterns and apply similar patterns for smaller quants. q4_0 was successfull from the start, later I ran into issues with q4_1, q5_0, q5_1. It took several hours to recompile them (they also need GGML_CUDA_FA_ALL_QUANTS=ON to be enabled), but the issue was fixed. After re-testing at the same prompt length all quants run at about the same speed. Still though I think there is room for improvement, but for maximum memory squeeze and performance q4_0 looks like the sweet spot for now. For a little bit better quality use q8_0, or q5_1 which sits between q4_0 and q8_0 in quality.
Additional information
Fixes #27109. Tested on 2x RTX 3090 with Qwen 3.8 27B, outputs are numerically correct.
llama.cpp prebuild for rtx 3090 lower Quants fast prefill fix (if you don't want to compile): https://github.com/Cybertiron/llama.cpp/releases/tag/b27109-quant-kv-fix
Requirements