autocast.processors.diffusion#

class LolaElucidatedDenoiser(backbone, schedule, c_noise_scale=10.0)[source]#

Bases: Denoiser

LoLA EDM-style denoiser preconditioning.

This mirrors ElucidatedDenoiser in LoLA’s lola/diffusion.py. The main difference from Azula’s local KarrasDenoiser is the modulation input scale: LoLA feeds 10 * log(sigma / alpha) to the time embedding.

Parameters:
  • backbone (Module)

  • schedule (Schedule)

  • c_noise_scale (float)

forward(x_t, t, **kwargs)[source]#
Parameters:
  • x_t (Tensor) – A noisy tensor \(x_t\), with shape \((B, *)\).

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

  • kwargs – Optional keyword arguments.

Returns:

The posterior \(q_\phi(X \mid x_t)\).

Return type:

GaussianPosterior

loss(x, t, **kwargs)[source]#
Parameters:
Return type:

Tensor

class DiffusionProcessor(backbone, schedule, denoiser_type='karras', learning_rate=0.0001, n_steps_output=4, n_channels_out=1, sampler_steps=50, sampler='euler', sampler_order=2)[source]#

Bases: Processor

Diffusion Processor.

Parameters:
  • backbone (Module)

  • schedule (Schedule)

  • denoiser_type (str)

  • learning_rate (float)

  • n_steps_output (int)

  • n_channels_out (int)

  • sampler_steps (int)

  • sampler (str)

  • sampler_order (int)

map(x, global_cond)[source]#

Map input window of states/times to output window using denoiser.

Parameters:
Return type:

Tensor

forward(x, global_cond=None)[source]#

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

Parameters:
Return type:

Tensor

loss(batch)[source]#

Training step with diffusion loss.

Sample random time steps and compute loss between denoised output and the clean data.

Parameters:

batch (EncodedBatch)

Return type:

Tensor

sample(x_t, cond, global_cond=None, num_steps=100, sampler=None, eta=0.0, return_trajectory=False, silent=True, **sampler_kwargs)[source]#

Generate samples via reverse diffusion using Azula’s samplers.

Parameters:
  • x_t (Tensor) – Starting noise (B, T, C, W, H)

  • cond (Tensor) – Conditioning input (B, T_cond, C_cond, W, H)

  • global_cond (Tensor | None) – Optional non-spatial conditioning/modulation tensor.

  • num_steps (int) – Number of denoising steps

  • sampler (str | None) – Type of sampler to use. Defaults to the configured self.sampler when unset. - ‘euler’: Euler ODE solver (fast, deterministic) - ‘heun’: Heun’s method (more accurate, deterministic) - ‘ddim’: DDIM sampler (eta controls stochasticity) - ‘ddpm’: DDPM sampler (stochastic) - ‘ab’: Adams-Bashforth ODE solver with z-prediction - ‘vab’: Adams-Bashforth ODE solver with v-prediction

  • eta (float) – Stochasticity parameter for DDIM (0=deterministic, 1=stochastic)

  • return_trajectory (bool) – If True, return all intermediate steps

  • silent (bool) – If True, hide progress bar

  • **sampler_kwargs – Additional kwargs passed to sampler

Returns:

Generated samples (B, T, C, W, H) Or if return_trajectory=True: List of tensors

Return type:

Tensor