Class DDIMScheduler<T>
- Namespace
- AiDotNet.NeuralNetworks.Diffusion.Schedulers
- Assembly
- AiDotNet.dll
DDIM (Denoising Diffusion Implicit Models) scheduler implementation.
public sealed class DDIMScheduler<T> : NoiseSchedulerBase<T>, INoiseScheduler<T>
Type Parameters
TThe numeric type used for calculations.
- Inheritance
-
DDIMScheduler<T>
- Implements
- Inherited Members
Remarks
DDIM is a faster variant of DDPM that can achieve similar quality with far fewer denoising steps. While DDPM requires many steps (often 1000), DDIM can achieve similar quality with 50 or fewer steps by using a different mathematical formulation.
For Beginners: DDIM is like a shortcut for removing noise from images.
Imagine you have a very blurry photo and need to make it clear:
- DDPM (original method): Take 1000 tiny steps to slowly reveal the image
- DDIM (this method): Take 50 larger steps to reveal the image faster
The magic is the "eta" parameter:
- eta=0: Deterministic - same input always produces same output (faster, consistent)
- eta=1: Stochastic - adds randomness like DDPM (slower, more variety)
- eta between 0-1: Mix of both behaviors
Key advantages of DDIM:
- Much faster generation (10-50x fewer steps needed)
- Deterministic option allows reproducible results
- Can interpolate smoothly between images (useful for animations)
Reference: "Denoising Diffusion Implicit Models" by Song et al., 2020
Constructors
DDIMScheduler(SchedulerConfig<T>)
Initializes a new instance of the DDIM scheduler.
public DDIMScheduler(SchedulerConfig<T> config)
Parameters
configSchedulerConfig<T>Configuration for the scheduler including beta schedule parameters.
Remarks
For Beginners: Create a DDIM scheduler with custom settings, or use CreateDefault() for standard DDPM defaults.
// Create with default settings
var config = SchedulerConfig<double>.CreateDefault();
var scheduler = new DDIMScheduler<double>(config);
// Set up for 50 inference steps
scheduler.SetTimesteps(50);
Exceptions
- ArgumentNullException
Thrown when config is null.
Methods
Step(Vector<T>, int, Vector<T>, T, Vector<T>?)
Performs one DDIM denoising step.
public override Vector<T> Step(Vector<T> modelOutput, int timestep, Vector<T> sample, T eta, Vector<T>? noise = null)
Parameters
modelOutputVector<T>The model's noise prediction (epsilon).
timestepintThe current timestep in the diffusion process.
sampleVector<T>The current noisy sample.
etaTStochasticity parameter:
- 0 = fully deterministic (pure DDIM)
- 1 = fully stochastic (equivalent to DDPM)
- Values in between interpolate the behavior
noiseVector<T>Optional noise for stochastic sampling. Required when eta > 0 for true stochastic behavior. If null and eta > 0, falls back to deterministic (zero noise).
Returns
- Vector<T>
The denoised sample for the previous timestep.
Remarks
The DDIM step formula (simplified): 1. Predict original sample: x_0 = (x_t - sqrt(1-alpha_cumprod) * eps) / sqrt(alpha_cumprod) 2. Compute "direction pointing to x_t": d = sqrt(1-alpha_prev - sigma^2) * eps 3. Compute previous sample: x_{t-1} = sqrt(alpha_prev) * x_0 + d + sigma * noise
For Beginners: This function takes your current noisy image and the model's guess of what noise is in it, then removes some of that noise to get a cleaner image. The eta parameter controls whether this removal is exact (eta=0) or has some randomness (eta>0).
Exceptions
- ArgumentNullException
Thrown when modelOutput or sample is null.
- ArgumentException
Thrown when modelOutput and sample have different lengths.
- ArgumentOutOfRangeException
Thrown when timestep is out of range.