docstr: Produces a sample in inference mode. This is called when producing
  samples.
docstr_tok: ["Produces","a","sample","in","inference","mode",".","This","is","called","when","producing","samples","."]
code: def run_inference_sample(self, name):
      """Produces a sample in inference mode. This is called when producing
      samples.
      """
      with torch.no_grad():
          if self.last_batch is None:
              return
          x, y = self.last_batch
  
          # Preparing model for inference by removing weight norm
          # inference_generator = copy.deepcopy(self.hparams.generator)
          inference_generator = type(self.hparams.generator)(
              in_channels=self.hparams.in_channels,
              out_channels=self.hparams.out_channels,
              resblock_type=self.hparams.resblock_type,
              resblock_dilation_sizes=self.hparams.resblock_dilation_sizes,
              resblock_kernel_sizes=self.hparams.resblock_kernel_sizes,
              upsample_kernel_sizes=self.hparams.upsample_kernel_sizes,
              upsample_initial_channel=self.hparams.upsample_initial_channel,
              upsample_factors=self.hparams.upsample_factors,
              inference_padding=self.hparams.inference_padding,
              cond_channels=self.hparams.cond_channels,
              conv_post_bias=self.hparams.conv_post_bias,
          ).to(
              self.device
          )  # Gets a new instance
          inference_generator.load_state_dict(
              self.hparams.generator.state_dict()
          )  # Copies weights
          inference_generator.remove_weight_norm()
          sig_out = inference_generator.inference(x)
          spec_out = self.hparams.mel_spectogram(
              audio=sig_out.squeeze(0).cpu()
          )
      if self.hparams.use_tensorboard:
          self.tensorboard_logger.log_audio(
              f"{name}/audio_target",
              y.squeeze(0),
              self.hparams.sample_rate,
          )
          self.tensorboard_logger.log_audio(
              f"{name}/audio_pred",
              sig_out.squeeze(0),
              self.hparams.sample_rate,
          )
          self.tensorboard_logger.log_figure(f"{name}/mel_target", x)
          self.tensorboard_logger.log_figure(
              f"{name}/mel_pred", spec_out
          )
      else:
          # folder name is the current epoch for validation and "test" for test
          folder = (
              self.hparams.epoch_counter.current
              if name == "Valid"
              else "test"
          )
          self.save_audio("target", y.squeeze(0), folder)
          self.save_audio("synthesized", sig_out.squeeze(0), folder)
  
file_path: speechbrain/recipes/LibriTTS/vocoder/hifigan/train.py
imports: import sys
  import torch
  from hyperpyyaml import load_hyperpyyaml
  import speechbrain
  from speechbrain.utils.data_utils import scalarize
  import torchaudio
  import os
label_desc: Use image node_id 9 for calling the HifiGanBrain obj's underlying member method code with example usage: obj.run_inference_sample(name) without return types