Two ways to make a picture
A model that makes a 1024 × 1024 picture has to produce more than 3 million numbers (three colours for each pixel), and they all have to fit together: the shadow has to match the sun, and the left eye has to match the right one. Today there are two main ways to do it.
The first works like a language model. A picture tokenizer turns any picture into a grid of codes taken from a fixed list, its codebook, and a decoder turns codes back into pixels. A transformer then learns to predict the codes one after another, left to right and top to bottom, exactly as it predicts words (the press-enter lesson). DeepSeek’s Janus-Pro works this way: a 384 × 384 picture is 576 codes. Janus gives the model two separate eyes, one encoder for understanding pictures and another tokenizer for drawing them, because the two jobs need different details. VAR, from ByteDance and Peking University, predicts a whole small picture first and then larger and larger versions of it, and won a best-paper award at NeurIPS 2024.
The second way is diffusion: start from pure random noise and remove a little of it at a time, over many steps, until a picture is left. Every step works on the whole picture at once. Nearly all of today’s leading open image and video models work this way, including FLUX, Qwen-Image, Wan and HunyuanVideo, so most of this lesson is about diffusion.
| One token at a time | Diffusion | |
|---|---|---|
| How it makes a picture | Predicts picture codes in order, like words | Cleans noise off the whole picture, step by step |
| Examples | Janus-Pro (DeepSeek), VAR (ByteDance) | FLUX, Qwen-Image, Wan, HunyuanVideo |
| Strength | One model can read and write text and pictures | The best picture quality, and easy editing |
| Weakness | Hundreds or thousands of passes, one per code; the codebook loses fine detail | Many passes over the whole picture, each one costly |
Some models mix the two, for example by writing a rough plan as tokens and finishing it with diffusion.
Quick check
Diffusion: learning to remove noise
Training a diffusion model starts with real pictures and spoils them on purpose. Add a little random noise to a photo, and it is still easy to see. Add more, then more, until nothing is left but static, like an old television with no signal. At every level of noise, the network is shown the spoiled picture and asked one question: which noise was added? The 2020 paper that made this work well was called DDPM.
noisy = √ā × clean + √(1 − ā) × noiseā (alpha-bar) goes from 1 to 0 as the noise level rises: at the start it is all picture, at the end all noise
error = (noise − guess)²the network guesses the noise; training makes this squared error smaller, as in the learning-downhill lesson
1,000levels of noise in the original paper
To make a new picture, run it backwards. Start from pure noise, ask the network which noise is there, take away part of it, and ask again. Each answer is a guess, but each step makes the picture a little clearer, and the next guess is easier. The original model needed all 1,000 steps; better ways to take the steps soon cut that to about 50.
This interactive part needs JavaScript.
The demo shows what a picture looks like at each level of noise, from static to clear. It cheats: it already knows the finished picture and only mixes it with less and less noise. A real model never sees the answer. At every step it has to work out what picture could be hiding under the noise, and the picture you would watch appear is its guess.
In 2022 two groups found a simpler path, called flow matching or rectified flow. Draw a straight line from the clean picture to the noise. Every point on the line is a mix of the two. The network learns the direction of the line, called the velocity. To make a picture, start at the noise end and walk against that direction, back to the picture end. Straight paths can be walked in fewer, bigger steps. Stable Diffusion 3, FLUX, Wan and Qwen-Image are all trained this way.
noisy = (1 − t) × clean + t × noisea straight line: t = 0 is the picture, t = 1 is pure noise. Papers write xₜ = (1 − t)x₀ + tε
velocity = noise − cleanwhich way, and how far, the line runs from picture to noise
error = (velocity − guess)²the network learns to guess the velocity from the noisy picture and t
next = noisy − step × guessone step back towards the picture; repeat until t = 0
Quick check
Working in a smaller space
Running a big network over all 3 million numbers of a 1024 × 1024 picture, 50 times over, is far too slow. The 2021 paper behind Stable Diffusion, on latent diffusion, found a way round it. First train a separate network, a VAE (variational autoencoder), that squeezes a picture into a much smaller grid of numbers, its latent, and can turn that grid back into the picture almost perfectly. Then do all the diffusion in that small space.
512 × 512 × 3 = 786,432numbers in a 512 × 512 picture
64 × 64 × 4 = 16,384numbers in its latent: each side 8 times smaller, with 4 channels instead of 3 colours
786,432 ÷ 16,384 = 48times fewer numbers for the denoiser to work on
- Promptyour words
- Text encoderone vector per token, read once
- Denoiserstarts from noise in the latent space and cleans it, step after step
- VAE decoderturns the clean latent into pixels, once
- Picturefor example 1024 × 1024
The denoiser used to be a U-Net, a convolutional network (the before-transformers lesson). Since the 2022 paper on diffusion transformers (DiT) it is usually a transformer: cut the latent into patches of 2 × 2 squares, turn each patch into a token, and run transformer layers, just as a vision transformer does with a photo (the vision lesson). Stable Diffusion 3 and FLUX put the text tokens and the picture tokens into the same attention, each with their own weights, so every word can look at every part of the picture and back. This design is called MMDiT.
1024 ÷ 8 = 128latent squares along each side, after the VAE
128 ÷ 2 = 64tokens along each side, after 2 × 2 patches
64 × 64 = 4,096tokens, processed again at every step
Quick check
Steering with words, and saving steps
A denoiser that is given the prompt still tends to drift towards a safe, average picture. The fix most models use is classifier-free guidance (2022). At every step, run the network twice: once with your prompt and once with an empty prompt. The difference between the two answers points in the direction your words pull. Then go further in that direction than the network would on its own.
guided = without + w × (with − without)w = 1 is the plain answer with the prompt; a larger w follows the prompt harder
w ≈ 5a typical value for video models such as Wan
50 steps × 2 passes = 100passes through the whole network for one picture
A negative prompt uses the same trick. Instead of an empty prompt, the second pass gets a description of what you do not want, such as “blurry, extra fingers, text”, and guidance pushes the picture away from it. It costs nothing extra, because the second pass runs anyway.
One hundred passes through a network with billions of weights takes time. Distillation cuts it down: a finished model, the teacher, makes pictures in 50 steps, and a student model learns to get the same result in far fewer, bigger steps. Methods have names such as progressive distillation, consistency models and adversarial distillation, which adds a judge as in a GAN. Guidance can be learned by the student too, so it needs only one pass per step.
| Model | Steps | Passes per step | Passes in all |
|---|---|---|---|
| A typical model without distillation | 50 | 2 (with guidance) | 100 |
| FLUX 3 Image Klein, distilled (October 2026) | 16 | 1 (no guidance) | 16 |
| Qwen-Image-2.1-Turbo | 8 | 1 (guidance set to 1) | 8 |
Steps and guidance from the makers’ model cards and announcements.
Put distillation together with 8-bit numbers (the quantization lesson) and the savings multiply. Tests published with FLUX 3 Image Klein report that one 1024 × 1024 picture takes 78 seconds on an RTX 4070 at 50 steps with 16-bit numbers, and under 9 seconds with the distilled model in 8 bits.
Quick check
Video: pictures through time
A video is pictures in a row, usually 16 or 24 of them a second. Make each frame on its own and they flicker: the shirt changes colour, the tree moves. So video models make the whole clip at once, as one block of space and time. OpenAI’s 2024 report on Sora called the tokens spacetime patches: small boxes that cover a few pixels across, a few down and a few frames deep.
Alibaba’s Wan models show the recipe in the open. Wan’s VAE squeezes every 4 frames into 1 latent frame and each side 8 times. It keeps the first frame on its own, so a single picture is simply a video one frame long. Then the transformer cuts patches of 2 × 2, as for pictures.
16 × 5 + 1 = 81frames: 16 a second for 5 seconds, plus the first frame
1 + 80 ÷ 4 = 21latent frames: the first one alone, then one for every 4
832 ÷ 16 = 52 and 480 ÷ 16 = 30tokens across and down: 8 times from the VAE, then 2 from the patches
21 × 52 × 30 = 32,760tokens, at every step
This interactive part needs JavaScript.
Attention compares every token with every other one (the attention lesson), so its work grows with the square of the number of tokens. Five seconds of 720p in Wan2.1 is 75,600 tokens, about 18 times a 1024 × 1024 picture, and about 340 times the attention work. Wan’s report says that at a million tokens, attention takes up to 95 % of the training time. This is why video is the most expensive thing these models make.
Wan2.2 (July 2025) added two ideas worth knowing. The first is experts by noise level (the mixture-of-experts lesson): one expert handles the early, noisy steps that set the layout, and another handles the late steps that add detail, just like the fog lifting. Together they have 27 billion parameters, but only one expert of about 14 billion runs at each step. The second is a VAE that squeezes harder, 16 times along each side, so the small TI2V-5B model makes 720p video at 24 frames a second from fewer tokens than Wan2.1 needs for 480p. Its makers say it makes five seconds in under 9 minutes on one consumer graphics card.
Long videos are rarely made in one piece. They are made in parts, each part looking back at the frames before it. Sand AI’s MAGI-1 is built for this: it cleans one short chunk of frames after another, so the video can keep growing.
| Model | Lab | First released | Worth knowing |
|---|---|---|---|
| Wan2.1, Wan2.2 | Alibaba | February 2025, July 2025 | Apache 2.0 licence, from 1.3 to 27 billion parameters |
| HunyuanVideo | Tencent | December 2024 | 13 billion parameters, with a full technical report |
| CogVideoX | Zhipu AI and Tsinghua University | August 2024 | 2 and 5 billion parameters, an early open video model |
| Step-Video-T2V | StepFun | February 2025 | 30 billion parameters, clips of up to 204 frames |
| MAGI-1 | Sand AI | April 2025 | Makes video chunk by chunk, so clips can grow |
| Open-Sora 2.0 | HPC-AI Tech | March 2025 | Its makers report training it for about 200,000 US dollars |
From each lab’s report or code page. Several strong video models from China, such as Kling and Seedance, are closed.
Do video models understand the world they show? A 2024 study by ByteDance and Tsinghua researchers trained video models on simple simulated balls that move and bounce by the laws of physics. Within the range of their training, the models were nearly perfect. Outside it, they failed, and more data or bigger models did not fix it. Instead of learning the laws, they copied the most similar training example, matching colour first, then size, then speed, and shape last. A made-up video is not evidence of how anything really moves.
Quick check
Copying and creating
Here is a puzzle. Suppose a denoiser were perfect for its training set: at every step it worked out exactly which training picture could be behind the noise. Walking back from noise would then always end on one of the training pictures. A perfect model would only copy. Yet real models make pictures nobody has seen. The program below lets you watch both happen, with points on a circle instead of pictures.
"""tiny_diffusion.py: turn noise into new points, step by step, the way image models turn noise into pictures.
pip install numpy, then: python tiny_diffusion.py"""
import numpy as np
rng = np.random.default_rng(0)
# The training set: 12 points on a circle. An image model has millions of pictures instead.
angles = np.linspace(0, 2 * np.pi, 12, endpoint=False)
data = np.stack([np.cos(angles), np.sin(angles)], axis=1)
def denoise(x, t, blur=0.0):
"""The best guess of the clean point behind each noisy point x, at noise level t (1 = pure noise)."""
s = max(t, blur) # blur > 0 imitates a network, which is never as sharp as this formula
# x = (1 - t) * clean + t * noise, so ask how well each training point explains x
d2 = ((x[:, None, :] - (1 - t) * data[None, :, :]) ** 2).sum(-1)
w = np.exp(-(d2 - d2.min(1, keepdims=True)) / (2 * s * s))
w /= w.sum(1, keepdims=True)
return w @ data # a weighted average of the training points
def sample(n, steps, blur=0.0):
x = rng.standard_normal((n, 2)) # start from pure noise
ts = np.linspace(1, 0, steps + 1)
for t, t_next in zip(ts[:-1], ts[1:]):
velocity = (x - denoise(x, t, blur)) / t # the direction from the clean point towards the noise
x = x - (t - t_next) * velocity # one step back, against that direction
return x
def report(name, x):
off = np.abs(np.linalg.norm(x, axis=1) - 1).mean()
nearest = np.linalg.norm(x[:, None, :] - data[None, :, :], axis=-1).min(1)
print(f"{name:<24} distance from the circle {off:.3f} copies of a training point {np.mean(nearest < 0.01):4.0%}")
report("pure noise", rng.standard_normal((1000, 2)))
report("1 step", sample(1000, 1))
report("4 steps", sample(1000, 4))
report("50 steps", sample(1000, 50))
report("50 steps, a little blur", sample(1000, 50, blur=0.3))
report("50 steps, a lot of blur", sample(1000, 50, blur=0.6))
- The training set is 12 points on a circle. A new point counts as good if it lands on the circle, and as a copy if it lands on one of the 12 points.
denoiseis the perfect answer for this training set: a weighted average of the training points, weighted by how well each one explains the noisy point. Real models learn an approximation of it from examples.sampleis flow matching from the earlier section: start from noise at t = 1, estimate the velocity, and step back to t = 0.blurmakes the denoiser less sharp than perfect, a stand-in for the limits of a real network. It runs in about a second on an ordinary computer, with no graphics card.
pure noise distance from the circle 0.539 copies of a training point 0%
1 step distance from the circle 1.000 copies of a training point 0%
4 steps distance from the circle 0.101 copies of a training point 0%
50 steps distance from the circle 0.000 copies of a training point 100%
50 steps, a little blur distance from the circle 0.051 copies of a training point 0%
50 steps, a lot of blur distance from the circle 0.405 copies of a training point 0%
- 1 step: every point lands at the centre of the circle, 1.000 away from it. At pure noise, every training point is equally likely, so the best single guess is their average. In pictures, the average of everything is a grey blur, which is what one undistilled step gives.
- 4 steps: close to the circle already. 50 steps: exactly on it, and every point is a copy of a training point. The perfect denoiser only memorises.
- A little blur: still close to the circle, but no copies. The points spread all the way round it, into places the training set never had a point. That is new output that still fits the data.
- A lot of blur: too far from perfect, and the points miss the circle. A model has to be good, but not perfect, to create.
Real models still copy sometimes. In 2023 Nicholas Carlini and colleagues pulled more than a thousand training pictures back out of image models, including Stable Diffusion, mostly pictures that appeared many times in the training data. So a model can reproduce a real person’s photo or an artist’s work. Never assume that what it makes is new.
Quick check
Words in pictures, and whose world they show
Ask a good model today for a shop sign that says “Pharmacy” in English, and it will usually spell it right. Ask for the same sign in Urdu, Arabic, Hindi or Bengali and it is a different story. A 2025 benchmark of popular models across many scripts found illegible letters, broken shapes and wrong words in non-Latin scripts, worst for scripts like Arabic and Chinese.
Chinese has improved fastest because Chinese labs trained for it on purpose. Qwen-Image’s makers built a test of 8,105 common characters, one per picture. Their model drew 58 % of them correctly, against 33 % for ByteDance’s Seedream 3.0 and 36 % for an OpenAI image model. That is their own test of their own model, and even the leader got about four in ten wrong. Comparable tests for Urdu, Pashto or Sindhi are hard to find.
Pictures carry culture too. The CUBE benchmark (2024) asked models for the food, landmarks and art of eight countries and found large gaps: a famous temple in India drawn wrongly, a Japanese dish turned into a cartoon. A short prompt about a culture tends to return a narrow, repeated picture of it. Describe what you mean in detail, and ask someone who knows the place to check.
Is each job fine for an image model with a quick look, or one to check carefully or avoid?
-
A colourful background for a school poster
Answer: Fine with a quick look
-
A poster that shows the dose of a medicine
Answer: Check carefully or avoid
-
Pictures for a story about a talking goat
Answer: Fine with a quick look
-
A picture of a real politician at an event that never happened
Answer: Check carefully or avoid
-
A labelled diagram of the heart for a biology class
Answer: Check carefully or avoid
-
Ideas for how to lay out a classroom display
Answer: Fine with a quick look
-
An “old photo” of your town to show as history
Answer: Check carefully or avoid
-
A sign with words in Urdu or Pashto
Answer: Check carefully or avoid
Using it honestly
The tool that draws a storybook goat can also make a fake photo of a real person. A few rules protect other people and you: never make a picture or video of a real person without their permission; never show a made-up picture as a real photo; and say clearly when a picture or video was made by AI.
Governments and companies are building labels. Since 1 September 2025, China’s rules require AI-made text, pictures, video and sound to carry a visible label and a hidden one in the file’s data. C2PA “content credentials” are a signed record, stored in the file, of how it was made and changed. Google’s SynthID hides a watermark in the pixels themselves.
When a surprising picture or video reaches you, ask who posted it first, whether trustworthy news sources report the same event, and whether a reverse image search finds an older or different version. Odd hands, garbled text and wrong shadows used to give fakes away; newer models make fewer of these mistakes, so checking the source matters more than staring at the pixels.
Quick check
Make one on your own computer
You do not need a paid service. Open models now make pictures on a mid-range graphics card, and short videos on a large one. The figures below come from the models’ makers; they were not measured for this lesson.
| Model | Makes | Graphics memory | Speed reported |
|---|---|---|---|
| FLUX 3 Image Klein, 8-bit | Pictures, up to 4K, and edits | 8 GB | Under 9 seconds for 1024 × 1024 on an RTX 4070 |
| Qwen-Image-2.1-Turbo | Pictures and edits | More: a 7-billion-parameter denoiser plus its text encoder | 8 steps; smaller 4-bit versions made by others exist |
| Wan2.1 T2V-1.3B | 5 seconds of 480p video | 8.19 GB | About 4 minutes on an RTX 4090 |
| Wan2.2 TI2V-5B | 5 seconds of 720p video | A 24 GB card such as the RTX 4090 | Under 9 minutes |
From the makers’ model cards, reports and announcements, October 2026.
- Install ComfyUI, a free program that runs these models on your computer. It has a ready-made Windows version.
- Download a model’s files from Hugging Face. Some, such as FLUX 3 Image Klein, are gated: you accept the maker’s terms on the model page first.
- Open the Templates panel and pick the template for that model.
- Write a prompt, choose a size, and run it. Start small, such as 768 × 768 or two seconds of video, to learn how long your computer takes.
- Write down the seed, the number that chose the starting noise. The same seed with the same settings gives the same picture again, so you can change one thing at a time.
If you prefer Python, the diffusers library runs the same models, and most model cards show a short example. Online services and free notebooks can run them too, but then your prompts and pictures leave your computer, and a service can close, as Sora did.
Remember
- Pictures can be made one token at a time, like text (Janus-Pro), or by diffusion, which cleans noise off the whole picture over many steps. Most leading open models use diffusion.
- Training adds noise to real pictures and teaches a network to undo it. Flow matching draws a straight line from picture to noise and learns its direction, which allows fewer steps.
- Models work in a VAE’s latent space, 8 or 16 times smaller along each side, and a transformer turns 2 × 2 patches of it into tokens: 4,096 for a 1024 × 1024 picture in Wan2.1’s design.
- Classifier-free guidance runs the network with and without the prompt and pushes further towards the prompt. Distillation cuts 100 passes to 8 or 16.
- Video is one block of space and time. Five seconds of 480p in Wan2.1 is 32,760 tokens, and attention work grows with the square of that.
- A perfect denoiser only copies its training data; real models create because they are imperfect, and they still sometimes copy.
- Text in non-Latin scripts and pictures of less-photographed cultures are weak spots. Add important words yourself, and check.
- Never fake a real person, never pass a made-up picture off as real, and remember that a missing label proves nothing.
Words to know
- Diffusion model
- A model that makes pictures, video or sound by starting from noise and removing it step by step.
- Denoiser
- The network inside a diffusion model that guesses, at each step, what noise to remove.
- Flow matching
- Training a model to learn the direction of a straight line from a clean picture to noise. Also called rectified flow.
- Velocity
- In flow matching, the direction and distance from the picture to the noise. The model guesses it and steps against it.
- Latent
- The small grid of numbers a VAE turns a picture into. Diffusion happens there, not on the pixels.
- VAE
- Variational autoencoder: a network that squeezes a picture into a latent and turns it back again.
- DiT
- Diffusion transformer: a denoiser that cuts the latent into patches and treats each patch as a token.
- Text encoder
- The model that turns a prompt into the vectors the denoiser reads. It decides which languages the prompt can use.
- Classifier-free guidance
- Running the denoiser with and without the prompt and pushing further in the direction of the prompt.
- Negative prompt
- A description of what you do not want, used in place of the empty prompt in guidance.
- Distillation
- Training a fast student model to match a slow teacher in far fewer steps.
- Spacetime patch
- A token of a video: a small box a few pixels across, a few down and a few frames deep.
- Seed
- The number that chooses the starting noise. The same seed and settings give the same picture.
- Memorisation
- A model reproducing a training example instead of making something new.
- Content credentials (C2PA)
- A signed record inside a file that says how it was made and changed.
- Deepfake
- A made-up picture, video or voice of a real person, made to look real.
Go to the source
This lesson is built on these papers and documents. Paper links open arxiv.org, a separate site.
-
Denoising Diffusion Probabilistic Models
DDPM: add noise in many small steps, train a network to predict it, and run the steps backwards.
-
Diffusion Models Beat GANs on Image Synthesis
The paper that moved the field from GANs to diffusion.
-
Flow Matching for Generative Modeling
Training on straight paths from data to noise.
-
Flow Straight and Fast: Learning to Generate and Transfer Data with Rectified Flow
Rectified flow, the same straight-line idea from another group.
-
High-Resolution Image Synthesis with Latent Diffusion Models
Diffusion in a VAE’s latent space: the paper behind Stable Diffusion.
-
Scalable Diffusion Models with Transformers
DiT: latent patches as tokens, and transformers instead of U-Nets.
-
Scaling Rectified Flow Transformers for High-Resolution Image Synthesis
Stable Diffusion 3: rectified flow and MMDiT, with text and picture tokens in one attention.
-
Classifier-Free Diffusion Guidance
Guidance from one network run with and without the condition.
-
Adversarial Diffusion Distillation
A student that makes pictures in one to four steps, trained with a judge.
-
Janus-Pro: Unified Multimodal Understanding and Generation with Data and Model Scaling
DeepSeek’s model that reads and draws pictures as tokens, with separate encoders for each job.
-
Visual Autoregressive Modeling: Scalable Image Generation via Next-Scale Prediction
VAR: predict a picture coarse to fine, one scale at a time.
-
Qwen-Image Technical Report
A 20-billion-parameter MMDiT with Qwen2.5-VL as its text encoder, trained step by step to write Chinese and English.
-
Wan: Open and Advanced Large-Scale Video Generative Models
An open video model in full: the 3D VAE, the token counts, the cost of attention and the training data.
-
Video generation models as world simulators
The Sora report: videos as spacetime patches for a transformer.
-
MAGI-1: Autoregressive Video Generation at Scale
Sand AI’s model that makes video chunk by chunk.
-
How Far is Video Generation from World Model: A Physical Law Perspective
Video models copy the nearest training case instead of learning physics.
-
Extracting Training Data from Diffusion Models
More than a thousand training pictures pulled back out of image models.
-
An analytic theory of creativity in convolutional diffusion models
Why imperfect denoisers create: mosaics of patches from many training pictures.
-
Beyond Aesthetics: Cultural Competence in Text-to-Image Models
CUBE: food, landmarks and art of eight countries, and the gaps.
-
Challenges in Generating Accurate Text in Images: A Benchmark for Text-to-Image Models on Specialized Content
Text in generated pictures across many scripts, including Arabic, Hindi and Bengali.
Check yourself
6 questions. Tap the answer you think is right.
0 of 6 answered
Lesson complete
Answer every question above to complete this lesson.
Your progress is saved on this device only.
Next lessonSpeech and sound: models that listen and talk