# Distillation and Small Models

> Use a large model's outputs to train a small, fast, cheap model that matches it on your specific task. Free notes, key concepts, resources and a mini project.

Canonical: https://www.internhack.in/roadmaps/tracks/ai-engineer/distillation
Last updated: 2026-11-28

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](https://www.internhack.in/roadmaps/tracks/ai-engineer/hosted-fine-tuning)

**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

1. Collect a large set of realistic inputs for one narrow task.
2. Generate outputs with the teacher model and your best prompt, possibly with reasoning.
3. **Filter** with graders, code checks or human review so only correct outputs remain.
4. Fine-tune the student (hosted or with LoRA) on the filtered pairs.
5. 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](https://platform.openai.com/docs/guides/distillation) (OpenAI)
- [Hugging Face LLM Course](https://huggingface.co/learn/llm-course) (Hugging Face)

Previous: [LoRA and Parameter-Efficient Fine-Tuning](https://www.internhack.in/roadmaps/tracks/ai-engineer/lora-peft) · Next: [Vision and Document Understanding](https://www.internhack.in/roadmaps/tracks/ai-engineer/vision-inputs)

## More in Fine-Tuning and Model Customization

- [Prompting vs RAG vs Fine-Tuning](https://www.internhack.in/roadmaps/tracks/ai-engineer/when-to-fine-tune)
- [Preparing Fine-Tuning Datasets](https://www.internhack.in/roadmaps/tracks/ai-engineer/fine-tuning-data)
- [Hosted Fine-Tuning Services](https://www.internhack.in/roadmaps/tracks/ai-engineer/hosted-fine-tuning)
- [LoRA and Parameter-Efficient Fine-Tuning](https://www.internhack.in/roadmaps/tracks/ai-engineer/lora-peft)
- [Distillation and Small Models](https://www.internhack.in/roadmaps/tracks/ai-engineer/distillation)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [AI Engineer Roadmap](https://www.internhack.in/roadmaps/tracks/ai-engineer)
