Class PNDMScheduler<T>
- Namespace
- AiDotNet.NeuralNetworks.Diffusion.Schedulers
- Assembly
- AiDotNet.dll
PNDM (Pseudo Numerical Methods for Diffusion Models) scheduler implementation.
public sealed class PNDMScheduler<T> : NoiseSchedulerBase<T>, INoiseScheduler<T>
Type Parameters
TThe numeric type used for calculations.
- Inheritance
-
PNDMScheduler<T>
- Implements
- Inherited Members
Remarks
PNDM uses pseudo numerical methods to accelerate diffusion sampling. It can achieve high-quality results with even fewer steps than DDIM by using a combination of linear multi-step methods and improved transfer techniques.
For Beginners: PNDM is an advanced method for fast image generation.
Think of diffusion like walking down a mountain (from noise to clean image):
- DDPM: Take 1000 tiny careful steps
- DDIM: Take 50 medium steps
- PNDM: Take 20 smart steps using "momentum" from previous steps
The key insight is that PNDM remembers its previous predictions and uses them to make better guesses about where to step next. It's like a ball rolling down a hill - it uses its momentum to move faster.
Advantages:
- Very fast generation (often 20-25 steps for good quality)
- Uses multi-step methods from numerical analysis
- Good balance of speed and quality
The scheduler operates in two phases:
- Prk (Pseudo Runge-Kutta) for initial steps
- Plms (Pseudo Linear Multi-Step) for remaining steps
Reference: "Pseudo Numerical Methods for Diffusion Models on Manifolds" by Liu et al., 2022
Constructors
PNDMScheduler(SchedulerConfig<T>)
Initializes a new instance of the PNDM scheduler.
public PNDMScheduler(SchedulerConfig<T> config)
Parameters
configSchedulerConfig<T>Configuration for the scheduler including beta schedule parameters.
Remarks
For Beginners: Create a PNDM scheduler for fast, high-quality generation. PNDM works best with 20-50 inference steps.
// Create PNDM scheduler with default settings
var config = SchedulerConfig<double>.CreateDefault();
var scheduler = new PNDMScheduler<double>(config);
// Set up for 25 inference steps (PNDM works well with few steps)
scheduler.SetTimesteps(25);
Exceptions
- ArgumentNullException
Thrown when config is null.
Methods
GetState()
Gets the current scheduler state for checkpointing.
public override Dictionary<string, object> GetState()
Returns
- Dictionary<string, object>
A dictionary containing the scheduler's state.
LoadState(Dictionary<string, object>)
Loads scheduler state from a checkpoint.
public override void LoadState(Dictionary<string, object> state)
Parameters
stateDictionary<string, object>The state dictionary to load from.
Remarks
Note: The counter is not restored because the model output history (_ets) cannot be serialized without significant overhead. Restoring counter without history would cause incorrect behavior in PLMS mode which relies on previous outputs. After loading state, the scheduler will restart from the warmup (PRK) phase.
SetTimesteps(int)
Sets up the inference timesteps and resets the scheduler state.
public override void SetTimesteps(int inferenceSteps)
Parameters
inferenceStepsintNumber of denoising steps to use during inference.
Exceptions
- ArgumentOutOfRangeException
Thrown when inferenceSteps is invalid.
Step(Vector<T>, int, Vector<T>, T, Vector<T>?)
Performs one PNDM 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.
etaTNot used in PNDM (deterministic scheduler). Included for interface compatibility.
noiseVector<T>Not used in PNDM. Included for interface compatibility.
Returns
- Vector<T>
The denoised sample for the previous timestep.
Remarks
PNDM uses a two-phase approach: 1. First few steps use pseudo Runge-Kutta (prk) method 2. Remaining steps use pseudo linear multi-step (plms) method
The plms method uses history of previous predictions to extrapolate a better estimate for the current step.
For Beginners: This method intelligently combines current and past predictions to take larger, more accurate steps. It's like using a running average to smooth out predictions and make faster progress.
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.