1# x0: [B, C, H, W] real image in [-1,1] or [0,1]2t = sample_uniform_t(batch_size)3alpha_t = get_alpha(t) # precomputed schedule4eps = torch.randn_like(x0) # Gaussian noise5
6# forward noising7xt = (alpha_t.sqrt() * x0 +8 (1 - alpha_t).sqrt() * eps)9
10pred_eps = model(xt, t) # predict noise11
12loss = ((pred_eps - eps)**2).mean()1# x0: [B, C, H, W]2t = sample_uniform_t(batch_size)3x1 = torch.randn_like(x0) # Gaussian prior4
5# forward interpolation6xt = (1 - t) * x0 + t * x17
8# true velocity9v_true = x1 - x010
11pred_v = model(xt, t) # predict velocity12
13loss = ((pred_v - v_true)**2).mean()