diffusion_models.utils.ema
Module Contents
- unwrap_model(model)[source]
Return the module underneath a
torch.compilewrapper (if any).torch.compilereturns anOptimizedModulethat shares its parameters with the original module but prefixes every state dict key with_orig_mod.. The EMA, checkpoints and optimizer must always deal with the original module so that keys stay stable whether or not compilation is on.
- class ExponentialMovingAverage(model, decay=0.999, warmup_steps=0)[source]
Keeps an exponential moving average (EMA) of a model’s weights.
The EMA model is a frozen, eval-mode deep copy of the tracked model. The EMA is compile-aware: a
torch.compile-d model can be passed in, as both the copy and every update operate on the underlying module, and the EMA model itself is never compiled, so its keys stay free of_orig_mod.prefixes. Floating point parameters are averaged, while buffers (e.g. BatchNorm running statistics and integer counters) are copied verbatim from the tracked model, as averaging them is meaningless.- Parameters: