Latent Diffusion & Stable Diffusion
While DDPMs are powerful, they are extremely slow and computationally expensive because they operate directly on pixels. For a image, the network has to process 262,144 pixels at every step.
Stable Diffusion solved this by moving the process into Latent Space.
1. The Perceptual Compression (The VAE)
Instead of diffusing the image itself, we use a Variational Autoencoder (VAE) to compress the image into a smaller "latent" representation .
- Pixel Space: (Huge)
- Latent Space: (Small)
The Diffusion process happens entirely in this compressed space. Once we've denoised the latent vector, the VAE Decoder turns it back into a high-resolution image. This makes Stable Diffusion 8x - 64x faster than pixel-based models.
2. Conditioning: The CLIP Bridge
How does the model know to draw a "Cyberpunk Forest"? It uses Cross-Attention.
- Text Encoding: Your prompt is fed into a text encoder (CLIP).
- Tokens to Vectors: The text is converted into a sequence of mathematical vectors.
- Attention Mechanism: At every layer of the U-Net, the image-latents "look" at the text-vectors to decide which pixels should become trees and which should become neon lights.
3. Classifier-Free Guidance (CFG)
CFG is a trick to make the model follow your prompt more strictly. During generation, the model predicts the noise twice:
- Once with the prompt.
- Once without the prompt (using empty text).
The model then pushes the generation away from the unconditioned version and towards the prompted version.
The CFG Scale: A higher scale makes the image more vibrant and "correct" to the prompt, but too high can make the image look burnt or distorted.
4. The Ecosystem
Stable Diffusion isn't just one model; it's a framework that supports:
| Technique | Purpose |
|---|---|
| ControlNet | Adds spatial control (e.g., following a human pose or a sketch). |
| LoRA | Fine-tunes the model on a specific style or character with very little data. |
| Inpainting | Repairs or replaces specific parts of an image. |
| Textual Inversion | Teaches the model a new concept by finding its "word vector." |
Stable Diffusion = (Latent Space Diffusion) + (CLIP Text Conditioning) + (Iterative Refinement). It is the standard for open-source generative art today.