Skip to content
VRAM Lab

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

Share
Close-up of a processor on a green circuit board
Close-up of a processor on a green circuit board. Photo He Junhui / Unsplash
On this page (8)
  1. Key takeaways
  2. Where model size comes from
  3. What quantization is
  4. The other half of the bill: the KV cache
  5. Speed: memory bandwidth is what counts
  6. A bigger model or a better quantization?
  7. Summary
  8. FAQ

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 GB

16 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:

VariantBits per weight8B sizeQuality
F161616.0 GBreference
Q8_0~8.58.5 GBpractically lossless
Q6_K~6.66.6 GBhard to tell apart
Q5_K_M~5.75.7 GBvery good
Q4_K_M~4.84.9 GBbest trade-off
IQ3_M~3.73.8 GBclear degradation
Q2_K~2.63.2 GBfor curiosity only

Llama 3.1 8B: file size by quantization

Weights only, without the KV cache. The lines mark common VRAM sizes.

051015208 GB12 GBF1616 GBQ8_08.5 GBQ6_K6.6 GBQ5_K_M5.7 GBQ4_K_M4.9 GBIQ3_M3.8 GBQ2_K3.2 GB
Show data
F1616 GB
Q8_08.5 GB
Q6_K6.6 GB
Q5_K_M5.7 GB
Q4_K_M4.9 GB
IQ3_M3.8 GB
Q2_K3.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_length

For 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
051015204K8K16K32K64K128Kcontext (tokens)Q4_K_M weightsf16 16 GBq8_0 8.5 GB
Show data
context (tokens)f16q8_0
4K0.5 GB0.3 GB
8K1 GB0.5 GB
16K2 GB1.1 GB
32K4 GB2.1 GB
64K8 GB4.3 GB
128K16 GB8.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 size

An 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:

  1. Smaller quantization = faster generation, because there are fewer bytes to read.
  2. 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.

05001,0001,5002,000RTX 50901,792 GB/sRTX 3090936 GB/sRTX 5060 Ti 16 GB448 GB/sDDR5-5600 2ch90 GB/s

Source: NVIDIA specifications, JEDEC DDR5-5600

Show data
RTX 50901,792 GB/s
RTX 3090936 GB/s
RTX 5060 Ti 16 GB448 GB/s
DDR5-5600 2ch90 GB/s

Qwen3 32B

llama.cpp · RTX 3090 24 GB

Q4_K_M
VRAM
22.1GB
Generation
33tok/s
Context
12K
GPU memory 22.1 / 24 GB

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_M is a sensible start, Q8_0 is 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.

Found it useful? Pass it on.

Share
Esc
↑↓ select↵ openCtrl K or / to search