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: Generate samples from the model and yield intermediate samples from
  each timestep of diffusion.
  
  Arguments are the same as p_sample_loop().
  Returns a generator over dicts, where each dict is the return value of
  p_sample().
docstr_tok: ["Generate","samples","from","the","model","and","yield","intermediate","samples","from","each","timestep","of","diffusion",".","Arguments","are","the","same","as","p_sample_loop","(",")",".","Returns","a","generator","over","dicts",",","where","each","dict","is","the","return","value","of","p_sample","(",")","."]
code: def p_sample_loop_progressive(
      self,
      model,
      shape,
      noise=None,
      clip_denoised=True,
      denoised_fn=None,
      cond_fn=None,
      model_kwargs=None,
      device=None,
      progress=False,
      skip_timesteps=0,
      init_image=None,
      randomize_class=False,
      cond_fn_with_grad=False,
  ):
      """
      Generate samples from the model and yield intermediate samples from
      each timestep of diffusion.
  
      Arguments are the same as p_sample_loop().
      Returns a generator over dicts, where each dict is the return value of
      p_sample().
      """
      if device is None:
          device = model.parameters()[0].place
      assert isinstance(shape, (tuple, list))
      if noise is not None:
          img = noise
      else:
          img = paddle.randn(shape)
  
      if skip_timesteps and init_image is None:
          init_image = paddle.zeros_like(img)
  
      indices = list(range(self.num_timesteps - skip_timesteps))[::-1]
  
      if init_image is not None:
          my_t = paddle.ones([shape[0]], dtype="int64") * indices[0]
          img = self.q_sample(init_image, my_t, img)
  
      if progress:
          # Lazy import so that we don't depend on tqdm.
          from tqdm.auto import tqdm
  
          indices = tqdm(indices)
  
      for i in indices:
          t = paddle.to_tensor([i] * shape[0], place=device)
          if randomize_class and "y" in model_kwargs:
              model_kwargs["y"] = paddle.randint(
                  low=0,
                  high=model.num_classes,
                  shape=model_kwargs["y"].shape,
              )
          # with paddle.no_grad():
          sample_fn = (
              self.p_sample_with_grad
              if cond_fn_with_grad
              else self.p_sample
          )
          out = sample_fn(
              model,
              img,
              t,
              clip_denoised=clip_denoised,
              denoised_fn=denoised_fn,
              cond_fn=cond_fn,
              model_kwargs=model_kwargs,
          )
          yield out
          img = out["sample"]
  
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 17 for calling the GaussianDiffusion obj's underlying member method code with example usage: obj.p_sample_loop_progressive(model, shape, noise, clip_denoised, denoised_fn, cond_fn, model_kwargs, device, progress, skip_timesteps, init_image, randomize_class, cond_fn_with_grad) without return types