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: Uses the done predictor to "chop" a batch of samples
  according to when it believes generation to be finished
  at a given state
  
  Arguments
  ---------
  samples: torch.Tensor
      a tensor of samples
  
  wav: torch.Tensor
      a tensor of generated audio (optional)
  
  Returns
  -------
  done_pred: torch.Tensor
      the raw output of the "done" predictor
  samples_cut: list
      a list of samples
docstr_tok: ["Uses","the","done","predictor","to","``","chop","''","a","batch","of","samples","according","to","when","it","believes","generation","to","be","finished","at","a","given","state","Arguments","--","--","--","--","-","samples",":","torch.Tensor","a","tensor","of","samples","wav",":","torch.Tensor","a","tensor","of","generated","audio","(","optional",")","Returns","--","--","--","-","done_pred",":","torch.Tensor","the","raw","output","of","the","``","done","''","predictor","samples_cut",":","list","a","list","of","samples"]
code: def cut_samples(self, samples, wav):
      """Uses the done predictor to "chop" a batch of samples
      according to when it believes generation to be finished
      at a given state
  
      Arguments
      ---------
      samples: torch.Tensor
          a tensor of samples
  
      wav: torch.Tensor
          a tensor of generated audio (optional)
  
      Returns
      -------
      done_pred: torch.Tensor
          the raw output of the "done" predictor
      samples_cut: list
          a list of samples
  
      """
      done_in = samples.squeeze(1)[:, :, : self.hparams.spec_n_mels]
      done_pred = self.modules.done_detector(done_in)
      lens_pred = done_pred.squeeze().argmax(dim=-1)
      # NOTE: A poorly trained "done detector" may not cross the threshold
      # at all - in this case the sample will not be "cut"
      lens_pred[lens_pred == 0] = samples.size(2)
      samples_cut = [
          sample[:, :length, :]
          for sample, length in zip(samples, lens_pred)
      ]
      wav_lens_pred = (lens_pred / samples.size(2) * wav.size(-1)).int()
      wav_cut = [
          sample[:length] for sample, length in zip(wav, wav_lens_pred)
      ]
      return samples_cut, wav_cut
  
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 18 for calling the DiffusionBrain obj's underlying member method code with example usage: obj.cut_samples(samples, wav) and returns: samples_cut,  wav_cut