Perform a DDIM scheduler step
Description
Performs a single denoising step using the DDIM (Denoising Diffusion Implicit Models) algorithm. This function takes the output from a diffusion model at a specific timestep and computes the previous (less noisy) sample in the diffusion process.
Usage
ddim_scheduler_step(model_output, timestep, sample, schedule, eta = 0,
use_clipped_model_output = FALSE, thresholding = FALSE,
generator = NULL, variance_noise = NULL,
clip_sample = FALSE, set_alpha_to_one = FALSE,
prediction_type = c("epsilon", "sample", "v_prediction"),
dtype = torch::torch_float32(), device = "cpu")
Arguments
model_output: Numeric array. The output from the diffusion model, typically representing predicted noise or the denoised sample depending onprediction_type.timestep: Integer. The current timestep in the diffusion process.sample: Numeric array. The current noisy sample at timestept.schedule: List. The DDIM scheduler object containing the necessary parameters created from ddim_scheduler_create()eta: Numeric. Controls the stochasticity of the process. When eta=0, DDIM is deterministic. When eta=1, it’s equivalent to DDPM. Default: 0use_clipped_model_output: Logical. Whether to clip the model output before computing the sample update. Can improve stability. Default: FALSEthresholding: Logical. Whether to apply thresholding to the output. Default: FALSEgenerator: An optional random number generator for reproducibility. Default: NULLvariance_noise: Optional pre-generated noise for the variance when eta > 0. If NULL and eta > 0, noise will be generated. Default: NULLclip_sample: Logical. Whether to clip the sample. Default: FALSEset_alpha_to_one: Logical. Whether to override the final alpha value to 1. Used for numerical stability in the final step. Default: FALSEprediction_type: Character. The type of prediction the model outputs. Options are:- “epsilon”: The model predicts the noise
- “sample”: The model predicts the denoised sample directly
- “v_prediction”: The model predicts the velocity vector (v) Default: “epsilon”
dtype: The data type to use for computations. Default is torch_float32().device: The device to use for computations. Options are “cpu” and “cuda”.
Details
The DDIM step function implements the core sampling algorithm of DDIM described in Song et al. 2020. It computes the previous sample x_t-1 given the current sample x_t and the model output.
The algorithm differs from DDPM by using a non-Markovian diffusion process that allows for deterministic sampling and fewer inference steps without sacrificing quality.
When using prediction_type="epsilon" (most common), the model predicts the
noise that was added to create the current noisy sample. For prediction_type="sample",
the model predicts the clean sample directly. The v_prediction option implements
the v-parameterization from Salimans & Ho (2022).
Value
A list containing:
prev_sample: The less noisy sample at timestep t-1pred_original_sample: The predicted denoised sample
References
Song, J., Meng, C., & Ermon, S. (2020). “Denoising Diffusion Implicit Models.” https://arxiv.org/abs/2010.02502
Salimans, T., & Ho, J. (2022). “Progressive Distillation for Fast Sampling of Diffusion Models.” https://arxiv.org/abs/2202.00512
Examples
# Perform a denoising step
result <- ddim_scheduler_step(
model_output = model_output,
timestep = timestep,
sample = sample,
eta = 0, # Deterministic sampling
prediction_type = "epsilon")