Skip to content

dew.diffusion.presets

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.

NameSummary
EDMTrains on log-normal sigmas with the EDM preconditioning and lambda weighting.
CosineThe cosine beta table with v-prediction.
CosineContinuousFlaxDiff’s continuous cosine schedule (CosineContinuousNoiseScheduler) with v-prediction, as FlaxDiff pairs its cosine schedule (inference_prototype.ipynb at 15c55b001).
CosineGeneralFlaxDiff’s tangent grid of sigmas (CosineGeneralNoiseScheduler), variance exploding, with the EDM preconditioning at its sigma_data, as FlaxDiff pairs its variance-exploding schedules.
ExpFlaxDiff’s exponential beta table (ExpNoiseScheduler) with epsilon prediction, FlaxDiff’s trainer’s default (GeneralDiffusionTrainer, flaxdiff/trainer at 15c55b001).
FlowRectified flow on the linear path with velocity prediction.
JiTRectified flow where the model predicts the clean sample and is scored in velocity space (JiT).
KarrasTrains the EDM preconditioning on sigmas drawn uniformly along the rho-spaced grid it samples on.
MeanFlowRectified flow on the linear path, with a model that predicts the average velocity over an interval.
PresetThe interface every member of the presets registry follows.
ResolutionShiftFlux’s time shift by resolution, as the Flux pipelines’ calculate_shift computes it.
ShortcutRectified flow on the linear path, with a model that predicts the velocity of one step of a given size.
SqrtThe square-root schedule with the plain x_0 loss, from Diffusion-LM.

dataclass source

class EDM(
sigma_min: float = 0.002,
sigma_max: float = 80.0,
rho: float = 7.0,
sigma_data: float = 0.5,
regime: Literal['pixel', 'latent'] | None = None,
P_mean: float | None = None,
P_std: float | None = None,
min_snr_gamma: float | None = None,
)

Trains on log-normal sigmas with the EDM preconditioning and lambda weighting.

It samples on the rho-spaced Karras grid. The sigma distribution depends on the space the model denoises. regime="pixel" draws Karras et al. 2022’s exp(N(-1.2, 1.2^2)) for pixels in [-1, 1], and regime="latent" draws EDM2’s exp(N(-0.4, 1.0^2)) (Karras et al. 2024) for an autoencoder’s latents. P_mean and P_std, when set, override the regime’s values, and a record that stores both rebuilds without a regime. A preset with neither a regime nor both values builds no process. DiffusionRunConfig sets the regime from whether the run has an autoencoder.

def lognormal() -> tuple[float, float]

Return the training sigmas’ log mean and log standard deviation.

Raises ValueError when neither regime nor both P_mean and P_std are set.

dataclass source

class Cosine(
timesteps: int = 1000,
beta_end: float = 0.999,
p2_loss_weight_k: float = 1.0,
p2_loss_weight_gamma: float = 1.0,
min_snr_gamma: float | None = None,
)

The cosine beta table with v-prediction.

The table is improved-diffusion’s (CosineNoiseScheduler), with its betas clipped at 0.999 so the last step keeps some signal. At its defaults (k = 1, gamma = 1), the P2 weight is 1 / (1 + SNR), which makes the v loss an unweighted x_0 loss. Another p2_loss_weight_gamma changes that.

def prediction() -> PredictionTransform

dataclass source

class CosineContinuous(min_snr_gamma: float | None = None)

FlaxDiff’s continuous cosine schedule (CosineContinuousNoiseScheduler) with v-prediction, as FlaxDiff pairs its cosine schedule (inference_prototype.ipynb at 15c55b001).

def prediction() -> PredictionTransform

dataclass source

class CosineGeneral(
sigma_min: float = 0.02,
sigma_max: float = 80.0,
kappa: float = 1.0,
sigma_data: float = 1.0,
min_snr_gamma: float | None = None,
)

FlaxDiff’s tangent grid of sigmas (CosineGeneralNoiseScheduler), variance exploding, with the EDM preconditioning at its sigma_data, as FlaxDiff pairs its variance-exploding schedules. kappa scales the grid’s tangent: with another than 1 it runs from sigma_min / kappa^2 to sigma_max / kappa^2.

def prediction() -> PredictionTransform

dataclass source

class Exp(
timesteps: int = 1000,
beta_end: float = 0.999,
p2_loss_weight_k: float = 1.0,
p2_loss_weight_gamma: float = 1.0,
min_snr_gamma: float | None = None,
)

FlaxDiff’s exponential beta table (ExpNoiseScheduler) with epsilon prediction, FlaxDiff’s trainer’s default (GeneralDiffusionTrainer, flaxdiff/trainer at 15c55b001). The P2 weight arguments are those of Cosine.

def prediction() -> PredictionTransform

dataclass source

class Flow(
shift: float = 1.0,
logit_mean: float = 0.0,
logit_std: float = 1.0,
density: Density = 'logit_normal',
mode_scale: float = 1.29,
resolution_shift: ResolutionShift | None = None,
min_snr_gamma: float | None = None,
)

Rectified flow on the linear path with velocity prediction.

density is SD3’s density of training times (see FlowMatchingScheduler): logit-normal at logit_mean and logit_std, the heavy-tailed mode density at mode_scale, cosmap, or uniform. shift is SD3’s static resolution shift. resolution_shift sets the shift from the image size instead, for both training and sampling, so giving it together with a shift other than 1.0 raises ValueError.

dataclass source

class JiT(logit_mean: float = 0.8, logit_std: float = 0.8, t_eps: float = 0.05)

Rectified flow where the model predicts the clean sample and is scored in velocity space (JiT).

JiT is Li & He 2025, “Back to Basics: Let Denoising Generative Models Denoise”, and the loss is VelocityLoss with t_eps. The training times are LTH14/JiT’s logit-normal at P_mean -0.8 and P_std 0.8. The reference puts the clean sample at time 1, so in Dew’s time, with noise at 1, that is logit_mean 0.8. The reference’s noise_scale is 1, its value at 256 pixels.

dataclass source

class Karras(
sigma_min: float = 0.002,
sigma_max: float = 80.0,
rho: float = 7.0,
sigma_data: float = 0.5,
min_snr_gamma: float | None = None,
)

Trains the EDM preconditioning on sigmas drawn uniformly along the rho-spaced grid it samples on.

def prediction() -> PredictionTransform

dataclass source

class MeanFlow(logit_mean: float = -0.4, logit_std: float = 1.0)

Rectified flow on the linear path, with a model that predicts the average velocity over an interval.

This is MeanFlow’s convention (Geng et al. 2025, “Mean Flows for One-step Generative Modeling”), and its process sets Process.interval. The training times are Gsunshine/meanflow’s logit-normal at P_mean -0.4 and P_std 1.0, which measures time the same way Dew does, with noise at 1. It trains under MeanFlowObjective, and one Euler step over the whole grid samples it.

class source

class Preset(Protocol)

The interface every member of the presets registry follows.

Each member is a frozen dataclass of a convention’s numbers, and calling it returns the process it describes.

dataclass source

class ResolutionShift(
base_shift: float = 0.5,
max_shift: float = 1.15,
base_tokens: int = 256,
max_tokens: int = 4096,
tokens: int | None = None,
)

Flux’s time shift by resolution, as the Flux pipelines’ calculate_shift computes it.

mu is linear in a token count, equal to base_shift at base_tokens and max_shift at max_tokens, and the shift is exp(mu). shift() returns it and raises ValueError while tokens is unset.

at counts the image’s 16 x 16-pixel cells, which is the grid Flux’s constants are stated on (an 8x autoencoder under 2x2 patches). That grid is a reference and does not match every model’s own token count. A model that tokenizes the image differently, such as a 32x autoencoder under 1x1 patches, should set tokens to its own count. DiffusionRunConfig sets an unset tokens from the data’s resolution on the 16 x 16 grid.

def at(height: int, width: int) -> ResolutionShift

Return this shift for an image of height x width pixels, counted in 16 x 16-pixel cells.

def shift() -> float

dataclass source

class Shortcut()

Rectified flow on the linear path, with a model that predicts the velocity of one step of a given size.

This is a shortcut model’s convention (Frans et al. 2025, “One Step Diffusion via Shortcut Models”), and its process sets Process.interval. It trains under ShortcutObjective, which draws its own times on dyadic grids.

dataclass source

class Sqrt(min_snr_gamma: float | None = None)

The square-root schedule with the plain x_0 loss, from Diffusion-LM.

Diffusion-LM is Li et al. 2022.

def prediction() -> PredictionTransform