autocast.processors.diffusion#

class DiffusionProcessor(backbone, schedule, denoiser_type='karras', learning_rate=0.0001, n_steps_output=4, n_channels_out=1, sampler_steps=50, sampler='euler')[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)

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, num_steps=100, sampler='euler', 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)

  • num_steps (int) – Number of denoising steps

  • sampler (str) – Type of sampler to use: - ‘euler’: Euler ODE solver (fast, deterministic) - ‘heun’: Heun’s method (more accurate, deterministic) - ‘ddim’: DDIM sampler (eta controls stochasticity) - ‘ddpm’: DDPM sampler (stochastic)

  • 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