Diffusion Models Needs review

Stable Diffusion

SD

Year of appearance
2022
Researchers
Robin Rombach, Andreas Blattmann, Dominik Lorenz, Patrick Esser, Björn Ommer (CompVis) with Stability AI and Runway
Organisation
CompVis (LMU Munich), Stability AI, Runway
Architecture type
Text-conditioned latent diffusion model
Learning mechanism
self-supervised
Tasks
Text-to-image generation, Image editing, Image inpainting

An open-weights latent diffusion model that generates 512×512 images from a text description, with a frozen CLIP text encoder, a latent U-Net and a VAE.

Architecture diagram

Displayed configuration: Stable Diffusion v1 (512×512, latent 4×64×64) — U-Net: 859,520,964; VAE: 83,653,863; text encoder: 123,060,480.

Layer table (19 nodes)
LayerTypeInputOutputRepetitionParametersFormulaMACs
Text (up to 77 tokens)input7710—
CLIP ViT-L/14 text encoder (frozen)encoder7777 × 7681123,060,480From the reference PyTorch implementation6,649,251,840
Random latent z_Tnoise4 × 64 × 6410—
Step embedding t (sinusoidal + MLP)embed128012,050,560From the reference PyTorch implementation2,048,000
conv_in 3×3conv4 × 64 × 64320 × 64 × 64111,840From the reference PyTorch implementation47,185,920
64×64: residual + spatial Transformer (320)block320 × 64 × 64320 × 32 × 32110,524,480From the reference PyTorch implementation54,775,480,320
32×32: residual + spatial Transformer (640)block320 × 32 × 32640 × 16 × 16136,818,560From the reference PyTorch implementation34,181,939,200
16×16: residual + spatial Transformer (1280)block640 × 16 × 161280 × 8 × 81139,992,320From the reference PyTorch implementation31,885,230,080
8×8: two residual blocks (1280)block1280 × 8 × 81280 × 8 × 8162,277,120From the reference PyTorch implementation3,778,150,400
Middle: residual + spatial Transformer + residualblock1280 × 8 × 81280 × 8 × 8197,038,080From the reference PyTorch implementation6,049,792,000
8×8: three residual blocksupsample1280 × 8 × 81280 × 16 × 161162,241,280From the reference PyTorch implementation12,902,400,000
16×16: + spatial Transformerupsample1280 × 16 × 161280 × 32 × 321258,330,880From the reference PyTorch implementation75,772,395,520
32×32: + spatial Transformerupsample1280 × 32 × 32640 × 64 × 64171,413,120From the reference PyTorch implementation83,411,763,200
64×64: + spatial Transformerupsample640 × 64 × 64320 × 64 × 64118,810,560From the reference PyTorch implementation98,783,150,080
GroupNorm + SiLU + conv_outconv320 × 64 × 644 × 64 × 64112,164From the reference PyTorch implementation47,185,920
Scheduler (for example PNDM or DDIM, 50 steps) + classifier-free guidanceprocessε̂_cond, ε̂_uncondz_{t−1}10—
VAE decoder (64×64×4 → 512×512×3)decoder4 × 64 × 643 × 512 × 512149,490,199From the reference PyTorch implementation1,257,259,466,752
512×512 imageoutput3 × 512 × 5123 × 512 × 51210—
VAE encoder (for training and img2img)encoder3 × 512 × 5128 × 64 × 64134,163,664encoder + quant_conv in AutoencoderKL—

Configuration figures: Stable Diffusion v1 (512×512, latent 4×64×64)

Parameters (computed from the layers)1,066,235,307 (≈1.07B)
Parameters (published in the source)860,000,000 (≈860M)
MACs401,636,720,640 (≈401.64B)
FLOPs ≈ 2 × MACs803,273,441,280 (≈803.27B)
Input shape
Text + z_T ∈ ℝ^{4×64×64}
Output shape
3×512×512
Depth
U-Net with four resolutions (320, 640, 1280, 1280)
Complexity
50 × 2 × U-Net + VAE decoder per image.
Parameters note
Model card: a U-Net of about 860M parameters and a 123M text encoder.
MACs note
For a single U-Net pass (401.6 billion). Classifier-free guidance doubles it, and 50 steps multiply it by 50; the VAE decoder once ≈ 1257 billion; the text encoder ≈ 6.6 billion.
Calculation assumptions: UNet2DConditionModel with the default configuration and cross_attention_dim = 768, AutoencoderKL with the SD v1 configuration, and CLIPTextModel with the ViT-L/14 configuration; computed on the meta device.

MAC = a multiplication followed by an addition. The figures are for one forward pass of one sample with the stated dimensions; they are an analytical calculation, not a measurement of run time.

Scientific explanation

Historical background

Its weights were released publicly in August 2022, which spread text-to-image generation to personal machines; it was followed by versions 2.x, XL and 3.

The problem it addresses

Making high-quality text-to-image generation available on consumer hardware instead of closed services.

Core idea

Applying LDM to huge image-text pairs (LAION), with a CLIP condition through cross-attention, and classifier-free guidance.

Architecture description

CLIP ViT-L/14 (text) → a latent U-Net with four resolutions and spatial Transformers → VAE (f = 8, 4 latent channels).

Data flow

Text → CLIP → 77×768; z_T → (U-Net + cross-attention + scheduler) × 50 → z₀ → VAE decoder → 512×512 image.

Inputs

A text description (and an optional image in img2img).

Outputs

A 512×512 image.

Training procedure

Training the U-Net on LAION-5B subsets at resolution 256 then 512, dropping the text condition 10% of the time to enable classifier-free guidance.

Loss functions

Latent diffusion loss (squared error of the noise).

Computational complexity

About 0.4 trillion multiply-adds per U-Net pass (computed here).

Computational requirements

The original training used hundreds of A100 GPUs; inference runs on a single GPU.

Advantages

  • Open weights
  • Runs on a consumer GPU (about 10GB)
  • A broad ecosystem (ControlNet and LoRA)

Limitations

  • Biases and controversial training data
  • Weak with text inside images and with hands
  • Needs dozens of steps

Equations

Classifier-free guidance Classifier-free guidance

\hat{\boldsymbol\epsilon} = \boldsymbol\epsilon_\theta(\mathbf{z}_t, t, \varnothing) + s \cdot \big(\boldsymbol\epsilon_\theta(\mathbf{z}_t, t, \mathbf{c}) - \boldsymbol\epsilon_\theta(\mathbf{z}_t, t, \varnothing)\big)

Combining a conditional and an unconditional prediction with a guidance scale s (for example 7.5).

Symbols: c: text representation, ∅: empty text

Latent-space dimensions Latent size

512 \times 512 \times 3 \;\xrightarrow{\;\mathcal{E},\, f = 8\;}\; 64 \times 64 \times 4

A reduction by a factor of 48 in the number of values.

Simplified loss Simplified objective

L_{simple} = \mathbb{E}_{t, \mathbf{x}_0, \boldsymbol\epsilon}\left[\left\lVert \boldsymbol\epsilon - \boldsymbol\epsilon_\theta\!\left(\sqrt{\bar\alpha_t}\mathbf{x}_0 + \sqrt{1 - \bar\alpha_t}\,\boldsymbol\epsilon,\; t\right) \right\rVert^2\right]

The network predicts the added noise.

Symbols: ε_θ: denoising network

Applications

Related models

References

  1. Original paper Robin Rombach, Andreas Blattmann, Dominik Lorenz, Patrick Esser, Björn Ommer. (2022). High-resolution image synthesis with latent diffusion models. CVPR 2022, 10674–10685. doi:10.1109/CVPR52688.2022.01042 Verified
  2. Configuration source CompVis, Stability AI, Runway. (2022). Stable Diffusion (CompVis/stable-diffusion repository and model card). GitHub repository. Link Needs review
  3. Related reference Alec Radford, Jong Wook Kim, Chris Hallacy, Aditya Ramesh, Gabriel Goh, Sandhini Agarwal, Girish Sastry, Amanda Askell, Pamela Mishkin, Jack Clark, Gretchen Krueger, Ilya Sutskever. (2021). Learning transferable visual models from natural language supervision. ICML 2021 (PMLR 139). arXiv:2103.00020 Verified
Scientific review note: A first scientific draft based on the original paper and reference implementations; it needs review by a specialist before final approval.

Version 1 — last updated 2026-11-15.