tutorial 7 min read

GGUF Quantization: Q4_K_M vs Q5_K_M vs Q8_0 Explained

Ludovico Bessi

By Ludovico Bessi

Senior Machine Learning Engineer at Google · Zurich

Compare GGUF Q4_K_M, Q5_K_M, and Q8_0 for local LLM inference in llama.cpp and Ollama: exact RAM/VRAM math, perplexity loss, decode speed, and which to pick.

GGUF quantization llama.cpp Ollama LLM inference
GGUF Quantization Comparison: Q4_K_M vs Q5_K_M vs Q8_0 Memory and Quality
GGUF Q4_K_M vs Q5_K_M vs Q8_0 weight memory and quality trade-offs on 8B and 70B local models.

TL;DR

  • Start with GGUF Q4_K_M for local LLMs on laptops, consumer GPUs, and Apple Silicon (~4.85 bits/weight, fastest decode, only ~1–2% perplexity drop).
  • Upgrade to Q5_K_M (~5.7 bits/weight) when you have RAM headroom and want stronger coding, math, or structured JSON fidelity.
  • At the same RAM footprint, a larger model at Q4_K_M almost always beats a smaller model at Q8_0.

Direct answer: Start with Q4_K_M for almost every local LLM setup on laptops, consumer GPUs, and Apple Silicon — it cuts model weights nearly 4× compared to FP16 (~4.9 GB for 8B, ~42 GB for 70B) with only a ~1–2% perplexity cost and the fastest decode speed. Step up to Q5_K_M when you have extra RAM headroom and care about coding, math, or strict JSON accuracy. Use Q8_0 only when you have abundant memory (e.g., 128 GB Mac Studio) or need a near-lossless FP16 baseline for evaluation.

Want to size your exact hardware and context window? Try our free interactive LLM VRAM & Quantization Calculator, or join 13k+ ML engineers getting weekly serving deep dives on Machine Learning at Scale (Substack).

GGUF Q4_K_M vs Q5_K_M vs Q8_0 at a Glance

Format Effective Bits / Weight 8B Model Weights 70B Model Weights Perplexity Impact Relative Decode Speed Best For
Q4_K_M ~4.85 bits ~4.9 GB ~42 GB Small (~1–2%) Fastest (1.0×) Default for 16–64 GB RAM & 24 GB GPUs
Q5_K_M ~5.70 bits ~5.7 GB ~50 GB Very low (<0.8%) ~0.85× Coding, math, structured extraction with headroom
Q8_0 ~8.50 bits ~8.5 GB ~75 GB Near-zero (<0.1%) ~0.58× Near-FP16 fidelity on 128 GB unified memory
FP16 (baseline) 16.0 bits ~16 GB ~140 GB 0% ~0.32× Cloud training / reference evaluation

What Does the _K_M Suffix Actually Mean?

In llama.cpp, K-quants (like Q4_K_M and Q5_K_M) use mixed-precision block quantization rather than crushing every tensor to the exact same bit-width:

  • Attention output (wv, wo) and feed-forward down-projection layers are more sensitive to quantization noise, so _K_M ("medium") automatically promotes those sensitive tensors to higher precision (6-bit in Q4_K_M, 6-bit/8-bit in Q5_K_M).
  • _K_S ("small") keeps almost all tensors at the base bit-width — saving a few percent of RAM at a noticeable accuracy penalty.
  • Q8_0 uses uniform 8-bit quantization in blocks of 32 weights with one FP16 scale per block. Because 8 bits already preserve nearly all dynamic range, mixed-precision promotion is unnecessary.

Why Bigger Model at Q4 Beats Smaller Model at Q8

One rule holds consistently across local LLM benchmarks: at the same memory budget, a larger model at Q4_K_M almost always beats a smaller model at Q8_0 or FP16.

For example, a 14B or 24B model at Q4_K_M (9–15 GB) dramatically outperforms an 8B model at Q8_0 (8.5 GB) on reasoning, code generation, and instruction following — even though both occupy a similar memory footprint. Only drop below Q4_K_M (into Q3_K_M or Q2_K) as a last resort: below 4 bits, hallucination rates and instruction-following drift rise sharply.

Don't Forget the KV Cache

Weight size is only half the budget. Long contexts (32K–128K tokens) can easily consume 5–20+ GB of extra RAM/VRAM for the KV cache alone. In llama.cpp and Ollama, you can quantize the KV cache separately (-ctk q8_0 -ctv q8_0) to halve context memory without touching weights. Plug your exact model and context length into the LLM VRAM & Quantization Calculator to verify before downloading a 50 GB file.

When NOT to Use GGUF

GGUF shines for single-user local inference, CPU/Apple Silicon, and hybrid CPU+GPU offloading. If you are serving concurrent production users on cloud NVIDIA GPUs (L40S, A100, H100), skip GGUF and use FP8, AWQ, or GPTQ under vLLM or SGLang for continuous batching and Marlin CUDA kernels. See our head-to-head comparison: AWQ vs GPTQ and LLM Quantization: GPTQ vs AWQ vs GGUF.

Want weekly production ML & LLM serving breakdowns in your inbox? Subscribe free to Machine Learning at Scale on Substack.

Frequently Asked Questions

What is the difference between GGUF Q4_K_M, Q5_K_M, and Q8_0?

Q4_K_M averages ~4.85 bits per weight using mixed-precision K-quants (~42 GB for a 70B model) and is the best speed-to-quality default. Q5_K_M averages ~5.7 bits (~50 GB for 70B) for slightly higher coding/reasoning accuracy. Q8_0 uses uniform 8-bit blocks (~75 GB for 70B) and is virtually lossless compared to FP16.

Is Q4_K_M or Q8_0 better for local LLM inference?

Q4_K_M is better for most users because it runs ~1.7× faster and uses nearly half the RAM of Q8_0, letting you run a much larger model (for example 24B at Q4_K_M instead of 8B at Q8_0) in the same memory budget.

What does K_M mean in GGUF quantization?

K stands for K-quant mixed-precision block quantization, and M stands for medium. It keeps most weights at the target bit-width while promoting the most sensitive attention and feed-forward tensors to 6-bit precision to preserve accuracy.

Get the Machine Learning at Scale newsletter

Join 13k+ ML engineers reading weekly deep dives on production ML systems and growing your ML career to Senior and beyond. Free on Substack.

Subscribe Free on Substack
Ludovico Bessi, Senior ML Engineer at Google

Ludovico Bessi

Senior Machine Learning Engineer at Google in Zurich. Previously worked on large-scale abuse ML systems, end-to-end YouTube Ads, YouTube Shopping recommendations, CERN, and Volvo. Writes the weekly Machine Learning at Scale newsletter.

Related Articles