One 5-second clip from a video diffusion model takes about 30 minutes on one GPU. Sparse attention, 4-bit math and few-step sampling stack, and together the lecture reports 112 times faster.
Learn where a video model spends its compute. Then remove most of it: skip attention pairs, multiply in 4 bits, and sample in a few steps.
Switch the three savings on, one at a time. Watch which part of the bar shrinks, and see that each one only pays once the others have run. Then we build each saving, piece by piece.
You need a little Python and what a probability is. It helps to know Part I, but each idea we need gets one line of recall.
Based on Lecture 18 of MIT 6.5940: TinyML and Efficient Deep Learning Computing (Fall 2026), taught by Song Han and the MIT HAN Lab. Lecture 18 slides. Every idea is re-taught here in our own words and devices. It follows Lecture 17, Diffusion Models I and leads into Distributed Training.
Per-pass numbers are the lecture's count for Wan2.2 at 72K tokens, in BF16-equivalent petaFLOPs (slide 59). Dense: attention 9.75, linear layers 2.24, other 0.066. Sparse attention brings attention to 1.14; DeltaQuant brings the linear layers to 0.59. The 50-step baseline is illustrative; 4 steps matches AnyFlow's 4-step setting. Compute is not wall-clock time: the measured end-to-end speedup with all three is 112 times (slide 65).
Chapter 0
Count the tokens in a short clip, and see why the cost grows with the square of that count
You type "a golden retriever runs in circles on a lawn" and press generate. A good open video model returns 5 seconds of video. On one GPU, it takes about half an hour. Where does the time go?
Recall from Part I: a diffusion model starts from pure noise and removes a little noise in each denoising step. Each step runs one transformer over latent tokens, small patches that an autoencoder made from the video. A video model's transformer uses 3D full attention: every token looks at every other token, across space and time.
Call the number of latent frames f, the tokens in each frame s, and the text prompt tokens t. The sequence length L counts them all.
L equals f times s, plus t.
Multiply the frames f by the tokens per frame s. Add the prompt tokens t.
With illustrative 720p numbers: f = 33, s = 3,600, t = 256 gives L = 119,056. Attention compares L × L, about 1.4 × 1010 pairs, in every head of every layer of every step.
Pick a resolution and drag the frames. The marker shows your sequence length. The bars are the measured runtime split at three lengths.
The bars are the lecture's HunyuanVideo profile (slide 4). Attention takes 51%, 73% and 82% of the runtime at 17k, 45k and 120k tokens. Linear layers take 22%, 12% and 12%. Tokens per frame are illustrative.
Attention costs about L2 × d work, where d is the width of each token's vector. Linear layers cost about L × d2. So once L passes d by far, attention wins. State-of-the-art video models pass 70,000 tokens for only 5 seconds of video. Attention bounds both training and inference.
The symptom: double the clip length and the generation time grows about four times. The measurement: profile one step and read each operator's share of time. The fix: compute only the attention pairs that matter. Chapters 1 to 4 build that fix.
Chapter 1
See that each attention head looks either inside one frame or along one position, and keep only those pairs
Plot an attention map from HunyuanVideo or Wan 2.1: queries down, keys across, bright where a query attends. The lecture names three patterns. The map breaks into blocks, one per frame pair. Nearby frames get more attention. Inside a frame block, nearby tokens get more attention.
Sparse VideoGen (SVG, ICML 2025) sorts attention heads (the parallel attention units in a layer) into two kinds. A spatial head attends within the same frame. A temporal head attends across frames, at the same position. Neither needs the full map.
Each frame has 4 tokens. The head computes the blue cells; outlines mark frames. Choose a head type, then add frames and watch the density.
A toy with s = 4 tokens per frame. Real masks also keep the text tokens and some neighbours, so SVG runs at about 30% density (slide 11).
How much of the map does a spatial head keep? It keeps f blocks of s by s cells, out of an (f · s) by (f · s) map.
Density equals f times s squared, over f s, all squared, which is one over f.
Count the kept blocks, f of them, each s by s. Divide by the whole map. The s cancels, so density is one over f. A temporal head keeps one over s the same way.
With f = 33: a spatial head keeps 1/33, about 3% of the map. With s = 3,600: a temporal head keeps 1/3,600, under 0.03%.
The split between head types shifts with the model, the prompt and the denoising step. In CogVideoX and HunyuanVideo, the lecture shows about 34% to 53% of heads spatial. So SVG decides at run time. For each head it samples 1% of the queries and runs both masks and full attention on them. It keeps the mask with the lower mean squared error. That online profiling costs about 3%.
The failure: give a temporal head a spatial mask and it loses the frame-to-frame link, so motion flickers. Measure the error of each mask against full attention on the sampled queries. Fix: pick per head, per step.
Chapter 2
Move the tokens of a temporal head next to each other in memory, then multiply the speedups of each step
Skipping 70% of the cells does not make attention 70% faster by itself. A GPU reads memory in tiles: fixed runs of neighbouring numbers. If the numbers you need lie far apart, the GPU reads whole tiles to get a few of them.
The tokens sit in frame-major order: all of frame 1, then all of frame 2. A spatial head needs one frame, so it reads neighbours. A temporal head needs the same position in every frame. Those tokens sit s apart: strided.
Sixteen tokens, 4 frames of 4, in memory tiles of 4. Purple marks the tokens one temporal head needs. Switch the order.
A toy with 4-number tiles. The transpose only reorders memory, so the attention output is the same (slide 13).
SVG's layout transform transposes the tokens to token-major order for temporal heads, so each group becomes one dense block. The math stays the same, so quality stays the same. On the lecture's chart it runs 1.7 times faster than naive sparse attention and tracks the theoretical speed.
SVG then adds three changes, and the speedups multiply. Call them S1, S2 and S3.
S equals S-one times S-two times S-three.
Each change divides what is left of the time. So multiply S-one, S-two and S-three to get S.
S = 1.06 × 1.81 × 1.21 = 2.32, the slide's 2.33. On HunyuanVideo the run falls from about 2,240 s to about 960 s.
Results: 2.28 times faster on CogVideoX and 2.33 times on HunyuanVideo, with PSNR held at 28 to 30 and no fine-tuning of the base model.
The failure: a sparse kernel that skips cells but reads strided memory. Measure latency against the theoretical time for that density. Fix: reorder so each kept group is contiguous.
Chapter 3
Cluster the queries and keys, move each cluster into one block, and compute only the blocks that matter
Two tokens that show the dog's ear attend to each other, even when they sit far apart in the frame. Sparse VideoGen2 (SVG2, NeurIPS 2025) starts from that: which pairs matter depends on meaning, not position. On its profile, 3D attention takes over 80% of the runtime, and keeping 13% of it recovers 95% of the attention.
Call a cell critical if it carries a large attention weight. Block-sparse kernels compute whole blocks of neighbouring cells. If critical cells lie far apart, every block holds a few of them, so the kernel either misses them or computes mostly waste.
Blue cells are critical. The kernel computes the yellow blocks, densest first. Change the order, then the budget.
A toy: 16 tokens in 4 clusters, critical where a query cluster attends a key cluster. The slide's real map: position blocks give 70.5% recall at 68% budget; permuted blocks give 90% at 28% (slide 20).
SVG2 runs k-means on the queries and on the keys, which groups similar tokens. Then it permutes each cluster into a contiguous block. The output is the same, because attention does not care about order once you undo the permutation. A top-p rule estimates each block's score from the cluster centroids, at under 1% overhead. It keeps blocks until their share of the score reaches p.
How much of the computed work is useful? Name three shares. The recall R is the share of critical cells you computed. The budget B is the share of all cells you computed. And c is the share of all cells that are critical.
E equals R times c, over B.
R times c is the share of the whole map that is critical and computed. Divide by B, the share computed, to get E.
The slide's map has c of about 0.27. Position blocks: E = 0.705 × 0.27 / 0.68 = 0.28, the slide's 27.9%. Permuted: E = 0.90 × 0.27 / 0.28 = 0.87, the slide's 86.6%.
K-means on every step would be slow. A centroid cache reuses the last step's centroids, which makes k-means 76 times faster. Results: HunyuanVideo 30 to 13 minutes (2.30 times, PSNR 30.5); Wan 2.1 30 to 16 minutes (1.89 times, PSNR 25.8).
The failure: a high budget with low recall, the slide's 68% for 70.5%. Measure E. Fix: permute before you pick blocks.
Chapter 4
Halve the density each time the frame distance doubles, and the cost grows as L log L, not L squared
SVG and SVG2 decide masks at run time. Radial Attention (NeurIPS 2025) asks a different question: is there one fixed mask that works for every head? The lecture shows that attention scores decay with temporal distance (frames apart) and with spatial distance (tokens apart in a frame). Both fall like an energy decay.
So Radial Attention splits the map into bands of diagonals. The central band, near frames, has full density. Each band outward has twice the area and half the density. Inside a frame block, it keeps only the central diagonals, and their width shrinks with distance. The mask is static: no profiling.
Left: the frame-level mask, darker where density is higher. Right: compute against frames, dense against radial. Drag the frames.
Computed here: frame distance d sits in band b at density 2−b. Band b is 0 for d = 0, else floor(log2 d) + 1. The band rule and the band count are the lecture's (slides 30 to 32).
Bands equals two times the ceiling of log base two of f, minus one.
Count the doublings from 1 to f. There is one band per doubling on each side, plus one shared centre. Each band does about L work, so the total is about L times log L.
With f = 32: log2 32 = 5, so bands = 2 × 5 − 1 = 9. Computed exactly, the mask keeps 14% of the dense map.
At the default length it needs no training. On HunyuanVideo, compute falls from 612 to 339 TFLOPs and latency from 1,649 s to 876 s, at PSNR 25.5. The mask is also trainable. A LoRA (a small add-on of low-rank weights) adapts the model to 4 times longer videos in about 20 hours on one H100 node. Against a dense LoRA, training drops from 746 to 171 GPU hours. Latency drops from 2,895 s to 781 s, at Vision Reward 0.134.
The failure: a fixed mask can drop a long-range pair a prompt needs. Measure quality against dense attention per prompt. Fix: the mask keeps an attention sink column, and a short LoRA run adapts the model to the mask.
Chapter 5
Read a roofline, see that a diffusion layer is compute bound, and meet the outliers that break 4-bit activations
Attention is now cheaper. The linear layers are next, and the tool is quantization: storing numbers in fewer bits (see Quantization I). W4A16 means 4-bit weights with 16-bit activations. W4A4 means both in 4 bits.
For a language model generating one token at a time, W4A16 helps a lot: the chip waits on memory, and smaller weights arrive faster. Does the same trick speed up a diffusion model?
A roofline answers it. Call the computation intensity I: the multiply-adds (MACs) done per number loaded from memory. Call the memory speed B, in numbers per second, and the chip's top speed Ppeak.
P equals the minimum of P-peak and I times B.
If I times B is below P-peak, memory limits you. Otherwise the arithmetic units limit you, and only a faster format helps.
On an NVIDIA B200, P-peak is 2.25 PetaMACs for FP16, 4.5 for FP8 or INT8, and 9 for FP4. A layer with 4,096 tokens reuses each weight about 4,096 times, so I is about 4,096: past every ridge. P = P-peak.
Each line is one weights-by-activations format. Pick one, then drag the intensity toward a diffusion layer's.
Peaks are the lecture's B200 table (slide 40). The ridge points, about 600 MACs per number and about 150 for INT4 × FP16, are read off the slide's chart.
INT4 × FP16 still multiplies in FP16, so its ceiling stays at 2.25. The lecture's verdict: diffusion models are compute bound even at batch size one, and weight-only quantization cannot speed them up. Only W4A4 reaches the 4-bit ceiling, 4 times FP16.
The failure is quality. Naive W4A4 on PixArt-Σ drops Image Reward from 0.931 to −1.12. The cause is outliers: a few channels with values far larger than the rest. One 4-bit scale must cover the outlier, so the small values get few effective levels.
Measure each channel's maximum. Smoothing raises the score to 0.508. Chapter 6 closes the gap.
Chapter 6
Push the activation outliers into the weights, then peel the weight outliers off into a small 16-bit branch
Both sides of a layer have outliers, so both resist 4 bits. SVDQuant (ICLR 2025 Highlight) fixes them in two moves.
Move 1: smoothing. Divide each activation channel by a factor λ and multiply the matching weight row by the same λ. The product stays the same. Write the smoothed sides as X̂ and Ŵ. The activations become easy to quantize, and the weights get the outliers: easy activations, harder weights.
Move 2: a low-rank branch. The singular value decomposition (SVD) finds the few directions that hold most of a matrix. Take the top r of them as two thin 16-bit matrices L1 and L2. Their product holds the outliers, and the residual Ŵ − L1L2 is small and flat.
X-hat W-hat equals X-hat L-one L-two, plus X-hat times W-hat minus L-one L-two.
Split W-hat into the low-rank part L-one L-two and the residual. Run X-hat through both and add. Only the residual branch goes to 4 bits.
Take an illustrative 3,072 by 3,072 layer and rank r = 32. The branch has 2 × 3,072 × 32 = 196,608 numbers, 2% of the layer. In 16 bits that is 393 KB beside a 4.7 MB 4-bit residual.
Three 8 by 8 maps: the smoothed weight, the 16-bit branch, the residual that goes to 4 bits. Raise the rank and watch the residual flatten.
A toy 8 by 8 weight with two outlier rows, decomposed live by power iteration and quantized to 4 bits with one scale. The paper uses rank 32 on real layers (slide 50).
Run naively, the extra branch reads the input and writes the output again, and that memory traffic is slow. The Nunchaku engine fuses kernels that share data. The down projection and the quantize step share the input. The up projection and the 4-bit multiply share the output. One layer drops from 461 µs to 322 µs, 1.43 times.
Results on FLUX.1-dev: memory falls from 22.7 GiB to 6.5 GiB and latency from 111.7 s to 12.9 s, 8.7 times. LPIPS (lower is closer to the 16-bit image) is 0.223, better than NF4's 0.272 and naive INT4's 0.322. On a laptop RTX 4090, one step runs 10.1 times faster, and the 12B model fits in 16 GB with no CPU offloading.
The failure: smoothing alone, which leaves the weight outliers. Measure the residual's maximum value. Fix: raise the rank until it stops falling.
Chapter 7
Neighbouring video tokens look alike, so keep their mean in high precision and the small differences in 4 bits
Count Wan2.2's compute at 72K tokens in BF16-equivalent FLOPs. Attention takes 9.75 PF (80.9%) and linear layers 2.24 PF. Add Radial Attention and SageAttention (quantized attention) and attention falls to 1.14 PF, 3.51 times less. Now the linear layers hold 65% of the work. The bottleneck moved.
Smoothing has a weakness in video diffusion. The outlier channels and their sizes change across denoising timesteps, but you can use only one fixed smoothing scale. A scale tuned for step 0 leaves step 20 hard to quantize.
DeltaQuant (CVPR 2026) applies SVDQuant's idea to activations. Neighbouring tokens in space and time look alike, so it groups them into small tiles. Call one token x and its tile's mean x̄.
x is about Q-high of x-bar, plus Q-low of x minus x-bar.
Average the tokens of a tile to get x-bar and keep it precise. Subtract x-bar from each token x. The differences are small, so 4 bits cover them well.
The slide's first tile has tokens (−9.5, 4.8, 18.8), (−10.0, 5.5, 20.6) and (−10.5, 4.7, 20.6). The mean is (−10.0, 5.0, 20.0). The first delta is (0.5, −0.2, −1.2): its largest value is 1.2, not 18.8.
Two tiles of three tokens, three channels each. Cells redden with error. Switch the method, then lower the bits.
The token values are the slide's (slide 63); we recompute the deltas from them. Each token gets one symmetric scale across its channels. The mean stays exact here.
With DeltaQuant the linear layers fall to 0.59 PF: 6.70 times less compute than BF16 overall. On Wan2.2, model size falls 2.9 times (26.6 to 9.2 GiB) and memory 2.3 times. Radial plus Sage attention alone reaches 1.5 times; DeltaQuant pushes one step to 4.6 times at 720p and 7.2 times at 480p. With few-step distillation and efficient attention, the lecture reports 112 times end to end.
The failure: tiles that mix unlike tokens, such as an edge and the sky, so deltas stay large. Measure the delta range per tile. Fix: tile by spatial and temporal neighbours.
Chapter 8
Subtract each cluster's centroid from the cached keys, then quantize the residual in stages
Some video models make a clip chunk by chunk, each chunk attending to the ones before. This is autoregressive generation. To avoid recomputing the past, the model stores the past tokens' keys and values: the KV cache. For a long video the cache, not the weights, fills the GPU.
Quant VideoGen (ICML 2026) stores that cache in 2 bits. The raw cache resists it. Keys reach about 102 in a few outlier channels, and one shared scale wastes precision. Naive INT2 (KIVI) collapses to PSNR 21.6.
The pipeline needs no training and no calibration data:
x is about c plus q-one plus q-two, and so on.
Start from the centroid c. Add q-one to fix most of the gap. Add q-two to fix what q-one missed. Stop when the error is small enough.
On the lecture's chart, the first stage cuts the error 5.83 times. On LongCat-Video, the cache falls from 34 GB to 5 GB, 6.8 times, at PSNR 28.7 against KIVI's 21.6.
Left: 24 cached keys by 8 channels, the input to stage 1. Right: error per stage, log scale. Switch the method, then add stages.
A toy cache: 3 groups of keys with one outlier channel near 60 to 110, k-means and 2-bit min-max quantization run live. Real results are the slide's (slides 70 to 72).
The smoothing cuts key-cache error 6.93 times at INT2 and 7.08 times at INT4, value-cache error about 2.6 times, at under 4% latency. Centroids carry over from step to step. HY-WorldPlay's cache falls from 21 GB to 4 GB, and an 8B model runs on one RTX 4090.
The failure: one scale for the whole cache, set by the outlier channel. Measure the reconstruction error per channel. Fix: subtract centroids, then add stages until the error flattens.
Chapter 9
Teach a student to jump between any two noise levels, so it is fast with 4 steps and better with 32
Every saving so far makes one denoising pass cheaper. Distillation cuts the number of passes: a teacher model that needs many steps trains a student that needs few (see Knowledge Distillation). We count steps as NFE, the number of network calls.
Recall that sampling follows a path from noise at time T to data at time 0. A network gives the velocity v: which way, and how fast, z should move at time t (see Flow Matching). The teacher takes small Euler steps of size Δ along it.
z at t minus delta equals z-t minus delta times v of z-t and t.
Ask the network for the velocity v at z-t. Move z-t against it by delta. Repeat until time 0.
In the toy below at t = 1, the velocity is v = z. One step with delta = 1 gives z − z = 0 for every sample: the average of the two data points, not either one.
The path curves, so big Euler steps cut corners. A flow map learns the whole jump from time t to any earlier time r. It predicts u, the average velocity over that stretch, and moves zt by (t − r) times u. A consistency model always jumps to time 0 and adds fresh noise to continue. A flow map moves to the next time directly.
Time runs from noise (left) to data (right); the data sit at −1 and +1. Faint lines are the true paths. Pick a sampler, then change the steps.
A toy: 1-D data at −1 and +1, with the exact velocity for a straight noise-to-data path. The student is an ideal flow map, the teacher's path integrated finely; a learned student has errors.
AnyFlow trains in two stages. Stage 1 uses a MeanFlow objective to teach a LoRA student the flow map on teacher data. Stage 2 is on-policy: the student samples its own rollouts, and a distribution-matching loss (DMD) compares them with the teacher's. That fixes errors the student makes on its own samples.
The lecture's chart shows the payoff. Consistency students peak early: Self-Forcing scores about 83.4 on VBench at 4 steps and about 82.3 at 32. AnyFlow keeps rising. AnyFlow-FAR scores 84.05 at 4 NFE and 84.41 at 32, above Krea-Realtime-14B's 83.25. It works for causal and bidirectional models, from 1.3B to 14B parameters.
The failure: a student that gets worse with more steps. Measure quality at 2, 4, 8, 16 and 32 NFE. Fix: learn transitions between times, not only endpoints.
Chapter 10
Keep the numbers, the terms, the checklist and the core code in one place
The lecture's summary has two halves. Part I covered the basics (denoising, conditional and latent diffusion) and efficient architectures (the deep compression autoencoder and hybrid linear attention). This part covered long context and inference: sparsity, quantization and distillation.
| What | Value | Where |
|---|---|---|
| Attention share of runtime | 51%, 73%, 82% at 17k, 45k, 120k tokens | Chapter 0, slide 4 |
| SVG profiling | 1% of queries, about 3% overhead, lossless at about 30% density | Chapter 1, slides 11 to 12 |
| SVG speedup | 1.06 × 1.81 × 1.21 = 2.33 on HunyuanVideo; 2.28 on CogVideoX | Chapter 2, slides 14 to 15 |
| SVG2 effective compute | 27.9% by position, 86.6% permuted | Chapter 3, slide 20 |
| SVG2 speedup | HunyuanVideo 30 to 13 min (2.30 times), Wan 2.1 30 to 16 min | Chapter 3, slide 25 |
| Radial bands and cost | 2⌈log2 f⌉ − 1 bands, O(L log L) | Chapter 4, slide 32 |
| Radial, 4 times longer video | 746 to 171 GPU hours, 2,895 s to 781 s | Chapter 4, slide 36 |
| B200 peaks | FP16 2.25, FP8 or INT8 4.5, FP4 9 PetaMACs | Chapter 5, slide 40 |
| SVDQuant on FLUX.1-dev | 22.7 to 6.5 GiB, 111.7 s to 12.9 s, LPIPS 0.223 | Chapter 6, slide 53 |
| Nunchaku fused kernels | 461 µs to 322 µs, 1.43 times | Chapter 6, slide 52 |
| DeltaQuant on Wan2.2 | linear 2.24 to 0.59 PF; 4.6 times at 720p, 7.2 at 480p; 112 times with all three | Chapter 7, slides 59 and 65 |
| Quant VideoGen | 34 GB to 5 GB, PSNR 28.7 against 21.6 | Chapter 8, slide 71 |
| AnyFlow-FAR | 84.05 at 4 NFE, 84.41 at 32 NFE | Chapter 9, slide 81 |
| Term | Meaning |
|---|---|
| Spatial, temporal head | A head that attends within one frame, or along one position across frames. |
| Layout transform | A transpose that makes the tokens a head needs contiguous. |
| Semantic permutation | Reorder tokens by cluster so critical cells form dense blocks. |
| Radial mask | A fixed mask whose density halves as frame distance doubles. |
| W4A4 | 4-bit weights and 4-bit activations, so the multiply runs in 4 bits. |
| Low-rank branch | Two thin 16-bit matrices that carry a layer's weight outliers. |
| Delta token | A token minus its tile's mean. |
| Flow map | A model that jumps from any time t to any earlier time r. |
pythonimport numpy as np def quant(x, bits): # symmetric, one scale per row qmax = 2**(bits - 1) - 1 s = np.abs(x).max(-1, keepdims=True) / qmax return np.clip(np.round(x / s), -qmax - 1, qmax) * s def svdquant_linear(X_hat, W_hat, r=32): # X_hat: [tokens, cin], W_hat: [cin, cout] U, S, Vt = np.linalg.svd(W_hat, full_matrices=False) L1, L2 = U[:, :r] * S[:r], Vt[:r] # 16-bit low-rank branch R = W_hat - L1 @ L2 # small residual return X_hat @ L1 @ L2 + quant(X_hat, 4) @ quant(R.T, 4).T def delta_quant(tiles, bits=4): # tiles: [n_tiles, tokens, channels] mean = tiles.mean(1, keepdims=True) # kept in high precision return mean + quant(tiles - mean, bits) def radial_density(f): # share of the dense map a radial mask keeps d = np.abs(np.arange(f)[:, None] - np.arange(f)[None, :]) band = np.where(d == 0, 0, np.floor(np.log2(np.maximum(d, 1))) + 1) return (2.0 ** -band).mean() # f = 32 gives 0.145
This lesson follows Lecture 18 of MIT 6.5940: TinyML and Efficient Deep Learning Computing (Fall 2026), taught by Song Han and the MIT HAN Lab. Read the lecture on the course site, which links the slides. The lecture presents Sparse VideoGen, Sparse VideoGen2, Radial Attention, SVDQuant, DeltaQuant, Quant VideoGen and AnyFlow. All explanations, devices and worked examples here are our own, except where we say a number is the slide's.
Now press Teach. Explain, from memory, how the cost moves from attention to the linear layers to the step count. Name the tool that removes each. Then go back to the three savings at the top and switch them on in a new order.