Consistency Distillation
Module: Generative AI | Difficulty: Advanced
Consistency Distillation
Train student to match teacher's ODE trajectory:
Progressive Distillation
- Train teacher with steps
- Train student in 2 steps
- Student becomes new teacher
- Repeat times
One-Step Generation
class ConsistencyDistillation:
def __init__(self, teacher, student, ema_decay=0.999):
self.teacher = teacher
self.student = student
self.teacher_ema = EMA(teacher, ema_decay)
def loss(self, x0, t1, t2):
xt1 = self.add_noise(x0, t1)
xt2 = self.add_noise(x0, t2)
s1 = self.student(xt1, t1)
with torch.no_grad():
s2 = self.teacher_ema(xt2, t2)
return ((s1 - s2)**2).mean()
| Steps | FID (Consistency) | FID (Progressive) |
|---|---|---|
| 1 | 4.12 | 8.3 |
| 2 | 3.45 | 5.1 |
| 4 | 3.21 | 4.2 |
| 8 | 3.11 | 3.6 |