Model Distillation & Quantization
Make models smaller and faster: quantization (GGUF, GPTQ, AWQ), knowledge distillation, the accuracy-vs-efficiency trade-off, and when self-hosting a compressed model makes sense.
On this page
Distillation and quantization make models smaller, cheaper and faster — the techniques behind running capable models on modest hardware. They matter most when you self-host. This tutorial explains them and the accuracy-versus-efficiency trade-off, honestly noting when a hosted API makes the whole topic moot.
Key Takeaways
- Quantization stores weights at lower precision — big memory savings, small accuracy cost.
- Distillation trains a small student to mimic a large teacher — capability in a smaller package.
- GGUF, GPTQ, AWQ are quantization formats/methods; the right one depends on your runtime.
- These matter when you self-host; a hosted API removes the need for most teams.
The efficiency problem
Full-precision large models need substantial GPU memory and are expensive to run. If you self-host — for privacy, cost or offline operation — compression is what makes it feasible. If you use a hosted API, the provider handles all of this and you can largely skip this topic.
Quantization
A model's weights are numbers, normally stored at 16-bit precision. Quantization stores them at lower precision — 8-bit or 4-bit — trading a little accuracy for large savings:
| Precision | Relative memory | Quality |
|---|---|---|
| 16-bit (full) | 100% | Baseline |
| 8-bit | ~50% | Near-identical |
| 4-bit | ~25% | Small, usually acceptable, degradation |
A 4-bit quantized model uses roughly a quarter of the memory, which is often the difference between fitting on your hardware and not. The quality cost is usually modest and task-dependent — measure it on your evaluation set rather than assuming.
The formats
- GGUF — a widely-used format for running quantized models on CPU and consumer hardware, standard with llama.cpp and Ollama. If you run models locally, you will meet GGUF.
- GPTQ — a quantization method that carefully chooses how to compress weights to preserve accuracy, common for GPU inference.
- AWQ (Activation-aware Weight Quantization) — protects the weights that matter most to the model's activations, often preserving quality well at low bit-widths.
Which to use depends on your runtime and hardware. For CPU or mixed hardware, GGUF; for GPU serving, GPTQ or AWQ are common. See low-latency LLM serving.
Knowledge distillation
Distillation transfers capability from a large "teacher" model into a smaller "student" by training the student to mimic the teacher's outputs. The student learns not just the right answers but the teacher's output distribution, which packs more of the teacher's behaviour into fewer parameters than training the small model on raw data would.
Distillation is how some notably small models achieve surprising capability. They rarely fully match the teacher on the hardest tasks, but for many uses a distilled small model is good enough at a fraction of the cost — the basis of small language models.
The accuracy-efficiency trade-off
Every compression technique trades quality for efficiency. The engineering question is where on that curve your task sits:
When this matters for you
- Self-hosting for privacy or offline — quantization makes it fit your hardware.
- High-volume, cost-sensitive workloads — a quantized or distilled small model can serve the easy majority cheaply, routing hard cases to a bigger model.
- Edge and on-device — small quantized models run where a hosted API cannot reach.
And when it does not: if a hosted API meets your latency, cost and privacy needs, quantization is operational complexity you do not have to take on. Most application teams are in this category.
Next
Frequently Asked Questions
What is model quantization?
What is knowledge distillation?
What is the difference between GGUF, GPTQ and AWQ?
Should I quantize a model or just use a hosted API?
Related tutorials
- LLM Evaluation & BenchmarksHow to evaluate LLMs and LLM applications: what public benchmarks like MMLU and HumanEval measure, their limits, and building a custom evaluation suite that reflects your real task.
- Guardrails & Safety SystemsBuild guardrails around LLMs: input filtering, output validation against schemas and rules, content moderation, jailbreak defense and layered safety — deterministic controls in Java.
- Tokenization & Context WindowsUnderstand tokens and context windows: how BPE tokenization works, why code costs more tokens, managing the context budget, and the token math behind LLM cost — for Java developers.
- LLMOps & MLOps for Generative AIThe operational practice of running LLM features: prompt versioning, evaluation in CI/CD, model registries, A/B testing and canary rollouts of prompt and model changes — for Java teams.