class_docstr: Class that manages the training loop. See speechbrain.core.Brain.
  
  Arguments
  ---------
  modules : dict of str:torch.nn.Module pairs
      These modules are passed to the optimizer by default if they have
      trainable parameters, and will have ``train()``/``eval()`` called on them.
  opt_class : torch.optim class
      A torch optimizer constructor that takes only the list of
      parameters (e.g. a lambda or partial function definition). By default,
      this will be passed all modules in ``modules`` at the
      beginning of the ``fit()`` method. This behavior can be changed
      by overriding the ``configure_optimizers()`` method.
  hparams : dict
      Each key:value pair should consist of a string key and a hyperparameter
      that is used within the overridden methods. These will
      be accessible via an ``hparams`` attribute, using "dot" notation:
      e.g., self.hparams.model(x).
  run_opts : dict
      A set of options to change the runtime environment.
class_docstr_tok: ["Class","that","manages","the","training","loop",".","See","speechbrain.core.Brain",".","Arguments","--","--","--","--","-","modules",":","dict","of","str",":","torch.nn.Module","pairs","These","modules","are","passed","to","the","optimizer","by","default","if","they","have","trainable","parameters",",","and","will","have","``","train","(",")","``","\/","``","eval","(",")","``","called","on","them",".","opt_class",":","torch.optim","class","A","torch","optimizer","constructor","that","takes","only","the","list","of","parameters","(","e.g",".","a","lambda","or","partial","function","definition",")",".","By","default",",","this","will","be","passed","all","modules","in","``","modules","``","at","the","beginning","of","the","``","fit","(",")","``","method",".","This","behavior","can","be","changed","by","overriding","the","``","configure_optimizers","(",")","``","method",".","hparams",":","dict","Each","key",":","value","pair","should","consist","of","a","string","key","and","a","hyperparameter","that","is","used","within","the","overridden","methods",".","These","will","be","accessible","via","an","``","hparams","``","attribute",",","using","``","dot","''","notation",":","e.g.",",","self.hparams.model","(","x",")",".","run_opts",":","dict","A","set","of","options","to","change","the","runtime","environment","."]
docstr: Runs all the computation of that transforms the input into the
  output probabilities over the N classes.
  
  Arguments
  ---------
  batch : PaddedBatch
      This batch object contains all the relevant tensors for computation.
  stage : sb.Stage
      One of sb.Stage.TRAIN, sb.Stage.VALID, or sb.Stage.TEST.
  
  Returns
  -------
  predictions : Tensor
      Tensor that contains the posterior probabilities over the N classes.
docstr_tok: ["Runs","all","the","computation","of","that","transforms","the","input","into","the","output","probabilities","over","the","N","classes",".","Arguments","--","--","--","--","-","batch",":","PaddedBatch","This","batch","object","contains","all","the","relevant","tensors","for","computation",".","stage",":","sb.Stage","One","of","sb.Stage.TRAIN",",","sb.Stage.VALID",",","or","sb.Stage.TEST",".","Returns","--","--","--","-","predictions",":","Tensor","Tensor","that","contains","the","posterior","probabilities","over","the","N","classes","."]
code: def compute_forward(self, batch, stage):
      """Runs all the computation of that transforms the input into the
      output probabilities over the N classes.
  
      Arguments
      ---------
      batch : PaddedBatch
          This batch object contains all the relevant tensors for computation.
      stage : sb.Stage
          One of sb.Stage.TRAIN, sb.Stage.VALID, or sb.Stage.TEST.
  
      Returns
      -------
      predictions : Tensor
          Tensor that contains the posterior probabilities over the N classes.
      """
  
      # We first move the batch to the appropriate device.
      batch = batch.to(self.device)
  
      # Compute features, embeddings, and predictions
      feats, lens = self.prepare_features(batch, stage)
  
      autoencoder_out = None
      cond_emb = None
      if self.is_conditioned:
          cond_labels = self.get_cond_labels(batch)
          cond_emb = self.compute_cond_emb(cond_labels)
      if self.diffusion_mode == DiffusionMode.LATENT:
          mask_value = self.modules.global_norm.normalize(
              self.mask_value_norm
          )
          latent_mask_value = self.get_latent_mask_value(mask_value)
          (
              train_sample_diffusion,
              autoencoder_out,
          ) = self.modules.diffusion_latent.train_sample_latent(
              feats,
              length=lens,
              out_mask_value=mask_value,
              cond_emb=cond_emb,
              latent_mask_value=latent_mask_value,
          )
          pred, noise, noisy_sample = train_sample_diffusion
      else:
          (
              pred,
              noise,
              noisy_sample,
          ) = self.modules.diffusion.train_sample(
              feats, lens=lens, cond_emb=cond_emb
          )
  
      pred_done, feats_done, lens_done = None, None, None
      if self.use_done_detector:
          feats_done, lens_done = self.prepare_features_done(
              batch, feats, lens
          )
          pred_done = self.modules.done_detector(
              feats_done.squeeze(1), lens_done
          )
  
      # NOTE: lens can change because of the additional padding needed to account
      # NOTE: for downsampling
      return DiffusionPredictions(
          pred,
          noise,
          noisy_sample,
          feats,
          lens,
          autoencoder_out,
          feats_done,
          lens_done,
          pred_done,
      )
  
imports: import logging
  import sys
  import torch
  import speechbrain
  import os
  from collections import namedtuple
  from audiomnist_prepare import prepare_audiomnist
  from hyperpyyaml import load_hyperpyyaml
  from torchaudio import functional
  from speechbrain.dataio.dataio import length_to_mask, write_audio
  from speechbrain.dataio.dataset import apply_overfit_test
  from speechbrain.utils import data_utils
  from speechbrain.utils.train_logger import plot_spectrogram
  from enum import Enum
  from speechbrain.utils.distributed import run_on_main
  from speechbrain.utils.data_utils import dict_value_combinations, dist_stats, masked_mean, masked_min, masked_max, masked_std, match_shape
label_desc: Use image node_id 3 for calling the DiffusionBrain obj's underlying member method code with example usage: obj.compute_forward(batch, stage) and returns: DiffusionPredictions