MLCrack

    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:

    1. Train teacher on task.

    2. Generate soft labels: teacher's output probabilities (softmax with temperature T>1 to soften distributions).

    3. 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:

    1. 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).

    2. Compress LLMs for edge deployment.

    3. Ensemble distillation: distill an ensemble into one model. Modern: self-distillation, online distillation, multi-task distillation.