class_docstr: An implementation of a classic Denoising Diffusion Probabilistic Model (DDPM)
  
  Arguments
  ---------
  model: nn.Module
      the underlying model
  
  timesteps: int
      the number of timesteps
  
  noise: str|nn.Module
      the type of noise being used
      "gaussian" will produce standard Gaussian noise
  
  
  beta_start: float
      the value of the "beta" parameter at the beginning at the end of the process
      (see the paper)
  
  beta_end: float
      the value of the "beta" parameter at the end of the process
  
  show_progress: bool
      whether to show progress during inference
  
  Example
  -------
  >>> from speechbrain.nnet.unet import UNetModel
  >>> unet = UNetModel(
  ...     in_channels=1,
  ...     model_channels=16,
  ...     norm_num_groups=4,
  ...     out_channels=1,
  ...     num_res_blocks=1,
  ...     attention_resolutions=[]
  ... )
  >>> diff = DenoisingDiffusion(
  ...     model=unet,
  ...     timesteps=5
  ... )
  >>> x = torch.randn(4, 1, 64, 64)
  >>> pred, noise, noisy_sample = diff.train_sample(x)
  >>> pred.shape
  torch.Size([4, 1, 64, 64])
  >>> noise.shape
  torch.Size([4, 1, 64, 64])
  >>> noisy_sample.shape
  torch.Size([4, 1, 64, 64])
  >>> sample = diff.sample((2, 1, 64, 64))
  >>> sample.shape
  torch.Size([2, 1, 64, 64])
code: def __init__(
      self,
      model,
      timesteps=None,
      noise=None,
      beta_start=None,
      beta_end=None,
      sample_min=None,
      sample_max=None,
      show_progress=False,
  ):
      if timesteps is None:
          timesteps = DDPM_REF_TIMESTEPS
      super().__init__(model, timesteps=timesteps, noise=noise)
      if beta_start is None or beta_end is None:
          scale = DDPM_REF_TIMESTEPS / timesteps
          if beta_start is None:
              beta_start = scale * DDPM_DEFAULT_BETA_START
          if beta_end is None:
              beta_end = scale * DDPM_DEFAULT_BETA_END
      self.beta_start = beta_start
      self.beta_end = beta_end
      alphas, betas = self.compute_coefficients()
      self.register_buffer("alphas", alphas)
      self.register_buffer("betas", betas)
      alphas_cumprod = self.alphas.cumprod(dim=0)
      self.register_buffer("alphas_cumprod", alphas_cumprod)
      signal_coefficients = torch.sqrt(alphas_cumprod)
      noise_coefficients = torch.sqrt(1.0 - alphas_cumprod)
      self.register_buffer("signal_coefficients", signal_coefficients)
      self.register_buffer("noise_coefficients", noise_coefficients)
      alphas_cumprod_prev = F.pad(
          alphas_cumprod[:-1], (1, 0), value=1.0
      )
      posterior_variance = (
          betas * (1.0 - alphas_cumprod_prev) / (1.0 - alphas_cumprod)
      )
      self.register_buffer("posterior_variance", posterior_variance)
      self.register_buffer(
          "posterior_log_variance", posterior_variance.log()
      )
      posterior_mean_weight_start = (
          betas
          * torch.sqrt(alphas_cumprod_prev)
          / (1.0 - alphas_cumprod)
      )
      posterior_mean_weight_step = (
          (1.0 - alphas_cumprod_prev)
          * torch.sqrt(alphas)
          / (1.0 - alphas_cumprod)
      )
      self.register_buffer(
          "posterior_mean_weight_start", posterior_mean_weight_start
      )
      self.register_buffer(
          "posterior_mean_weight_step", posterior_mean_weight_step
      )
      sample_pred_model_coefficient = (1.0 / alphas_cumprod).sqrt()
  
      self.register_buffer(
          "sample_pred_model_coefficient", sample_pred_model_coefficient
      )
      sample_pred_noise_coefficient = (1.0 / alphas_cumprod - 1).sqrt()
      self.register_buffer(
          "sample_pred_noise_coefficient", sample_pred_noise_coefficient
      )
      self.sample_min = sample_min
      self.sample_max = sample_max
      self.show_progress = show_progress
  
imports: from collections import namedtuple
  import torch
  from torch import nn
  from torch.nn import functional
  from tqdm.auto import tqdm
  from speechbrain.utils.data_utils import unsqueeze_as
  from speechbrain.dataio.dataio import length_to_mask
  from speechbrain.utils import data_utils
label_desc: Use image node_id 1 to create a new DenoisingDiffusion object from inherited base classes: Diffuser with example: obj = DenoisingDiffusion(model, timesteps, noise, beta_start, beta_end, sample_min, sample_max, show_progress)