MCPcopy Create free account
hub / github.com/VisionXLab/OF-Diff / _prior_bpd

Method _prior_bpd

ldm/models/diffusion/ddpm.py:879–891  ·  view source on GitHub ↗

Get the prior KL term for the variational lower-bound, measured in bits-per-dim. This term can't be optimized, as it only depends on the encoder. :param x_start: the [N x C x ...] tensor of inputs. :return: a batch of [N] KL values (in bits), one per batch el

(self, x_start)

Source from the content-addressed store, hash-verified

877 extract_into_tensor(self.sqrt_recipm1_alphas_cumprod, t, x_t.shape)
878
879 def _prior_bpd(self, x_start):
880 """
881 Get the prior KL term for the variational lower-bound, measured in
882 bits-per-dim.
883 This term can't be optimized, as it only depends on the encoder.
884 :param x_start: the [N x C x ...] tensor of inputs.
885 :return: a batch of [N] KL values (in bits), one per batch element.
886 """
887 batch_size = x_start.shape[0]
888 t = torch.tensor([self.num_timesteps - 1] * batch_size, device=x_start.device)
889 qt_mean, _, qt_log_variance = self.q_mean_variance(x_start, t)
890 kl_prior = normal_kl(mean1=qt_mean, logvar1=qt_log_variance, mean2=0.0, logvar2=0.0)
891 return mean_flat(kl_prior) / np.log(2.0)
892
893 def p_losses(self, x_start, cond, t, noise=None):
894 noise = default(noise, lambda: torch.randn_like(x_start))

Callers

nothing calls this directly

Calls 3

normal_klFunction · 0.90
mean_flatFunction · 0.90
q_mean_varianceMethod · 0.80

Tested by

no test coverage detected