sd_unet_condition
The cross-attention U-Net that denoises Stable Diffusion's latents under text guidance.
Diffusion and generative · 520 operations Checked
Click or tap a spot to read it up close. Scroll or drag inside the diagram to move through it. Zoom with + and − or Ctrl and scroll. Press 0 for the whole graph. Swipe inside the diagram to move through it. Use + and − to zoom.
At a glance
- Parameters
- 1.5M
- Operations
- 520
- Framework
- PyTorch
- Recurrent
- No
- Published
- CVPR 2022
- Cited by
- 734 (as of 19 October 2026)
- Authors
- Robin Rombach, Andreas Blattmann, Dominik Lorenz and others
- Source
- diffusers 0.38.0
- Checked
- Passed: the trace was replayed operation by operation and matched the model's own output for this input.
Files
The file opened in a new tab. Use your browser's Save command there to keep it.
The diagram is a drawing of a TorchLens trace of the source code. It contains no code or weights.
Details
- Stable ID
- m9095
- Graph hash
- e8f43175abc3cf1e213999cdcfb4881599a65f912a82c5a5c1020220b5f90205
- Skeleton hash
- 4de02d871be278f17cb941587fddcd2608ca6bde75b61c679ebdb26d66d406e7
- Architecture hash
- d12dff028b674f25f2c070e5317a8533d83131a558a820d5dc9aeb282bcd2e3c
- Diagram SHA-256
- 6f9ef4452734cf46e64a6b7f7db0db6b79372ccb399bc7aea5a061bae5522fec
- TorchLens version
- 2.36.0
- Renderer
- graphviz 2.43.0+pyvips 3.2.0+libvips 8.18.7+render-opts@06c1f0d3
- Check
- Forward pass replayed in PyTorch
What it is
The Stable Diffusion UNet is the denoising network at the heart of Stable Diffusion, a latent text-to-image diffusion model. Rather than working on pixels, it denoises in the latent space of a pretrained autoencoder, the paper's central move for making diffusion affordable. In the traced graph the network takes a noisy latent together with a timestep, the role the paper assigns to its time-conditional UNet backbone.
The authors started from the observation that pixel-space diffusion models are costly, with training of the most powerful models running to hundreds of GPU days. Their fix was to split learning in two: first train an autoencoder that gives a lower-dimensional space perceptually equivalent to the images, then train the diffusion model inside it. Because the diffusion model is designed to work with the two-dimensional structure of that latent, compression can stay relatively mild and reconstructions remain very good.
What makes this a conditional UNet is cross-attention: the authors augment the UNet backbone with the cross-attention mechanism so that inputs such as text can steer the denoising. A domain-specific encoder first turns the prompt into an intermediate representation, which is then mapped to the intermediate layers of the UNet via cross-attention. Concretely, the self-attention layer of the older ablated UNet is replaced by a shallow transformer that alternates self-attention, a position-wise MLP and a cross-attention layer. The paper's own text-to-image model was a 1.45B parameter KL-regularized LDM trained on LAION-400M, with a BERT-tokenizer feeding a transformer text encoder.
Stable Diffusion v1 swaps in a CLIP ViT-L/14 text encoder, pairs the UNet with a downsampling-factor 8 autoencoder, and the UNet alone weighs in at 860M parameters. The model was pretrained on 256x256 images and then finetuned on 512x512 images. For the later v1 checkpoints the text conditioning was dropped 10% of the time during training to improve classifier-free guidance sampling.
Key idea. Latent diffusion moves the denoising UNet out of pixel space and into the latent space of a pretrained autoencoder, cutting the compute needed to train and sample diffusion models. Cross-attention layers added to that UNet turn it into a flexible generator for general conditioning inputs such as text or bounding boxes.
- stable diffusion
- stable diffusion unet
- UNet2DConditionModel
- latent diffusion
- LDM
- latent diffusion model
- text-to-image
- diffusion
- denoising unet
- cross-attention
- CompVis
- diffusers
AI-written summary, based on the paper and checked automatically against it; not reviewed by a person. Corrections welcome.
Cite the paper
@misc{rombach2022highresolutionimagesynthesislatent,
title={High-Resolution Image Synthesis with Latent Diffusion Models},
author={Robin Rombach and Andreas Blattmann and Dominik Lorenz and Patrick Esser and Björn Ommer},
year={2022},
eprint={2112.10752},
archivePrefix={arXiv},
primaryClass={cs.CV},
url={https://arxiv.org/abs/2112.10752},
}