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.
| Name | Summary |
|---|---|
EDM | Trains on log-normal sigmas with the EDM preconditioning and lambda weighting. |
Cosine | The cosine beta table with v-prediction. |
Flow | Rectified flow on the linear path with velocity prediction. |
JiT | Rectified flow where the model predicts the clean sample and is scored in velocity space (JiT). |
Karras | Trains the EDM preconditioning on sigmas drawn uniformly along the rho-spaced grid it samples on. |
MeanFlow | Rectified flow on the linear path, with a model that predicts the average velocity over an interval. |
Preset | The interface every member of the presets registry follows. |
ResolutionShift | Flux’s time shift by resolution, as the Flux pipelines’ calculate_shift computes it. |
Shortcut | Rectified flow on the linear path, with a model that predicts the velocity of one step of a given size. |
Sqrt | The square-root schedule with the plain x_0 loss, from Diffusion-LM. |
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.
EDM.lognormal
Section titled “EDM.lognormal”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.
Cosine
Section titled “Cosine”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.
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.
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.
Karras
Section titled “Karras”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.
MeanFlow
Section titled “MeanFlow”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.
Preset
Section titled “Preset”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.
ResolutionShift
Section titled “ResolutionShift”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.
ResolutionShift.at
Section titled “ResolutionShift.at”def at(height: int, width: int) -> ResolutionShiftReturn this shift for an image of height x width pixels, counted in 16 x 16-pixel cells.
ResolutionShift.shift
Section titled “ResolutionShift.shift”def shift() -> floatShortcut
Section titled “Shortcut”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.
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.