Distillation and Small Models
Use a large model's outputs to train a small, fast, cheap model that matches it on your specific task.
Advanced · about 4 hours · difficulty 4/5
Learn first: Hosted Fine-Tuning Services
Distillation transfers a skill from a large "teacher" model to a smaller "student". In application work this usually means: run the best model on many real inputs, keep the good outputs, and fine-tune a small model on them.
Why do it
- Cost: small models can be many times cheaper per token.
- Latency: faster responses for interactive or high-volume features.
- Deployment: run on your own hardware, on-device or offline.
The recipe
- Collect a large set of realistic inputs for one narrow task.
- Generate outputs with the teacher model and your best prompt, possibly with reasoning.
- Filter with graders, code checks or human review so only correct outputs remain.
- Fine-tune the student (hosted or with LoRA) on the filtered pairs.
- Evaluate the student against the teacher on a held-out set. Aim for "good enough" on your metrics, not identical.
Things to watch
- Check provider terms of service; some restrict using outputs to train competing models.
- Students generalize less well outside the task they were trained for, so route unusual inputs to the larger model.
- Re-distill when the teacher or your task changes.
Related ideas
Small models also shine with good prompts alone, as classifiers, routers, rerankers and guardrails. Try a small model with a strong prompt before distilling.
Good enough to move on
You can distill one narrow task from a large model into a small one and show a cost and latency comparison with an acceptable quality gap.
Key concepts
- Teacher and student models
- Generating and filtering outputs
- Fine-tuning the student
- Quality vs cost trade-off
- Routing hard inputs to the teacher
- Terms of service checks
Mini project
Distill a product-description extraction task from a large model into a small one using 2,000 filtered examples, and report accuracy, cost and p95 latency for both.
Check yourself
Why must you filter the teacher's outputs before training, rather than using them all?
Free resources
- OpenAI docs: model distillation (OpenAI)
- Hugging Face LLM Course (Hugging Face)