Book Deep-Read · Generative AI System Design Interview · Chapter 11
Generative AI System Design Interview · Ch 11 · Ali Aminian, Hao Sheng & Alex Xu · 2024
You have probably seen AI draw a picture: type a sentence, wait a few seconds, get an image. This chapter asks the next question — type a sentence, get a moving video. That sounds like "just draw more pictures," but the whole chapter is about one thing: the gap in between is not a difference of quantity. It is a new problem.
Feed "a ginger cat jumps onto a sofa" to an image model one hundred and twenty times, take the hundred and twenty pictures, and play them in order. You get a twitching clip: the cat gets fatter and thinner, the sofa pattern changes every frame, and halfway through the jump it has become a different cat. Each picture is fine on its own. Together they are unwatchable.
Because an image model has no memory. Every time, it starts from a fresh blob of random noise and paints again, with no idea what the previous picture contained. But a video is precisely "photographs with a memory": viewers will forgive slightly worse image quality, yet they spot "that is not the same cat" instantly. Human eyes are far fussier about breaks in time than about sharpness.
Build "time" into the model itself, instead of patching it afterwards. Two intuitions:
First, let the model glance sideways. On top of letting every patch of the picture consult the other patches (that governs composition), let the same spot in the previous and next frames consult each other (that governs motion). Whatever the cat's ear looked like this frame, next frame has to take a look before putting down the brush.
Second, sketch, then fill in, then enlarge. Like making an animated film: draw a handful of key poses first, then fill in the in-between frames, then colour and scale everything up at the end. The hardest step happens only once, on the smallest and roughest sheet of paper; the two steps after it are far cheaper.
That is why today's products all look alike: you type a sentence, wait tens of seconds or even minutes (not seconds), and get back a fixed-length clip of four to eight seconds. Want it longer? Take the last few frames as a new beginning and keep writing. The cost is concrete too: the further you extend, the more it drifts — by the third or fourth segment, that ginger cat may have quietly changed colour.
An image is judged on "does it look right"; a video is judged on "does the next frame still recognise the last one". The fix is to put time inside the model so the same spot consults itself across frames — and the exploding compute can only be spread out by working in stages: sketch, fill in, enlarge.
Want the mechanisms, notation and diagrams? → Switch to the deep read
Text-to-video is not text-to-image ×N. The chapter's core claim: temporal consistency has to be written into the model's structure as a first-class citizen, not patched on afterwards — and the moment you write it in, compute explodes along two axes at once, frame count and resolution. So the whole chapter has exactly two engineering threads: how to build time in, and how to spread the compute out. Nearly every architecture in video generation today is a compromise between those two.
This is the closing problem of Part II's ten interview questions in Generative AI System Design Interview, and the most compute-hungry of them. It stands directly on Chapter 8 (high-resolution image synthesis · latent diffusion) and Chapter 9 (text-to-image · cross-attention and classifier-free guidance): "how to paint one frame well and make it obey the prompt" is taken as given here, and the chapter adds exactly one new thing — time. In the real world it maps to Sora, Veo, Runway and friends, and to any generative backend where you submit a job, queue, and collect the output later.
Start with the scale. A 5-second clip at 24 fps is 120 frames. Generate it frame by frame the way Chapter 9 would, and — taking a single image on one A100 to be a few seconds — a hundred and twenty frames is minutes, at best. What you get for those minutes is unwatchable: each frame is solved afresh from independent random noise, so the content drifts semantically with nothing holding it down.
What happens if you don't solve it? Two bad things at once. One, the quality ceiling is nailed shut: people are far more sensitive to breaks in time than to per-frame sharpness — an extra finger in one frame may go unnoticed, but a sofa pattern that changes every frame is obvious to a child. Two, the cost ceiling is nailed shut: a video's pixel count is frames × height × width, so moving the same model onto video multiplies the compute, and nobody can pay that. The real problem of this chapter is therefore: buy temporal consistency out of an exploding compute budget.
One distinction has to be drawn first. Frame interpolation can only make already-consistent motion smoother; it assumes the two neighbouring frames were two instants of the same scene to begin with. The failure of independent per-frame generation is not "not smooth enough" — it is semantic drift: the cat in frame 40 and the cat in frame 41 are simply not the same cat, and an interpolated frame between them is just a smeared blend of two cats. The test is blunt: interpolation is a smoother. It fixes jitter; it cannot fix "the thing got swapped out".
So the conclusion is hard: time has to enter the generative process itself, not sit behind it.
The mainstream move is called inflation: take a trained text-to-image model (the latent U-Net or DiT of Chapters 8 and 9), leave every spatial layer untouched and insert new temporal layers into each block — convolution or attention running along the axis of "same spatial position, different frames." The payoff is direct: image quality and prompt adherence are inherited wholesale, the new parameters only have to learn "how things move," and the amount of paired text-video data you need drops sharply — which neatly patches the fact that video data is far scarcer than image-text data.
Why not just do full 3D attention? Cost. Say a clip is T latent frames of S tokens each. Flatten the whole thing into one attention pass and you compute (T·S)² pairs; split it into "spatial attention within a frame + temporal attention across frames" and you compute T·S² + S·T². Plug in realistic numbers — T=21, S=1024 — and the first is about 460 million pairs, the second about 22 million: a factor of 20. That factor of 20 is the entire reason most video models today are factorized.
The cost has to be stated honestly: factorizing means no token can see "another place and another moment" in a single step. Long-range space-time relationships are only built indirectly, by stacking layers. So factorized models break down first on big camera moves and objects streaking across the frame — exactly the cases that need position and moment to shift together. That is precisely what motivated the later route of cutting space and time into joint patches and running full attention over them, with Sora as its best-known example.
Chapter 8 already moved denoising into latent space — the picture is squeezed spatially by an autoencoder, denoised there, then decoded. Video has to squeeze one more axis: time. The typical device is a causal 3D autoencoder: 8×8 spatially, 4× temporally, which together take a clip down to roughly 1/256 of its size (channels aside). Without this step, neither cascades nor long context are on the table.
One detail worth remembering: the official CogVideoX repository hard-codes the generatable frame count as 8N+1 (the 5B model) or 16N+1 (the 1.5 model, default 81). That +1 is not padding — it falls out of a causal design in which the first frame is encoded on its own and the rest are compressed in fixed-size groups. The first frame has to be independently recoverable for the most common use of all to work: hand me one image, extend it into a clip. A constraint that looks arbitrary in the API is really the shape of the autoencoder showing through.
This is the engineering structure most worth taking away. Rather than running the whole denoising process at target resolution and target frame rate, split it into a relay:
Why it pays: compute scales roughly as frames × side². Run the expensive full denoising once on the canvas where both frame count and side length are smallest, and the two later stages — large in area though they are — can use shallower models and fewer sampling steps. Google's Imagen Video (2022) was exactly a base model feeding a chain of interleaved temporal and spatial super-resolution models; and Vertex AI shipping "upscale to 1080p / 4K" today as a capability decoupled from generation is the same structure projected onto the product surface.
The cost is equally clear: a cascade is a pipeline that accumulates error — whatever motion the base model gets wrong, the two later stages simply render more crisply. And several models means several trainings, several deployments and several monitoring stories, with end-to-end tuning all but impossible.
What comes out of the above is usually a few seconds. For more, the chapter's main road is autoregressive extension: take the last few frames of the generated segment as the condition for the next one. Stability AI's official repository states the scale plainly: Stable Video Diffusion was "trained to generate 14 frames," and SVD-XT is "finetuned for 25 frame generation" — fourteen to twenty-five frames, two or three seconds at ordinary frame rates. Everything longer is stitched.
The price of stitching is drift: each segment takes the previous one's output as input, error accumulates down the chain, and colour, lighting and character identity slide away. Extension is also inherently serial — more GPUs will not parallelise it. The mitigation is to re-inject the global conditioning at every segment (prompt embedding, first frame, reference image) so each one anchors back to the same source rather than to its predecessor.
The soul of this chapter is how you buy consistency with compute — three routes, none of them free.
Table 1 · Choosing among the three generation routes
| Route | Mechanism | When to pick it | Cost |
|---|---|---|---|
| Per-frame image model + interpolation | Denoise each frame independently, smooth the motion afterwards | Style transfer guided frame-by-frame by a source video, or near-static shots | Basically unusable for pure text-to-video — interpolation fixes jitter, never semantic drift |
| Native space-time model, one shot | Space-time tokens denoised together, full attention possible | Big camera moves, fast motion, shots needing long-range consistency | Context length ∝ frames × area, attention cost grows quadratically; costliest to train and to run |
| Cascade (base + temporal SR + spatial SR) | Skeleton at low res / low fps, then add frames and enlarge stage by stage | High-resolution output on a finite budget — the industry default | Error compounds per stage; several models to train, ship and monitor; end-to-end tuning is hard |
Table 2 · When you want a longer clip
| Strategy | Mechanism | Cost |
|---|---|---|
| Just extend the context | Denoise more frames in one pass | Attention cost grows with frames squared — memory gives out first; long clips are scarce in training data anyway |
| Autoregressive extension | Last few frames condition the next segment | Drift compounds; serial and unparallelisable, so latency grows linearly with length |
| Hierarchical: keyframes, then fill | Generate sparse keyframes across the whole span, then fill in each interval | Best global consistency, but the wide gaps between keyframes are the hardest motion to align — teleporting artifacts |
The choice compresses to one sentence: if your setting is "a few seconds, previewable, regenerable," a cascade plus fixed-length clips is almost always right; only when "one long take with a moving camera" is itself the selling point is it worth paying the full space-time attention bill. This is a different calculus from text-to-image, where the dominant variables are fidelity and prompt adherence. Here the dominant variable is how long consistency holds.
The product shape is basically dictated by compute. Video generation is almost always an asynchronous job — submit, queue, poll, collect. That is a different backend from text-to-image, where you wait synchronously for a few seconds: you need a job queue, preemptible GPU scheduling, recoverable job state, and a two-stage delivery of "low-resolution preview first, full render after the user confirms," because one regeneration costs GPU-minutes.
Cost is a design constraint, not an after-the-fact invoice. Per-second pricing is the norm externally; on the training side, the open-source Open-Sora project publishes the training cost of its 11B model as $200K. The value of that number is not that it is cheap — it is that "can we train this?" has become a budget question with an answer.
Safety and compliance bind harder than for images. Prompt-side filtering, output-side detection and provenance marking (watermark / C2PA) are all mandatory: a forgery that moves is far more convincing than a still, so likeness and copyright risk are not in the same league.
Generating is only the start. The finished clip still has to be transcoded into multiple bitrates and shipped over a CDN — no different from an ordinary video-on-demand system, and routinely missed in design answers.
16N + 1 where N <= 10 (default 81)," alongside "5 seconds or 10 seconds," "16 frames / second," "1360 * 768" — while the 5B model is 8N+1, "6 seconds," "720 * 480." That +1 in the API is the autoencoder's temporal compression showing through.THUDM · CogVideo repository (2024) · github.com/THUDM/CogVideo① The problem: text-to-video is not text-to-image ×N. Human eyes are far more sensitive to breaks in time than to per-frame sharpness, while compute grows as frames × side² — consistency and cost are both pinned at once.
② Core claim: temporal consistency must be written into the model's structure, not patched on. Interpolation is a smoother; it cannot fix semantic drift.
③ Mechanism one: inflate a text-to-image model into 3D — keep the spatial layers, insert temporal ones. Quality and prompt adherence are inherited, the new parameters only learn "how to move," and the video-data scarcity problem is sidestepped.
④ Why factorize: full 3D attention is (T·S)²; spatial + temporal is T·S² + S·T². At T=21, S=1024 that is about 20× apart. The cost is that long-range space-time links are only built indirectly, by stacking layers.
⑤ Mechanism two: the latent space compresses time as well (typically 8×8 spatially, 4× temporally); CogVideoX's 8N+1 / 16N+1 API constraint is that structure surfacing.
⑥ Mechanism three: the cascade — skeleton at low res / low fps, then temporal SR, then spatial SR. The hard step runs once on the smallest canvas; the cost is compounding error and several models to operate.
⑦ Long video: autoregressive extension is the main road, paying in drift and serialisation; mitigate by re-injecting global conditioning per segment rather than anchoring only to the previous one.
⑧ In production: async jobs, queues, preemptible GPU scheduling, and "low-res preview → final render" delivery; cost billed by the GPU-second; safety via input filtering, output detection and watermarking.
⑨ Evaluation: FVD is blind to temporal artifacts and CLIP score is blind to time altogether — automatic metrics are a sieve, and human review is still the judge.