Update EMA weights after each training step.
(self, model: nn.Module)
| 223 | |
| 224 | @torch.no_grad() |
| 225 | def update(self, model: nn.Module): |
| 226 | """Update EMA weights after each training step.""" |
| 227 | for name, param in model.named_parameters(): |
| 228 | if param.requires_grad and name in self.shadow: |
| 229 | self.shadow[name].mul_(self.decay).add_( |
| 230 | param.data, alpha=1.0 - self.decay |
| 231 | ) |
| 232 | |
| 233 | def apply(self, model: nn.Module): |
| 234 | """Load EMA weights into model (for evaluation/sampling).""" |