class_docstr: Utilities for training and sampling diffusion models.
  
  Ported directly from here, and then adapted over time to further experimentation.
  https://github.com/hojonathanho/diffusion/blob/1e0dceb3b3495bbe19116a5e1b3596cd0706c543/diffusion_tf/diffusion_utils_2.py#L42
  
  :param betas: a 1-D numpy array of betas for each diffusion timestep,
                starting at T and going to 1.
  :param model_mean_type: a ModelMeanType determining what the model outputs.
  :param model_var_type: a ModelVarType determining how variance is output.
  :param loss_type: a LossType determining the loss function to use.
  :param rescale_timesteps: if True, pass floating point timesteps into the
                            model so that they are always scaled like in the
                            original paper (0 to 1000).
docstr: 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.
           - 'pred_xstart': the x_0 predictions.
docstr_tok: ["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",".","-","'pred_xstart","'",":","the","x_0","predictions","."]
code: def _vb_terms_bpd(
      self,
      model,
      x_start,
      x_t,
      t,
      clip_denoised=True,
      model_kwargs=None,
  ):
      """
      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.
               - 'pred_xstart': the x_0 predictions.
      """
      (
          true_mean,
          _,
          true_log_variance_clipped,
      ) = self.q_posterior_mean_variance(x_start=x_start, x_t=x_t, t=t)
      out = self.p_mean_variance(
          model,
          x_t,
          t,
          clip_denoised=clip_denoised,
          model_kwargs=model_kwargs,
      )
      kl = normal_kl(
          true_mean,
          true_log_variance_clipped,
          out["mean"],
          out["log_variance"],
      )
      kl = mean_flat(kl) / np.log(2.0)
  
      decoder_nll = -discretized_gaussian_log_likelihood(
          x_start,
          means=out["mean"],
          log_scales=0.5 * out["log_variance"],
      )
      assert decoder_nll.shape == x_start.shape
      decoder_nll = mean_flat(decoder_nll) / np.log(2.0)
  
      # At the first timestep return the decoder NLL,
      # otherwise return KL(q(x_{t-1}|x_t,x_0) || p(x_{t-1}|x_t))
      output = th.where((t == 0), decoder_nll, kl)
      return {"output": output, "pred_xstart": out["pred_xstart"]}
  
imports: import enum
  import math
  import numpy
  import torch
  from .nn import mean_flat
  from .losses import normal_kl, discretized_gaussian_log_likelihood
label_desc: Use image node_id 17 for calling the GaussianDiffusion obj's underlying member method code with example usage: obj._vb_terms_bpd(model, x_start, x_t, t, clip_denoised, model_kwargs) and returns: dict