In Stable Diffusion and other diffusion models, the denoising process during inference is inherently probabilistic rather than deterministic. This is because the underlying mathematical framework of diffusion models is based on stochastic differential equations (SDEs) and probabilistic modeling of data distributions. Here's why the denoiser is probabilistic and why samplers are essential during inference:
1. The Nature of the Diffusion Process
Forward Process (Noising):
- The forward diffusion process incrementally adds Gaussian noise to the data over a series of time steps.
- This process is modeled as a Markov chain where each step ( x_t ) is obtained by adding noise to ( x_{t-1} ).
- Mathematically, this is represented as:
[
x_t = \sqrt{1 - \beta_t} \cdot x_{t-1} + \sqrt{\beta_t} \cdot \epsilon_t
]
where ( \beta_t ) controls the variance schedule and ( \epsilon_t ) is standard Gaussian noise.
Reverse Process (Denoising):
- The goal during inference is to reverse this noising process to generate new data samples from pure noise.
- The reverse process involves sampling from the conditional probability distributions ( p_{\theta}(x_{t-1} | x_t) ).
- These conditional distributions are inherently probabilistic due to the added noise in the forward process.
2. Probabilistic Modeling and Sampling
Score Matching and Stochasticity:
- The denoiser (often a neural network like a U-Net) is trained to predict the noise ( \epsilon ) added at each step or, equivalently, the score function ( \nabla_{x_t} \log p_t(x_t) ).
- This score function indicates the direction to adjust ( x_t ) to increase the data probability density.
- However, the reverse diffusion is not just about following the gradient (which would be deterministic) but also about appropriately adding stochasticity to capture the uncertainty and diversity in the data distribution.
Need for Samplers:
- To sample from ( p_{\theta}(x_{t-1} | x_t) ), we use samplers that incorporate both the predicted mean (from the denoiser) and a randomness component.
- Common samplers include Euler-Maruyama, Heun's method, or other SDE solvers that handle stochastic processes.
- These samplers ensure that the generated samples faithfully represent the underlying data distribution, capturing modes and variations present in the training data.
3. Limitations of Deterministic Denoising
Loss of Diversity:
- A deterministic denoiser would produce the same output ( x_{t-1} ) given the same ( x_t ), reducing the diversity of generated samples.
- Stochasticity allows the model to explore different plausible denoising trajectories, leading to varied and realistic samples.
Mismatch with Training Objective:
- The denoiser is trained under a probabilistic framework to minimize the variational bound between the model distribution and the data distribution.
- Using a deterministic update during inference would be inconsistent with the probabilistic nature of the model and the loss function used during training.
4. Mathematical Foundation
Stochastic Differential Equations (SDEs):
- Diffusion models can be framed in terms of SDEs, where the reverse process is an SDE that involves both drift (deterministic) and diffusion (stochastic) terms.
- The general form of the reverse-time SDE is:
[
dx = [f(x, t) - g(t)^2 \nabla_x \log p_t(x)] dt + g(t) d\bar{w}
]
where ( d\bar{w} ) represents the reverse-time Wiener process (Brownian motion).
Sampling as Solving SDEs:
- Solving this SDE to generate samples requires stochastic numerical methods that incorporate randomness at each step.
- Deterministic methods would fail to solve the SDE accurately, leading to poor approximations of the data distribution.
Conclusion
In summary, the denoiser in Stable Diffusion is probabilistic because:
- The reverse diffusion process is fundamentally a stochastic process requiring sampling from conditional probability distributions.
- Stochasticity ensures that the model captures the full diversity and uncertainty inherent in the data distribution.
- Deterministic denoising would not align with the probabilistic training framework and would limit the model's ability to generate diverse and realistic samples.
Therefore, samplers are essential during inference to properly navigate the stochastic reverse diffusion process and generate high-quality, varied samples from the model.