Table of Contents

Class DiffusionModelOptions<T>

Namespace
AiDotNet.Models.Options
Assembly
AiDotNet.dll

Configuration options for diffusion-based generative models.

public class DiffusionModelOptions<T> : ModelOptions

Type Parameters

T

The numeric type used for calculations.

Inheritance
DiffusionModelOptions<T>
Derived
Inherited Members

Remarks

This options class provides configuration for all diffusion model parameters including training hyperparameters, scheduler configuration, and generation settings.

For Beginners: Diffusion models work by learning to reverse a gradual noising process. These options control how the model trains and generates samples:

  • LearningRate: How big of a step to take during training
  • TrainTimesteps: How many noise levels to use (more = finer control)
  • BetaStart/BetaEnd: How much noise at each step

Properties

BetaEnd

Gets or sets the ending beta value (noise variance at t=T).

public double BetaEnd { get; set; }

Property Value

double

The ending beta value, defaulting to 0.02.

Remarks

For Beginners: Beta end is the amount of noise added at the final timestep. It should be larger than beta start to ensure samples become nearly pure noise. The default of 0.02 is from the original DDPM paper.

BetaSchedule

Gets or sets the type of beta schedule to use.

public BetaSchedule BetaSchedule { get; set; }

Property Value

BetaSchedule

The beta schedule type, defaulting to Linear.

Remarks

For Beginners: The beta schedule determines how noise variance changes across timesteps. Linear is simplest and widely compatible. ScaledLinear is used by Stable Diffusion. SquaredCosine often provides better quality results.

BetaStart

Gets or sets the starting beta value (noise variance at t=0).

public double BetaStart { get; set; }

Property Value

double

The starting beta value, defaulting to 0.0001.

Remarks

For Beginners: Beta start is the amount of noise added at the first timestep. It should be small since early timesteps should preserve most of the signal. The default of 0.0001 is from the original DDPM paper.

ClipSample

Gets or sets whether to clip predicted samples to [-1, 1].

public bool ClipSample { get; set; }

Property Value

bool

True to clip samples, false otherwise. Defaults to false.

Remarks

For Beginners: Clipping can prevent extreme values that might cause numerical instability, but may reduce output quality if the model is well-trained. Generally leave this as false unless you experience numerical issues.

DefaultInferenceSteps

Gets or sets the default number of inference steps for generation.

public int DefaultInferenceSteps { get; set; }

Property Value

int

The number of inference steps, defaulting to 50.

Remarks

For Beginners: During generation, you don't need all 1000 training timesteps. Using fewer steps (like 50) is much faster while still producing good quality. DDIM and PNDM schedulers are designed to work well with fewer steps.

LearningRate

Gets or sets the learning rate for training parameter updates.

public double LearningRate { get; set; }

Property Value

double

The learning rate, defaulting to 0.001.

Remarks

For Beginners: The learning rate controls how big each step is during training. A value of 0.001 means taking small, careful steps. If this value is too large, the model might overshoot the optimal solution. If it's too small, training will take a very long time. The default of 0.001 is a good starting point for most diffusion models.

LossFunction

Gets or sets the loss function for training.

public ILossFunction<T>? LossFunction { get; set; }

Property Value

ILossFunction<T>

The loss function, or null to use Mean Squared Error.

Remarks

For Beginners: The loss function measures how wrong the model's predictions are. Mean Squared Error (MSE) is standard for diffusion models since they predict continuous values. Leave as null to use the default MSE loss.

PredictionType

Gets or sets what the model is trained to predict.

public DiffusionPredictionType PredictionType { get; set; }

Property Value

DiffusionPredictionType

The prediction type, defaulting to Epsilon (noise).

Remarks

For Beginners: This must match what the diffusion model was trained to predict. Most models use Epsilon (noise) prediction. Some newer models use velocity prediction or direct sample prediction.

TrainTimesteps

Gets or sets the number of timesteps used during training.

public int TrainTimesteps { get; set; }

Property Value

int

The number of training timesteps, defaulting to 1000.

Remarks

For Beginners: This controls how many discrete noise levels the model learns. More timesteps (like 1000) give finer control over the denoising process but require more computation. The default of 1000 is standard for DDPM/DDIM models.