Topic 3 of 6 · 5 min read
Picking a quant level like Q4_K_M
Goal: Choose a quant level for a model that must fit a stated memory budget and explain what is given up.
Pick the highest quant level that fits your memory with room for context; Q4_K_M is the common default, and quality drops quickly below it.
Check yourself · 1 of 3
In the name Q4_K_M, what does the M stand for?
Why it matters
One model on the Hub may come in a dozen GGUF files from Q2 to Q8. The choice sets the size, the speed and how many mistakes the model makes. A level too high will not load. A level too low gives a model that looks fine in a chat and fails on harder tasks.
The levels
| Level | Bits (approx.) | What to expect |
|---|---|---|
| Q8_0 | about 8.5 | Almost indistinguishable from 16-bit; twice the size of Q4 |
| Q6_K | about 6.6 | Very close to 16-bit |
| Q5_K_M | about 5.7 | Small loss; good when you have spare memory |
| Q4_K_M | about 4.8 | The usual sweet spot of size and quality |
| Q3_K_M | about 3.9 | Visible loss, mainly on reasoning and code |
| Q2_K | about 3.4 | Large loss; only when nothing else fits |
The figures are the averages in llama.cpp's own tables; see the discussion reference for numbers per model.
K-quants and i-quants
K-quants (Q4_K, Q5_K) split weights into blocks with their own scales, and the suffix S, M, L says how many sensitive tensors get extra bits. M keeps some tensors at higher precision, so it beats S at a small size cost.
I-quants (IQ3_XS, IQ4_XS) use a lookup scheme that keeps more quality at very low bit counts. They are slower on some CPUs, and they are made with an importance matrix (the lowest ones require it).
Importance matrix
An importance matrix (imatrix) is a file made by running the model over sample text and recording which weights matter most. The quantizer then spends its bits there. It helps most below Q4 and costs nothing at run time.
Choosing
- Compute free memory: GPU or unified memory minus 2 GB for the system.
- Subtract the KV cache for your target context.
- Pick the largest level whose file fits what remains.
- If you land below Q4, try a smaller model at Q4 or higher instead.
Before and after
Before: a 70B model at Q2_K squeezed into 24 GB to keep "the big model". After: a 32B model at Q4_K_M, which usually answers better than the 70B at 2 bits and runs faster.
What goes wrong
- Taking the smallest file because it loads, then blaming the model for poor answers.
- Choosing Q8 when Q5_K_M fits with more context room and no real difference on your tasks.
- Mixing up a quant of a base model and an instruct model.
Examples
16 GB Mac, 14B model
The 14B at Q4_K_M is about 9 GB. That leaves room for a 16k context. Q6_K at about 12 GB leaves too little room once macOS takes its share, so choose Q5_K_M or stay at Q4_K_M.
Same budget, two choices
At about 20 GB, a 32B model at Q4_K_M (about 19 GB) gives up quality to fit. A 14B model at Q8_0 (about 15 GB) gives up capacity. For code and reasoning the larger Q4 usually wins; test both on your tasks.
Key points
- Q4_K_M is the common default; Q5 and Q6 trade size for a little more quality, and Q8 is nearly lossless.
- In K-quant names the S, M, L suffix sets how many sensitive tensors keep extra bits.
- I-quants and importance matrices help most at 3 bits and below.
- Fit the file and the KV cache in memory first, then pick the highest level that fits.
- A smaller model at Q4 or higher often beats a larger model squeezed to Q2.
Common mistakes
- Judging a quant by one chat session instead of a task set.
- Using Q2 or Q3 for code or math, where errors compound.
- Ignoring the KV cache when matching file size to memory.
Check yourself · 2 of 3
You have 24 GB and want the best answers. Which choice is usually better for coding?
Check yourself · 3 of 3
What does an importance matrix do during quantization?
Practice items, not counted towards your mastery.
Start here
- Quantization overview (Hugging Face Transformers docs) (opens in a new tab)DocsFree
Hugging Face's comparison of quantization methods (GPTQ, AWQ, bitsandbytes and others) and what each supports.
- llama.cpp quantize tool (opens in a new tab)DocsFree
The official list of quant types, the importance-matrix option and the llama-quantize command line.
- GGUF on the Hugging Face Hub (opens in a new tab)DocsFree
What the GGUF file format holds and how the Hub shows quant types for a repository.
More for this topic
- llama.cpp discussion: quantization types and perplexity (opens in a new tab)ArticleFree
Maintainers' tables of size and perplexity for each quant type, the evidence behind common level choices.