GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — k-quants by ikawrakow · Pull Request #1684 · ggml-org/llama.cpp

Conversation

@ikawrakow

@ikawrakow ikawrakow commented Jun 3, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

What

This PR adds a series of 2-6 bit quantization methods, along with quantization mixes, as proposed in #1240 and #1256. Scalar, AVX2, ARM_NEON, and CUDA implementations are provided.

Why

This is best explained with the following graph, which shows perplexity on the wikitext dataset as a function of model size:
ppl_vs_size

Note that the x-axis (model size in GiB) is logarithmic. The various circles on the graph show the perplexity of different quantization mixes added by this PR (see details below for explanation). The different colors indicate the LLaMA variant used (7B in black, 13B in red, 30B in blue, 65B in magenta). The solid squares in the corresponding color represent (model size, perplexity) for the original fp16 model. The dashed lines are added for convenience to allow for a better judgement of how closely the quantized models approach the fp16 perplexity. As we can see from this graph, generation performance as measured by perplexity is basically a fairly smooth function of quantized model size, and the quantization types added by the PR allow the user to pick the best performing quantized model, given the limits of their compute resources (in terms of being able to fully load the model into memory, but also in terms of inference speed, which tends to depend on the model size). As a specific example, the 2-bit quantization of the 30B model fits on the 16 GB RTX 4080 GPU that I have available, while the others do not, resulting in a large difference in inference performance.

Perhaps worth noting is that the 6-bit quantized perplexity is within 0.1% or better from the original fp16 model.

Another interesting observation is that the relative quantization error (as measured by perplexity) does not decrease with increasing number of weights in the base model, as one might hypothesize based on the lower quantization error observed at 13B compared to 7B (see, e.g., this table on the main page). The 13B model is indeed somehow better amenable to quantization, but relative quantization error goes back to the 7B level for the 30B and 65B models. This is illustrated with the following graph, which represents an alternative view of the data in the above graph, by showing the relative difference to the fp16 model in percent. Note that now the x-axis, being the ratio of the quantized size to the fp16 model size, is linear, while the y-axis (percent error) is logarithmic.

ppl_vs_size_relative

How (Details)

In the existing ggml quantization types we have "type-0" (Q4_0, Q5_0) and "type-1" (Q4_1, Q5_1). In "type-0", weights w are obtained from quants q using w = d * q, where d is the block scale. In "type-1", weights are given by w = d * q + m, where m is the block minimum. I use this to describe the quantizations being added by this PR.

The following new quantization types are added to ggml:

  • GGML_TYPE_Q2_K - "type-1" 2-bit quantization in super-blocks containing 16 blocks, each block having 16 weight. Block scales and mins are quantized with 4 bits. This ends up effectively using 2.5625 bits per weight (bpw)
  • GGML_TYPE_Q3_K - "type-0" 3-bit quantization in super-blocks containing 16 blocks, each block having 16 weights. Scales are quantized with 6 bits. This end up using 3.4375 bpw.
  • GGML_TYPE_Q4_K - "type-1" 4-bit quantization in super-blocks containing 8 blocks, each block having 32 weights. Scales and mins are quantized with 6 bits. This ends up using 4.5 bpw.
  • GGML_TYPE_Q5_K - "type-1" 5-bit quantization. Same super-block structure as GGML_TYPE_Q4_K resulting in 5.5 bpw
  • GGML_TYPE_Q6_K - "type-0" 6-bit quantization. Super-blocks with 16 blocks, each block having 16 weights. Scales are quantized with 8 bits. This ends up using 6.5625 bpw
  • GGML_TYPE_Q8_K - "type-0" 8-bit quantization. Only used for quantizing intermediate results. The difference to the existing Q8_0 is that the block size is 256. All 2-6 bit dot products are implemented for this quantization type.

This is exposed via llama.cpp quantization types that define various "quantization mixes" as follows:

  • LLAMA_FTYPE_MOSTLY_Q2_K - uses GGML_TYPE_Q4_K for the attention.vw and feed_forward.w2 tensors, GGML_TYPE_Q2_K for the other tensors.
  • LLAMA_FTYPE_MOSTLY_Q3_K_S - uses GGML_TYPE_Q3_K for all tensors
  • LLAMA_FTYPE_MOSTLY_Q3_K_M - uses GGML_TYPE_Q4_K for the attention.wv, attention.wo, and feed_forward.w2 tensors, else GGML_TYPE_Q3_K
  • LLAMA_FTYPE_MOSTLY_Q3_K_L - uses GGML_TYPE_Q5_K for the attention.wv, attention.wo, and feed_forward.w2 tensors, else GGML_TYPE_Q3_K
  • LLAMA_FTYPE_MOSTLY_Q4_K_S - uses GGML_TYPE_Q4_K for all tensors
  • LLAMA_FTYPE_MOSTLY_Q4_K_M - uses GGML_TYPE_Q6_K for half of the attention.wv and feed_forward.w2 tensors, else GGML_TYPE_Q4_K
  • LLAMA_FTYPE_MOSTLY_Q5_K_S - uses GGML_TYPE_Q5_K for all tensors
  • LLAMA_FTYPE_MOSTLY_Q5_K_M - uses GGML_TYPE_Q6_K for half of the attention.wv and feed_forward.w2 tensors, else GGML_TYPE_Q5_K
  • LLAMA_FTYPE_MOSTLY_Q6_K- uses 6-bit quantization (GGML_TYPE_Q8_K) for all tensors

Not mentioned explicitly above is the fact that with this PR, all quantization variants use 6-bit quantization for the output.weight tensor. This lowers the perplexity of, e.g., Q4_0 by about 0.03 at 7B.

The code is quite lengthy, so it is added via separate files k_quants.h, k_qunats.c instead of being added to ggml.c. I think that it would be better to also factor out all other quantization types from ggml.c, but that is up to @ggerganov to decide.

Performance

The following table summarizes the performance results (perplexity, model size, run time for single token prediction). It is basically designed after the corresponding table on the main page).

Model Measure F16 Q2_K Q3_K_S Q3_K_M Q3_K_L Q4_K_S Q4_K_M Q5_K_S Q5_K_M Q6_K
7B perplexity 5.9066 6.7764 6.4571 6.1503 6.0869 6.0215 5.9601 5.9419 5.9208 5.9110
7B file size 13.0G 2.67G 2.75G 3.06G 3.35G 3.56G 3.80G 4.33G 4.45G 5.15G
7B ms/tok@4th, M2 Max 116 56 81 69 76 50 55 70 71 75
7B ms/tok@8th, M2 Max 111 36 46 36 46 36 40 44 46 51
7B ms/tok@4th, RTX-4080 60 15.5 18.6 17.0 17.7 15.5 16.0 16.7 16.9 18.3
7B ms/tok@4th, Ryzen7950X 214 57 58 61 67 68 71 81 82 93
13B perplexity 5.2543 5.8545 5.6033 5.4498 5.4063 5.3404 5.3002 5.2785 5.2638 5.2568
13B file size 25.0G 5.13G 5.27G 5.88G 6.45G 6.80G 7.32G 8.36G 8.60G 9.95G
13B ms/tok@4th, M2 Max 216 103 156 148 144 95 102 132 134 142
13B ms/tok@8th, M2 Max 213 67 83 77 83 68 73 81 84 95
13B ms/tok@4th, RTX-4080 - 25.3 29.2 29.3 25.5 26.2 26.2 28.6 28.9 30.0
13B ms/tok@4th, Ryzen7950X 414 109 113 118 129 130 137 156 161 180

I realize the above table is not easy to read, so adding a shortened version that shows a subset of the above data:

Model Measure F16 Q2_K Q3_K_M Q4_K_S Q5_K_S Q6_K
7B perplexity 5.9066 6.7764 6.1503 6.0215 5.9419 5.9110
7B file size 13.0G 2.67G 3.06G 3.56G 4.33G 5.15G
7B ms/tok @ 4th, M2 Max 116 56 69 50 70 75
7B ms/tok @ 8th, M2 Max 111 36 36 36 44 51
7B ms/tok @ 4th, RTX-4080 60 15.5 17.0 15.5 16.7 18.3
7B ms/tok @ 4th, Ryzen 214 57 61 68 81 93
13B perplexity 5.2543 5.8545 5.4498 5.3404 5.2785 5.2568
13B file size 25.0G 5.13G 5.88G 6.80G 8.36G 9.95G
13B ms/tok @ 4th, M2 Max 216 103 148 95 132 142
13B ms/tok @ 8th, M2 Max 213 67 77 68 81 95
13B ms/tok @ 4th, RTX-4080 - 25.3 29.3 26.2 28.6 30.0
13B ms/tok @ 4th, Ryzen 414 109 118 130 156 180

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

FNsi, lin72h, ggerganov, FSSRepo, swittk, VitorNaidek, mqy, quintmiam, wfkpk, remorses, and 177 more reacted with thumbs up emoji Carolmelon, utkarshshukla2912, and guofenggitlearning reacted with laugh emoji Green-Sky, FNsi, lin72h, KerfuffleV2, FSSRepo, VitorNaidek, RachidAR, drax-xard, quintmiam, Excigma, and 35 more reacted with hooray emoji cosmic-snow, tomaarsen, iceychris, lin72h, kerrickchan, lrq3000, he29-net, morgendigital, cx0, decoherencer, and 41 more reacted with heart emoji FNsi, lin72h, SlyEcho, cmp-nct, ryseek, Extraltodeus, Priestru, the-cashman, wfkpk, watsy0007, and 24 more reacted with rocket emoji mqy, iceychris, ArianJM, dukebw, zhouwg, horseee, silentoplayz, pseelam02, CraneCooker, caseyvanburen, and 3 more reacted with eyes emoji
All reactions
  • 👍 187 reactions
  • 😄 3 reactions
  • 🎉 45 reactions
  • ❤️ 51 reactions
  • 🚀 34 reactions
  • 👀 13 reactions
Iwan Kawrakow added 26 commits June 3, 2023 14:43
Iwan Kawrakow
Starting to add k-quantization to ggml
8673a41
I think it is better to have quantization separate from
ggml. For now just adding the k-quants there, but it would be
better to also factor out the existing ggml quantizations.
Iwan Kawrakow
Adding Q3_K and Q8_K (de)-quantization
b4f7134
Iwan Kawrakow
Q3_K now working on CUDA and AVX2/scalar
c93cce3
CUDA is not ideal - ~50% slower than Q4_0 for
single token prediction, about the same in batch
mode (perplexity). CPU single token is ~55 ms
(on Ryzen 7950X).
Iwan Kawrakow
Some improvement for Q3_K on CUDA
a3c0673
It is now ~22.5 ms/token on my GPU, so ~30% slower than Q4_0.
Iwan Kawrakow
Some more CUDA optimizations for Q3_K
3d8b1de
Single token is now 20.5 ms/token (~20% slower than Q4_0).
Perplexity is on par with Q4_0.
Iwan Kawrakow
Adding Q4_K - scalar, AVX2, CUDA
a0b8e9f
Performance is the same or perhaps very slightly better than Q4_0 on the CPU.
On the GPU, single token prediction is ~10% better than Q4_0,
batch mode (perplexity is about the same).
Iwan Kawrakow
Adding Q6_K - scalar, AVX2, CUDA
cf221af
Performance is ~40% lower compared to Q4_K on the CPU.
This is to be expected, considering that we are memory bound
on the CPU and the 6-bit model is ~44% larger than the 4-bit.
On the GPU, single token prediction is ~6% lower than Q4_0,
batch mode (perplexity) is even closer (but still slower).
Iwan Kawrakow
Adding Q5_K - scalar, AVX2, CUDA
b835d0f
Performance is ~20% lower compared to Q4_K on the CPU.
This is to be expected, considering that we are memory bound
on the CPU and the 5-bit model is ~22% larger than the 4-bit.
On the GPU, single token prediction is about the same as Q4_0
for both, single token and batch prediction.
Iwan Kawrakow
Per convention, all QX_K quantizations use Q5_K for output.weight
5c5191a
Iwan Kawrakow
Adding quantization mixes
d537b97
Iwan Kawrakow
Quantization mixes: didn't quite get what I wanted in the last commit
54f808d
Iwan Kawrakow
Q4_K dot product for ARM_NEON
a2533a7
Iwan Kawrakow
Q6_K dot product for ARM_NEON
5ca15ce
Iwan Kawrakow
Q5_K dot product for ARM_NEON
a197eb5
Iwan Kawrakow
Adding Q3_K dot for ARM_NEON
13264fa
It is 22% slower than Q4_K, despite the smaller model size.
On x86_64, where we are memory bound, the Q3_K model is
quite a bit faster than Q4_K.
Iwan Kawrakow
A very slightly faster ARM_NEON Q3_K dot
4faa040
Iwan Kawrakow
Adding Q2_K - just CUDA for now
b439efb
Token prediction is pretty good - about 15.5 ms on a RTX 4080.
Perplexity is about the same as Q4_K.
Iwan Kawrakow
Adding scalar and AVX2 Q2_K dot
8516fdf
Iwan Kawrakow
Adding ARM_NEON Q2_K dot
6ec7057
About the same performance as Q4_K.
Iwan Kawrakow
A slightly faster ARM_NEON Q2_K dot
7bcc376
Single token prediction is now ~36 ms on M2 Max.
The code is much simpler too.
Iwan Kawrakow
Fixed bug in Q2_K CUDA dot product kernel
e51ce72
Stranegly enough, for the few prompts I tried with the 7B model
the responses looked perfectly reasonable. Only realized something
is not quite right when I tried the larger models and started getting
nonse back.

In any case, Q2_K single token evaluation time on an RTX 4080 in a Ryzen7950X
box iusing CUDA and model fully loaded on the GPU are
  ~15.5 ms for 7B, ~25.4 ms for 13B, and ~55.8 ms for 30B.
The max number of layers that fit in VRAM for The 65B is 32.
With that, we get ~330 ms per token, which is not that much faster
than just running on the CPU (~470 ms per token).
Iwan Kawrakow
Don't print zeros/NaNs when no count histogram has been collected
c5959d5
Iwan Kawrakow
A 10% faster CUDA vector dot kernel for Q3_K
9a9c5a0
Q3_K is now running at ~18.5 ms / token on CUDA,
so the gap to Q4_0 is only 10%.
It seems memory acccess pattern is more important for
performance than the amount of computation the kernel
does.
Iwan Kawrakow
A slightly daster Q4_K AVX2 dot product
894210a
For perplexity, where we are less memory bound, time per
pass drops by ~5%. Barely measurable difference for single
token prediction.
Iwan Kawrakow
A slightly faster ARM_NEON A4_K dot product
abd99a8
Iwan Kawrakow
Minor
8f5d42d
@ikawrakow
ikawrakow requested a review from ggerganov June 3, 2023 15:24
github-actions[bot]

This comment was marked as off-topic.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Iwan Kawrakow
Fix quantization error test
6ef1382
We cannot possibly be expecting rmse < 0.002 for 2- and 3-bit
quantization variants.
github-actions[bot]

This comment was marked as off-topic.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@asomoza asomoza mentioned this pull request Aug 19, 2024
NF4 Flux params in diffusers huggingface/diffusers#9165
Closed
@fedric95

fedric95 commented Sep 8, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

So The "2.5625 bits per weight" is not the final figure for Q2_K? I think the figure is around 3.3-3.4?

The figure is 2.5625 bpw for the tensors quantized with 2 bits and 4.5 bpw for the tensors quantized with 4 bits. The specific quantization mix exposed as LLAMA_FTYPE_MOSTLY_Q2_K results in

((11008 + 2*4096)*4.5 + (2*11008 + 2*4096)*2.5625)/(3*11008 + 4*4096) = 3.315 bpw

for the LLaMA 7B model (ignoring 1-d tensors, which always remain as f32 in llama.cpp).

I know that is an old comment and I am sorry abou that, but it would be great to know how you ended up with this formula, I am trying to replicate it for also other quantization schemas and other models

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@BarfingLemurs BarfingLemurs mentioned this pull request Sep 26, 2024
about precision loss microsoft/T-MAC#52
Closed
@HAOYON-666

HAOYON-666 commented Sep 29, 2024

Copy link
Copy Markdown

(myenv) (base) root@master-22:/data/zhy/tools/llama.cpp/build_cuda/bin# ./main -m /data/zhy/models/Llama-3-chinese-8b-instruct-v3-q4_k_m/llama-3-chinese-8b-instruct-v3-q4_k_m.gguf
-n -1
-ngl 256
-t 12
--color
-r "User:"
--in-prefix " "
-i
-p
User:'想聊聊什么话题呢?聊聊吗?
bash: ./main: 没有那个文件或目录

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@HAOYON-666

HAOYON-666 commented Sep 29, 2024

Copy link
Copy Markdown

please give me some suggestion

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@QingtaoLi1 QingtaoLi1 mentioned this pull request Nov 5, 2024
Introduce New Lookup-Table(LUT)-Based Matrix Multiplication Method #10181
Open
2 of 4 tasks
@SamuelHafner

SamuelHafner commented Nov 13, 2024

Copy link
Copy Markdown

Thank you for your work. But do you know the original papers of quantizitation types

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Green-Sky

Green-Sky commented Nov 13, 2024

Copy link
Copy Markdown
Collaborator

@SamuelHafner there is no original paper for k-quants. They where cooked up by @ikawrakow

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@SamuelHafner

SamuelHafner commented Nov 13, 2024

Copy link
Copy Markdown

@Green-Sky So in general there is no Paper for different k-quants. Like ollama use also kquants. So there i no paper?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ikawrakow

ikawrakow commented Nov 13, 2024

Copy link
Copy Markdown
Contributor Author

There are no papers on k- or i-quants because I don't like writing papers. Combined with me enjoying the luxury of not needing another paper on my CV, and me not looking for a job or for investment, I see no reason to go and advertise on arXiv.

On the other hand, not having published a paper (or papers) allows other quantization researchers to ignore k- and i-quants, despite HF being littered with GGUFs containing k- and i-quantized models. Which makes their new shiny quantization methods look better than they actually are. Which is good for keeping the hype wave going.

So, in short, a win-win 😃

shashanknimje, lin72h, The-Inscrutable-X, YunjieYu, CharlieASExp, divmgl, hsfzxjy, BXYMartin, dtlzhuangz, BayRanger, and 16 more reacted with thumbs up emoji arty-hlr, arashakb, unterumarmung, and Borzyszkowski reacted with thumbs down emoji Green-Sky, lin72h, fedric95, DavidZyy, jrudolph, genggng, YunjieYu, DeryabinIvan, divmgl, LeeKLTW, and 20 more reacted with laugh emoji robogast, ThatDocBoi, and OxillenGlow reacted with confused emoji lin72h, fellhorn, divmgl, morbalint, fiskrt, nevernever69, akshat-sj, abdur-rehman-ad, and kalaspuffar reacted with heart emoji robogast, StrideZhou, nevernever69, Puiching-Memory, and Sai-Suraj-27 reacted with eyes emoji
All reactions
  • 👍 26 reactions
  • 👎 4 reactions
  • 😄 30 reactions
  • 😕 3 reactions
  • ❤️ 9 reactions
  • 👀 5 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Bearsaerker Bearsaerker mentioned this pull request Mar 12, 2025
Eval bug: Gemma 3 extremly slow prompt processing when using quantized kv cache. #12352
Closed
@jiafatom jiafatom mentioned this pull request Apr 15, 2025
k quant intel/neural-compressor#2169
Closed
@lgyStoic

lgyStoic commented Apr 19, 2025

Copy link
Copy Markdown

Could someone please explain why the file sizes of q2_k and q3_k are not as small as expected? The q2_k model has 2.5625 bits per weight, while the q4_k model has 4.5 bits per weight. However, their file sizes do not correspond proportionally to this.

Q2_K is a quantization mix as explained in the PR. The attention.wv, attention.wo and feed_forward.w2 tensors are quantized with 4 bits (Q4_K) when using Q2_K. Without doing so, the perplexity becomes very high (around 9.0 for the 7B model). This is also discussed in #1256

sorry @ikawrakow , I am bit confused with how the 2.5625 come out ; as you description
GGML_TYPE_Q2_K - "type-1" 2-bit quantization in super-blocks containing 16 blocks, each block having 16 weight. Block scales and mins are quantized with 4 bits. This ends up effectively using 2.5625 bits per weight (bpw

So, I compute with this logic :
(16 weights) * (2 bit) + 4bit * 1scale + 4bit * 1zero_point, so the total bit in block is 40; and division with 16 weight, the result is 2.5, and the other result I suppose is not the same as your's.
image
could you has a deep explain, how 2.6525 comes out?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jrudolph

jrudolph commented Apr 19, 2025 via email

Copy link
Copy Markdown
Contributor
There's 2*16bit per superblock missing in your calculation. https://github.com/ggml-org/llama.cpp/blob/6408210082cc0a61b992b487be7e2ff2efbb9e36/ggml/src/ggml-common.h#L175 Garry Ling ***@***.***> schrieb am Sa., 19. Apr. 2025, 05:10:
…
Could someone please explain why the file sizes of q2_k and q3_k are not as small as expected? The q2_k model has 2.5625 bits per weight, while the q4_k model has 4.5 bits per weight. However, their file sizes do not correspond proportionally to this. Q2_K is a quantization mix as explained in the PR. The attention.wv, attention.wo and feed_forward.w2 tensors are quantized with 4 bits (Q4_K) when using Q2_K. Without doing so, the perplexity becomes very high (around 9.0 for the 7B model). This is also discussed in #1256 <#1256> sorry @ikawrakow <https://github.com/ikawrakow> , I am bit confused with how the 2.5625 come out ; as you description GGML_TYPE_Q2_K - "type-1" 2-bit quantization in super-blocks containing 16 blocks, each block having 16 weight. Block scales and mins are quantized with 4 bits. This ends up effectively using 2.5625 bits per weight (bpw So, I compute with this logic : (16 weights) * (2 bit) + 4bit * 1scale + 4bit * 1zero_point, so the total bit in block is 40; and division with 16 weight, the result is 2.5, and the other result I suppose is not the same as your's. image.png (view on web) <https://github.com/user-attachments/assets/4bb05eb0-f8ed-46c4-8b1f-251de1a77599> could you has a deep explain, how 2.6525 comes out? — Reply to this email directly, view it on GitHub <#1684 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AAACNDALZMI6MLOE5KYUM4L22G5CHAVCNFSM6AAAAAAYZLHGCCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDQMJWGQ4TAMRVGU> . You are receiving this because you are subscribed to this thread.Message ID: ***@***.***> *lgyStoic* left a comment (ggml-org/llama.cpp#1684) <#1684 (comment)> Could someone please explain why the file sizes of q2_k and q3_k are not as small as expected? The q2_k model has 2.5625 bits per weight, while the q4_k model has 4.5 bits per weight. However, their file sizes do not correspond proportionally to this. Q2_K is a quantization mix as explained in the PR. The attention.wv, attention.wo and feed_forward.w2 tensors are quantized with 4 bits (Q4_K) when using Q2_K. Without doing so, the perplexity becomes very high (around 9.0 for the 7B model). This is also discussed in #1256 <#1256> sorry @ikawrakow <https://github.com/ikawrakow> , I am bit confused with how the 2.5625 come out ; as you description GGML_TYPE_Q2_K - "type-1" 2-bit quantization in super-blocks containing 16 blocks, each block having 16 weight. Block scales and mins are quantized with 4 bits. This ends up effectively using 2.5625 bits per weight (bpw So, I compute with this logic : (16 weights) * (2 bit) + 4bit * 1scale + 4bit * 1zero_point, so the total bit in block is 40; and division with 16 weight, the result is 2.5, and the other result I suppose is not the same as your's. image.png (view on web) <https://github.com/user-attachments/assets/4bb05eb0-f8ed-46c4-8b1f-251de1a77599> could you has a deep explain, how 2.6525 comes out? — Reply to this email directly, view it on GitHub <#1684 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AAACNDALZMI6MLOE5KYUM4L22G5CHAVCNFSM6AAAAAAYZLHGCCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDQMJWGQ4TAMRVGU> . You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
lgyStoic reacted with thumbs up emoji lgyStoic reacted with laugh emoji
All reactions
  • 👍 1 reaction
  • 😄 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nickfraser nickfraser mentioned this pull request May 28, 2025
Feat (brevitas_examples/llm): GGUF export Xilinx/brevitas#1291
Merged
14 tasks
@mmwillet mmwillet mentioned this pull request May 31, 2025
Add and test quantization from Kokoro mmwillet/TTS.cpp#15
Closed
@MaoJianwei

MaoJianwei commented Jun 23, 2025

Copy link
Copy Markdown

Good reference. Thanks!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ikawrakow ikawrakow mentioned this pull request Jun 27, 2025
Use cuBLAS for large batches and quants with block size 16 ikawrakow/ik_llama.cpp#559
Merged
@jiangshibiao

jiangshibiao commented Sep 7, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

I'm reviewing the details for GGML_TYPE_Q?_K based on the above description and the merged code, and I have a question about Q2_K. The description says:

GGML_TYPE_Q2_K - "type-1" 2-bit quantization in super-blocks containing 16 blocks, each block having 16 weight. Block scales and mins are quantized with 4 bits. This ends up effectively using 2.5625 bits per weight (bpw)

My understanding is that the "type-1" quantization with 4-bit scales/mins will add 0.5 bpw. The quoted value of 2.5625 bpw would only make sense if the extra quantization overhead for the super-block were 16 bits in total.
Looking at the actual implementation:

// Effectively 2.625 bits per weight
typedef struct {
    uint8_t scales[QK_K/16]; // scales and mins, quantized with 4 bits
    uint8_t qs[QK_K/4];      // quants
    GGML_EXTENSION union {
        struct {
            ggml_half d;    // super-block scale for quantized scales
            ggml_half dmin; // super-block scale for quantized mins
        } GGML_COMMON_AGGR_S;
        ggml_half2 dm;
    } GGML_COMMON_AGGR_U;
} block_q2_K;
static_assert(sizeof(block_q2_K) == 2*sizeof(ggml_half) + QK_K/16 + QK_K/4, "wrong q2_K block size/padding");

From this struct layout, the extra overhead should be 32 bits (2 ggml_half values or 1 ggml_half2 ), which would make the effective cost reach 2.625 bpw, consistent with the code comments. My question is: Should the description reporting 2.5625 bpw be considered a mistake or outdated?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@michalharakal michalharakal mentioned this pull request Nov 23, 2025
[R] reasearch quantization SKaiNET-developers/SKaiNET#208
Closed
@qskousen qskousen mentioned this pull request Mar 26, 2026
Does ggufy support converting Q5_K_M, Q5_K_S, Q4_K_M, Q4_K_S, Q3_K_M, and Q3_K_S? qskousen/ggufy#1
Closed
Seunghhon pushed a commit to Seunghhon/llama.cpp that referenced this pull request Apr 26, 2026
@ikawrakow Iwan Kawrakow @ggerganov
ggml : add SOTA 2,3,4,5,6 bit k-quantizations (ggml-org#1684)
bb72f45
* Starting to add k-quantization to ggml

I think it is better to have quantization separate from
ggml. For now just adding the k-quants there, but it would be
better to also factor out the existing ggml quantizations.

* Adding Q3_K and Q8_K (de)-quantization

* Q3_K now working on CUDA and AVX2/scalar

CUDA is not ideal - ~50% slower than Q4_0 for
single token prediction, about the same in batch
mode (perplexity). CPU single token is ~55 ms
(on Ryzen 7950X).

* Some improvement for Q3_K on CUDA

It is now ~22.5 ms/token on my GPU, so ~30% slower than Q4_0.

* Some more CUDA optimizations for Q3_K

Single token is now 20.5 ms/token (~20% slower than Q4_0).
Perplexity is on par with Q4_0.

* Adding Q4_K - scalar, AVX2, CUDA

Performance is the same or perhaps very slightly better than Q4_0 on the CPU.
On the GPU, single token prediction is ~10% better than Q4_0,
batch mode (perplexity is about the same).

* Adding Q6_K - scalar, AVX2, CUDA

Performance is ~40% lower compared to Q4_K on the CPU.
This is to be expected, considering that we are memory bound
on the CPU and the 6-bit model is ~44% larger than the 4-bit.
On the GPU, single token prediction is ~6% lower than Q4_0,
batch mode (perplexity) is even closer (but still slower).

* Adding Q5_K - scalar, AVX2, CUDA

Performance is ~20% lower compared to Q4_K on the CPU.
This is to be expected, considering that we are memory bound
on the CPU and the 5-bit model is ~22% larger than the 4-bit.
On the GPU, single token prediction is about the same as Q4_0
for both, single token and batch prediction.

* Per convention, all QX_K quantizations use Q5_K for output.weight

* Adding quantization mixes

* Quantization mixes: didn't quite get what I wanted in the last commit

* Q4_K dot product for ARM_NEON

* Q6_K dot product for ARM_NEON

* Q5_K dot product for ARM_NEON

* Adding Q3_K dot for ARM_NEON

It is 22% slower than Q4_K, despite the smaller model size.
On x86_64, where we are memory bound, the Q3_K model is
quite a bit faster than Q4_K.

* A very slightly faster ARM_NEON Q3_K dot

* Adding Q2_K - just CUDA for now

Token prediction is pretty good - about 15.5 ms on a RTX 4080.
Perplexity is about the same as Q4_K.

* Adding scalar and AVX2 Q2_K dot

* Adding ARM_NEON Q2_K dot

About the same performance as Q4_K.

* A slightly faster ARM_NEON Q2_K dot

Single token prediction is now ~36 ms on M2 Max.
The code is much simpler too.

* Fixed bug in Q2_K CUDA dot product kernel

Stranegly enough, for the few prompts I tried with the 7B model
the responses looked perfectly reasonable. Only realized something
is not quite right when I tried the larger models and started getting
nonse back.

In any case, Q2_K single token evaluation time on an RTX 4080 in a Ryzen7950X
box iusing CUDA and model fully loaded on the GPU are
  ~15.5 ms for 7B, ~25.4 ms for 13B, and ~55.8 ms for 30B.
The max number of layers that fit in VRAM for The 65B is 32.
With that, we get ~330 ms per token, which is not that much faster
than just running on the CPU (~470 ms per token).

* Don't print zeros/NaNs when no count histogram has been collected

* A 10% faster CUDA vector dot kernel for Q3_K

Q3_K is now running at ~18.5 ms / token on CUDA,
so the gap to Q4_0 is only 10%.
It seems memory acccess pattern is more important for
performance than the amount of computation the kernel
does.

* A slightly daster Q4_K AVX2 dot product

For perplexity, where we are less memory bound, time per
pass drops by ~5%. Barely measurable difference for single
token prediction.

* A slightly faster ARM_NEON A4_K dot product

* Minor

* Fix quantization error test

We cannot possibly be expecting rmse < 0.002 for 2- and 3-bit
quantization variants.

* Fix docker build

I have been sloppy with vector reinterpret casts on ARM_NEON.
It seems clang is very forgiving in that regard.

* Added forgotten ggml.o dependence on k_quants.h to the Makefile

* Had unintentionally committed the Makefile with -Ofast enabled

* ggml : rename k_quants -> ggml-quants-k, use lowercase in code

---------

Co-authored-by: Iwan Kawrakow <[email protected]>
Co-authored-by: Georgi Gerganov <[email protected]>
phuongncn pushed a commit to phuongncn/llama.cpp-gx10-dgx-sparks-deepseekv4 that referenced this pull request Apr 28, 2026
@ikawrakow Iwan Kawrakow @ggerganov
ggml : add SOTA 2,3,4,5,6 bit k-quantizations (ggml-org#1684)
083663f
* Starting to add k-quantization to ggml

I think it is better to have quantization separate from
ggml. For now just adding the k-quants there, but it would be
better to also factor out the existing ggml quantizations.

* Adding Q3_K and Q8_K (de)-quantization

* Q3_K now working on CUDA and AVX2/scalar

CUDA is not ideal - ~50% slower than Q4_0 for
single token prediction, about the same in batch
mode (perplexity). CPU single token is ~55 ms
(on Ryzen 7950X).

* Some improvement for Q3_K on CUDA

It is now ~22.5 ms/token on my GPU, so ~30% slower than Q4_0.

* Some more CUDA optimizations for Q3_K

Single token is now 20.5 ms/token (~20% slower than Q4_0).
Perplexity is on par with Q4_0.

* Adding Q4_K - scalar, AVX2, CUDA

Performance is the same or perhaps very slightly better than Q4_0 on the CPU.
On the GPU, single token prediction is ~10% better than Q4_0,
batch mode (perplexity is about the same).

* Adding Q6_K - scalar, AVX2, CUDA

Performance is ~40% lower compared to Q4_K on the CPU.
This is to be expected, considering that we are memory bound
on the CPU and the 6-bit model is ~44% larger than the 4-bit.
On the GPU, single token prediction is ~6% lower than Q4_0,
batch mode (perplexity) is even closer (but still slower).

* Adding Q5_K - scalar, AVX2, CUDA

Performance is ~20% lower compared to Q4_K on the CPU.
This is to be expected, considering that we are memory bound
on the CPU and the 5-bit model is ~22% larger than the 4-bit.
On the GPU, single token prediction is about the same as Q4_0
for both, single token and batch prediction.

* Per convention, all QX_K quantizations use Q5_K for output.weight

* Adding quantization mixes

* Quantization mixes: didn't quite get what I wanted in the last commit

* Q4_K dot product for ARM_NEON

* Q6_K dot product for ARM_NEON

* Q5_K dot product for ARM_NEON

* Adding Q3_K dot for ARM_NEON

It is 22% slower than Q4_K, despite the smaller model size.
On x86_64, where we are memory bound, the Q3_K model is
quite a bit faster than Q4_K.

* A very slightly faster ARM_NEON Q3_K dot

* Adding Q2_K - just CUDA for now

Token prediction is pretty good - about 15.5 ms on a RTX 4080.
Perplexity is about the same as Q4_K.

* Adding scalar and AVX2 Q2_K dot

* Adding ARM_NEON Q2_K dot

About the same performance as Q4_K.

* A slightly faster ARM_NEON Q2_K dot

Single token prediction is now ~36 ms on M2 Max.
The code is much simpler too.

* Fixed bug in Q2_K CUDA dot product kernel

Stranegly enough, for the few prompts I tried with the 7B model
the responses looked perfectly reasonable. Only realized something
is not quite right when I tried the larger models and started getting
nonse back.

In any case, Q2_K single token evaluation time on an RTX 4080 in a Ryzen7950X
box iusing CUDA and model fully loaded on the GPU are
  ~15.5 ms for 7B, ~25.4 ms for 13B, and ~55.8 ms for 30B.
The max number of layers that fit in VRAM for The 65B is 32.
With that, we get ~330 ms per token, which is not that much faster
than just running on the CPU (~470 ms per token).

* Don't print zeros/NaNs when no count histogram has been collected

* A 10% faster CUDA vector dot kernel for Q3_K

Q3_K is now running at ~18.5 ms / token on CUDA,
so the gap to Q4_0 is only 10%.
It seems memory acccess pattern is more important for
performance than the amount of computation the kernel
does.

* A slightly daster Q4_K AVX2 dot product

For perplexity, where we are less memory bound, time per
pass drops by ~5%. Barely measurable difference for single
token prediction.

* A slightly faster ARM_NEON A4_K dot product

* Minor

* Fix quantization error test

We cannot possibly be expecting rmse < 0.002 for 2- and 3-bit
quantization variants.

* Fix docker build

I have been sloppy with vector reinterpret casts on ARM_NEON.
It seems clang is very forgiving in that regard.

* Added forgotten ggml.o dependence on k_quants.h to the Makefile

* Had unintentionally committed the Makefile with -Ofast enabled

* ggml : rename k_quants -> ggml-quants-k, use lowercase in code

---------

Co-authored-by: Iwan Kawrakow <[email protected]>
Co-authored-by: Georgi Gerganov <[email protected]>
ljubomirj pushed a commit to ljubomirj/llama.cpp that referenced this pull request May 6, 2026
@ikawrakow Iwan Kawrakow @ggerganov
ggml : add SOTA 2,3,4,5,6 bit k-quantizations (ggml-org#1684)
d5294ff
* Starting to add k-quantization to ggml

I think it is better to have quantization separate from
ggml. For now just adding the k-quants there, but it would be
better to also factor out the existing ggml quantizations.

* Adding Q3_K and Q8_K (de)-quantization

* Q3_K now working on CUDA and AVX2/scalar

CUDA is not ideal - ~50% slower than Q4_0 for
single token prediction, about the same in batch
mode (perplexity). CPU single token is ~55 ms
(on Ryzen 7950X).

* Some improvement for Q3_K on CUDA

It is now ~22.5 ms/token on my GPU, so ~30% slower than Q4_0.

* Some more CUDA optimizations for Q3_K

Single token is now 20.5 ms/token (~20% slower than Q4_0).
Perplexity is on par with Q4_0.

* Adding Q4_K - scalar, AVX2, CUDA

Performance is the same or perhaps very slightly better than Q4_0 on the CPU.
On the GPU, single token prediction is ~10% better than Q4_0,
batch mode (perplexity is about the same).

* Adding Q6_K - scalar, AVX2, CUDA

Performance is ~40% lower compared to Q4_K on the CPU.
This is to be expected, considering that we are memory bound
on the CPU and the 6-bit model is ~44% larger than the 4-bit.
On the GPU, single token prediction is ~6% lower than Q4_0,
batch mode (perplexity) is even closer (but still slower).

* Adding Q5_K - scalar, AVX2, CUDA

Performance is ~20% lower compared to Q4_K on the CPU.
This is to be expected, considering that we are memory bound
on the CPU and the 5-bit model is ~22% larger than the 4-bit.
On the GPU, single token prediction is about the same as Q4_0
for both, single token and batch prediction.

* Per convention, all QX_K quantizations use Q5_K for output.weight

* Adding quantization mixes

* Quantization mixes: didn't quite get what I wanted in the last commit

* Q4_K dot product for ARM_NEON

* Q6_K dot product for ARM_NEON

* Q5_K dot product for ARM_NEON

* Adding Q3_K dot for ARM_NEON

It is 22% slower than Q4_K, despite the smaller model size.
On x86_64, where we are memory bound, the Q3_K model is
quite a bit faster than Q4_K.

* A very slightly faster ARM_NEON Q3_K dot

* Adding Q2_K - just CUDA for now

Token prediction is pretty good - about 15.5 ms on a RTX 4080.
Perplexity is about the same as Q4_K.

* Adding scalar and AVX2 Q2_K dot

* Adding ARM_NEON Q2_K dot

About the same performance as Q4_K.

* A slightly faster ARM_NEON Q2_K dot

Single token prediction is now ~36 ms on M2 Max.
The code is much simpler too.

* Fixed bug in Q2_K CUDA dot product kernel

Stranegly enough, for the few prompts I tried with the 7B model
the responses looked perfectly reasonable. Only realized something
is not quite right when I tried the larger models and started getting
nonse back.

In any case, Q2_K single token evaluation time on an RTX 4080 in a Ryzen7950X
box iusing CUDA and model fully loaded on the GPU are
  ~15.5 ms for 7B, ~25.4 ms for 13B, and ~55.8 ms for 30B.
The max number of layers that fit in VRAM for The 65B is 32.
With that, we get ~330 ms per token, which is not that much faster
than just running on the CPU (~470 ms per token).

* Don't print zeros/NaNs when no count histogram has been collected

* A 10% faster CUDA vector dot kernel for Q3_K

Q3_K is now running at ~18.5 ms / token on CUDA,
so the gap to Q4_0 is only 10%.
It seems memory acccess pattern is more important for
performance than the amount of computation the kernel
does.

* A slightly daster Q4_K AVX2 dot product

For perplexity, where we are less memory bound, time per
pass drops by ~5%. Barely measurable difference for single
token prediction.

* A slightly faster ARM_NEON A4_K dot product

* Minor

* Fix quantization error test

We cannot possibly be expecting rmse < 0.002 for 2- and 3-bit
quantization variants.

* Fix docker build

I have been sloppy with vector reinterpret casts on ARM_NEON.
It seems clang is very forgiving in that regard.

* Added forgotten ggml.o dependence on k_quants.h to the Makefile

* Had unintentionally committed the Makefile with -Ofast enabled

* ggml : rename k_quants -> ggml-quants-k, use lowercase in code

---------

Co-authored-by: Iwan Kawrakow <[email protected]>
Co-authored-by: Georgi Gerganov <[email protected]>
AlexiAlp pushed a commit to minghaop/llama.cpp that referenced this pull request Jun 2, 2026
@ikawrakow Iwan Kawrakow @ggerganov
ggml : add SOTA 2,3,4,5,6 bit k-quantizations (ggml-org#1684)
32dc063
* Starting to add k-quantization to ggml

I think it is better to have quantization separate from
ggml. For now just adding the k-quants there, but it would be
better to also factor out the existing ggml quantizations.

* Adding Q3_K and Q8_K (de)-quantization

* Q3_K now working on CUDA and AVX2/scalar

CUDA is not ideal - ~50% slower than Q4_0 for
single token prediction, about the same in batch
mode (perplexity). CPU single token is ~55 ms
(on Ryzen 7950X).

* Some improvement for Q3_K on CUDA

It is now ~22.5 ms/token on my GPU, so ~30% slower than Q4_0.

* Some more CUDA optimizations for Q3_K

Single token is now 20.5 ms/token (~20% slower than Q4_0).
Perplexity is on par with Q4_0.

* Adding Q4_K - scalar, AVX2, CUDA

Performance is the same or perhaps very slightly better than Q4_0 on the CPU.
On the GPU, single token prediction is ~10% better than Q4_0,
batch mode (perplexity is about the same).

* Adding Q6_K - scalar, AVX2, CUDA

Performance is ~40% lower compared to Q4_K on the CPU.
This is to be expected, considering that we are memory bound
on the CPU and the 6-bit model is ~44% larger than the 4-bit.
On the GPU, single token prediction is ~6% lower than Q4_0,
batch mode (perplexity) is even closer (but still slower).

* Adding Q5_K - scalar, AVX2, CUDA

Performance is ~20% lower compared to Q4_K on the CPU.
This is to be expected, considering that we are memory bound
on the CPU and the 5-bit model is ~22% larger than the 4-bit.
On the GPU, single token prediction is about the same as Q4_0
for both, single token and batch prediction.

* Per convention, all QX_K quantizations use Q5_K for output.weight

* Adding quantization mixes

* Quantization mixes: didn't quite get what I wanted in the last commit

* Q4_K dot product for ARM_NEON

* Q6_K dot product for ARM_NEON

* Q5_K dot product for ARM_NEON

* Adding Q3_K dot for ARM_NEON

It is 22% slower than Q4_K, despite the smaller model size.
On x86_64, where we are memory bound, the Q3_K model is
quite a bit faster than Q4_K.

* A very slightly faster ARM_NEON Q3_K dot

* Adding Q2_K - just CUDA for now

Token prediction is pretty good - about 15.5 ms on a RTX 4080.
Perplexity is about the same as Q4_K.

* Adding scalar and AVX2 Q2_K dot

* Adding ARM_NEON Q2_K dot

About the same performance as Q4_K.

* A slightly faster ARM_NEON Q2_K dot

Single token prediction is now ~36 ms on M2 Max.
The code is much simpler too.

* Fixed bug in Q2_K CUDA dot product kernel

Stranegly enough, for the few prompts I tried with the 7B model
the responses looked perfectly reasonable. Only realized something
is not quite right when I tried the larger models and started getting
nonse back.

In any case, Q2_K single token evaluation time on an RTX 4080 in a Ryzen7950X
box iusing CUDA and model fully loaded on the GPU are
  ~15.5 ms for 7B, ~25.4 ms for 13B, and ~55.8 ms for 30B.
The max number of layers that fit in VRAM for The 65B is 32.
With that, we get ~330 ms per token, which is not that much faster
than just running on the CPU (~470 ms per token).

* Don't print zeros/NaNs when no count histogram has been collected

* A 10% faster CUDA vector dot kernel for Q3_K

Q3_K is now running at ~18.5 ms / token on CUDA,
so the gap to Q4_0 is only 10%.
It seems memory acccess pattern is more important for
performance than the amount of computation the kernel
does.

* A slightly daster Q4_K AVX2 dot product

For perplexity, where we are less memory bound, time per
pass drops by ~5%. Barely measurable difference for single
token prediction.

* A slightly faster ARM_NEON A4_K dot product

* Minor

* Fix quantization error test

We cannot possibly be expecting rmse < 0.002 for 2- and 3-bit
quantization variants.

* Fix docker build

I have been sloppy with vector reinterpret casts on ARM_NEON.
It seems clang is very forgiving in that regard.

* Added forgotten ggml.o dependence on k_quants.h to the Makefile

* Had unintentionally committed the Makefile with -Ofast enabled

* ggml : rename k_quants -> ggml-quants-k, use lowercase in code

---------

Co-authored-by: Iwan Kawrakow <[email protected]>
Co-authored-by: Georgi Gerganov <[email protected]>
AlexiAlp pushed a commit to minghaop/llama.cpp that referenced this pull request Jun 2, 2026
@ikawrakow Iwan Kawrakow @ggerganov
ggml : add SOTA 2,3,4,5,6 bit k-quantizations (ggml-org#1684)
ae0ead1
* Starting to add k-quantization to ggml

I think it is better to have quantization separate from
ggml. For now just adding the k-quants there, but it would be
better to also factor out the existing ggml quantizations.

* Adding Q3_K and Q8_K (de)-quantization

* Q3_K now working on CUDA and AVX2/scalar

CUDA is not ideal - ~50% slower than Q4_0 for
single token prediction, about the same in batch
mode (perplexity). CPU single token is ~55 ms
(on Ryzen 7950X).

* Some improvement for Q3_K on CUDA

It is now ~22.5 ms/token on my GPU, so ~30% slower than Q4_0.

* Some more CUDA optimizations for Q3_K

Single token is now 20.5 ms/token (~20% slower than Q4_0).
Perplexity is on par with Q4_0.

* Adding Q4_K - scalar, AVX2, CUDA

Performance is the same or perhaps very slightly better than Q4_0 on the CPU.
On the GPU, single token prediction is ~10% better than Q4_0,
batch mode (perplexity is about the same).

* Adding Q6_K - scalar, AVX2, CUDA

Performance is ~40% lower compared to Q4_K on the CPU.
This is to be expected, considering that we are memory bound
on the CPU and the 6-bit model is ~44% larger than the 4-bit.
On the GPU, single token prediction is ~6% lower than Q4_0,
batch mode (perplexity) is even closer (but still slower).

* Adding Q5_K - scalar, AVX2, CUDA

Performance is ~20% lower compared to Q4_K on the CPU.
This is to be expected, considering that we are memory bound
on the CPU and the 5-bit model is ~22% larger than the 4-bit.
On the GPU, single token prediction is about the same as Q4_0
for both, single token and batch prediction.

* Per convention, all QX_K quantizations use Q5_K for output.weight

* Adding quantization mixes

* Quantization mixes: didn't quite get what I wanted in the last commit

* Q4_K dot product for ARM_NEON

* Q6_K dot product for ARM_NEON

* Q5_K dot product for ARM_NEON

* Adding Q3_K dot for ARM_NEON

It is 22% slower than Q4_K, despite the smaller model size.
On x86_64, where we are memory bound, the Q3_K model is
quite a bit faster than Q4_K.

* A very slightly faster ARM_NEON Q3_K dot

* Adding Q2_K - just CUDA for now

Token prediction is pretty good - about 15.5 ms on a RTX 4080.
Perplexity is about the same as Q4_K.

* Adding scalar and AVX2 Q2_K dot

* Adding ARM_NEON Q2_K dot

About the same performance as Q4_K.

* A slightly faster ARM_NEON Q2_K dot

Single token prediction is now ~36 ms on M2 Max.
The code is much simpler too.

* Fixed bug in Q2_K CUDA dot product kernel

Stranegly enough, for the few prompts I tried with the 7B model
the responses looked perfectly reasonable. Only realized something
is not quite right when I tried the larger models and started getting
nonse back.

In any case, Q2_K single token evaluation time on an RTX 4080 in a Ryzen7950X
box iusing CUDA and model fully loaded on the GPU are
  ~15.5 ms for 7B, ~25.4 ms for 13B, and ~55.8 ms for 30B.
The max number of layers that fit in VRAM for The 65B is 32.
With that, we get ~330 ms per token, which is not that much faster
than just running on the CPU (~470 ms per token).

* Don't print zeros/NaNs when no count histogram has been collected

* A 10% faster CUDA vector dot kernel for Q3_K

Q3_K is now running at ~18.5 ms / token on CUDA,
so the gap to Q4_0 is only 10%.
It seems memory acccess pattern is more important for
performance than the amount of computation the kernel
does.

* A slightly daster Q4_K AVX2 dot product

For perplexity, where we are less memory bound, time per
pass drops by ~5%. Barely measurable difference for single
token prediction.

* A slightly faster ARM_NEON A4_K dot product

* Minor

* Fix quantization error test

We cannot possibly be expecting rmse < 0.002 for 2- and 3-bit
quantization variants.

* Fix docker build

I have been sloppy with vector reinterpret casts on ARM_NEON.
It seems clang is very forgiving in that regard.

* Added forgotten ggml.o dependence on k_quants.h to the Makefile

* Had unintentionally committed the Makefile with -Ofast enabled

* ggml : rename k_quants -> ggml-quants-k, use lowercase in code

---------

Co-authored-by: Iwan Kawrakow <[email protected]>
Co-authored-by: Georgi Gerganov <[email protected]>
This was referenced Oct 17, 2026
llm/inference: GGUF k-quants described as mixing precision within a tensor TokenCemetery/teach#162
Closed
fix(learning): correct k-quant description in llm/inference TokenCemetery/teach#164
Merged
This was referenced Nov 8, 2026
fix(content): reviewed corrections of errors reported in the vault (cross-checks of issue-50e, issue-49) DamienBecherini/ia-on-prem-vault#54
Merged
fix(content): reviewed corrections of errors reported in the vault (cross-checks of fix-2026-11-08-2) DamienBecherini/ia-on-prem-vault#57
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@github-actions github-actions[bot] github-actions[bot] left review comments
@ggerganov ggerganov ggerganov approved these changes
+1 more reviewer
@fleszar1 fleszar1 fleszar1 left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

high priority Very important issue Less than 4 bits Efforts related to viable quantized models using <4 bits research 🔬 Review Complexity : High Generally require indepth knowledge of LLMs or GPUs Tensor Encoding Scheme https://github.com/ggerganov/llama.cpp/wiki/Tensor-Encoding-Schemes

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

20 participants

@ikawrakow @KerfuffleV2 @Midaychi @EwoutH @0cc4m @TheBloke @AlvL1225 @shouyiwang @alankila @Alumniminium @bczreasons @mirek190 @okpatil4u @x4080 @pbronez @cosmic-snow @viperwasp @zhaohb @JohannesGaessler @RonanKMcGovern
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.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.