diffusion_models.utils.schemas ============================== .. py:module:: diffusion_models.utils.schemas Module Contents --------------- .. py:class:: PredictionType Initialize self. See help(type(self)) for accurate signature. .. py:attribute:: Epsilon :value: 'epsilon' The noise added to the image. .. py:attribute:: V :value: 'v' The velocity, :math:`v = \sqrt{\bar{\alpha}}\epsilon - \sqrt{1-\bar{\alpha}}x_0`. .. py:class:: TrainingConfiguration A training configuration for simple experiment management. .. py:attribute:: training_name :type: str The name of the training. .. py:attribute:: batch_size :type: int The batch size used for training. .. py:attribute:: learning_rate :type: float The learning rate of the training. .. py:attribute:: number_of_epochs :type: int The number of epoch used for training. .. py:attribute:: checkpoint_rate :type: int :value: 100 The rate at which checkpoints are saved.. .. py:attribute:: mixed_precision_training :type: bool :value: False Whether or not to use automatic mixed precision training. .. py:attribute:: mixed_precision_dtype :type: str :value: 'bfloat16' ``bfloat16`` (no gradient scaling needed) or ``float16`` (uses a ``GradScaler``). :type: The autocast dtype when mixed precision is on .. py:attribute:: channels_last :type: bool :value: False Whether to use the ``channels_last`` memory format for the model and its inputs. This speeds up mixed precision training on tensor cores but is very slow in fp32, so it should be combined with ``mixed_precision_training``. .. py:attribute:: gradient_clip :type: Optional[float] :value: None Whether or not to clip gradients. .. py:attribute:: ema_decay :type: Optional[float] :value: None The decay of the exponential moving average of the weights. Disabled when None. .. py:attribute:: ema_warmup_steps :type: int :value: 0 When positive, ramps the EMA decay up as ``(1 + n) / (warmup + n)`` (capped at ``ema_decay``). .. py:attribute:: latest_checkpoint_rate :type: Optional[int] :value: None The rate (in epochs) at which the rolling ``latest.pt`` is overwritten. Disabled when None. .. py:attribute:: num_workers :type: int :value: 4 The number of dataloader worker processes. ``0`` loads data in the main process. .. py:attribute:: pin_memory :type: bool :value: True Whether the dataloader copies batches into pinned memory (only used with CUDA). .. py:attribute:: persistent_workers :type: bool :value: True Whether dataloader workers are kept alive between epochs (needs ``num_workers > 0``). .. py:attribute:: prefetch_factor :type: Optional[int] :value: None Batches prefetched per worker. Uses the torch default when None (needs ``num_workers > 0``). .. py:attribute:: compile :type: bool :value: False Whether to ``torch.compile`` the model's forward pass during training. Checkpoints and the EMA always hold the uncompiled model's weights. .. py:class:: EvaluationConfiguration Settings of the FID / KID evaluation that runs during training. .. py:attribute:: fid_rate :type: Optional[int] :value: None The rate (in epochs) at which FID/KID is computed and logged. Also computed after the last epoch. Disabled when None. .. py:attribute:: number_of_samples :type: int :value: 5000 The number of generated (and real) images compared. Only compare scores that use the same number. .. py:attribute:: batch_size :type: int :value: 100 The batch size used for sampling and feature extraction. .. py:attribute:: compute_kid :type: bool :value: True Whether to also compute the Kernel Inception Distance. .. py:attribute:: kid_subset_size :type: int :value: 1000 The KID subset size. .. py:attribute:: seed :type: int :value: 0 The seed of the sampling noise, so scores are comparable across runs. .. py:attribute:: num_workers :type: int :value: 4 Dataloader workers used to read the real images. .. py:class:: LogConfiguration An object to manage logging configuration. .. py:attribute:: log_rate :type: int :value: 10 The rate at which training metrics are logged. .. py:attribute:: image_rate :type: int :value: 50 The rate at which images are generated for visualization. This can be used to validate model performance. .. py:attribute:: number_of_images :type: int :value: 5 The number of images to generate. .. py:attribute:: weight_rate :type: Optional[int] :value: None The rate (in steps) at which weight histograms are logged. Disabled when None. .. py:class:: BetaSchedulerConfiguration A simplified beta scheduler configuration. .. py:attribute:: steps :type: int The number of steps in the beta scheduler. .. py:attribute:: betas :type: torch.Tensor The beta values. .. py:attribute:: alpha_bars :type: torch.Tensor The alpha bar values. .. py:class:: Checkpoint A simplified checkpoint framework for easy saving and loading. .. py:attribute:: epoch :type: int The current epoch. .. py:attribute:: model_state_dict :type: Dict[str, Any] The model state dict. .. py:attribute:: optimizer_state_dict :type: Dict[str, Any] The optimizer state dict. .. py:attribute:: beta_scheduler_config :type: BetaSchedulerConfiguration The beta scheduler configuration. .. py:attribute:: scaler :type: Optional[Dict[str, Any]] :value: None The GradScaler instance. .. py:attribute:: ema_model_state_dict :type: Optional[Dict[str, Any]] :value: None The state dict of the EMA (exponential moving average) weights, if tracked. .. py:attribute:: ema_num_updates :type: Optional[int] :value: None The number of EMA updates performed so far (needed to resume the EMA warmup). .. py:attribute:: completed_epochs :type: Optional[int] :value: None The number of fully completed epochs. Training resumes from here. .. py:attribute:: tensorboard_run_name :type: Optional[str] :value: None The name of the tensorboard run. .. py:attribute:: image_channels :type: int :value: 3 The number of image channels used in the training. .. py:attribute:: prediction_type :type: str :value: 'epsilon' What the model predicts (``"epsilon"`` or ``"v"``). Legacy checkpoints are epsilon. .. py:attribute:: config_yaml :type: Optional[str] :value: None The resolved configuration (YAML) of the run that produced this checkpoint. .. py:attribute:: loss :type: Optional[float] :value: None The final loss value recorded. .. note:: This is a legacy parameter and will be removed in a future release. .. py:method:: from_file(file_path, map_location = None) :classmethod: Load and instantiate a checkpoint from a file. :param file_path: The path to the checkpoint file. :param map_location: A function, torch. device, string or a dict specifying how to remap storage location. :returns: A checkpoint instance. .. py:method:: get_model_state_dict(use_ema = True) Get the weights to load into a model. :param use_ema: Prefer the EMA weights when the checkpoint has them. Falls back to the raw weights (with a warning) for checkpoints without EMA. :returns: A model state dict. .. py:method:: to_file(file_path) Saves a checkpoint to a file. The write is atomic: the checkpoint goes to a temporary file which then replaces the destination, so readers never see a partial file. .. py:class:: OldCheckpoint .. py:attribute:: epoch :type: int .. py:attribute:: model_state_dict :type: Dict[str, Any] .. py:attribute:: optimizer_state_dict :type: Dict[str, Any] .. py:attribute:: scaler :type: Optional[Dict[str, Any]] .. py:attribute:: tensorboard_run_name :type: Optional[str] :value: None .. py:attribute:: loss :type: Optional[float] :value: None .. py:method:: from_file(file_path) :classmethod: .. py:method:: to_file(file_path) .. py:method:: to_new_checkpoint(beta_scheduler) .. py:class:: Timestep .. py:attribute:: current :type: torch.Tensor .. py:attribute:: previous :type: Optional[torch.Tensor] :value: None