Hello! Welcome back.
In our previous lesson, we explored an autoregressive approach to video generation where the model predicts the next frame conditioned on the final, clean output of the previous one. This was achieved by concatenating the frames along the channel axis. While effective, this method treats the previous frame as a static, external condition.
Today, we'll dive deeper and explore a more tightly integrated method for ensuring temporal consistency. Instead of just showing the model the final previous frame, we will propagate information through the latent space from one frame's generation process to the next. Your learning outcome for this lesson is to implement a consistency mechanism based on latent variable propagation between frames. We'll examine two distinct and powerful ways to achieve this, moving from conditioning on pixels to guiding the diffusion process itself.
From Pixel-Space to Latent-Space Conditioning
Last time, the core operation was essentially U-Net(concat(z_0^(n-1), z_t^n), t), where z_0^(n-1) is the final, fully denoised latent of the previous frame. This is a form of conditioning on a finished product.
Latent variable propagation (LVP) is about influencing the process of generation. The information from frame n-1 is used to structure the denoising steps of frame n. This creates a more fluid and deeply connected link between frames. The diagram below offers a high-level conceptual view of this feedback loop.

Let's now explore two concrete implementations of this concept.
Method 1: Previous Latent as a Noise Prior
Our first method comes from the paper "Glad: A Streaming Scene Generator," which proposes a frame-by-frame generation style with a dedicated Latent Variable Propagation (LVP) module.
The core idea is to treat the denoised latent features of the previous frame as the noise prior for the current frame. In a standard DDPM, the noise ε added to an image is sampled from a simple Gaussian distribution, N(0, I). In this LVP approach, the noise distribution is structured by the previous frame.
Glad: A Streaming Scene Generator for Autonomous Driving
The paper 'Glad: A Streaming Scene Generator for Autonomous Driving' provides a clear definition and mathematical formulation for this type of latent variable propagation. We'll focus on their LVP module.
Please read Section 3.1, 'Latent Variable Propagation'. Pay close attention to Equation (1) and the explanation that follows. This is the heart of the mechanism.
As you've read, the forward diffusion process for frame n is modified. Let's look at the key part of Equation (1):
In a standard DDPM, the covariance matrix of the noise is simply . Here, it is replaced with , where is the fully denoised latent of the previous frame. The function is a normalization layer (like LayerNorm) to make the latent's statistics similar to that of noise.
Intuition: The model is no longer predicting unstructured Gaussian noise. It's trained to predict noise that is correlated with the structure of the previous frame. This implicitly guides the current frame to be a plausible continuation of the last one.
Implementation for Training and Inference
This theoretical change has direct consequences for your implementation, particularly in how you handle data during training and how you structure the inference loop.
Glad: A Streaming Scene Generator for Autonomous Driving
Now, let's look at how the 'Glad' paper makes this practical for training and inference.
Please read Section 3.2 'Streaming Data Sampler' and Section 3.3 'Inference'. These sections describe the practical pipeline for implementing LVP.
From a practical engineering perspective, here's the breakdown:
-
Training (Streaming Data Sampler): To ensure consistency between training and inference, you can't just pick random pairs of frames. You need to process video clips sequentially.
- For a given video clip, start with frame 1. The "previous frame" can be pure Gaussian noise.
- Train the model on frame 1 to predict the target noise. The model outputs a denoised latent .
- Crucially, instead of discarding this, you use the ground-truth latent of frame 1, , as the noise prior for training on frame 2. You cache this latent.
- At iteration 2, you train on frame 2, using the cached to structure the noise as per Eq. (1). You then use the ground-truth as the prior for frame 3, and so on.
This "streaming" approach ensures the model is trained in the same autoregressive manner it will be used in for inference.
-
Inference: The inference loop directly mimics the training process.
- Generate frame
n-1and get its fully denoised latent . - To generate frame
n, instead of starting the reverse diffusion process from pure random noise , you initialize the process using as the noise prior. The paper states this as , meaning the starting "noise" for framenis simply the denoised latent from framen-1. - You then run the standard reverse diffusion process to generate .
- Repeat for the desired number of frames.
- Generate frame
This method provides a strong, direct link between frames by weaving the structure of one frame into the very noise distribution of the next.
Method 2: Consistent Context-Aware Inference
Our second method offers a different, equally powerful way to propagate latent information. It comes from the paper "ChronoDepth," which focuses on temporally consistent video depth estimation, but the mechanism is general-purpose.
The core idea is to use the previous frame's clean latent as a noiseless, fixed condition for a portion of the next generative clip, rather than using it to define the noise. This requires a unique training strategy to work.
Learning Temporally Consistent Video Depth from Video ...
Let's examine this alternative from the 'ChronoDepth' paper. It introduces a 'Consistent Context-Aware Strategy'.
Please read Section 3.2 'Consistent Context-Aware Strategy' and review 'Algorithm 3' for the inference pseudocode. This will explain both the special training requirement and the novel inference loop.
This strategy is clever and has two key parts: a training modification and a corresponding inference procedure.
-
Training Modification: The model must learn to denoise different frames that are at different noise levels within the same clip. Instead of sampling one noise level for the whole clip, you sample an independent noise level for each frame
iin the clip. The U-Net's conditioning input for noise now becomes a per-frame variable. This prepares the model for the unusual inputs it will see during inference. -
Inference (Sliding Window with Overlap):
- Generate the first clip (e.g., frames 0-15) using the standard denoising process, starting from pure noise.
- To generate the next clip, which overlaps with the first (e.g., frames 8-23, with an overlap of 8 frames), you do the following for each denoising step
t:- The overlapping part (frames 8-15): Initialize these frames with the final, clean latents from the previous generation. You do not add noise to them.
- The new part (frames 16-23): Initialize these with standard noisy latents .
- Concatenate and Denoise: The input to the U-Net at step
tis a concatenation of the clean past and the noisy future:concat(z_0^(8:15), z_t^(16:23)). - Noise Level Conditioning: The model is told the noise level for the first part is effectively zero (or a very small constant ) and the noise level for the second part is .
- The model's output is a denoised prediction for the entire clip, but you only use the new part () to update your latents for the next step. The clean part acts as a fixed anchor.
This method ensures the model's prediction for the new frames is perfectly consistent with the already-generated frames at every single step of the denoising process, virtually eliminating the flickering artifacts that can occur at clip boundaries.
Test your understanding!
You are implementing the forward pass for a U-Net using the ChronoDepth training strategy. The model receives a batch of noisy latents z_t of shape (B, F, C, H, W) and corresponding per-frame noise levels noise_levels of shape (B, F).
Assuming your model uses the preconditioning from the EDM paper (cin, cskip, cout, cnoise), how would you need to adapt these functions or their inputs to handle the per-frame noise levels? Write a short pseudocode snippet or describe the tensor manipulations required.
Show answer
The key is to broadcast the per-frame noise levels to match the dimensions of the latent tensor z_t before they are used by the preconditioning functions.
# z_t.shape: (B, F, C, H, W)
# noise_levels.shape: (B, F)
# The preconditioning functions (cskip, cout, cin, cnoise) expect
# a noise level for each element in the batch. Here, our "elements"
# are individual frames. We need to reshape the inputs to treat
# frames as batch items.
B, F, C, H, W = z_t.shape
# Reshape latents and noise levels so frames are in the batch dimension
z_t_reshaped = z_t.view(B * F, C, H, W)
noise_levels_reshaped = noise_levels.view(B * F)
# Now, the standard preconditioning functions will work correctly
# as they receive a batch of size B*F.
c_skip = cskip_function(noise_levels_reshaped) # Shape: (B*F, 1)
c_out = cout_function(noise_levels_reshaped) # Shape: (B*F, 1)
c_in = cin_function(noise_levels_reshaped) # Shape: (B*F, 1)
# These need to be broadcast to match the reshaped latent tensor.
# For example, when applying c_in:
model_input = c_in.view(B * F, 1, 1, 1) * z_t_reshaped
# The noise embedding for the U-Net itself would also use the reshaped levels.
# c_noise_embedding = cnoise_function(noise_levels_reshaped) # Shape: (B*F, D)
# After the U-Net forward pass, the output would be reshaped back to
# (B, F, C, H, W) if needed.
This reshaping allows you to reuse the standard preconditioning logic by temporarily treating each frame as a separate item in a larger batch.
Conclusion
In this lesson, we have moved beyond simple frame-concatenation and explored two sophisticated methods for latent variable propagation to ensure temporal consistency.
Key Takeaways:
- Latent Variable Propagation (LVP) creates a more deeply integrated temporal link than conditioning on the final output of the previous frame.
- The "Glad" LVP approach uses the previous denoised latent to create a structured noise prior, guiding the generation of the current frame. This is implemented with a sequential, "streaming" training and inference pipeline.
- The "ChronoDepth" Consistent Context-Aware approach uses the previous clean latents as a fixed, noiseless anchor in a sliding window. This requires a special training strategy where the model learns to handle per-frame noise levels.
- Both methods are powerful techniques for generating long, coherent videos by explicitly managing the flow of information between frames at the latent level.
Next Lesson Preview:
So far, our consistency mechanisms have been autoregressive, meaning each frame depends only on the one(s) that came before it. In the next lesson, we will explore a different paradigm: applying temporal attention for coherent video generation. This non-autoregressive approach allows every frame in a clip to attend to every other frame, enabling the model to capture complex, non-sequential relationships and generate all frames in parallel. This will be a key building block for more advanced video generation architectures.