Q4_K_M and Q8_0 are GGUF weight types in llama.cpp. Q8_0 stores 8.5 bits per weight and on llama.cpp's Llama 3 8B scoreboard has a mean KL divergence from FP16 of 0.001355, picking the same top token 97.674% of the time. Q4_K_M averages 4.89 bits per weight, so the file is 4.58 GiB against 7.96 GiB (58% of the size), with a KL divergence of 0.031273 and 91.901% top-token agreement. In the quantize README's Llama 3.1 8B table, Q4_K_M generates tokens 41% faster (71.93 vs 50.93 tokens per second) while Q8_0 is 5% faster at prompt processing. An importance matrix cuts Q4_K_M's KL divergence by 10%, to 0.028152. Run Q8_0 when the file plus the KV cache for your context fits in VRAM, and Q4_K_M with an imatrix when it does not. This week, quantize one model you already run both ways and score both files with llama-perplexity --kl-divergence on your own text.
Q4_K_M vs Q8_0 comes down to size against fidelity, and llama.cpp has already measured both. Q8_0 stores GGUF weights at 8.5 bits each and on the project's Llama 3 8B scoreboard has a mean KL divergence from FP16 of 0.001355, choosing the same top token as the 16-bit model 97.674% of the time. Q4_K_M averages about 4.9 bits per weight, so the file is 58% the size of Q8_0 (4.58 vs 7.96 GiB on that model), at a KL divergence of 0.031273 and 91.901% top-token agreement, and it generates tokens about 41% faster because decoding is limited by memory reads. Run Q8_0 when it fits in VRAM with the context you need, and run Q4_K_M quantized with an importance matrix when it does not.
Both names are weight file types: they set how the model's parameters are stored in the .gguf file. They are separate from the precision of the KV cache, which llama.cpp sets with its own flags and which has its own accuracy cost; if your search for q8_0 was about cache types, the KV cache quantization accuracy benchmarks cover that. Every llama.cpp flag, table and source line below is read from llama.cpp v1.1.0, the latest release on December 2, 2026. Nothing here was run by us; the numbers are llama.cpp's published measurements.
What Q4_K_M and Q8_0 mean
Q8_0 is the simpler format. The weights are cut into blocks of 32, and each block stores 32 signed 8-bit integers plus one 16-bit scale. Dequantizing is one multiply per weight, the stored integer times the block scale. The storage cost is 32 x 8 bits plus 16 bits for the scale, 272 bits per 32 weights, or 8.5 bits per weight, as the block_q8_0 struct in ggml-common.h lays out and Hugging Face's description of the GGUF quantization types describes.
Q4_K is one of the K-quants, added to llama.cpp in pull request #1684 in June 2023. Weights are grouped in super-blocks of 256, made of eight blocks of 32. Each block has its own scale and minimum, and those scales and minimums are themselves quantized to 6 bits against two 16-bit super-block scales, one for the scales and one for the minimums. The result is 4.5 bits per weight. Q6_K uses the same super-block idea at 6.5625 bits per weight.
Q4_K_M is a recipe that mixes those types across tensors. The suffix marks the mix: Q4_K comes in S and M variants, Q3_K in S, M and L. In llama-quant.cpp at v1.1.0, the Q4_K_M rules are:
Those promoted tensors are why Q4_K_M lands at 4.8944 bits per weight on Llama 3.1 8B instead of Q4_K's 4.5. Q5_K_M follows the same pattern with Q5_K as the base and Q6_K for attn_v and ffn_down. The --pure flag on llama-quantize turns the mixture off and writes every tensor at the base type.
Quality loss: perplexity and KL divergence from llama.cpp's scoreboard
The Llama 3 8B scoreboard in the llama-perplexity README quantizes one model to every type and scores each file against FP16 logits on the Wikitext-2 test set, on CUDA with one RTX 4090. The rows that matter for this decision:
The top-token column comes from the README's separate Llama 2 vs Llama 3 comparison table, which reports it for the types without an importance matrix; blank cells are types that table does not include. The f16 row is not zero because the stored reference logits are cast to 16-bit integers to save space, so 0.000551 is the floor for any file measured this way.
KL divergence measures how far the quantized model's whole probability distribution over the next token has moved from the FP16 model's distribution, averaged over every position in the text. Zero means identical. It catches changes that perplexity averages away, because perplexity looks only at the probability of the correct token and a quantized model can lose probability on some tokens while gaining it on others. A 2024 paper, Accuracy is Not All You Need, showed that compressed models can match baseline accuracy on benchmarks while flipping individual answers, and proposed KL divergence and answer flips as the better measure.
Same top token is the share of positions where both models put the highest probability on the same token. At greedy decoding, a mismatch is a different token in the output. Q8_0 disagrees with FP16 at 2.3% of positions and Q4_K_M at 8.1%.
The tail makes the difference sharper. In the same comparison table, the worst single-position drop in the correct token's probability is 24.3 percentage points for Q8_0 and 98.7 for Q4_K_M. At the 99.9th percentile of increases, Q8_0 moves by 6.402 percentage points and Q4_K_M by 27.084. The average change is small, while a few individual tokens drop from likely to close to zero probability. For extraction from contracts or clinical notes, where one wrong field is a defect, those rare flips matter more than the average.
Three caveats apply to every number in that table. The scoreboard is labelled with revision f364eb6f, so it predates v1.1.0 and was not re-measured for it. The measurements cover one model on one text: the README states that perplexity is not directly comparable between models, especially with different tokenizers. And models differ in how much they lose. Llama 2 7B at Q4_K_M has a KL divergence of 0.012686, while Llama 3 8B at the same type has 0.031273, so the newer model lost more than twice as much. Do not assume a Qwen, Gemma or mixture-of-experts model sits where Llama 3 8B does; the measurement procedure further down tells you where yours sits.
| Type | imatrix | Size (GiB) | Perplexity | KL divergence | RMS change in p | Same top token |
|---|---|---|---|---|---|---|
| f16 | none | 14.97 | 6.233160 | 0.000551 | 0.787% | |
| q8_0 | none | 7.96 | 6.234284 | 0.001355 | 1.198% | 97.674% |
| q6_K | none | 6.14 | 6.253382 | 0.005452 | 2.295% | 96.031% |
| q5_K_M | none | 5.33 | 6.288607 | 0.010762 | 3.160% | |
| q4_K_M | Wikitext, 10m tokens | 4.58 | 6.382937 | 0.028152 | 5.251% | |
| q4_K_M | none | 4.58 | 6.407115 | 0.031273 | 5.519% | 91.901% |
| q4_K_S | none | 4.37 | 6.500529 | 0.043136 | 6.562% |
File size and VRAM
The llama-quantize README lists bits per weight and file size for every type on Llama 3.1 8B:
On that model Q4_K_M is 58% of Q8_0. The same README's memory table gives Llama 3.1 70B at 43.1 GB in Q4_K_M and Llama 3.1 405B at 249.1 GB, so a 70B model at 4 bits needs most of a 48 GB card, or two 24 GB cards, before any KV cache is allocated.
Current models show that the ratio moves with the architecture. From the file listings of ggml-org's Qwen3.8-27B GGUF repository and its Qwen3.6-35B-A3B repository, in decimal gigabytes:
The 27B dense model saves 9.2 GB out of 28.6 going from Q8_0 to Q4_K_M, a smaller share than the 8B or the MoE model. Read the file sizes for the model you plan to run instead of applying a fixed percentage.
VRAM is the weight file plus the KV cache for your context and concurrency plus the compute buffers llama.cpp allocates. The KV cache does not change when you switch the weight file from Q8_0 to Q4_K_M; its size depends on the model's layer count, KV heads, head dimension, context length and the cache type you set. For a worked per-token KV calculation and per-file sizing on one current model, see the Inkling 2 Mini VRAM breakdown.
The fit check for the 27B model on a 24 GB card is short arithmetic. The Q8_0 file is 28.60 GB, larger than the card before any cache is allocated, so it does not load fully on the GPU. The Q4_K_M file is 19.40 GB and leaves a few gigabytes for the KV cache and buffers, enough for a single user at a moderate context. On a 48 GB card, or two 24 GB cards with the layers split, the Q8_0 file fits with room for context, and the decision moves from capacity to speed and fidelity.
| Type | Bits per weight | Size (GiB) |
|---|---|---|
| Q4_K_S | 4.6672 | 4.36 |
| Q4_K_M | 4.8944 | 4.58 |
| Q5_K_M | 5.7036 | 5.33 |
| Q6_K | 6.5633 | 6.14 |
| Q8_0 | 8.5008 | 7.95 |
| F16 | 16.0005 | 14.96 |
| Model | BF16 | Q8_0 | Q4_K_M | Q4_K_M / Q8_0 |
|---|---|---|---|---|
| Qwen3.8-27B (dense) | 53.81 GB | 28.60 GB | 19.40 GB | 68% |
| Qwen3.6-35B-A3B (MoE) | 69.38 GB | 36.90 GB | 20.54 GB | 56% |
Speed: prompt processing vs token generation
The quantize README's Llama 3.1 8B table also reports throughput for a 512-token prompt (pp512) and 128 generated tokens (tg128):
The README does not state the hardware or backend for this table, so compare the ratios between rows and do not expect these absolute rates on your machine. Q4_K_M generates 1.41 times as fast as Q8_0, and Q8_0 processes the prompt 5% faster than Q4_K_M.
Both directions follow from how inference uses the weights. Generating one token reads every weight in the model once and does little arithmetic per byte, so the rate tracks memory bandwidth divided by file size: fewer bytes, more tokens per second. Prompt processing runs many tokens through each weight at once, so it is limited by compute, and Q8_0's simple dequantization costs less than unpacking K-quant super-blocks. F16 is the fastest at prefill and the slowest at generation for the same reason.
For an interactive assistant, generation rate is what users feel. For a batch job that summarizes long documents with short outputs, prefill dominates and the two types are close. If long prompts are being reprocessed on every turn, check that separately, because prompt re-processing in llama.cpp with hybrid and sliding-window models repeats the whole prefill whichever weight type you load.
| Type | Prompt processing (t/s) | Generation (t/s) |
|---|---|---|
| Q4_K_S | 818.55 | 76.71 |
| Q4_K_M | 821.81 | 71.93 |
| Q5_K_M | 758.69 | 67.23 |
| Q6_K | 812.01 | 58.67 |
| Q8_0 | 865.09 | 50.93 |
| F16 | 923.49 | 29.17 |
Make and check your own Q4_K_M
Downloaded files are convenient, and the llama.cpp -hf flag defaults to Q4_K_M when you omit the quant tag. To pin the type, name it:
./build/bin/llama-server -hf ggml-org/Qwen3.8-27B-GGUF:Q8_0
Making the files yourself from a BF16 GGUF gives you two things a download does not: an importance matrix built from your own text, and a reference file to measure against. Start by quantizing the same BF16 file to both types:
./build/bin/llama-quantize model-BF16.gguf model-Q8_0.gguf Q8_0 ./build/bin/llama-quantize model-BF16.gguf model-Q4_K_M.gguf Q4_K_M
Quantizing loads the whole model, and the README states that memory and disk requirements are the same, so a 27B BF16 file needs about 54 GB of RAM and disk on the machine doing it.
./build/bin/llama-imatrix -m model-BF16.gguf -f domain-text.txt -o imatrix.gguf -ngl 99 ./build/bin/llama-quantize --imatrix imatrix.gguf model-BF16.gguf model-Q4_K_M.gguf Q4_K_M
# 1) record the reference logits once (large file) ./build/bin/llama-perplexity -m model-BF16.gguf -f eval-text.txt --kl-divergence-base bf16-logits.kld -ngl 99 # 2) score each quantized file against them ./build/bin/llama-perplexity -m model-Q8_0.gguf --kl-divergence-base bf16-logits.kld --kl-divergence -ngl 99 ./build/bin/llama-perplexity -m model-Q4_K_M.gguf --kl-divergence-base bf16-logits.kld --kl-divergence -ngl 99
./build/bin/llama-quantize --target-size 22g --state-file --imatrix imatrix.gguf model-BF16.gguf model-22g.gguf
Build an importance matrix from domain text
An importance matrix (imatrix) records which weights carry the most signal on a sample of text, and llama-quantize spends its precision on those. The feature came in pull request #4861 in January 2024. On the scoreboard, a Wikitext imatrix cut Q4_K_M's KL divergence from 0.031273 to 0.028152, a 10% reduction, at the same 4.58 GiB. The scoreboard lists Q8_0 without one and reports imatrix rows only for 4-bit and smaller types, so this step is for the Q4_K_M file. Per the llama-imatrix README, -m and -f are required and the output defaults to imatrix.gguf: Use text from the documents the model will see in production: policy manuals, contract templates, de-identified case notes. The Wikitext imatrix behind the scoreboard row was tuned on encyclopedia prose, and a matrix from your own domain targets the weights your workload exercises.
Measure KL divergence against BF16 on your own text
The check takes two runs of llama-perplexity. The first records the BF16 model's logits for every position in an evaluation text; the second scores each quantized file against them: In the scoring run the tokens come from the logits file, so -f is only needed the first time. Use a different text from the one that built the imatrix, so the score is not measured on the calibration data. The default context is 512 tokens, and the evaluation text must hold at least two contexts' worth. Plan disk for the logits file: the README puts it at 11 GiB for Llama 2 and 37 GiB for Llama 3 on Wikitext-2, and the file grows with the length of the evaluation text and the size of the model's vocabulary. Domain text as long as the Wikitext-2 test set needs disk on the same order, so size the evaluation text to the disk you have. The output prints mean KL divergence, the percentiles of change in token probability and same top token, the same statistics as the scoreboard, so you can place your model against Llama 3 8B's numbers.
Hit a size budget between the two
v1.1.0 added --target-bpw and --target-size to llama-quantize (from pull request #15550, listed in the v1.1.0 release notes). Instead of a fixed recipe, the tool scores tensors and picks per-tensor types to meet a bits-per-weight average or a file size. For the 27B model on a 32 GB card, where Q8_0's 28.60 GB leaves too little room for context and Q4_K_M's 19.40 GB leaves room unused, a 22 GiB target (llama-quantize reads the g suffix as GiB, about 23.6 GB) sits between them: The type argument is optional with a target set. --state-file saves the scoring work to a file named after the model so an interrupted run resumes, and a rerun with a different target reuses it. Score the result with the same KL divergence run as the other two files.
Which to choose on-prem
Inside a regulated perimeter the GPU budget is fixed and owned, which makes the first row a capacity question. The cards in the rack decide whether Q8_0 loads with the context the workload needs; if they cannot hold it, Q4_K_M with a domain imatrix is the file to run. For larger models, the hardware choice comes first, and our DGX Spark vs Mac Studio comparison covers the unified-memory boxes that hold Q8_0 files of 30B to 70B models.
Both checks in this post run entirely on local text. The imatrix and the KL divergence run read your documents on your own machine, so calibration and validation data never leave the network. In an air-gapped environment, -hf is not available: download the BF16, Q8_0 and Q4_K_M files on a connected machine, record their SHA-256 hashes, carry them across your transfer process, and load them by local path with -m. Keep the BF16 GGUF as the reference artifact, so when a new llama.cpp build or model revision arrives you can requantize and rerun the same two-step check against the same evaluation text. If llama-server is serving those files to other teams, harden the llama.cpp server and its RPC port before it goes on the network.
If you are deciding between llama.cpp with GGUF files and a GPU serving stack for many concurrent users, the formats differ again; the Ollama vs vLLM comparison covers that choice. For more on picking, sizing and running open-weight models, see the LLM models guide. When the work is sizing models to the GPUs you already own and validating them on your own data, our on-premise AI development team builds and documents that setup inside your infrastructure.
This week, take one model you already serve, quantize its BF16 file to Q8_0 and Q4_K_M, and run llama-perplexity --kl-divergence on a few hundred thousand tokens of your own documents. If Q4_K_M's KL divergence sits near Llama 3 8B's 0.031 and Q8_0 fits on your card, switch to Q8_0; if it does not fit, build the imatrix from the same documents and requantize.
| Your situation | Run | Why |
|---|---|---|
| Q8_0 plus the KV cache for your full context fits in VRAM | Q8_0 | 0.001355 KL divergence on Llama 3 8B, the closest quantized type to 16-bit |
| Q8_0 does not fit, Q4_K_M does with context to spare | Q4_K_M with an imatrix from your own text | 58% of the bytes on Llama 3 8B, 41% faster generation |
| Q8_0 almost fits, or Q4_K_M leaves a lot of memory idle | Q5_K_M, Q6_K, or --target-size | Q6_K at 0.005452, Q5_K_M at 0.010762 on Llama 3 8B |
| Generation speed matters more than the last points of fidelity | Q4_K_M | Decode tracks bytes read per token |
| Field extraction where one wrong token is a defect | Q8_0, or Q6_K if Q8_0 does not fit | Smaller worst-case token probability drops |
| Bigger model at Q4_K_M or smaller model at Q8_0 | Measure both on real tasks | KL divergence cannot compare different models |
FAQ
Quick answers to the questions this post tends to raise.



