Skip to content

dew.diffusion

Forward processes, noise schedules and the parameterizations over them.

Process pairs a schedule with a prediction transform, and a run’s objective and every solver read that process. presets holds the named combinations, and discrete has the masked-token process.

Each name below is imported from its own module when first read, so a discrete text process reads none of the image schedules and presets.

NameSummary
ConsistencyBoundaryThe boundary parameterization of a latent consistency model, as in Diffusers’ LCMScheduler.
ContinuousNoiseSchedulerA schedule whose time is a fraction of the trajectory, not an index. Documented in dew.diffusion.schedules.
CosineNoiseSchedulerThe cosine beta table of Nichol and Dhariwal 2021. Documented in dew.diffusion.schedules.
DenoiserDenoises with one model, its parameters and its conditions. Documented in dew.diffusion.process.
DirectPredictionTransform
DiscreteNoiseSchedulerA variance preserving schedule tabulated from betas, DDPM style. Documented in dew.diffusion.schedules.
EDMNoiseSchedulerDraws training sigmas from exp(N(P_mean, P_std^2)). Documented in dew.diffusion.schedules.
EpsilonPredictionTransform
FlowMatchPredictionTransformThe model predicts the rectified flow velocity u = epsilon - x_0.
FlowMatchingSchedulerRectified flow / conditional flow matching on the linear path. Documented in dew.diffusion.schedules.
GeneralizedNoiseSchedulerThe variance-exploding schedule family of the EDM paper. Documented in dew.diffusion.schedules.
KarrasPredictionTransformThe EDM preconditioning of the model’s input and output.
KarrasVENoiseSchedulerPlaces sigmas along t with the rho spacing of the EDM paper. Documented in dew.diffusion.schedules.
LinearNoiseSchedulerThe linear beta table of DDPM, scaled to the step count. Documented in dew.diffusion.schedules.
MinSNRWeights the loss with min-SNR-gamma.
NoiseSchedulerDefines a forward process x_t = alpha(t) x_0 + sigma(t) eps on the time domain [0, T]. Documented in dew.diffusion.schedules.
PredictionTransformDefines what the model predicts and how x_0 and epsilon are recovered from its output.
ProcessPairs a noise schedule with what the model predicts on it and how the loss is weighted. Documented in dew.diffusion.process.
ScheduleWeightingWeights the loss with the schedule’s own weight.
SourceLimitedPredictionLimits x_0 the way a published scheduler’s step does.
SqrtContinuousNoiseSchedulerSquare-root schedule from Diffusion-LM. Documented in dew.diffusion.schedules.
VPredictionTransformThe model predicts v = alpha eps - sigma x_0, divided by sqrt(alpha^2 + sigma^2).
VelocityLossScores a clean-sample prediction in velocity space on the linear path, as JiT’s loss does.
WeightingWeights a per-example loss, given the schedule and the prediction transform.
broadcast_ratesReturn the schedule’s rates (alpha, sigma) at t, shaped to broadcast against x.
cosine_beta_scheduleReturn the cosine beta table of Nichol and Dhariwal 2021. Documented in dew.diffusion.schedules.
discreteMasked (absorbing-state) discrete diffusion, with the interface of the Gaussian one.
expandReturn a per-example coefficient [B] reshaped to broadcast against x [B, ...]. Documented in dew.diffusion.schedules.
linear_beta_scheduleReturn DDPM’s betas, linear from beta_start to beta_end over 1000 steps. Documented in dew.diffusion.schedules.
presetsNamed diffusion conventions, stored as dataclasses in a run’s run.json.

class source

class ConsistencyBoundary(
inner: PredictionTransform,
timestep_scaling: float = 10.0,
sigma_data: float = 0.5,
)

The boundary parameterization of a latent consistency model, as in Diffusers’ LCMScheduler.

The method is from Luo et al. 2023 (arXiv 2310.04378). inner converts the model’s output to x_0, and the consistency function is f = c_skip x_t + c_out x_0, with c_skip = sigma_data^2 / (s^2 + sigma_data^2) and c_out = s / sqrt(s^2 + sigma_data^2) at the scaled time s = timestep_scaling t. So f is x_t itself at t = 0. The returned x_0 is f, and epsilon is recovered from it.

def pred_transform(x_t, prediction, rates, t)
def backward_diffusion(x_t, prediction, rates)
def get_input_scale(rates)

class source

class DirectPredictionTransform(PredictionTransform)

DirectPredictionTransform.backward_diffusion

Section titled “DirectPredictionTransform.backward_diffusion”
def backward_diffusion(x_t, prediction, rates)

class source

class EpsilonPredictionTransform(PredictionTransform)

EpsilonPredictionTransform.backward_diffusion

Section titled “EpsilonPredictionTransform.backward_diffusion”
def backward_diffusion(x_t, prediction, rates)
def get_target(x_0, epsilon, rates)

EpsilonPredictionTransform.target_error_scale

Section titled “EpsilonPredictionTransform.target_error_scale”
def target_error_scale(snr)

class source

class FlowMatchPredictionTransform(PredictionTransform)

The model predicts the rectified flow velocity u = epsilon - x_0.

This is the constant velocity of the linear path, so x_0 and epsilon are each one step from x_t along it.

FlowMatchPredictionTransform.backward_diffusion

Section titled “FlowMatchPredictionTransform.backward_diffusion”
def backward_diffusion(x_t, prediction, rates)
def get_target(x_0, epsilon, rates)

FlowMatchPredictionTransform.target_error_scale

Section titled “FlowMatchPredictionTransform.target_error_scale”
def target_error_scale(snr)

class source

class KarrasPredictionTransform(sigma_data: float = 0.5, *, velocity: bool = False)

The EDM preconditioning of the model’s input and output.

This is Table 1 of Karras et al. 2022. The model’s input is c_in x_t, and its raw output F gives x_0 = c_skip x_t + c_out F. The loss compares that x_0 with the clean sample, so the target is x_0, and a weight defined on the x_0 loss, such as min-SNR’s, applies without conversion. EDM’s lambda = 1 / c_out^2 is the schedule’s own weight on this loss.

velocity matches Diffusers 0.34.0’s EDM prediction_type="v_prediction". Its precondition_outputs negates c_out, so the model outputs the velocity of the preconditioned path instead of the offset to its endpoint.

KarrasPredictionTransform.backward_diffusion

Section titled “KarrasPredictionTransform.backward_diffusion”
def backward_diffusion(x_t, prediction, rates)
def pred_transform(x_t, prediction, rates, t)
def get_input_scale(rates)

dataclass source

class MinSNR(gamma: float)

Weights the loss with min-SNR-gamma.

min-SNR-gamma is from Hang et al. 2023. The weight is min(SNR, gamma) on the x_0 loss, converted into the space the model trains in, and it replaces the schedule’s own weight. At zero SNR (a table whose last step keeps no signal) the epsilon conversion is 0 / 0, so the weight there is one, as the authors’ code sets it.

class source

class PredictionTransform(*, normalize_input: bool = False)

Defines what the model predicts and how x_0 and epsilon are recovered from its output.

The base class provides the x_0 target and the identity output transform. A subclass must implement backward_diffusion, because the base raises NotImplementedError. With normalize_input, the model’s input is scaled by 1 / sqrt(alpha^2 + sigma^2).

rates in every method is the schedule’s (alpha, sigma) pair, already shaped to broadcast against the batch.

divides_by_signal: bool

Whether recovering (x_0, epsilon) from a prediction divides by the signal rate alpha, and so is undefined where alpha is 0, as at a rectified flow’s pure-noise end.

def pred_transform(x_t, prediction, rates, t) -> jax.Array

Return the model’s raw output at (x_t, t) as a prediction in target space.

t is passed for a parameterization whose scaling depends on the time itself and not on the rates, such as ConsistencyBoundary.

def forward_diffusion(x_0, epsilon, rates) -> tuple[jax.Array, ArrayLike, jax.Array]

Return (x_t, c_in, target) for a clean sample and its noise.

x_t is the noised sample alpha x_0 + sigma epsilon, c_in is the scale applied to the model’s input, and target is what the model should output for x_t.

def backward_diffusion(x_t, prediction, rates) -> tuple[jax.Array, jax.Array]

Return (x_0, epsilon) recovered from a prediction in target space.

def get_target(x_0, epsilon, rates) -> jax.Array
def get_input_scale(rates) -> ArrayLike
def target_error_scale(snr) -> ArrayLike

Return ||target error||^2 / ||x_0 error||^2 at the given SNR.

min-SNR-gamma and the other loss weights are defined on the x_0 loss. Dividing such a weight by this ratio converts it into the space the model trains in.

dataclass source

class ScheduleWeighting()

Weights the loss with the schedule’s own weight.

class source

class SourceLimitedPrediction(
inner: PredictionTransform,
*,
clip: float | None = None,
threshold: tuple[float, float] | None = None,
recompute_epsilon: bool = True,
)

Limits x_0 the way a published scheduler’s step does.

inner recovers x_0 from the model’s output, and then either dynamic thresholding or a plain clamp to clip limits it. Thresholding, given as threshold=(ratio, maximum), follows Saharia et al. 2022. Each sample’s level is its own ratio quantile of |x_0|, kept between 1 and maximum, and x_0 is clamped to that level and then divided by it. When a source declares both limits, thresholding is used, because that is the order in which the source’s step tests them. Giving neither raises ValueError.

recompute_epsilon is whether the source recomputes epsilon from the limited x_0. DDPM’s posterior, DEIS and the noise-prediction DPM-Solver algorithms do, so the limit reaches their update through epsilon as well. DDIM keeps the model’s own output as its epsilon, so only its x_0 term is limited.

The limit is not linear in the model’s output. So a guided walk applies it once, when it converts the combined output, and not to each guidance branch.

def pred_transform(x_t, prediction, rates, t)

SourceLimitedPrediction.backward_diffusion

Section titled “SourceLimitedPrediction.backward_diffusion”
def backward_diffusion(x_t, prediction, rates)
def get_target(x_0, epsilon, rates)
def get_input_scale(rates)

SourceLimitedPrediction.target_error_scale

Section titled “SourceLimitedPrediction.target_error_scale”
def target_error_scale(snr)

class source

class VPredictionTransform(PredictionTransform)

The model predicts v = alpha eps - sigma x_0, divided by sqrt(alpha^2 + sigma^2).

def backward_diffusion(x_t, prediction, rates)
def get_target(x_0, epsilon, rates)
def target_error_scale(snr)

dataclass source

class VelocityLoss(t_eps: float = 0.05)

Scores a clean-sample prediction in velocity space on the linear path, as JiT’s loss does.

JiT is Li & He 2025, “Back to Basics: Let Denoising Generative Models Denoise”. With x_t = (1 - sigma) x_0 + sigma eps, the velocity is (x_0 - x_t) / sigma, so its squared error is the squared x_0 error over sigma^2. sigma is floored at t_eps in both the target and the prediction, as the reference clamps it. The weight replaces the schedule’s own weight. Calling it on a process that does not predict with DirectPredictionTransform raises ValueError.

class source

class Weighting(Protocol)

Weights a per-example loss, given the schedule and the prediction transform.

function source

def broadcast_rates(schedule: NoiseScheduler, t, x) -> tuple[jax.Array, jax.Array]

Return the schedule’s rates (alpha, sigma) at t, shaped to broadcast against x.

module

Masked (absorbing-state) discrete diffusion, with the interface of the Gaussian one.

The forward process replaces each token with a mask id independently, with a probability that grows with t in [0, 1]. MaskingSchedule.alpha(t) is the fraction of tokens still visible at t. Training minimizes the continuous-time negative ELBO of MDLM (Sahoo et al. 2024, “Simple and Effective Masked Diffusion Language Models”), which is the cross entropy of the model’s prediction at the masked positions, weighted by -alpha’(t) / (1 - alpha(t)).

Sampling reverses the process one interval at a time. A masked token is revealed with probability (alpha(s) - alpha(t)) / (1 - alpha(t)), and a revealed token is drawn from the model’s categorical distribution. This is MDLM’s _ddpm_update.

DiscreteProcess provides what dew.sampling.sample needs from a process: a time grid, an initial state and a denoiser. The denoiser’s two outputs sit where a Gaussian denoiser returns x_0 and epsilon. They are the model’s argmax fill of the masked positions and the log-probabilities the solver draws from.

module

Named diffusion conventions, stored as dataclasses in a run’s run.json.

A convention is a choice of noise schedule, prediction target, loss weighting and sampling grid. A preset is a frozen dataclass of the numbers that define one convention. An objective builds the preset’s Process when it is constructed. You can also call a preset to build its process yourself, to inspect the schedule or to sample at a low level. A record that holds a preset’s fields rebuilds the preset exactly.