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).
class_docstr_tok: ["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 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 element.
docstr_tok: ["Get","the","prior","KL","term","for","the","variational","lower-bound",",","measured","in","bits-per-dim",".","This","term","ca","n'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","element","."]
code: def _prior_bpd(self, x_start):
      """
      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 element.
      """
      batch_size = x_start.shape[0]
      t = th.tensor(
          [self.num_timesteps - 1] * batch_size, device=x_start.device
      )
      qt_mean, _, qt_log_variance = self.q_mean_variance(x_start, t)
      kl_prior = normal_kl(
          mean1=qt_mean, logvar1=qt_log_variance, mean2=0.0, logvar2=0.0
      )
      return mean_flat(kl_prior) / np.log(2.0)
  
imports: import enum
  import math
  import numpy
  import torch
  import torch
  from tqdm import tqdm
  from TTS.tts.layers.tortoise.dpm_solver import DPM_Solver, NoiseScheduleVP, model_wrapper
label_desc: Use image node_id 24 for calling the GaussianDiffusion obj's underlying member method code with example usage: obj._prior_bpd(x_start) and returns: unknown