azula.guidance.cfg

Classifier-free guidance (CFG) internals.

References

Classifier-Free Diffusion Guidance (Ho et al., 2022)

Classes

CFGDenoiser

Creates a CFG denoiser module.

Descriptions

class azula.guidance.cfg.CFGDenoiser(denoiser)[source]

Creates a CFG denoiser module.

Parameters:

denoiser (Denoiser) – A denoiser \(q_\phi(X \mid X_t)\).

forward(x_t, t, positive, negative={}, guidance=1.0, **kwargs)[source]
Parameters:
  • x_t (Tensor) – A noisy tensor \(x_t\), with shape \((B, *)\).

  • t (Tensor) – The time \(t\), with shape \(()\) or \((B)\).

  • positive (dict[str, Any]) – The positive label \(c_+\) as a dictionary of keyword arguments.

  • negative (dict[str, Any]) – The negative label \(c_-\) as a dictionary of keyword arguments.

  • guidance (float | Tensor) – The classifier-free guidance strength \(\omega \in \mathbb{R}_+\).

  • kwargs – Optional keyword arguments.

Returns:

The Dirac delta \(\delta(X - \mu)\) where

\[\mu = (1 + \omega) \, \mu_\phi(x_t \mid c_+) - \omega \, \mu_\phi(x_t \mid c_-) \, .\]

Return type:

DiracPosterior