ML SYSTEM DESIGN & MLOPS · INTERVIEW QUESTION
What is model distillation? How is it used in production?
🟡 intermediate · Model Serving
Hint: Training a smaller 'student' model to mimic a larger 'teacher' model.
Answer
Knowledge distillation trains a compact student model to reproduce the behavior of a large teacher model.
Process:
-
Train teacher on task.
-
Generate soft labels: teacher's output probabilities (softmax with temperature T>1 to soften distributions).
-
Train student on combination of hard labels (ground truth) and soft labels (teacher output). Loss = α·CE(student, hard_labels) + (1-α)·KL(teacher_soft || student_soft), commonly multiplied by T².
Why soft labels help: they encode 'dark knowledge' — inter-class similarities (e.g., a '7' is more like a '1' than a '0').
Production uses:
-
Deploy smaller/faster model (the DistilBERT paper reports 40% fewer parameters, 60% faster inference and about 97% of BERT's language-understanding performance on its evaluation, not on every task).
-
Compress LLMs for edge deployment.
-
Ensemble distillation: distill an ensemble into one model. Modern: self-distillation, online distillation, multi-task distillation.
Related questions
- What are the key techniques for making Transformers efficient in production? Explain KD, quantization, pruning, and graph optimization.
- How do you deploy a fine-tuned LLM in production on cloud infrastructure?
- What is continuous batching for LLM inference? How does it improve throughput?
- Design a real-time ML serving system for a recommendation engine handling 10k QPS.
- What is LLMOps and how does it differ from traditional MLOps?