Implement a frame-aware corruption function for drift simulation in video diffusion models. Given a batch of video frames, add noise that increases over the temporal dimension to simulate temporal drift. The noise level for each frame should follow a specified schedule.
import random, math
def frame_aware_corrupt(
frames: list[list[float]], noise_schedule: list[float], seed: int = 42
) -> list[list[float]]:
rng = random.Random(seed)
T = len(frames)
corrupted = [row[:] for row in frames]
for t in range(T):
nl = noise_schedule[t]
scale = math.sqrt(1 - nl ** 2)
corrupted[t] = [scale * v + nl * rng.gauss(0, 1) for v in frames[t]]
return corruptedt gets a noise level sigma_t from the schedule. Later frames typically get higher noise to simulate accumulated drift.x_corrupted = sqrt(1 - sigma^2) * x_clean + sigma * noise, which preserves the signal variance.sigma values across the temporal axis, we simulate the model's decreasing certainty about frames further from the conditioning anchor.