Distilarea cunoștințelor

term_id: knowledge_distillation

Category: training_techniques

Definition

Distilarea cunoștințelor este o metodă de învățare automată utilizată pentru a comprima o rețea neuronală mare și complexă (profesorul) într-o rețea mai mică și mai eficientă (studentul). Modelul student este antrenat să

Summary

Distilarea cunoștințelor este o tehnică de comprimare a modelelor în care un model student mai mic învață să imite comportamentul unui model profesor mai mare.

Key Concepts

  • Model profesor-student
  • Comprimarea modelelor
  • Ținte moi (Soft Targets)
  • Eficiență

Use Cases

  • Implementarea modelelor pe dispozitive edge
  • Reducerea latenței de inferență
  • Scăderea costurilor de calcul în cloud

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)