Latent Diffusion to SANA
Stable Diffusion, VAE and CFG, Diffusion Transformers, PixArt-α and SANA — implemented in PyTorch
What you'll learn
- ✓Explain why latent diffusion is faster and how the VAE, scaling factor and two-stage training fit together
- ✓Implement text-conditional latent diffusion with CLIP embeddings and cross-attention
- ✓Implement classifier-free guidance for training (condition dropout) and sampling (guidance scale)
- ✓Build a Diffusion Transformer with adaLN-Zero conditioning and train it with class and CLIP conditions
- ✓Understand PixArt-α's multimodal DiT block and reproduce it on MNIST latents
- ✓Implement SANA's linear attention block and rectified-flow (flow matching) training and few-step sampling
About this course
This course picks up where DDPM ends and follows the field to the models that dominate today. We move diffusion into a compressed latent space with a VAE (the idea behind Stable Diffusion), add text conditioning with CLIP and classifier-free guidance, replace the U-Net with a Transformer (DiT), and finish with the efficient architectures of 2024: PixArt-α and SANA with linear attention and rectified flow.
Each chapter follows the same recipe: read the paper, derive the key equations in plain language, implement the model in PyTorch, train it on MNIST latents, and look at the samples. You will implement a two-stage latent pipeline, a text-conditional U-Net with cross-attention, CFG training with condition dropout and CFG sampling, DiT blocks with adaLN-Zero, CLIP-conditioned DiT, the multimodal DiT of PixArt, and SANA's linear attention with a rectified-flow scheduler.
Every lecture shows the notebook on screen while the narration explains each cell. Trade-offs and failure modes are discussed openly, and every model is compared with the one before it so you understand what each paper actually changed.
Prerequisite: DDPM and DDIM basics — from our course *DDPM and DDIM from Scratch* or equivalent.
**Licensing.** The models you train here are yours, but two pretrained components are downloaded and frozen: `stabilityai/sd-vae-ft-mse` (MIT — no obligations beyond attribution) and `openai/clip-vit-base-patch32`, whose weights carry no declared licence and whose model card states that any deployed use, commercial or not, is out of scope. `Resources/LICENSES.md` sets this out and points at the fully permissive T5 conditioning path that sessions 5 and 6 already use.
Curriculum5 sections · 23 lectures · 2h 37m
Section 0. Welcome
Free previewSection 1. Latent Diffusion and Stable Diffusion
Free preview- ▶section 1 intro0:18
- ▶Latent diffusion intro3:48
- 🔒How latent diffusion works5:54
- 🔒Two stage training6:06
- 🔒VAE11:24
- 🔒Unconditional LDM implementation12:18
- 🔒Conditional LDM implementation11:06
- 🔒Classifier free guidance4:36
- 🔒CFG training implementation8:12
- 🔒Sampling implementation9:06
Section 2. Diffusion Transformers
- 🔒section 2 intro0:18
- 🔒DiT vs UNet4:00
- 🔒DiT implementation11:06
- 🔒DiT training and sampling4:18
- 🔒CLIP conditioned DiT8:42
- 🔒CLIP DiT sampling5:42
Section 3. PixArt-alpha
- 🔒section 3 intro0:18
- 🔒PixArt and MMDiT12:36
- 🔒PixArt training and sampling5:36
Section 4. SANA
- 🔒section 4 intro0:18
- 🔒SANA and rectified flow10:36
- 🔒SANA implementation18:48
Requirements
- · A computer with Python 3.10+ (a free Google Colab account is enough for most sessions)
- · Comfort reading Python code; you do not need to be an expert
- · Understanding of DDPM (forward/reverse process, noise-prediction loss) and DDIM
- · Basic PyTorch and the diffusers library basics
Who this is for
- · Engineers who fine-tune or deploy Stable Diffusion and want to understand its internals
- · Researchers and students following the DiT / PixArt / SANA line of work
- · Graduates of DDPM and DDIM from Scratch who want the modern models
- · Anyone building text-to-image systems who needs more than an API call
Read alongside the course
The voice-over in this course is synthesized with a text-to-speech model from scripts written and reviewed by the instructor, and the on-screen material (notebooks, code, slides) is the instructor's own work.