MCPcopy Index your code
hub / github.com/CompVis/diff2flow / validation_losses

Method validation_losses

diff2flow/flow.py:613–632  ·  view source on GitHub ↗

SD3 & Meta Movie Gen show that val loss correlates well with human quality. They compute the loss in equidistant segments in (0, 1) to reduce variance and average them afterwards. Default number of segments: 8 (Esser et al., page 21, ICML 2024).

(self, x1: Tensor, x0: Tensor = None, num_segments: int = 8, **cond_kwargs)

Source from the content-addressed store, hash-verified

611 return (vt - ut).square()
612
613 def validation_losses(self, x1: Tensor, x0: Tensor = None, num_segments: int = 8, **cond_kwargs):
614 """
615 SD3 & Meta Movie Gen show that val loss correlates well with human quality. They
616 compute the loss in equidistant segments in (0, 1) to reduce variance and average
617 them afterwards. Default number of segments: 8 (Esser et al., page 21, ICML 2024).
618 """
619 if x0 is None: x0 = torch.randn_like(x1)
620
621 assert num_segments > 0, "Number of segments must be greater than 0"
622 ts = torch.linspace(0, 1, num_segments+1)[:-1] + 1/(2*num_segments)
623 losses_per_segment = []
624 for t in ts:
625 t = torch.ones(x1.shape[0], device=x1.device) * t
626 xt = self.compute_xt(x0=x0, x1=x1, t=t)
627 ut = self.compute_ut(x0=x0, x1=x1, t=t)
628 vt = self.forward(x=xt, t=t, **cond_kwargs)
629 losses_per_segment.append((vt - ut).square().mean())
630
631 losses_per_segment = torch.stack(losses_per_segment)
632 return losses_per_segment.mean(), losses_per_segment

Callers

nothing calls this directly

Calls 3

compute_xtMethod · 0.95
compute_utMethod · 0.95
forwardMethod · 0.95

Tested by

no test coverage detected