"How much quality did I lose?" is an empirical question, and llama.cpp already ships the tool to answer it precisely rather than by feel. The workflow is: run perplexity on the original FP16 model, run it again on each quantized candidate, and compare.
Measuring degradation with llama.cpp's perplexity tool
1. Establish your FP16 baseline. Run llama-perplexity against the unquantized model on a fixed test corpus (Wikitext-2 is the common default) and record the baseline perplexity score.
2. Run the same test against each quantized candidate. Quantize to your candidate formats (Q8_0, Q6_K, Q4_K_M, etc.) and run the identical perplexity test on each — same corpus, same context length, so the comparison is apples-to-apples.
3. Compare delta-PPL, and cross-check with KL-divergence for borderline cases. The gap between baseline and quantized perplexity is your degradation number; llama.cpp's --kl-divergence-base/--kl-divergence flags add a token-distribution-level comparison if you need more resolution than an aggregate score gives you.
# 1. Baseline perplexity on the unquantized FP16 model
./llama-perplexity \
--model ./models/model-fp16.gguf \
--file ./wikitext-2-raw/wiki.test.raw
# 2. Same test on a quantized candidate
./llama-perplexity \
--model ./models/model-q4_k_m.gguf \
--file ./wikitext-2-raw/wiki.test.raw
# 3. Optional: token-distribution comparison vs. the FP16 baseline
./llama-perplexity \
--model ./models/model-q4_k_m.gguf \
--kl-divergence-base ./fp16-logits.kld \
--kl-divergence
| Quantization Level (LLaMA 3 8B, Wikitext-2) | Delta-PPL vs. FP16 (llama.cpp benchmark) |
|---|---|
| Q8_0 | ~0.002650 |
| Q6_K | ~0.021748 |
| Q4_K_M | ~0.175482 (± 0.004620) |
These are llama.cpp's own repo-committed benchmark figures, not third-party estimates — and the project's own documentation cautions they're implementation-specific, so don't treat them as universal constants across every model family or quantization tool. Re-running the perplexity test on your specific model and target quantization level is what actually tells you whether the degradation is acceptable for your use case.
Practical Challenge
Run llama-perplexity against an FP16 model and a Q4_K_M quantization of the same model on the same test file, and calculate the delta-PPL yourself.
Concept Check
Sources & Further Reading
- llama.cpp: Perplexity tool README — documents the
llama-perplexitytool, its--kl-divergencemode, and the source of the Q8_0/Q6_K/Q4_K_M delta-PPL benchmark figures cited above.
AI