Diffusion Models & Image Generation
Diffusion models generate images by learning to reverse a gradual noising process, and the specific engineering choice that made them practical at consumer scale, running that process in a compressed latent space instead of on raw pixels, is what this lesson unpacks in the depth AI-052's multimodal overview only had room to summarize.
Learning Objectives
- Explain the forward (noising) and reverse (denoising) diffusion process in technical depth.
- Describe why latent diffusion models like Stable Diffusion operate in a compressed VAE latent space, not pixel space.
- Explain text-to-image conditioning via cross-attention with CLIP and T5 text encoder embeddings.
- Compare the current image and video generation landscape: Midjourney, SDXL, DALL-E 3, Imagen, and Sora.
- Distinguish this lesson's technical depth from AI-052's introductory overview of multimodal generation.
Why This Matters
AI-052 introduced diffusion models as one modality among several, alongside vision-language understanding, audio, and video, giving each only a conceptual pass. Image generation has become its own product category, Midjourney alone reportedly serves millions of users generating images daily, and DALL-E 3's ChatGPT integration put text-to-image in front of hundreds of millions of people, so understanding the mechanism in real depth matters if you are building anything that touches image generation: choosing a model, debugging why a prompt isn't producing the expected composition, or estimating inference cost. This lesson goes under the hood of what AI-052 only named: the actual denoising math, why latent space is the efficiency trick that makes consumer-hardware image generation possible, and exactly how a text prompt steers pixels that don't exist yet.
Everyday Analogy
Picture a sculptor working in reverse: instead of starting with a block of marble and chiseling away, they start with what looks like solid static, television snow, and at each step remove a little bit of the noise, gradually revealing a shape. The sculptor doesn't do this randomly; they were trained by watching thousands of real statues slowly buried under increasing layers of static, so they learned exactly what static-removal step, at every level of noise, reveals a coherent statue rather than more static. A diffusion model does the same thing to an image: starting from pure random noise, it repeatedly asks "given this noise, what does the next, slightly-less-noisy version look like," reversing a process it only ever saw applied forward, real images being buried under noise, during training.
The Forward and Reverse Diffusion Process, in Depth
AI-052 summarized this in two sentences; here is the mechanism underneath both directions:
Forward process (training only). Take a real training image and add a small amount of Gaussian noise to it. Repeat this hundreds or thousands of times, at each step adding a little more noise according to a fixed schedule, until after enough steps the image is indistinguishable from pure random noise. This forward process has no learned parameters, it is a fixed mathematical recipe, and its purpose is purely to generate training pairs: (image at noise level t, image at noise level t+1) for every step along the way.
Reverse process (what the model learns). The neural network, typically a U-Net architecture in the original diffusion models and increasingly a diffusion transformer (DiT) in more recent ones, is trained to predict the noise that was added at each step, given the noisy image and the current noise level (timestep). Critically, the model does not predict the final clean image directly; it predicts the noise, which is then subtracted to produce a slightly cleaner image. At inference time, this reverses the entire forward process: start with pure random noise, ask the model to predict and remove a small amount of noise, repeat for the same number of steps (or fewer, with modern samplers), and a coherent image emerges from what began as static.
Samplers and step count. The number of reverse steps (typically 20β50 with modern samplers, though the earliest models needed 1,000) and the specific sampling algorithm, DDPM (the original, slow sampler), DDIM (a faster deterministic variant), or DPM++ (a further-optimized modern sampler), control the tradeoff between image quality and generation speed. This is the concrete engineering lever behind what a user experiences as "fast" versus "slow" image generation.
Latent Diffusion: Why Stable Diffusion Doesn't Touch Pixels Directly
Running the noise/denoise process described above directly on a full-resolution image, at the pixel level, is computationally brutal: a 1024Γ1024 image has over a million pixels across three color channels, and doing 20-50 denoising passes over that much data demands enormous compute. This was, in fact, exactly why the earliest diffusion image models were slow and required serious GPU hardware even for small images.
Latent diffusion, the architecture behind Stable Diffusion (and the technique that made running diffusion models on consumer GPUs practical at all), solves this by never touching pixels during the actual diffusion process:
- A Variational Autoencoder (VAE) is trained separately, ahead of time, to compress a real image into a much smaller latent representation, typically an 8x-per-dimension size reduction (so a 512Γ512 image compresses to a 64Γ64 latent grid), and to reliably reconstruct the original image back from that compressed latent.
- All the diffusion happens in this small latent space, not on the full-resolution image. The forward noising and reverse denoising process described above runs entirely on the compact latent grid, which is dramatically cheaper computationally since it's operating on roughly 1/64th the data volume of the raw pixels.
- Once the reverse diffusion process produces a clean latent representation, the VAE's decoder converts that latent back into a full-resolution pixel image as a final, single step.
This is the specific architectural decision, diffuse in latent space, decode to pixels only once at the end, that separates why Stable Diffusion can run on a single consumer GPU while earlier pixel-space diffusion models needed a data-center GPU cluster for the same output resolution.
Text Conditioning via Cross-Attention
None of the above explains how a text prompt like "a golden retriever wearing a tiny wizard hat, watercolor style" actually steers the denoising process toward that specific image instead of a random coherent one. The mechanism is cross-attention, the same attention mechanism from AI-012's transformer architecture, applied between the denoising network and a separately-computed text embedding:
- The text prompt is encoded into a sequence of embeddings by a text encoder, CLIP's text encoder in the original Stable Diffusion, or a larger language model like T5 in more recent systems (larger text encoders generally produce noticeably better prompt adherence, since they capture more of the prompt's compositional structure and detail).
- At every step of the reverse denoising process, the denoising network (U-Net or DiT) attends to these text embeddings via cross-attention layers interleaved throughout its architecture, in the same query/key/value mechanism AI-012 and AI-013 describe, except here the queries come from the image's latent representation and the keys/values come from the text embeddings.
- This means the text conditioning isn't applied once at the start; it actively steers every single denoising step, which is why changing part of a prompt can restructure the entire generated composition, not just add a detail at the end.
- Classifier-free guidance (mentioned briefly in AI-052) strengthens this steering further: the model is run twice at each step, once with the text conditioning and once without, and the final prediction is pushed further in the direction the text conditioning moved it, exaggerating prompt adherence beyond what plain conditioning alone would produce. A higher "guidance scale" setting, common in most image generation UIs, controls how aggressively this push is applied.
The Current Image and Video Generation Landscape
| Model | Provider | Distinguishing characteristic |
|---|---|---|
| Stable Diffusion 3 / SDXL | Stability AI | Open-weight latent diffusion; runs locally; the model most fine-tuned by the open-source community |
| FLUX | Black Forest Labs | Newer open-weight diffusion transformer (DiT) architecture, strong prompt adherence |
| DALL-E 3 | OpenAI | Tightly integrated with ChatGPT for prompt rewriting; strong instruction-following on complex, compositional prompts |
| Midjourney v6 | Midjourney | Closed, Discord/web-based; widely regarded as producing the strongest default aesthetic quality |
| Imagen 3 | Strong photorealism; integrated into Vertex AI and Google's consumer products | |
| Sora | OpenAI | Video diffusion transformer generating up to 1080p, up to 60-second clips from text, notable for physical and temporal coherence |
| Runway Gen-3 Alpha, Kling, Luma Dream Machine | Runway, Kuaishou, Luma | Competing video diffusion models, varying in temporal consistency, motion quality, and production-grade editing tools |
The video models extend the same latent diffusion and cross-attention conditioning principles across time as well as space, a diffusion transformer denoises a sequence of latent video frames jointly, which is why maintaining a consistent character or object across frames (temporal coherence) remains one of the field's hardest unsolved problems, discussed in AI-052's coverage of video generation limitations.
Real-World Showcase
- Stable Diffusion's open weights spawned an entire ecosystem of community fine-tunes and LoRA adapters (the same low-rank adaptation technique from AI-051, applied to image models), letting users specialize the base model for specific art styles or subjects without full retraining.
- Adobe Firefly is trained specifically on licensed and public-domain content, using the same latent diffusion architecture, positioned explicitly for commercial use where copyright provenance of training data matters to enterprise customers.
- Sora's demonstrated video generations showed diffusion transformers scaling the same denoising principle across the added dimension of time, producing short clips with camera motion and physical consistency that earlier, smaller video generation attempts could not achieve.
Try It Yourself
- Trace one prompt through the full latent diffusion pipeline: "a lighthouse at sunset, oil painting style" β text encoder produces embeddings β random noise latent β cross-attention-guided denoising steps β VAE decodes final latent to pixels. Write out each stage in your own words.
- Compare pixel-space diffusion to latent diffusion on paper: if a 512Γ512 image compresses to a 64Γ64 latent (an 8x reduction per dimension, so 64x fewer total values), roughly how much less data does each denoising step have to process?
- Generate the same prompt at a low guidance scale and a high guidance scale in an image generation tool you have access to (Stable Diffusion, DALL-E, or similar). Describe how the two outputs differ, and connect that difference back to what classifier-free guidance is mathematically doing.
Common Mistakes
- Treating "diffusion model" as synonymous with Stable Diffusion specifically, when DALL-E 3, Imagen, Midjourney, and Sora are all diffusion-based systems with different text encoders, architectures, and training data.
- Assuming higher step counts always produce meaningfully better images; modern samplers (DPM++) reach near-optimal quality in far fewer steps than the original DDPM sampler needed, and excess steps mostly add latency without proportional quality gains.
- Confusing latent diffusion's compression (a VAE trained to preserve visual information) with lossy image compression like JPEG; the VAE's latent space is learned specifically to be reconstructable back to a full image, not a general-purpose compression format.
- Assuming a higher classifier-free guidance scale is always better; pushed too high, it produces oversaturated, artifact-prone images rather than more faithful ones.
- Ignoring that this lesson's conditioning mechanism (cross-attention with text embeddings) is the same attention mechanism from AI-012 and AI-013, applied to a different pair of sequences, not a fundamentally different technique invented for images.
Key Takeaways
- Diffusion models learn to reverse a forward noising process, predicting and removing noise step by step until a coherent image emerges from random static.
- Latent diffusion, used by Stable Diffusion, runs the entire noise/denoise process in a compressed VAE latent space rather than on raw pixels, which is the specific efficiency choice that made consumer-GPU image generation practical.
- Text-to-image conditioning works via cross-attention between the denoising network and text embeddings from a text encoder (CLIP or T5), steering every single denoising step, strengthened further by classifier-free guidance.
- The current landscape spans open-weight models (Stable Diffusion 3, FLUX) and closed models (DALL-E 3, Midjourney, Imagen), plus video diffusion transformers (Sora, Runway, Kling) extending the same principles across time.
- This lesson goes substantially deeper than AI-052's introductory overview into the actual denoising mechanism, the latent-space efficiency trick, and the cross-attention conditioning math, rather than repeating that lesson's summary-level treatment.
Glossary
- Forward Diffusion Process
- The fixed, unlearned process of gradually adding Gaussian noise to a training image until it becomes indistinguishable from random noise.
- Reverse Diffusion Process
- The learned process where a neural network predicts and removes noise step by step, starting from random noise, to produce a coherent image. (see AI-052)
- U-Net
- The neural network architecture originally used in diffusion models to predict the noise at each denoising step.
- Diffusion Transformer (DiT)
- A newer diffusion model architecture that replaces the U-Net with a transformer, used in models like Sora and FLUX. (see AI-012)
- Latent Diffusion
- Running the noise/denoise process in a compressed VAE latent space rather than on raw pixels, the efficiency technique behind Stable Diffusion.
- Variational Autoencoder (VAE)
- A model trained to compress an image into a small latent representation and reconstruct it back, used to enter and exit latent space in latent diffusion.
- Cross-Attention
- The attention mechanism connecting a denoising network's image latents to text embeddings, steering generation toward a text prompt at every step. (see AI-013)
- Classifier-Free Guidance
- A technique that runs the diffusion model with and without text conditioning at each step, then exaggerates the difference to strengthen prompt adherence.
- Sampler
- The algorithm (DDPM, DDIM, DPM++) controlling how the reverse diffusion process steps from noise to image, trading off step count against image quality.
- Text Encoder
- A model (CLIP or T5) that converts a text prompt into embeddings used to condition image generation via cross-attention. (see AI-052)
- Diffusion Transformer Video Model
- A diffusion transformer extended across the time dimension to generate video, as in Sora, denoising a sequence of latent frames jointly.
References
- Ho, Jain & Abbeel, "Denoising Diffusion Probabilistic Models" (DDPM), NeurIPS 2020
- Rombach et al., "High-Resolution Image Synthesis with Latent Diffusion Models" (Stable Diffusion), CVPR 2022
- Ho & Salimans, "Classifier-Free Diffusion Guidance," 2022
- Peebles & Xie, "Scalable Diffusion Models with Transformers" (DiT), 2023
- OpenAI, "Video generation models as world simulators" (Sora technical report), 2024
- Stability AI Documentation β Stable Diffusion 3 and SDXL Model Cards
Diagram
Knowledge Check
8 questions