Cheat sheets

Video and 3D Generation

Video DiT patches and divided attention, world models, Gaussian splats, NeRF and multi-view 3D. Formulas and fixes.

  • Concepts and terms
  • Tasks and commands
  • Annotated code
  • Diagrams
  • Comparisons
  • Defaults and numbers
  • Troubleshooting
  • Questions and tips

Source

Video diffusion pipeline#

latenttokenscross-attentioneach stepclientVideoT framesmodel3D VAEspatiotemporalcompressionprocessPatchifyt_p, h_p, w_ppatchesclientPromptdensere-captionsmodelText encoderT5-XXLgpuVideo DiT3D positions,dividedattentionstoreDenoisedlatentε or vpredictionclientFramesVAE decodelatenttokenscross-attentioneach stepclientVideoT framesmodel3D VAEspatiotemporalcompressionprocessPatchifyt_p, h_p, w_p patchesclientPromptdense re-captionsmodelText encoderT5-XXLgpuVideo DiT3D positions, dividedattentionstoreDenoised latentε or v predictionclientFramesVAE decode

From Lesson 08.10, Lesson 04.28

Render and fit Gaussian splats#

1Projectmap each 3D Gaussian to 2D with cameraextrinsics and intrinsics.2Tileassign each 2D Gaussian to 16x16 screen tiles.3Sortsort the Gaussians by depth in each tile.4Compositeblend front-to-back into the pixel colour.5Losscompare the render with the ground-truth photo.6Backpropupdate (mu, q, s, alpha, c_lm) by gradientdescent.7Densifyclone small Gaussians and split large ones wherethe gradient is high.8Pruneremove Gaussians with low opacity. Train for~30,000 iterations.

From Lesson 04.22

Formulas and numbers#

Covariance
\Sigma = R S S^T R^T from the quaternion and the scales.
Projection
\Sigma' = J W \Sigma W^T J^T, a 2 × 2 covariance.
Composite
C = \sum_i \alpha_i T_i c_i with T_i = \prod_{j < i} (1 - \alpha_j). NeRF uses the same equation.
SH colour
degree L gives (L+1)^2 terms per channel. Degree 3 gives 16 terms.
Gaussian size
about 60 floats. Five million Gaussians use 240 MB.
Video tokens
(T / P_t) \cdot (H / P_h) \cdot (W / P_w)
Divided attention
(HW) \cdot T^2 + T \cdot (HW)^2 instead of O((THW)^2).
Raw video
10 s of 1080p at 24 fps is 240 frames, about 1.5 GB.

From Lesson 04.22, Lesson 04.28, Lesson 08.10

Tiny video DiT#

vid = torch.randn(1, 4, 8, 16, 16)(N, C, T, H, W)
model = TinyVideoDiT(in_channels=4, dim=64, depth=2, heads=2)
out, grid = model(vid)grid (4, 8, 8), out (1, 256, 32)
tokens, grid = self.patch(x)Conv3d, stride equals kernel
xt = x.view(n, T, H * W, d).permute(0, 2, 1, 3).reshape(n * H * W, T, d)
a, _ = self.time_attn(self.ln1(xt), self.ln1(xt), self.ln1(xt), need_weights=False)
xs = xt.view(n, T, H * W, d).reshape(n * T, H * W, d)
a, _ = self.space_attn(self.ln2(xs), self.ln2(xs), self.ln2(xs), need_weights=False)
xs = xs + self.mlp(self.ln3(xs))MLP after time and space

From 04.28 code/main.py, Lesson 04.28

Fit 2D splats to an image#

model = Splats2D(num_splats=64, image_size=64)
opt = torch.optim.Adam(model.parameters(), lr=0.05)
for step in range(200):
pred = model((64, 64))rasterise_2d inside
loss = F.mse_loss(pred, target)
opt.zero_grad(); loss.backward(); opt.step()
alphas = alphas.clamp(0.0, 0.99)in rasterise_2d
order = torch.argsort(depths)learned depth scalar in 2D
out = out + (T * a)[..., None] * colours_sorted[i][None, None, :]
T = T * (1.0 - a)transmittance

From Lesson 04.22, 04.22 code/main.py

Functions in the lessons#

TaskCode
Count video tokenscount_tokens(T, H, W, p_t=2, p_h=8, p_w=8)
Add 3D positionsrope_3d(tokens, t_dim, h_dim, w_dim, grid)
Time then space blockDividedAttentionBlock(dim=64, heads=2)
Patch plus time embedpatchify_with_pos(noisy)
Measure flickerframe_deltas(clip)
Gaussian densityeval_2d_gaussian(means, covs, points)
Build covariancesR @ S @ R.transpose(-1, -2)
View-dependent coloureval_sh_degree_3(sh_coeffs, dirs)

From 04.28 code/main.py, Lesson 04.28, 04.22 code/main.py, 08.10 code/main.py

nerfstudio and export#

CommandWhat it does
pip install nerfstudio gsplatInstalls the trainer and the CUDA rasteriser
ns-download-data exampleDownloads the example data
ns-train splatfacto --data path/to/dataTrains 3DGS. 10-30 minutes on an RTX 4090
.plyRaw Gaussian cloud. Portable, largest file
.splatQuantised format
KHR_gaussian_splattingglTF standard, portable across viewers
UsdVolParticleField3DGaussianSplatOpenUSD 26.03 schema

From Lesson 04.22

3D representations side by side#

FactorNeRF3D Gaussian splatsTriplaneMesh
StoresMLP weightsexplicit Gaussiansthree 2-D feature gridssurface plus PBR material
Renderray integrationrasterise and alpha-compositeray-marching plus an MLPgame engine
Speed100-1000x slower than mesh~100 fps at 1080p on a 4090LRM gives one in ~5 sTripoSR gives one in ~1 s
Editretrainmove a subset of Gaussiansnot coveredremesh before shipping

From Lesson 08.12, Lesson 04.22

World model families#

FactorVideo generationAction-conditionedRL world model
Inputtext or image promptpast frames + actionstate + action
Outputvideo framesnext framesnext latent + reward
Steer mid-rolloutnoyes, latent actionsyes
ExampleSora 2Genie 3DreamerV3

From Lesson 04.28

Defaults in the code#

SettingDefaultNote
patch_t, patch_h, patch_w2VideoPatch3D halves T, H and W
dim64Token width
heads2Each attention in the block
p_h, p_w in count_tokens8p_t is 2
num_splats64Splats2D in the code file
Adam lr0.05The code file uses 0.08
Alpha clamp0.99Upper bound per Gaussian
Initial Gaussians~100kSeeded from SfM points

From 04.28 code/main.py, Lesson 04.22, 04.22 code/main.py

Troubleshooting#

SymptomCauseFix
Frames flickerEach frame sampled aloneCouple frames through attention or shared noise
Out of memoryFull 3D attentionFactorize into spatial and temporal
Clips over 10s driftErrors accumulateSliding windows and keyframe anchors
Objects vanish or mergeNo persistent object modelRun object permanence checks before shipping
Blurry 3D fitViews disagree on structureMulti-view diffusion with shared attention
10M splats, overfitNo densify and prune controlUse densification and pruning heuristics
Mesh has holesImplicit field topologyRun a remesher before shipping
ValueError in rope_3dt_dim+h_dim+w_dim is not DSplit D across the three axes

From Lesson 08.10, Lesson 08.12, 04.28 code/main.py, Lesson 04.28

Questions#

Why did 3DGS replace NeRF?
It renders at 100+ fps, trains in minutes and edits directly.
Why does 3DGS match NeRF quality?
Both integrate the same radiance-field equation.
What limits a video DiT at serve time?
Memory bandwidth, not FLOPs.
What improved Sora most?
About 10x more detailed captions.
How does the 2026 3D stack work?
Diffusion makes multi-view images. A 3D fit, often splats, follows.
How is video quality measured?
FVD for visuals, CLIPScore per frame for prompt alignment.

From Lesson 04.22, Lesson 08.10, Lesson 08.12, Lesson 04.28