Generative Model Fundamentals
A generative model learns the distribution of some kind of data (text, images, audio, video) well enough to produce new samples from it, usually conditioned on an input: a prompt, an image, a voice sample. LLMs, image generators like Stable Diffusion and Midjourney, video models like Sora and Veo, and modern text-to-speech systems are all generative models, and they're built from a small set of ideas.
You need those ideas in ML system design interviews even when the question is about infrastructure. The model family decides the serving shape: an autoregressive model produces one token per forward pass and is limited by memory bandwidth, while a diffusion model runs the whole output through the network 4 to 50 times and is limited by compute. Guidance doubles the cost of each step. A latent autoencoder decides how big the problem is in the first place. And every generative product needs an evaluation story, which is harder than for a classifier, because there's no single right answer.
This post covers, in order:
- The two main families: autoregressive and diffusion models, and how they compare.
- Sampling: how outputs are drawn from each.
- Latent diffusion: why we generate in a compressed space.
- Conditioning and classifier-free guidance.
- Contrastive encoders (CLIP) and why they're everywhere.
- Other families in brief: GANs, VAEs and flows.
- Metrics: FID, CLIP score, MOS, WER and human preference.
The products built on these ideas are designed in Design a Text-to-Image Generation System, Design a Text-to-Video Generation System and Design a Text-to-Speech Service.
Two Ways to Generate
| Autoregressive | Diffusion / flow matching | |
|---|---|---|
| How it generates | One token at a time, each conditioned on the previous ones | All of the output at once, refined from noise over many steps |
| Data it fits best | Discrete sequences: text, code, audio codec tokens | Continuous data: images, video, audio latents |
| Passes per output | One per token (thousands for a long answer) | One per step (4-50), each over the whole output |
| Serving bottleneck | Memory bandwidth (reading weights for each token) | Compute (every step processes every position) |
| Streaming | Natural: tokens come out in order | Not natural: the output appears all at once at the end |
| Editing and infilling | Awkward (needs special training) | Natural (noise part of an image and regenerate it) |
| Examples | GPT, Claude, Llama; VALL-E-style TTS; Parti | Stable Diffusion, Imagen, Flux, Sora-style video |
The boundary is blurring. Multimodal LLMs emit image tokens autoregressively, diffusion language models exist, and TTS systems combine an autoregressive model with a diffusion or flow-matching decoder. But the two mechanisms, and their costs, are what you need to reason about.