Hand-deriving VAEs in 11 steps: the math behind GRPO's KL penalty and diffusion losses

ProfTomYeh · x · 2026-09-23

Prof. Tom Yeh shares an 11-step hand-derivation of the Variational Autoencoder, computing every forward pass and gradient by hand on three training examples.

Key steps:

Takeaway: one VAE diagram teaches the core of two modern methods — the KL penalty is exactly what RLHF methods like GRPO use to keep fine-tuned models from drifting off base, and the reconstruction loss (plain MSE) is what trains diffusion models to denoise. The VAE paper won ICLR's first Test of Time Award in 2024.

Original post →

More from Research

Research channel →