Knowledge Distillation

term_id: knowledge_distillation

Category: training_techniques

Definition

Knowledge distillation is een machine learning-methode die wordt gebruikt om een groot, complex neurale netwerk (de docent) te comprimeren tot een kleiner, efficiënter netwerk (de student). Het studentmodel wordt getraind om

Summary

Knowledge distillation is een techniek voor modelcompressie waarbij een kleiner studentmodel leert om het gedrag van een groter docentmodel na te bootsen.

Key Concepts

  • Docent-Studentmodel
  • Modelcompressie
  • Zachte Doelen
  • Efficiëntie

Use Cases

  • Implementeren van modellen op randapparatuur
  • Verminderen van inferentielatency
  • Verlagen van kosten voor cloudcomputing

Code Example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
import torch
import torch.nn as nn

def distillation_loss(student_logits, teacher_logits, temperature=2.0):
    T = temperature
    student_probs = nn.functional.softmax(student_logits / T, dim=1)
    teacher_probs = nn.functional.softmax(teacher_logits / T, dim=1)
    return nn.functional.kl_div(
        nn.functional.log_softmax(student_logits / T, dim=1),
        teacher_probs,
        reduction='batchmean'
    ) * (T * T)