How much VRAM do you need? GGUF quantization in practice
Q4_K_M, Q8_0, IQ3? We take quantization apart, calculate the memory needed for weights and KV cache, and check when a bigger model at a lower quantization beats a smaller one.
3 minutes read Czytaj po polsku

On this page (8)
Key takeaways
- Weights take roughly parameters × bits per weight / 8.
- Q4_K_M is the best trade-off, Q8_0 is practically lossless.
- The KV cache grows linearly with context and at 128K can take more than the model itself.
- A bigger model at Q4 usually beats a smaller one at Q8 for similar memory use.
The most common question in any discussion about local models is "will it fit?". The answer always depends on three things: the number of parameters, the quantization and the context length. Let's work it out properly once.
Where model size comes from
A model is essentially billions of numbers, the weights. Originally each one takes 16 bits (FP16 or BF16). A simple calculation for an 8B model:
8,000,000,000 weights × 16 bits = 128 Gb = 16 GB16 GB for a model that counts as small. A 70B model in FP16 is over 140 GB. That is why almost nobody runs models at full precision at home.
What quantization is
Quantization stores weights using fewer bits. The GGUF format (used by llama.cpp and Ollama) comes in a whole family of variants. The number after the "Q" is roughly the number of bits per weight, and the suffix describes the method:
| Variant | Bits per weight | 8B size | Quality |
|---|---|---|---|
F16 | 16 | 16.0 GB | reference |
Q8_0 | ~8.5 | 8.5 GB | practically lossless |
Q6_K | ~6.6 | 6.6 GB | hard to tell apart |
Q5_K_M | ~5.7 | 5.7 GB | very good |
Q4_K_M | ~4.8 | 4.9 GB | best trade-off |
IQ3_M | ~3.7 | 3.8 GB | clear degradation |
Q2_K | ~2.6 | 3.2 GB | for curiosity only |
Llama 3.1 8B: file size by quantization
Weights only, without the KV cache. The lines mark common VRAM sizes.
Show data
| F16 | 16 GB |
| Q8_0 | 8.5 GB |
| Q6_K | 6.6 GB |
| Q5_K_M | 5.7 GB |
| Q4_K_M | 4.9 GB |
| IQ3_M | 3.8 GB |
| Q2_K | 3.2 GB |
The K variants (k-quants) quantize weights in blocks and treat layers differently. The more important tensors, such as some of the attention layers, get more bits. Hence _S, _M and _L: small, medium and large mixes. The IQ variants (i-quants) use a smarter encoding and hold quality better than classic K-quants at 3–4 bits, at the cost of somewhat slower CPU inference.
The other half of the bill: the KV cache
Weights are not everything. During generation the model keeps the attention keys and values for every token in the context, the KV cache. Its size is:
KV = 2 × layers × KV_heads × head_dim × bytes × context_lengthFor Llama 3.1 8B (32 layers, 8 KV heads, head dimension 128) in FP16 that is 128 KB per token. At 8K of context that is 1 GB, at 128K it is already 16 GB, more than the Q8 weights themselves!
That is why it pays to quantize the KV cache to q8_0. In Ollama you do it with OLLAMA_KV_CACHE_TYPE=q8_0, which requires flash attention. Context memory is halved and the quality loss is negligible.
Llama 3.1 8B: KV cache vs context length
2 × 32 layers × 8 KV heads × 128 × bytes per value. q8_0 stores about 8.5 bits per value.
- f16
- q8_0
Show data
| context (tokens) | f16 | q8_0 |
|---|---|---|
| 4K | 0.5 GB | 0.3 GB |
| 8K | 1 GB | 0.5 GB |
| 16K | 2 GB | 1.1 GB |
| 32K | 4 GB | 2.1 GB |
| 64K | 8 GB | 4.3 GB |
| 128K | 16 GB | 8.5 GB |
Speed: memory bandwidth is what counts
To generate each token the GPU has to read all the weights from VRAM. The upper speed limit is therefore approximately:
tok/s ≈ memory bandwidth / model sizeAn RTX 3090 has about 936 GB/s. A 32B model at Q4_K_M weighs about 20 GB, so the theoretical ceiling is ~47 tok/s, and in practice you get 30–35. Two conclusions follow from this formula:
- Smaller quantization = faster generation, because there are fewer bytes to read.
- When some layers end up in system RAM (DDR5 bandwidth is about 60–90 GB/s), speed drops drastically. Those layers become the bottleneck.
Memory bandwidth
The ceiling for generation speed is roughly bandwidth divided by model size.
Source: NVIDIA specifications, JEDEC DDR5-5600
Show data
| RTX 5090 | 1,792 GB/s |
| RTX 3090 | 936 GB/s |
| RTX 5060 Ti 16 GB | 448 GB/s |
| DDR5-5600 2ch | 90 GB/s |
Qwen3 32B
llama.cpp · RTX 3090 24 GB
- VRAM
- 22.1GB
- Generation
- 33tok/s
- Context
- 12K
A tight fit. With a longer context, a q8_0 KV cache or the IQ4_XS variant gives you some headroom.
A bigger model or a better quantization?
Is a 14B model at Q8_0 better than a 32B model at Q4_K_M (with similar memory use)? The answer is surprisingly consistent: the bigger model at the lower quantization usually wins. The quality drop between Q8 and Q4 is smaller than the difference between consecutive model sizes. This rule stops working roughly below 3 bits per weight.
Summary
- Weights:
parameters × bits / 8. - Plus the KV cache, which grows linearly with context.
- Plus ~0.5–1 GB of buffers.
Q4_K_Mis a sensible start,Q8_0is practically the original.- A model that does not fit entirely in VRAM runs several times slower.
FAQ
Which quantization should I start with?
Q4_K_M. If you have VRAM to spare, move up to Q5_K_M or Q6_K.
Does quantizing the KV cache hurt answers?
At q8_0 the quality loss is negligible and context memory is halved. At q4_0 differences can become noticeable.
Why is the model slow even though my card is powerful?
Most often some layers do not fit in VRAM and the CPU computes them. Check with ollama ps or reduce the context.


