Skip to content
data

StableDiffusionConfig

extendsDiffusionModelConfig
StableDiffusionConfig(sample_size: int = 512, in_channels: int = 3, out_channels: int = 3, act_fn: GenerativeActivation = 'silu', num_train_timesteps: int = 1000, beta_start: float = 0.00085, beta_end: float = 0.012, beta_schedule: BetaSchedule = 'scaled_linear', prediction_type: Literal['epsilon', 'sample', 'v_prediction'] = 'epsilon', latent_channels: int = 4, downsample_factor: int = 8, vae_block_out_channels: tuple[int, ...] = (128, 256, 512, 512), vae_layers_per_block: int = 2, unet_block_out_channels: tuple[int, ...] = (320, 640, 1280, 1280), unet_layers_per_block: int = 2, attention_head_dim: int = 8, cross_attention_dim: int = 768, context_length: int = 77, steps_offset: int = 1, set_alpha_to_one: bool = False, norm_num_groups: int = 32)

Frozen configuration dataclass for every Stable Diffusion variant.

Parameters

sample_sizeint= 512
Image resolution. The latent side is sample_size // downsample_factor.
num_train_timestepsint= 1000
Diffusion steps the noise schedule spans.
beta_startfloat= 0.00085
Endpoints of the schedule.
beta_endfloat= 0.00085
Endpoints of the schedule.
beta_schedulestr= "scaled_linear"
"scaled_linear" interpolates linearly in β\sqrt{\beta} — not in β\beta. Getting this wrong produces a schedule that looks right on a plot and denoises to mush, which is why it is a named field rather than a constant.
latent_channelsint= 4
Channels of the first stage's latent. Four is what the released autoencoders use; it is a choice, not a consequence of the downsampling factor.
downsample_factorint= 8
The paper's ff. Fixed by the autoencoder's depth — one stride-2 stage per power of two — so it is validated against vae_block_out_channels rather than trusted.
vae_block_out_channelstuple of int= (128, 256, 512, 512)
Encoder widths, one per resolution. len - 1 stride-2 stages, hence f=2 len−1f = 2^{\,\mathrm{len}-1}.
vae_layers_per_blockint= 2
Residual blocks per resolution in the autoencoder.
unet_block_out_channelstuple of int= (320, 640, 1280, 1280)
U-Net widths, one per resolution.
unet_layers_per_blockint= 2
Residual blocks per resolution in the U-Net.
attention_head_dimint= 8
Attention heads, despite the name. The released configuration calls it attention_head_dim and the reference reads it as a count: at 8 a 320-wide stage gets eight heads of forty channels. Reading it as a dimension gives forty heads of eight, which has exactly the same parameters and different activations.
cross_attention_dimint= 768
Width of the conditioning sequence, and therefore of τθ\tau_\theta's output. 768 is CLIP ViT-L/14's text width; 1024 is OpenCLIP ViT-H's.
context_lengthint= 77
Length of the conditioning sequence.
steps_offsetint= 1
Added to every sampled timestep. The released scheduler visits 901, 801, … rather than 999, 899, …, and the offset is what produces the shift. A trajectory that omits it takes correct steps between the wrong times.
set_alpha_to_onebool= False
Whether the step past the end uses αˉ=1\bar\alpha = 1 or αˉ0\bar\alpha_0. The released configuration says false, so the final step bootstraps from alphas_cumprod[0] — very close to 1, and not 1.
norm_num_groupsint= 32
Groups for every lucid.nn.GroupNorm.

Notes

The defaults are the released v1 configuration, read from the published unet, vae and scheduler configs rather than from memory.

cross_attention_dim and context_length are not free: they must match whatever produces the conditioning. At the defaults they are exactly lucid.models.CLIPModel ViT-L/14's text_width and context_length, which is what the released model uses.

Examples

>>> from lucid.models.generative.stable_diffusion import StableDiffusionConfig
>>> config = StableDiffusionConfig()
>>> config.latent_size
64
>>> config.downsample_factor
8

Used by 6

Properties

1
prop

latent_size

→int
latent_size: int

Side of the square latent the U-Net operates on.

Returns

int

sample_size // downsample_factor.