World Models & Video DiTs: 3D Causal VAEs, Spatiotemporal RoPE & Action-Conditioned Rollouts
When I tested Gemini Omni in Making a Still Bird Fly and derived continuous-time transport in Flow Matching & Diffusion Transformers (DiT), one engineering question loomed over everything: how do you scale a 2D image DiT to coherent 3D video – and then turn a passive video generator into an interactive, action-conditioned World Model? Three architectural pillars make it work: a 3D Causal VAE, Factorized 3D RoPE, and Diffusion Forcing (CogVideoX, Yang et al., 2024, arXiv:2408.06072).
1. The 3D Causal VAE & Spatiotemporal Compression
A 5-second 720p video at 24 FPS has $120 \times 720 \times 1280 \times 3 \approx 332\text{ million}$ pixel values. A 3D Causal VAE compresses this by $4\times$ temporally and $8\times 8$ spatially (a $256\times$ reduction) into a latent tube $\mathbf{z} \in \mathbb{R}^{C \times (1 + (T-1)/4) \times (H/8) \times (W/8)}$. Crucially, frame 0 is compressed independently as a standalone image while every subsequent temporal convolution uses causal (left-only) padding:
Notice two superpowers here: (1) Because frame 0 is encoded causally without future lookahead, the exact same VAE and DiT seamlessly train on mixed batches of still images ($T=1$) and videos ($T=49$). (2) Giving every frame $t$ its own independent noise level $\tau_t \in [0, 1]$ (Diffusion Forcing) lets the model keep clean past history frames at $\tau_{\lt t} \approx 0$ while denoising future frames $\tau_t \to 0$ conditioned on user actions $\mathbf{a}_t$ (keyboard/camera pose) – turning a video DiT into a real-time interactive World Model!
PyTorch Implementation: CausalConv3d & Factorized 3D RoPEPyTorch
import torch
import torch.nn as nn
import torch.nn.functional as F
class CausalConv3d(nn.Module):
"""Left-only temporal padding so frame t never leaks information from future frames t+1."""
def __init__(self, c_in: int, c_out: int, kt: int = 3, ks: int = 3, st: int = 1, ss: int = 1):
super().__init__()
self.pad_t = kt - 1
self.pad_s = ks // 2
self.conv = nn.Conv3d(c_in, c_out, (kt, ks, ks), stride=(st, ss, ss), padding=0)
def forward(self, x: torch.Tensor) -> torch.Tensor:
# x: [B, C, T, H, W] -> F.pad order is (W_l, W_r, H_l, H_r, T_l, T_r)
x = F.pad(x, (self.pad_s, self.pad_s, self.pad_s, self.pad_s, self.pad_t, 0), mode="replicate")
return self.conv(x)
def apply_3d_rope(q: torch.Tensor, freqs_t, freqs_h, freqs_w):
"""Factorized 3D RoPE: splits head_dim into (d_t, d_h, d_w) orthogonal rotary subspaces."""
dt, dh, dw = freqs_t.shape[-1] * 2, freqs_h.shape[-1] * 2, freqs_w.shape[-1] * 2
qt, qh, qw = q.split([dt, dh, dw], dim=-1)
def rot(x, f):
x1, x2 = x[..., 0::2], x[..., 1::2]
c, s = f.cos(), f.sin()
return torch.stack([x1 * c - x2 * s, x1 * s + x2 * c], dim=-1).flatten(-2)
return torch.cat([rot(qt, freqs_t), rot(qh, freqs_h), rot(qw, freqs_w)], dim=-1)
| Architecture | Attention Pattern | Rollout Horizon | Interactive Action Control |
|---|---|---|---|
| Bidirectional Video DiT (CogVideoX) | Full 3D spatiotemporal | Fixed clip (5–10 s) | Text/image prompt only |
| Diffusion Forcing World Model | Block-causal + per-frame $\tau_t$ | Open-ended streaming | Per-frame keyboard/camera $\mathbf{a}_t$ via AdaLN |