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 using DDIM.
  
  Same usage as p_sample().
docstr_tok: ["Sample","x_","{","t-1","}","from","the","model","using","DDIM",".","Same","usage","as","p_sample","(",")","."]
code: def ddim_sample(
      self,
      model,
      x,
      t,
      clip_denoised=True,
      denoised_fn=None,
      cond_fn=None,
      model_kwargs=None,
      eta=0.0,
  ):
      """
      Sample x_{t-1} from the model using DDIM.
  
      Same usage as p_sample().
      """
      out_orig = self.p_mean_variance(
          model,
          x,
          t,
          clip_denoised=clip_denoised,
          denoised_fn=denoised_fn,
          model_kwargs=model_kwargs,
      )
      if cond_fn is not None:
          out = self.condition_score(
              cond_fn, out_orig, x, t, model_kwargs=model_kwargs
          )
      else:
          out = out_orig
  
      # Usually our model outputs epsilon, but we re-derive it
      # in case we used x_start or x_prev prediction.
      eps = self._predict_eps_from_xstart(x, t, out["pred_xstart"])
  
      alpha_bar = _extract_into_tensor(self.alphas_cumprod, t, x.shape)
      alpha_bar_prev = _extract_into_tensor(
          self.alphas_cumprod_prev, t, x.shape
      )
      sigma = (
          eta
          * paddle.sqrt((1 - alpha_bar_prev) / (1 - alpha_bar))
          * paddle.sqrt(1 - alpha_bar / alpha_bar_prev)
      )
      # Equation 12.
      # noise = th.randn_like(x)
      noise = paddle.randn(x.shape, x.dtype)
      mean_pred = (
          out["pred_xstart"] * paddle.sqrt(alpha_bar_prev)
          + paddle.sqrt(1 - alpha_bar_prev - sigma**2) * eps
      )
      nonzero_mask = paddle.cast((t != 0), "float32").reshape(
          [-1, *([1] * (len(x.shape) - 1))]
      )  # no noise when t == 0
      sample = mean_pred + nonzero_mask * sigma * noise
      return {"sample": sample, "pred_xstart": out_orig["pred_xstart"]}
  
imports: import enum
  import math
  import numpy
  import paddle
  from .losses import discretized_gaussian_log_likelihood
  from .losses import normal_kl
  from .nn import mean_flat
label_desc: Use image node_id 18 for calling the GaussianDiffusion obj's underlying member method code with example usage: obj.ddim_sample(model, x, t, clip_denoised, denoised_fn, cond_fn, model_kwargs, eta) and returns: dict