MCPcopy Create free account
hub / github.com/openai/point-e / _vb_terms_bpd

Method _vb_terms_bpd

point_e/diffusion/gaussian_diffusion.py:725–760  ·  view source on GitHub ↗

Get a term for the variational lower-bound. The resulting units are bits (rather than nats, as one might expect). This allows for comparison to other papers. :return: a dict with the following keys: - 'output': a shape [N] tensor of NLLs or KLs.

(self, model, x_start, x_t, t, clip_denoised=False, model_kwargs=None)

Source from the content-addressed store, hash-verified

723 img = out["sample"]
724
725 def _vb_terms_bpd(self, model, x_start, x_t, t, clip_denoised=False, model_kwargs=None):
726 """
727 Get a term for the variational lower-bound.
728
729 The resulting units are bits (rather than nats, as one might expect).
730 This allows for comparison to other papers.
731
732 :return: a dict with the following keys:
733 - 'output': a shape [N] tensor of NLLs or KLs.
734 - 'pred_xstart': the x_0 predictions.
735 """
736 true_mean, _, true_log_variance_clipped = self.q_posterior_mean_variance(
737 x_start=x_start, x_t=x_t, t=t
738 )
739 out = self.p_mean_variance(
740 model, x_t, t, clip_denoised=clip_denoised, model_kwargs=model_kwargs
741 )
742 kl = normal_kl(true_mean, true_log_variance_clipped, out["mean"], out["log_variance"])
743 kl = mean_flat(kl) / np.log(2.0)
744
745 decoder_nll = -discretized_gaussian_log_likelihood(
746 x_start, means=out["mean"], log_scales=0.5 * out["log_variance"]
747 )
748 if not self.discretized_t0:
749 decoder_nll = th.zeros_like(decoder_nll)
750 assert decoder_nll.shape == x_start.shape
751 decoder_nll = mean_flat(decoder_nll) / np.log(2.0)
752
753 # At the first timestep return the decoder NLL,
754 # otherwise return KL(q(x_{t-1}|x_t,x_0) || p(x_{t-1}|x_t))
755 output = th.where((t == 0), decoder_nll, kl)
756 return {
757 "output": output,
758 "pred_xstart": out["pred_xstart"],
759 "extra": out["extra"],
760 }
761
762 def training_losses(
763 self, model, x_start, t, model_kwargs=None, noise=None

Callers 2

training_lossesMethod · 0.95
calc_bpd_loopMethod · 0.95

Calls 5

p_mean_varianceMethod · 0.95
normal_klFunction · 0.85
mean_flatFunction · 0.85

Tested by

no test coverage detected