Lecture 17 · Video Generation (Wilson Yan)

Deep Unsupervised Learning · Lecture 17。个人学习讲义与配套实验,按主题整理并持续修订。

课程源码 ZIP ↓

个人整理的学习笔记,非官方讲义;课程来源与整理说明见课程介绍。配套示例未逐一运行验证。

本篇目录

Maps to: UC Berkeley CS294-158 Deep Unsupervised Learning (Spring 2024), Lecture 9 · Thu 3/14/2024 · Video Generation (Wilson Yan; 72 slides): video as a modality and how codecs compress it (I-, P- and B-frames, motion vectors on 16 × 16 macroblocks); factorization as a cascade of spatial and temporal super-resolution (Imagen Video, Make-A-Video, PYoCo, Lumiere); per-frame latent models and reusing text-to-image pretraining by inserting temporal layers (Align Your Latents, Emu Video, Stable Video Diffusion); spatio-temporal latent spaces from 3-D autoencoders (VideoGPT, TATS, LVDM) with the first frame treated separately (Phenaki, MAGVIT-v2, VideoPoet, WALT); lookup-free and finite scalar quantization (LFQ, FSQ); improving video models along three axes (scale, representation, data: filtering, synthetic captions, fine-tuning on high-quality clips); video models as physical simulators (Finn et al. 2016, UniSim, GAIA-1, RFM-1), for visual planning (MaskViT, UniPi) and as rewards (VIPER); video editing (ControlNet, ControlVideo, SDEdit, Dreamix, inpainting). Basis: The slides survey systems trained on millions of videos. These notes rebuild the ideas on moving ShapeWorld: one shape moving and bouncing in a 16 × 16 frame for 9 frames, whose hidden state is a small Markov chain — so the probability of any video, the information in each frame, and what an interpolator must invent between keyframes are computed exactly with the forward algorithm of a hidden Markov model. Every generated video is checked exactly: is every frame a valid shape, and is the whole video possible (p > 0)? On this testbed we compare tokenizers and quantizers, generation orders of one masked space-time Transformer, image pretraining, data curation, editing, and an action-conditioned next-frame simulator. Code: code/lecture17/ (5 scripts + video_world.py; PyTorch (CPU); 23 networks, cached; first runs take about 5 CPU-hours in all, reruns about 25 minutes) Reading time: 3.5 hours including running the code


0. How to read this lecture

0.1 Learning goals

After this lecture you should be able to:

  1. Explain why raw video is huge and where its information is: spatial redundancy within frames, temporal redundancy between them — and how codecs (I / P / B frames, motion vectors) and video models exploit it.
  2. Describe cascades (base model + temporal and spatial super-resolution) and what an interpolation stage must still invent between keyframes.
  3. Compare per-frame and spatio-temporal (causal 3-D) tokenizers, and VQ with LFQ / FSQ quantizers (codebook usage).
  4. Explain how one masked video model generates jointly, frame by frame, image-then-video or keyframes-then-interpolation, and what each order costs.
  5. Explain how video models reuse image models (inserted temporal layers, frozen spatial layers), and why data curation (motion filtering, recaptioning, fine-tuning) matters.
  6. Explain what makes a video model an action-conditioned simulator, why early video predictions were blurry, why errors accumulate in rollouts, and how a simulator is used for planning.

0.2 Prerequisites and scope

AssumedIntroduced here
Lecture 4 (Transformers, tokenizers, VQ-tokenized images), Lecture 8 (VQ-VAE)video codecs, temporal redundancy, keyframe cascades
Lectures 11–12 (diffusion, latent diffusion, ControlNet, SDEdit, inpainting)per-frame vs causal 3-D tokenizers, VQ / LFQ / FSQ
Lecture 10 (VQGAN tokens), Lecture 13 (masked prediction, MAE)masked space-time Transformers (MaskGIT), generation orders, inflation of image models
action-conditioned prediction, rollouts, planning with a learned simulator

Text-to-video conditioning is played by a class label (the shape’s kind) — our stand-in for a prompt. Diffusion-based video models are discussed but not trained: Lectures 11–12 built the diffusion machinery, and a masked discrete model (as in Phenaki, MAGVIT and VideoPoet’s MaskGIT variants) shows the same generation-order questions at a fraction of the cost.

0.3 Map

§1  video as a modality: size, codecs, temporal redundancy          ← code 01, Parts 1-3
§2  cascades: keyframes, then interpolation                         ← code 01, Part 4
§3  latent spaces: per-frame vs spatio-temporal tokenizers; VQ, LFQ, FSQ   ← code 02
§4  generating videos: one masked model, four orders                ← code 03
§5  improving video models: image pretraining, data, editing        ← code 04
§6  video models as simulators: actions, rollouts, planning         ← code 05
§7 summary   §8 pitfalls   §9 exercises   §10 further reading   §11 next lecture

0.4 Notation

A video v=(x0,…,xT−1)v = (x_0, \dots, x_{T-1}) of T=9T = 9 frames, each 16×1616 \times 16 binary pixels; hidden state st=(ct,ut)s_t = (c_t, u_t) = (shape configuration: kind, size, centre; velocity); action at∈{−1,0,1}2a_t \in \{-1, 0, 1\}^2; p(v)p(v) the exact probability; tokens zz from a tokenizer; “possible” means p(v)>0p(v) > 0.

0.5 The world (video_world.MovingShapes)

  • Frame 0: kind uniform over ShapeWorld’s 8, size “tiny” (r=2r = 2) or “small” (r=3r = 3), centre uniform over the positions where the shape fits — 1,952 possible frames, exactly 10.91 bits.
  • Motion: every step the shape moves by an action at=(vx,vy)∈{−1,0,1}2a_t = (v_x, v_y) \in \{-1, 0, 1\}^2 and bounces off the walls (a coordinate that would leave its range is reflected and the velocity flips). Actions are sticky: with probability 1−pturn=0.751 - p_{\text{turn}} = 0.75 the shape keeps its velocity, otherwise a new one is drawn uniformly from the 9 (so it keeps it with probability 0.75+0.25/9=0.7780.75 + 0.25/9 = 0.778). The first action is uniform.
  • Exact probabilities: the hidden state (1,952 configurations × 9 velocities) is a Markov chain and each frame is a deterministic rendering of it, so the forward algorithm gives p(v)p(v), p(xt∣x<t)p(x_t \mid x_{<t}) and the probability of any subset of frames (the others summed out); forward filtering, backward sampling draws exact samples of hidden frames given the visible ones. A brute-force enumeration over action sequences checks the forward algorithm in the module’s self-test.
  • Data: 10,000 training and 2,000 test videos, and 10,000 single frames (“images”).

1. Video as a modality

1.1 Video is big

Videos are stored with codecs (H.264, H.265, AV1). One minute of 1080p video at 24 frames per second is about 20 MB encoded (slides). Raw, the same minute is 1920×1080×31920 \times 1080 \times 3 bytes ×24×60\times 24 \times 60 = 9.0 GB (22.4 GB at 60 frames per second), and 35.8 GB as float32 — what a network actually sees. That is a compression ratio of about 450 : 1, and a hint of the difficulty: a video model must either work in a heavily compressed space or pay for gigabytes per minute.

Our videos are tiny — 9 frames of 16×1616 \times 16 binary pixels, 2,304 bits — but they keep the important property. Their exact entropy is 23.46 ± 0.12 bits per video (script 01, Part 1): an ideal ratio of 98 : 1.

1.2 How codecs compress

Codecs classify frames (slides):

  • I-frames (key frames) are coded on their own — they exploit spatial redundancy, like an image codec;
  • P-frames (predicted) are coded relative to an earlier frame: each 16×1616 \times 16 macroblock gets a motion vector (where it came from) plus a small residual;
  • B-frames (bidirectional) are coded relative to frames before and after.

P- and B-frames exploit temporal redundancy. The slides ask whether video models can take inspiration from this — the theme of the whole lecture.

1.3 Where the information is (script 01, Part 2)

The forward algorithm gives the exact information each frame adds, −log⁡2p(xt∣x<t)-\log_2 p(x_t \mid x_{<t}), averaged over 2,000 test videos:

frame012345678all
bits10.912.921.411.361.411.441.351.371.2823.46

The first frame is a whole image (kind, size, position). The second adds the velocity (log⁡29=3.17\log_2 9 = 3.17 bits, a little less because bounces make some velocities look alike). Every later frame adds only “did it turn?”: H(0.778,8×0.0278)=1.43H(0.778, 8 \times 0.0278) = 1.43 bits away from walls. Most of a video is predictable from its past, and the first frame is special — it carries almost half of the information. (Remember this for §3: tokenizers that treat the first frame separately.)

Codes for the same videos:

codebits per video
raw pixels2,304
zlib, one video at a time497
lzma on 500 videos at once99
lzma on frame differences (frame 0, then XOR of neighbouring frames)162
exact frame model, every frame coded on its own (“I-frames only”)98.2 = 9 × 10.91
I-frame + one motion vector per frame, coded uniformly (“P-frames”)36.3 = 10.91 + 8 log₂ 9
exact video model (motion coded with the sticky prior)23.5

Even the exact image model, applied frame by frame, needs 4.2× the floor: it ignores time. Motion vectors cut the cost to 36 bits; remembering the previous motion reaches the floor. A generic dictionary coder (lzma) that sees 500 videos needs about as many bits as the exact I-frame code — it knows nothing about shapes, but it copies byte strings from the previous frame and from earlier videos. Interestingly, XOR frame differences make it worse (162 bits): a shape that moved by one pixel differs from its old self in many scattered pixels. Motion vectors, not pixel differences, are the right residual — the reason codecs search for motion.

1.4 How far back must a model look? (Part 3)

H(x5∣the m previous frames)H(x_5 \mid \text{the } m \text{ previous frames}), exactly:

contextnone1 frame2 framesall 5 earlier frames
bits of frame 510.873.021.581.58

One frame shows where the shape is but not where it is going; two frames show the velocity, and then the past has nothing more to say (the state is position + velocity). The simulator of §6 therefore conditions on two frames.


2. Cascades: keyframes, then interpolation

Factorization as a cascade (slides): break video generation into smaller pieces — a base model at low resolution and low frame rate, then temporal super-resolution (TSR: interpolate frames between the base model’s frames) and spatial super-resolution (SSR) models. Imagen Video chains seven models — a base model, three temporal and three spatial super-resolution stages — trained on 14M text–video and 500M text–image pairs (slides); Make-A-Video and PYoCo follow similar plans. Lumiere argues against the temporal part of the cascade: its base model generates the whole clip at once (80 frames at 128 × 128, 16 fps), with only spatial super-resolution afterwards — because an interpolator that sees only distant keyframes cannot recover fast or ambiguous motion consistently (temporal aliasing).

How much does an interpolator have to invent? Script 01, Part 4 computes, exactly, H(keyframes)H(\text{keyframes}) and H(in-between frames∣keyframes)=H(v)−H(keyframes)H(\text{in-between frames} \mid \text{keyframes}) = H(v) - H(\text{keyframes}) for keyframes every ss frames:

stride sskeyframesbits in the keyframesbits the interpolator must inventvideos with > 1 bit to invent
1all23.460.000%
20, 2, 4, 6, 822.161.3036.8%
40, 4, 820.083.3864.0%
80, 817.146.3286.9%

Where the information is; keyframes vs interpolation

With keyframes every 8 frames, 6.3 bits — about a quarter of the video’s information — are not determined by the keyframes. Exact posterior samples (forward filtering, backward sampling) for one test video, given only frames 0 and 8, show what that means:

truth    : (13,13) -> (12,12) -> (11,11) -> (10,10) -> (9,10) -> (8,10) -> (7,10) -> (6,11) -> (5,12)
sample 1 : (13,13) -> (12,12) -> (11,11) -> (10,12) -> (9,13) -> (8,12) -> (7,12) -> (6,12) -> (5,12)
sample 2 : (13,13) -> (12,13) -> (11,13) -> (10,13) -> (9,12) -> (8,11) -> (7,10) -> (6,11) -> (5,12)
sample 3 : (13,13) -> (12,13) -> (11,13) -> (10,13) -> (9,13) -> (8,13) -> (7,13) -> (6,13) -> (5,12)

Whole alternative trajectories are consistent with the keyframes. A cascade is still a correct generative model if its interpolation stage samples this posterior — the chain rule p(v)=p(keys) p(rest∣keys)p(v) = p(\text{keys})\,p(\text{rest} \mid \text{keys}) is exact — but an interpolator trained with a regression loss would average the trajectories into a blur, and one that sees only a short window cannot keep the choices consistent across windows. Lumiere’s argument, in numbers.


3. Latent spaces: per-frame vs spatio-temporal tokenizers

3.1 Per-frame latents

Video models almost never work on pixels. The slides’ first family compresses each frame with an image autoencoder — a VQGAN when the prior is autoregressive, a VAE when it is a diffusion model — then models the sequence of per-frame latents: a base model on key frames (temporal compression by skipping frames) and frame-interpolation models to raise the frame rate (Align Your Latents, Emu Video, Stable Video Diffusion). The appeal: the autoencoder is an image autoencoder, so it can be taken from a text-to-image model (§5.1). The cost: every frame gets the same number of tokens, although (§1.3) frame 0 carries 10.9 bits and every later frame ~1.4.

3.2 Spatio-temporal latents

“Can we better temporally downsample our data? Just learn a 3D autoencoder!” (slides). VideoGPT (a 3-D CNN VQ-VAE + an autoregressive prior; e.g. 16 × 256 × 256 → 4 × 16 × 16 latents), TATS and LVDM (a 3-D VAE + a diffusion prior) compress time as well as space. But joint image + video training — which helps a lot, because text–image data are far more plentiful — needs a way to encode a single image. The fix (Phenaki, MAGVIT-v2, VideoPoet, WALT): treat the first frame separately and make the temporal processing causal, e.g. 17 × 256 × 256 → (1 + 4) × 16 × 16: the first latent frame depends only on frame 0, so an image is just a one-frame video.

Our CausalVideoAE does this in miniature: frame 0 gets its own latent frame; every block of kk later frames (plus the frame just before it, for causal context) becomes one latent frame — (1+8/k)(1 + 8/k) latent frames instead of 9.

3.3 Quantizers: VQ, LFQ, FSQ

A VQ layer replaces each encoder output by the nearest of KK learned codebook vectors (Lecture 8). Large codebooks are hard to use: codes that are never the nearest get no gradient and stay dead. The slides show two codebook-free alternatives: LFQ (lookup-free quantization, MAGVIT-v2): take the sign of each of dd numbers — an implicit codebook {−1,+1}d\{-1, +1\}^d of 2d2^d codes — plus an entropy penalty that asks each position to be confidently assigned while the batch as a whole uses many codes; and FSQ (finite scalar quantization): squash each of a few numbers into a bounded range and round it to one of LiL_i levels — ∏iLi\prod_i L_i codes, e.g. (8, 5, 5, 5) = 1,000. Both pass gradients straight through the rounding and make much larger codebooks usable (slides: “LFQ / FSQ methods allow much larger codebook sizes”).

3.4 Experiment: quantizers (script 02, Part 1)

Same patch-local encoder (one token per 4 × 4 patch, 16 tokens per frame) and decoder for every quantizer, 4,000 training steps; the whole world has only 384 distinct 4 × 4 patches:

quantizercodebookexact framespixel errorscodes usedperplexity
VQ64100.0%0.000%18.8%3
FSQ (4, 4, 4)6498.3%0.009%70.3%5
LFQ, 6 bits6486.6%0.170%35.9%3
VQ1,02494.5%0.097%1.3%3
FSQ (8, 5, 5, 5)1,00099.8%0.001%22.7%7
LFQ, 10 bits1,0243.1%6.024%0.2%2
LFQ, 10 bits, no entropy penalty1,02499.8%0.001%19.7%7

With a large codebook, VQ used 13 of its 1,024 codes; FSQ used 227 (the world has 384 distinct patches, so ~38% is the most a lossless tokenizer could need) and reconstructed 99.8% of frames exactly — the slides’ point about codebook usage, reproduced. (With small codebooks VQ did fine: its 12 used codes plus the decoder’s view of neighbouring tokens were enough.) LFQ with MAGVIT-v2’s entropy penalty failed at 10 bits: the penalty asks every bit to be +1 for half of all patches, but most patches are empty background, so it fights the data; without the penalty LFQ matched FSQ. (Perplexities are small because most tokens are empty patches.)

Two engineering lessons from getting here (plan vs reality): our first FSQ tokenizer collapsed to a single code — the encoder’s outputs drifted into tanh’s flat region where rounding never changes and gradients vanish — until a normalization layer before the quantizer kept them in range; and our first encoders were non-local (stacked 3 × 3 convolutions), so an empty patch got ~400 different codes depending on the shape nearby — a valid tokenizer, but one whose tokens a small generator could not learn to model (§4).

3.5 Experiment: temporal compression (script 02, Parts 2–3)

tokenizertokens per videoexact framesexact videosvideo possible
per-frame, 4 × 4 patches (FSQ 1,000)9 × 16 = 14499.8%98.8%98.8%
causal 3-D, 4 × 4 patches, stride 25 × 16 = 8079.7%24.0%24.0%
causal 3-D, 4 × 4 patches, stride 43 × 16 = 4828.9%2.4%2.4%
per-frame, 8 × 8 patches (FSQ 2,560)9 × 4 = 3623.2%3.5%3.5%
per-frame, 8 × 8 patch dictionary (exact)9 × 4 = 36100%100%100%

Exact reconstruction per frame, causal tokenizers: stride 2 75–82% on every frame; stride 4 57% on frame 0 and 22–28% on the others.

Codebook usage and per-frame reconstruction

Temporal compression saves tokens (144 → 80 → 48) — and sequence length is what makes video models expensive — but at the same training budget our causal 3-D tokenizers reconstructed only 24% and 2.4% of the videos exactly. The information is there (a video carries 23.5 bits; 48 tokens of 10 bits could hold 480), but packing several frames and their motion into one latent frame is a much harder learning problem than coding a frame; production 3-D tokenizers are large and trained long for this reason. Larger patches are the spatial version of the same trade-off: 8 × 8 patches give 4 tokens per frame, but our learned tokenizer reached only 23% exact frames. For the generation experiments we therefore use an exact dictionary of the 1,665 distinct 8 × 8 patches (36 tokens per video): every error in §4–§5 is the generator’s.


4. Generating videos: one masked model, four orders

4.1 Masked token models

Phenaki, MAGVIT and one of VideoPoet’s variants generate video tokens with a MaskGIT-style model: a bidirectional Transformer trained to predict randomly hidden tokens from the visible ones. To sample, start with everything hidden; at each step predict all hidden tokens in parallel, sample a token for each, keep the most confident ones and hide the rest again; repeat until nothing is hidden. Because the model can be conditioned on any subset of visible tokens, one network supports every generation order — joint generation, frame-by-frame prediction, image-to-video, interpolation — just by choosing which tokens are given and which are generated when.

Our model (SpaceTimeTransformer, ~0.5M parameters): token, spatial-position and frame embeddings plus a class embedding (the shape’s kind, our stand-in for a prompt); 4 blocks of factorized attention — spatial attention among the tokens of one frame, temporal attention among the tokens at the same position across frames, then an MLP (the factorization of Video Vision Transformers and of many video diffusion U-Nets; it is also what makes §5.1 possible). Training hides a random fraction of tokens (MaskGIT’s cosine schedule); in 60% of the examples some frames are kept fully visible — a prefix (future prediction) or a random subset (interpolation) — so the model learns the conditional tasks too. 10% of the time the class is dropped, enabling classifier-free guidance. Tokens: an exact dictionary of the 1,665 distinct 8 × 8 patches (4 tokens per frame, 36 per video), so every error is the generator’s.

4.2 Experiment (script 03)

One class-conditional model (483,393 parameters, 12,000 steps of 32 videos), 500 samples per row (the requested kinds cycle through all 8). Every order uses 36 network evaluations — one token fixed per evaluation — so they differ only in which tokens are decided when; two extra rows fix 2 or 4 tokens per evaluation (MaskGIT’s parallel decoding). “Changes / step” counts how often the displacement changes between steps (turns and bounces) among possible videos:

orderevaluationsframes validconsistent kind & sizevideo possiblechanges / stepstatic
true videos—100%100%100%0.321.8%
joint (all frames at once)3681.4%81.2%50.4%0.635.2%
image first, then video3684.8%84.4%60.8%0.584.2%
frame by frame3677.2%76.4%44.8%0.623.6%
keyframes, then interpolation3668.0%67.0%25.6%0.800.0%
joint, 2 tokens per evaluation1862.8%62.6%22.6%0.790.8%
joint, 4 tokens per evaluation951.8%51.2%10.4%0.840.8%

Video possible, by generation order

What the table says:

  1. Getting the motion right is the hard part. About 80% of samples have valid, consistent frames, but only half are possible videos: the shape jumps, or turns twice as often as in the true world (0.6 vs 0.32 changes per step). Pixels per frame are easy; physics across frames is not.
  2. Image first, then video (Emu Video’s factorization) was the best order: decide the content (kind, size, position) first, then only the motion. Frame by frame — committing to each frame before seeing the next — was a little worse than joint generation.
  3. Keyframes, then interpolation was the worst order (25.6%), and its samples change direction most often: generating frames 0, 4 and 8 first fixes the endpoints of motions the model must then reconnect — exactly the ambiguity of §2 (3.4 bits to invent per video), here imposed on a model that also chose the keyframes imperfectly. Lumiere’s argument for generating the whole clip at once, in numbers.
  4. Parallel decoding costs validity: fixing 2 or 4 tokens per evaluation halves or quarters the possible videos. Tokens decided in the same step are sampled independently given the rest — the same “independent pixels” problem as §6.2. The image-only model of §5.1 shows it most clearly: decoding a frame’s 4 tokens one per evaluation gives 99.2% valid frames, two per evaluation 25.6%, all four at once 4.8%.

Conditioning (Part 2): the first frame showed the requested kind in 92.2% of samples; classifier-free guidance w=1w = 1 raised that to 95.4% but lowered possible videos from 46.6% to 31.4%, and w=3w = 3 broke the videos (1.8% possible, 59.8% right kind). Guidance trades fidelity to the condition against sample quality — here sharply, because the model is small.

Plan vs reality: our first masked models, on the 16 tokens per frame of the learned 4 × 4 tokenizers, generated 0–1% valid frames — fragments of shapes. Context-dependent tokens (§3.4) and 144 tokens per video were too much for a 0.5M-parameter model trained for minutes; 4 exact tokens per frame, and 12,000 instead of 4,000 steps, made the experiment work.


5. Improving video models

5.1 Reusing an image model: inserted temporal layers

Key idea (slides): initialize a video model from a pretrained text-to-image model — its spatial layers (2-D convolutions, spatial attention) are applied to every frame — and insert temporal operations (1-D / 3-D convolutions, temporal attention) between them; optionally freeze the spatial parameters (Align Your Latents, Emu Video, Make-A-Video). If the new temporal layers start as the identity (zero-initialized output projections), the inflated model initially is the image model applied to every frame independently, and training only has to learn motion. Text–image data are far more plentiful than text–video data, so the spatial knowledge comes almost for free.

inflate() does exactly this: our image model has spatial attention only; the video model adds temporal attention with zero-initialized outputs and zero frame embeddings. Emu Video goes one step further and factorizes generation: first generate an image from the text, then generate the video conditioned on text and image (“image first, then video” in §4).

5.2 The data is the model

The slides’ three axes for better video models are scale, representation (more compressed latents) and data — “the data is essentially the model”. Recipes: filter out static videos (optical-flow scores), poorly aligned captions (CLIP scores) and low-quality clips (aesthetic scores, resolution, metadata); synthetic captions: good text–video pairs are rare on the web, so caption videos with a vision-language model (CoCa, LLaVA, ShareCaptioner, Video-LLaVA), or fine-tune one on a small set of high-quality captions and recaption everything — Stable Video Diffusion trained on ~150M purely synthetically captioned clips; fine-tune on a small set of very high-quality videos at the end.

5.3 Editing

Diffusion and masked models edit by partial regeneration. SDEdit (Lecture 12): noise the input to an intermediate level tt, then denoise with the new condition — small tt keeps the input (faithful), large tt follows the condition (edit). Applied frame-wise to video it flickers; video models apply it to the whole clip (the slides’ “made of wooden blocks” example). Dreamix first fine-tunes the video model on the input video (mixed video–image fine-tuning: reconstruct it from noised versions, also with temporal layers masked) so that regeneration keeps its appearance and motion; ControlNet / ControlVideo add structural conditions (edges, depth, pose) as extra inputs (Lecture 12); inpainting regenerates a masked region. Our masked-token analogue of SDEdit: hide a random fraction rr of a video’s tokens and regenerate them with a new class.

5.4 Experiments (script 04)

Image pretraining with 300 videos (Part 1). An image model (spatial attention only, 20,000 steps on 10,000 single frames) is inflated to 9 frames and fine-tuned for 3,000 steps on only 300 videos — all weights, or the temporal layers only — and compared with a model trained from scratch on the same 300 videos. “Test bits” is the loss of predicting all tokens of frames 1–8 from frame 0 in one pass (comparable across models, not a likelihood):

video modeltest bitsframes validconsistentvideo possiblerequested kind
image model, inflated, no video training4.60975.2%1.2%0.0%97.6%
from scratch on 300 videos6.96629.0%27.0%13.2%79.4%
inflated, fine-tuned on 300 videos (all weights)7.30563.2%54.0%23.4%93.4%
inflated, 300 videos, spatial layers frozen4.36379.4%23.2%1.0%91.6%
reference: from scratch on 10,000 videos3.55081.4%81.2%50.4%93.4%

The inflated image model before any video training draws good frames (75% valid, the right kind 98% of the time) that have nothing to do with each other (1.2% consistent): it is the image model applied to each frame independently, as designed. Fine-tuning it on 300 videos gives twice as many possible videos as training from scratch (23.4% vs 13.2%) and far better frames (63% vs 29% valid) — the image data carry the spatial knowledge. Freezing the spatial layers keeps the frames good and gives the best test loss, but the small temporal layers alone did not learn motion in 3,000 steps (1.0% possible). The test loss and the sample quality disagree: the fully fine-tuned model is over-confident on held-out videos (7.3 bits) while sampling better. With 300 videos nothing reaches the 10,000-video reference — pretraining reduces, but does not remove, the need for video data.

The data is the model (Part 2). A “web” set of 10,000 videos: half are static clips, and captions name the right kind only 55.8% of the time. Curation: a motion filter (keep videos in which some frame differs from the first: 4,895 kept); recaptioning with a small captioner trained on 200 labeled frames (100% accurate on single test frames, and its majority vote over 9 frames recaptioned 100% of the filtered videos correctly — our world is easy to caption); fine-tuning the raw model on 300 curated videos (1,000 steps):

training datastatic samplesrequested kind shownvideo possible
all web data, web captions24.4%75.6%37.4%
motion-filtered, web captions3.6%85.6%25.6%
motion-filtered + recaptioned9.8%88.4%54.0%
all web data, then fine-tuned on 300 curated videos34.4%95.6%49.4%
reference: 10,000 clean videos, true captions4.2%93.8%48.2%

Half the training data static → a quarter of the samples static; the motion filter removes almost all of them. Noisy captions → samples that often ignore the prompt; recaptioning fixes most of it, and filtering + recaptioning matched the clean reference. The short fine-tune on curated clips gave the best prompt-following of all (95.6%) but did not remove the static samples (34.4%, even more than before): 1,000 small steps on 300 videos taught the model what the captions mean, not to forget what half of its data looked like. (Filtering alone lowered the share of possible videos, 37.4% → 25.6% — with noisy captions on half as much data; we report it as measured.)

Editing (Part 3). Our masked-token analogue of SDEdit / video inpainting: regenerate the tokens of the patches the shape occupies (an inpainting mask), plus a random fraction rr of the background tokens, with a different requested kind. 400 test videos:

extra fraction rrtokens regeneratednew kind in every framecentre distance to the original (pixels)video possible
053%27.8%2.2816.8%
0.2565%37.2%2.5623.0%
0.577%29.2%2.9420.8%
0.7588%18.0%3.704.5%
1.0 (generate from scratch)100%79.8%5.6945.0%

Editing: the trade-off

Faithfulness falls steadily as more is regenerated (the shape stays within 2.3 pixels of its original path at r=0r = 0, wanders 5.7 pixels at r=1r = 1) — SDEdit’s trade-off. But edit success is not monotone, and partially regenerated videos are often impossible (5–23%): the model must reconcile a new kind with context that came from the old video, and our small model, trained only to fill random holes, does that badly. Generating from scratch is the most “successful” edit and the least faithful one. This is the problem Dreamix attacks by first fine-tuning the model on the input video, so that keeping its appearance and motion is what the model wants to do.


6. Video models as simulators

6.1 Why simulators

Much of the early work on video prediction was motivated by simulating the world: for robotics, self-driving and games (slides). Finn, Goodfellow & Levine (2016) predicted how a robot’s pushes move objects; today’s systems are trained on far more data: UniSim (a universal interactive simulator from heterogeneous datasets, conditioned on actions or language), GAIA-1 (Wayve’s world model for driving: video, text and actions as tokens), RFM-1 (Covariant’s robotics foundation model, which also predicts video). Three uses on the slides:

  • Simulation: “what happens if I do this?” — an action-conditioned model p(xt+1∣x≤t,at)p(x_{t+1} \mid x_{\le t}, a_t).
  • Visual planning: search over action sequences with the model and pick the one whose predicted video reaches a goal image (MaskViT); or generate a video plan from a text instruction and recover the actions from it with an inverse-dynamics model (UniPi).
  • Rewards: the likelihood of an agent’s behaviour under a video model trained on expert videos is a reward signal (VIPER) — “act so that your video looks like an expert’s”.

Two questions decide whether a video model is a useful simulator: does it know the effect of actions, and does it stay accurate when it is run open-loop, feeding on its own predictions?

6.2 Actions turn a blurry predictor into a simulator

Our world without actions is stochastic: from two frames the next velocity is the old one with probability 0.778, else one of 8 others. A predictor that outputs independent pixel probabilities — like most early video-prediction networks trained with a pixel loss — can at best output the per-pixel average of the possible futures: a blurry superposition. With the action the future is determined.

Experiment (script 05, Part 1). A next-frame predictor — a CNN with dilated convolutions, input the previous and current frames (two frames show the velocity, §1.4) and optionally the action as 9 one-hot channels, output an independent Bernoulli probability per pixel — trained on 35,000 transitions of the sticky random policy, compared with exact references computed from the world:

predictortest bits per framethresholded prediction exactpixels sampled independently: valid frame
CNN, no action22.1473.3%1.6%
CNN, with the action0.0299.5%99.1%
CNN, with the action + noise augmentation0.0499.6%98.0%
exact, no action: best independent-pixel predictor21.34—1.5%
exact, no action: the joint distribution (≤ 9 futures)1.47—100%
exact, with the action0100%100%
current frame      true next frame    p(pixel on), no action   with action
.....#####......   ................        .....
.....#...#......   .....#####......       .#####.               #####
.....#...#......   .....#...#......       .#. .#.               #   #
.....#...#......   .....#...#......       .#...#.               #   #
.....#####......   .....#...#......        #...#.               #   #
................   .....#####......        #####.               #####

(’ ’ < 5%, ’.’ < 30%, ’#’ ≥ 70%.) Without the action, the network is within 0.8 bits of the best possible independent-pixel predictor — and that best predictor is a blur: 21.3 bits for a future that has only 1.47 bits of real uncertainty, and pixels sampled from it form a valid frame 1.5% of the time. The problem is not the data but the model class: independent pixels cannot represent “one of nine sharp futures”. Two fixes: a model of the joint (autoregressive, diffusion, masked tokens — §4), or conditioning on the action, which makes the future (nearly) deterministic — the same network then predicts 99.5% of next frames exactly. This is why UniSim and GAIA-1 condition on actions, and why the first video-prediction papers (Finn et al. 2016) predicted motion given the robot’s action.

6.3 Open-loop rollouts: errors accumulate (Part 2)

A simulator is used open-loop: given the first two frames and a sequence of 30 actions, it consumes its own predictions. Fraction of 500 test episodes whose predicted frame is exactly right:

predictorstep 12481630
with the action99.8%99.4%99.0%97.8%94.2%90.6%
with the action + noise augmentation99.8%99.4%99.6%99.2%99.0%98.4%

Error accumulation in open-loop rollouts

A model that is right on 99.8% of single steps is exactly right after 30 steps only 90.6% of the time: its small errors become its next inputs — inputs unlike anything it saw in training (it was trained on true frames, “teacher forcing”), so the errors persist and grow. Noise augmentation — training on inputs with 2% of the pixels flipped — teaches the model to produce a clean next frame from a slightly wrong one, so it repairs its own errors: 98.4% after 30 steps. (The same idea appears as noise augmentation of the conditioning frames in cascaded and latent video diffusion, and as “diffusion forcing”; scheduled sampling trains on the model’s own predictions instead.)

6.4 Planning with a learned simulator (Part 3)

Model-predictive control: imagine 128 candidate action sequences of 8 steps (every straight segment “go in direction aa for kk steps, then stop”, plus random two-segment plans), roll each out in the simulator, score it by the distance between the predicted shape’s centre and the goal image’s, execute the best plan’s first 4 actions in the true world, observe, replan; 16 steps in all. 200 episodes, goals at least 5 pixels away, success = the shape ends exactly at the goal:

planner’s simulatorepisodes ending exactly at the goal
the true world (oracle)100%
learned, with the action100%
learned, with the action + noise augmentation100%
random actions, no planning1.0%

The learned simulators are as good as the true world for this planner: 8-step imagined rollouts are ~98–99% exact, and replanning every 4 steps from observed frames resets the drift — closed-loop use hides most of the open-loop error of §6.3. (A first version of the planner, with 64 random candidates and no straight-line plans, reached only 55% — with the oracle and with the learned models alike: the search, not the simulator, was the bottleneck.) MaskViT plans this way with a masked video model; UniPi instead generates the video plan directly and recovers actions with an inverse-dynamics model; VIPER uses a video model’s likelihood of the agent’s behaviour as a reward (for an exact version of that idea, our forward algorithm gives log⁡p(video)\log p(\text{video}) of any behaviour under the sticky policy).


7. Summary

  1. Video is redundant in time. Our videos hold 23.5 bits in 2,304 pixels: 10.9 in the first frame, ~1.4 in each later one. Coding frames independently costs 4× the floor even with the exact image model; motion vectors and a memory of the last motion reach it (§1). Two frames of context carry everything the past knows here.
  2. Cascades leave real work to interpolation: keyframes 8 frames apart leave 6.3 bits — whole trajectories — undetermined; generating keyframes first produced the fewest possible videos (25.6% vs 50–61% for other orders), Lumiere’s argument in numbers (§2, §4).
  3. Tokenizers: FSQ used 23% of a 1,000-entry codebook where VQ used 1.3% of 1,024 (the world has 384 distinct patches); LFQ’s entropy penalty failed on data that are mostly background. Causal 3-D tokenizers cut tokens 144 → 80 → 48 but reconstructed only 24% / 2.4% of videos at our budget — temporal compression moves the difficulty into the tokenizer (§3).
  4. One masked model, many orders: image-first-then-video was best (60.8% possible), joint 50.4%, frame by frame 44.8%; fixing several tokens per step cut validity sharply (independent sampling again); guidance traded validity for prompt-following (§4).
  5. Image pretraining helps when videos are scarce (an inflated image model doubled the possible videos with 300 training videos); data curation fixes what the data teaches (motion filter: static samples 24% → 4%; recaptioning: prompt-following 76% → 88%); editing by partial regeneration trades faithfulness for change, and is harder than generating (§5).
  6. Simulators: without actions the best independent-pixel predictor is a blur (21.3 bits vs 1.47 for the true uncertainty); with actions the next frame is predicted 99.5% exactly; open-loop errors accumulate (90.6% exact after 30 steps) unless the model is trained on noisy inputs (98.4%); a learned simulator planned as well as the true world (100%) (§6).

8. Common pitfalls

  1. Counting pixels instead of information. Our 2,304-pixel videos carry 23.5 bits, most of it in the first frame; a model (or tokenizer) that spends the same budget on every frame wastes most of it.
  2. Coding frame differences instead of motion. XOR differences made lzma worse (162 vs 99 bits); a one-pixel move changes many scattered pixels.
  3. Assuming an interpolator only fills in details. Between keyframes 8 frames apart, 6.3 bits — whole trajectories — are undetermined; a deterministic interpolator must blur or guess, and a keyframes-first generator produced the fewest possible videos.
  4. Reading reconstruction loss as “good enough”. A tokenizer at 0.1 bits per frame can still get frames wrong; exact checks (or task metrics) are what matter downstream. And a valid tokenizer can produce tokens a small generator cannot model (context-dependent codes).
  5. Fixing many tokens per decoding step. Tokens decided together are sampled independently given the rest; 2 or 4 per step cut the possible videos from 50% to 23% and 10%.
  6. Training on raw web data. Static clips became static samples, noisy captions weak prompt-following; filtering and recaptioning fixed both.
  7. Judging a simulator by one-step accuracy. A 99.5%-accurate next-frame model drifted to 90.6% after 30 open-loop steps; training on noisy inputs kept it at 98.4%.
  8. Predicting independent pixels of a stochastic future. Without the action, the best independent-pixel predictor is a blur whose pixel samples are valid frames 1.5% of the time.

9. Exercises

Exercise 1 (the information in a frame — derivation). In our world (away from walls), show that H(xt∣x<t)=H(0.778,8×0.0278)≈1.43H(x_t \mid x_{<t}) = H(0.778, 8 \times 0.0278) \approx 1.43 bits for t≥2t \ge 2, and log⁡29=3.17\log_2 9 = 3.17 for t=1t = 1.

Answer

Given two or more frames, the current velocity is known (the displacement between the last two frames). The next action keeps it with probability 1−p+p/9=0.75+0.0278=0.7781 - p + p/9 = 0.75 + 0.0278 = 0.778 and is each of the other 8 velocities with probability p/9=0.0278p/9 = 0.0278; away from walls every action gives a different next frame, so H(xt∣x<t)=−0.778log⁡20.778−8⋅0.0278log⁡20.0278=0.282+1.149=1.43H(x_t \mid x_{<t}) = -0.778\log_2 0.778 - 8 \cdot 0.0278\log_2 0.0278 = 0.282 + 1.149 = 1.43 bits. For t=1t = 1 the first action is uniform over 9: log⁡29=3.17\log_2 9 = 3.17 bits (bounces at walls merge some actions, hence the measured 2.92).

Exercise 2 (what an interpolator must invent — derivation). Show that H(in-between frames∣keyframes)=H(v)−H(keyframes)H(\text{in-between frames} \mid \text{keyframes}) = H(v) - H(\text{keyframes}), and explain why it grows with the stride.

Answer

The keyframes are a function of the video, so H(v)=H(v,keys)=H(keys)+H(v∣keys)H(v) = H(v, \text{keys}) = H(\text{keys}) + H(v \mid \text{keys}), and vv given the keys is exactly the in-between frames. With a larger stride, more turns happen between consecutive keyframes and many paths connect the same endpoints; the keyframes carry less of the information (H(keys)H(\text{keys}) falls from 23.46 to 17.14 bits from stride 1 to 8) and the rest must be invented: 0 → 1.30 → 3.38 → 6.32 bits.

Exercise 3 (the best independent-pixel predictor — derivation). For a future that is a mixture ∑kwk δx(k)\sum_k w_k\,\delta_{x^{(k)}} of frames, show that the independent-pixel model minimizing the expected cross-entropy predicts pi=∑kwkxi(k)p_i = \sum_k w_k x_i^{(k)} for every pixel ii, and that its expected loss is at least the joint entropy H(w)H(w).

Answer

The expected loss ∑kwk∑i−[xi(k)log⁡pi+(1−xi(k))log⁡(1−pi)]\sum_k w_k \sum_i -[x_i^{(k)}\log p_i + (1 - x_i^{(k)})\log(1 - p_i)] separates over pixels; for each pixel it is the cross-entropy of a Bernoulli(xˉi\bar x_i) with xˉi=∑kwkxi(k)\bar x_i = \sum_k w_k x_i^{(k)} against Bernoulli(pip_i), minimized at pi=xˉip_i = \bar x_i — the average of the futures (blur). Its value ∑ih(xˉi)\sum_i h(\bar x_i) is at least H(w)H(w) because a product distribution cannot represent the correlations between pixels (the loss of any model upper-bounds the entropy of what it codes). Script 05: 21.34 bits vs 1.47.

Exercise 4 (why rollouts drift). A next-frame model is exactly right with probability 1−ϵ1 - \epsilon per step on clean inputs, and once wrong it stays wrong. What fraction of 30-step rollouts is still exact? What changes if the model can repair a wrong input with probability qq?

Answer

(1−ϵ)30(1 - \epsilon)^{30}; for ϵ=0.005\epsilon = 0.005 (script 05’s 99.5%) this is 86% — the clean model’s 90.6% after 30 steps is of this order. If wrong frames are repaired with probability qq per step, the “wrong” state is no longer absorbing: the fraction of wrong frames settles near ϵ/(ϵ+q)\epsilon/(\epsilon + q) instead of growing. Noise augmentation trains exactly this repair (98.4% exact after 30 steps).

Exercise 5 (tokens and attention cost). A video of TT latent frames with SS tokens each is modelled with (a) full attention over all TSTS tokens, (b) factorized spatial + temporal attention. Compare the attention cost, and compute both for our per-frame 4 × 4 tokens (T = 9, S = 16) and the causal stride-4 tokenizer (T = 3, S = 16).

Answer

(a) (TS)2(TS)^2 score entries per layer; (b) TS2+ST2T S^2 + S T^2. Per-frame: (a) 1442=20,736144^2 = 20{,}736, (b) 9⋅256+16⋅81=3,6009 \cdot 256 + 16 \cdot 81 = 3{,}600. Stride 4: (a) 482=2,30448^2 = 2{,}304, (b) 3⋅256+16⋅9=9123 \cdot 256 + 16 \cdot 9 = 912. Temporal compression and factorization multiply; this is why production systems compress time and factorize attention — and why the tokenizer’s quality (§3.5) becomes the bottleneck.

Exercise 6 (classifier-free guidance). Explain why guidance weight w=3w = 3 raised nothing and broke the videos (1.8% possible), while w=1w = 1 improved prompt-following (92.2% → 95.4%).

Answer

Guidance samples from logits (1+w)ℓcond−w ℓuncond(1 + w)\ell_{\text{cond}} - w\,\ell_{\text{uncond}}, i.e. a distribution ∝p(z∣c)1+w/p(z)w\propto p(z \mid c)^{1 + w}/p(z)^{w} per token: it sharpens toward tokens that are typical of the class relative to the unconditional model. For a small model these log-ratios are noisy; with large ww the noise is amplified and tokens are chosen for “class-likeness” even when they break the shape or the motion. Moderate guidance helps fidelity; strong guidance trades away validity (Lecture 12’s FID-vs-guidance curve, in miniature).

Exercise 7 (coding). In script 05, train the action-conditioned predictor with noise augmentation 0.05 instead of 0.02. Predict the effect on one-step accuracy and on 30-step rollouts.

Answer

(Run it.) More input noise makes each training example harder (one-step accuracy on clean inputs may drop slightly) but teaches stronger repair; rollouts should stay accurate as long as the noise remains smaller than what the model can still interpret. Too much noise destroys the information about the shape and hurts both.


10. Further reading

From the slides

  • J. Ho et al. Imagen Video: High Definition Video Generation with Diffusion Models, 2022; U. Singer et al. Make-A-Video: Text-to-Video Generation without Text-Video Data, 2022; S. Ge et al. Preserve Your Own Correlation: A Noise Prior for Video Diffusion Models (PYoCo), ICCV 2023; O. Bar-Tal et al. Lumiere: A Space-Time Diffusion Model for Video Generation, 2024.
  • A. Blattmann et al. Align Your Latents: High-Resolution Video Synthesis with Latent Diffusion Models, CVPR 2023; R. Girdhar et al. Emu Video: Factorizing Text-to-Video Generation by Explicit Image Conditioning, 2023; A. Blattmann et al. Stable Video Diffusion: Scaling Latent Video Diffusion Models to Large Datasets, 2023.
  • W. Yan, Y. Zhang, P. Abbeel, A. Srinivas. VideoGPT: Video Generation using VQ-VAE and Transformers, 2021; S. Ge et al. Long Video Generation with Time-Agnostic VQGAN and Time-Sensitive Transformer (TATS), ECCV 2022; Y. He et al. Latent Video Diffusion Models for High-Fidelity Long Video Generation (LVDM), 2022.
  • R. Villegas et al. Phenaki: Variable Length Video Generation from Open Domain Textual Descriptions, ICLR 2023; L. Yu et al. Language Model Beats Diffusion — Tokenizer is Key to Visual Generation (MAGVIT-v2, LFQ), ICLR 2024; D. Kondratyuk et al. VideoPoet: A Large Language Model for Zero-Shot Video Generation, 2023; A. Gupta et al. Photorealistic Video Generation with Diffusion Models (WALT), 2023; F. Mentzer et al. Finite Scalar Quantization: VQ-VAE Made Simple, ICLR 2024.
  • C. Finn, I. Goodfellow, S. Levine. Unsupervised Learning for Physical Interaction through Video Prediction, NeurIPS 2016; M. Yang et al. Learning Interactive Real-World Simulators (UniSim), ICLR 2024; A. Hu et al. GAIA-1: A Generative World Model for Autonomous Driving, 2023; Covariant, RFM-1 (2024); A. Gupta et al. MaskViT: Masked Visual Pre-Training for Video Prediction, ICLR 2023; Y. Du et al. Learning Universal Policies via Text-Guided Video Generation (UniPi), NeurIPS 2023; A. Escontrela et al. Video Prediction Models as Rewards for Reinforcement Learning (VIPER), NeurIPS 2023.
  • L. Zhang, A. Rao, M. Agrawala. Adding Conditional Control to Text-to-Image Diffusion Models (ControlNet), ICCV 2023; M. Zhao et al. ControlVideo, 2023; C. Meng et al. SDEdit, ICLR 2022; E. Molad et al. Dreamix: Video Diffusion Models are General Video Editors, 2023.

Added by these notes

  • H. Chang et al. MaskGIT: Masked Generative Image Transformer, CVPR 2022 — the sampler of §4.
  • A. Arnab et al. ViViT: A Video Vision Transformer, ICCV 2021 — factorized space-time attention.
  • L. Rabiner. A Tutorial on Hidden Markov Models, Proc. IEEE 1989 — the forward algorithm and posterior sampling used for the exact numbers.
  • S. Bengio et al. Scheduled Sampling for Sequence Prediction with Recurrent Neural Networks, NeurIPS 2015 — training on one’s own predictions, the other remedy for rollout drift.

11. Next lecture

Lecture 18 changes the question: instead of generating data, use unlabeled data to help a classifier that has only a few labels — semi-supervised learning. When can unlabeled data help at all (the cluster assumption), what do entropy minimization, pseudo-labels and consistency regularization do, and how much of the reported gains survive a realistic evaluation?

← 返回课程目录