class_docstr: A base diffusion implementation
  
  Arguments
  ---------
  model: nn.Module
      the underlying model
  timesteps: int
      the number of timesteps
  noise: callable|str
      the noise function/module to use
  
      The following predefined types of noise are provided
      "gaussian": Gaussian noise, applied to the whole sample
      "length_masked_gaussian": Gaussian noise applied only
          to the parts of the sample that is not padding
docstr: Creates a sample for the training loop with a
  corresponding target
  Arguments
  ---------
  x: torch.Tensor
      the original data sample
  timesteps: torch.Tensor
      a 1-D integer tensor of a length equal to the number of
      batches in x, where each entry corresponds to the timestep
      number for the batch. If omitted, timesteps will be randomly
      sampled
  condition: torch.tensor
      the condition used for conditional generation
      Should be omitted during unconditional generation
  Returns
  -------
  pred: torch.Tensor
      the model output 0 prdicted noise
  noise: torch.Tensor
      the noise being applied
  noisy_sample
      the sample with the noise applied
code: def train_sample(self, x, timesteps=None, condition=None, **kwargs):
      """Creates a sample for the training loop with a
      corresponding target
      Arguments
      ---------
      x: torch.Tensor
          the original data sample
      timesteps: torch.Tensor
          a 1-D integer tensor of a length equal to the number of
          batches in x, where each entry corresponds to the timestep
          number for the batch. If omitted, timesteps will be randomly
          sampled
      condition: torch.tensor
          the condition used for conditional generation
          Should be omitted during unconditional generation
      Returns
      -------
      pred: torch.Tensor
          the model output 0 prdicted noise
      noise: torch.Tensor
          the noise being applied
      noisy_sample
          the sample with the noise applied
      """
      if timesteps is None:
          timesteps = sample_timesteps(x, self.timesteps)
      noisy_sample, noise = self.distort(
          x, timesteps=timesteps, **kwargs
      )
  
      # in case that certain models do not have any condition as input
      if condition is None:
          pred = self.model(noisy_sample, timesteps, **kwargs)
      else:
          pred = self.model(
              noisy_sample, timesteps, condition, **kwargs
          )
      return pred, noise, noisy_sample
  
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 3 for calling the Diffuser obj's underlying member method code with example usage: obj.train_sample(x, timesteps, condition) and returns: pred,  noise,  noisy_sample