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: Sample x_{t-1} from the model at the given timestep.
  
  :param model: the model to sample from.
  :param x: the current tensor at x_{t-1}.
  :param t: the value of t, starting at 0 for the first diffusion step.
  :param clip_denoised: if True, clip the x_start prediction to [-1, 1].
  :param denoised_fn: if not None, a function which applies to the
      x_start prediction before it is used to sample.
  :param cond_fn: if not None, this is a gradient function that acts
                  similarly to the model.
  :param model_kwargs: if not None, a dict of extra keyword arguments to
      pass to the model. This can be used for conditioning.
  :return: a dict containing the following keys:
           - 'sample': a random sample from the model.
           - 'pred_xstart': a prediction of x_0.
docstr_tok: ["Sample","x_","{","t-1","}","from","the","model","at","the","given","timestep",".",":","param","model",":","the","model","to","sample","from",".",":","param","x",":","the","current","tensor","at","x_","{","t-1","}",".",":","param","t",":","the","value","of","t",",","starting","at","0","for","the","first","diffusion","step",".",":","param","clip_denoised",":","if","True",",","clip","the","x_start","prediction","to","[","-1",",","1","]",".",":","param","denoised_fn",":","if","not","None",",","a","function","which","applies","to","the","x_start","prediction","before","it","is","used","to","sample",".",":","param","cond_fn",":","if","not","None",",","this","is","a","gradient","function","that","acts","similarly","to","the","model",".",":","param","model_kwargs",":","if","not","None",",","a","dict","of","extra","keyword","arguments","to","pass","to","the","model",".","This","can","be","used","for","conditioning",".",":","return",":","a","dict","containing","the","following","keys",":","-","'sample","'",":","a","random","sample","from","the","model",".","-","'pred_xstart","'",":","a","prediction","of","x_0","."]
code: def p_sample(
      self,
      model,
      x,
      t,
      clip_denoised=True,
      denoised_fn=None,
      cond_fn=None,
      model_kwargs=None,
  ):
      """
      Sample x_{t-1} from the model at the given timestep.
  
      :param model: the model to sample from.
      :param x: the current tensor at x_{t-1}.
      :param t: the value of t, starting at 0 for the first diffusion step.
      :param clip_denoised: if True, clip the x_start prediction to [-1, 1].
      :param denoised_fn: if not None, a function which applies to the
          x_start prediction before it is used to sample.
      :param cond_fn: if not None, this is a gradient function that acts
                      similarly to the model.
      :param model_kwargs: if not None, a dict of extra keyword arguments to
          pass to the model. This can be used for conditioning.
      :return: a dict containing the following keys:
               - 'sample': a random sample from the model.
               - 'pred_xstart': a prediction of x_0.
      """
      out = self.p_mean_variance(
          model,
          x,
          t,
          clip_denoised=clip_denoised,
          denoised_fn=denoised_fn,
          model_kwargs=model_kwargs,
      )
      noise = th.randn_like(x)
      nonzero_mask = (
          (t != 0).float().view(-1, *([1] * (len(x.shape) - 1)))
      )  # no noise when t == 0
      if cond_fn is not None:
          out["mean"] = self.condition_mean(
              cond_fn, out, x, t, model_kwargs=model_kwargs
          )
      sample = (
          out["mean"]
          + nonzero_mask * th.exp(0.5 * out["log_variance"]) * noise
      )
      return {"sample": sample, "pred_xstart": out["pred_xstart"]}
  
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 14 for calling the GaussianDiffusion obj's underlying member method code with example usage: obj.p_sample(model, x, t, clip_denoised, denoised_fn, cond_fn, model_kwargs) and returns: dict