diffusion_models.diffusion_trainer
Module Contents
- class DiffusionTrainer(model, dataset, optimizer, training_configuration, loss_function=F.l1_loss, log_configuration=LogConfiguration(), reverse_transforms=lambda x: ..., device='cuda', output_directory=None, run_config=None, resume_from=None, evaluation_configuration=None, evaluation_dataset=None)[source]
A diffusion trainer framework.
This is a simplified framework for training a diffusion models.
- Parameters:
model (BaseDiffusionModel) – A diffusion model.
dataset (Dataset) – A dataset to train on.
optimizer (Optimizer) – The optimizer to use.
training_configuration (TrainingConfiguration) – The training configuration to use.
loss_function (Callable) – The loss function to use.
log_configuration (LogConfiguration) – The logging configuration to use.
reverse_transforms (Callable) – The reverse transforms to use.
device (str) – The device to use.
output_directory (Optional[Union[str, Path]]) – Where to write this run’s artifacts. When provided, checkpoints go to
<output_directory>/checkpointsand tensorboard logs to<output_directory>/tensorboard. Otherwise the legacy../checkpoints/<name>and../runs/<name>locations are used.run_config (Optional[str]) – The resolved configuration (YAML) of the run. It is logged to tensorboard and stored in every checkpoint for reproducibility.
resume_from (Optional[Union[str, Path]]) – A checkpoint to resume training from. The model, optimizer, grad scaler and EMA are restored and training continues from the epoch after the last completed one. Resuming happens at an epoch boundary; progress within an interrupted epoch is lost.
evaluation_configuration (Optional[EvaluationConfiguration]) – When
fid_rateis set, FID (and KID) of samples from the EMA model (or the raw model without EMA) is computed every that many epochs, and after the last epoch, then logged to tensorboard. Needs theevaluationextra.evaluation_dataset (Optional[Dataset]) – The real reference images for the evaluation, ideally a held-out split.
- ema: ExponentialMovingAverage | None = None[source]
The EMA of the model weights, when
ema_decayis configured.