scheduler_add_noise

Add noise to latents using DDIM scheduler

Description

This function adds noise to the original latents according to the DDIM scheduler’s diffusion process. It computes the noisy latents based on the original latents, noise, and the current timestep.

Usage

scheduler_add_noise(original_latents, noise, timestep, scheduler_obj)

Arguments

  • original_latents: A torch tensor representing the original latents.
  • noise: A torch tensor representing the noise to be added.
  • timestep: An integer representing the current timestep in the diffusion process.
  • scheduler_obj: A list containing the DDIM scheduler parameters, including alphas_cumprod and timesteps. The alphas_cumprod represents how much of the original signal remains at each timestep of the diffusion process.

Details

The noise is added according to the standard diffusion forward process formula: noised_latents = sqrt(alpha_cumprod) * original_latents + sqrt(1-alpha_cumprod) * noise

Where alpha_cumprod is the cumulative product of (1-beta) values up to the specified timestep, with beta being the noise schedule.

Value

A torch tensor containing the noised latents, which represents the original latents with the appropriate amount of noise added for the given timestep.

Examples

# Assuming we have latents, noise, and a scheduler
noised_latents <- scheduler_add_noise(
  original_latents = latents,
  noise = torch::torch_randn_like(latents),
  timestep = scheduler$timesteps[1],
  scheduler_obj = scheduler
)