AutoencoderKL
The KL-regularized autoencoder behind latent diffusion, traced on diffusers' default config as a 256 px image reconstruction.
Diffusion and generative · 127 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
- 563.2K
- Operations
- 127
- Framework
- PyTorch
- Recurrent
- No
- Published
- CVPR 2022
- Cited by
- 736 (as of 5 October 2026)
- Authors
- Robin Rombach, Andreas Blattmann, Dominik Lorenz and others
- Source
- diffusers 0.38.0
- License
- MIT
- 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
- m138
- Graph hash
- 78c4bd4b5aa56ec3952f59a63d5b190c8e50d8fc745126a9c6b388ab32124ca1
- Skeleton hash
- e5090430ad35b6c5765c97881e99a592555fc4aaa5664019d3659be66a944c23
- Architecture hash
- 387ad6f530372539527c7571d83ed425215dccf32916bf13386fa1ce6bd1e565
- Diagram SHA-256
- ee4d1011236e27be24bda20541f0f1339f53bfe2faf01a37a5760e286b38954d
- 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
How this diagram was made
diffusers.AutoencoderKL()
What it is
AutoencoderKL is the KL-regularized image autoencoder that Robin Rombach, Andreas Blattmann, Dominik Lorenz, Patrick Esser and Björn Ommer trained as the first stage of their latent diffusion models, the compressor whose latent space Stable Diffusion-style generators work in. The motivation is cost: diffusion models typically operate directly in pixel space, so optimization of powerful DMs often consumes hundreds of GPU days and inference is expensive due to sequential evaluations. The fix is to apply them in the latent space of powerful pretrained autoencoders, and this network is that autoencoder.
The paper splits learning into two stages: first a perceptual compression stage which removes high-frequency details but still learns little semantic variation, then the generative model that learns the semantic and conceptual composition of the data. The perceptual compression model consists of an autoencoder trained by combination of a perceptual loss and a patch-based adversarial objective, which confines reconstructions to the image manifold by enforcing local realism and avoids the blurriness of pixel-space losses alone. The encoder downsamples the image by a factor f = H/h = W/w, and the authors investigate different downsampling factors f = 2m. To avoid arbitrarily high-variance latent spaces they tried two regularizations, and the KL variant, the one this member implements, imposes a slight KL-penalty towards a standard normal on the learned latent, similar to a VAE, whereas VQ-reg. uses a vector quantization layer within the decoder.
The trace here is the diffusers library's default configuration run end to end, image in and reconstructed image out, which is the encode-then-decode path the paper writes as x̃ = D(z) = D(E(x)). A quirk the paper notes is that LDMs trained in VQ-regularized latent spaces sometimes achieve better sample quality, even though the reconstruction capabilities of VQ-regularized first stage models slightly fall behind those of their continuous counterparts. The authors' repository later added a 1.45B latent diffusion model trained on the LAION-400M database and a class-conditional ImageNet model achieving a FID of 3.6 with classifier-free guidance, all built on first stages like this one.
Key idea. A perceptually and adversarially trained autoencoder with a slight KL penalty on its latent, giving diffusion models a compressed space to train in instead of pixels.
- autoencoderkl
- autoencoder kl
- stable diffusion vae
- sd vae
- latent diffusion
- ldm first stage
- kl-f8
- vae encoder decoder
- diffusers autoencoder
- rombach ommer
- compvis
AI-written summary, checked automatically against its sources; 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},
}