DDIM#

reverse_process

DDIM Reverse Denoising Process

linear_tau

linear tau schedule

quadratic_tau

quadratic tau schedule

DDIM

Reverse process and Sampling for DDIM

LitDDIM

LightningModule for sampling with DDIM with LitDDPM's checkpoints

DDIM Sampling#

dmme.ddim.reverse_process(x_tau_i, alpha_bar_tau_i, alpha_bar_tau_i_minus_one, noise_in_x_tau_i)[source]#

DDIM Reverse Denoising Process

Parameters:
  • model (nn.Module) – model for estimating noise

  • x_t (torch.Tensor) – x_t

  • t (int) – current timestep

  • noise (torch.Tensor) – noise

dmme.ddim.linear_tau(timesteps, sub_timesteps)[source]#

linear tau schedule

Parameters:
  • timesteps (int) – total timesteps \(T\)

  • sub_timesteps (int) – sub sequence length less than \(T\)

dmme.ddim.quadratic_tau(timesteps, sub_timesteps)[source]#

quadratic tau schedule

Parameters:
  • timesteps (int) – total timesteps \(T\)

  • sub_timesteps (int) – sub sequence length less than \(T\)

class dmme.ddim.DDIM(model, timesteps, sub_timesteps, tau_schedule='quadratic')[source]#

Reverse process and Sampling for DDIM

Parameters:
  • timesteps (int) – total timesteps \(T\)

  • tau_schedule (str) – tau schedule, “linear”`or `”quadratic”

sampling_step(x_tau_i, i)[source]#

Sample from \(p_\theta(x_{t-1}|x_t)\)

Parameters:
  • model (nn.Module) – model for estimating noise

  • x_t (torch.Tensor) – image of shape \((N, C, H, W)\)

  • t (int) – starting \(t\) to sample from

Returns:

generated sample of shape \((N, C, H, W)\)

Return type:

(torch.Tensor)

generate(img_size: Tuple[int, int, int, int])[source]#

Generate image of shape \((N, C, H, W)\) faster by only sampling the sub sequence

Parameters:

img_size (Tuple[int, int, int, int]) – image size to generate as a tuple \((N, C, H, W)\)

Returns:

generated image of shape \((N, C, H, W)\)

Return type:

(torch.Tensor)

Training Loop#

class dmme.ddim.LitDDIM(model: Module, lr: float = 0.0002, warmup: int = 5000, imgsize: Tuple[int, int, int] = (3, 32, 32), timesteps: int = 1000, decay: float = 0.9999, sample_steps: int = 50, tau_schedule: str = 'quadratic')[source]#

LightningModule for sampling with DDIM with LitDDPM’s checkpoints

Parameters:
  • model (nn.Module) – neural network predicting noise \(\epsilon_\theta\)

  • lr (float) – learning rate, defaults to \(2e-4\)

  • warmup (int) – linearly increases learning rate for warmup steps until lr is reached, defaults to 5000

  • imgsize (Tuple[int, int, int]) – image size in (C, H, W)

  • timestpes (int) – total timesteps for the forward and reverse process, \(T\)

  • decay (float) – EMA decay value

  • sample_steps (int) – sample steps for generation process

  • tau_schedule (str) – tau schedule to use for generation, “linear” or “quadratic”