class_docstr: HiFi-GAN model (https://arxiv.org/abs/2010.05646) that is used to generate audio from mel spectrogram.
class_docstr_tok: ["HiFi-GAN","model","(","https",":","\/\/arxiv.org\/abs\/2010.05646",")","that","is","used","to","generate","audio","from","mel","spectrogram","."]
code: def training_step(self, batch, batch_idx):
      audio, audio_len, audio_mel, _ = self._process_batch(batch)
  
      # Mel as input for L1 mel loss
      audio_trg_mel, _ = self.trg_melspec_fn(audio, audio_len)
      audio = audio.unsqueeze(1)
  
      audio_pred = self.generator(x=audio_mel)
      audio_pred_mel, _ = self.trg_melspec_fn(
          audio_pred.squeeze(1), audio_len
      )
  
      optim_g, optim_d = self.optimizers()
  
      # Train discriminator
      optim_d.zero_grad()
      mpd_score_real, mpd_score_gen, _, _ = self.mpd(
          y=audio, y_hat=audio_pred.detach()
      )
      loss_disc_mpd, _, _ = self.discriminator_loss(
          disc_real_outputs=mpd_score_real,
          disc_generated_outputs=mpd_score_gen,
      )
      msd_score_real, msd_score_gen, _, _ = self.msd(
          y=audio, y_hat=audio_pred.detach()
      )
      loss_disc_msd, _, _ = self.discriminator_loss(
          disc_real_outputs=msd_score_real,
          disc_generated_outputs=msd_score_gen,
      )
      loss_d = loss_disc_msd + loss_disc_mpd
      self.manual_backward(loss_d)
      optim_d.step()
  
      # Train generator
      optim_g.zero_grad()
      loss_mel = F.l1_loss(audio_pred_mel, audio_trg_mel)
      _, mpd_score_gen, fmap_mpd_real, fmap_mpd_gen = self.mpd(
          y=audio, y_hat=audio_pred
      )
      _, msd_score_gen, fmap_msd_real, fmap_msd_gen = self.msd(
          y=audio, y_hat=audio_pred
      )
      loss_fm_mpd = self.feature_loss(
          fmap_r=fmap_mpd_real, fmap_g=fmap_mpd_gen
      )
      loss_fm_msd = self.feature_loss(
          fmap_r=fmap_msd_real, fmap_g=fmap_msd_gen
      )
      loss_gen_mpd, _ = self.generator_loss(disc_outputs=mpd_score_gen)
      loss_gen_msd, _ = self.generator_loss(disc_outputs=msd_score_gen)
      loss_g = (
          loss_gen_msd
          + loss_gen_mpd
          + loss_fm_msd
          + loss_fm_mpd
          + loss_mel * self.l1_factor
      )
      self.manual_backward(loss_g)
      optim_g.step()
  
      self.update_lr()
  
      metrics = {
          "g_loss_fm_mpd": loss_fm_mpd,
          "g_loss_fm_msd": loss_fm_msd,
          "g_loss_gen_mpd": loss_gen_mpd,
          "g_loss_gen_msd": loss_gen_msd,
          "g_loss": loss_g,
          "d_loss_mpd": loss_disc_mpd,
          "d_loss_msd": loss_disc_msd,
          "d_loss": loss_d,
          "global_step": self.global_step,
          "lr": optim_g.param_groups[0]["lr"],
      }
      self.log_dict(metrics, on_step=True, sync_dist=True)
      self.log(
          "g_l1_loss",
          loss_mel,
          prog_bar=True,
          logger=False,
          sync_dist=True,
      )
  
imports: import itertools
  from pathlib import Path
  import torch
  import torch.nn.functional
  from hydra.utils import instantiate
  from omegaconf import DictConfig, OmegaConf, open_dict
  from pytorch_lightning.loggers.wandb import WandbLogger
  from nemo.collections.tts.losses.hifigan_losses import DiscriminatorLoss, FeatureMatchingLoss, GeneratorLoss
  from nemo.collections.tts.models.base import Vocoder
  from nemo.collections.tts.modules.hifigan_modules import MultiPeriodDiscriminator, MultiScaleDiscriminator
  from nemo.collections.tts.parts.utils.callbacks import LoggingCallback
  from nemo.collections.tts.parts.utils.helpers import get_batch_size, get_num_workers, plot_spectrogram_to_numpy
  from nemo.core.classes import Exportable
  from nemo.core.classes.common import PretrainedModelInfo, typecheck
  from nemo.core.neural_types.elements import AudioSignal, MelSpectrogramType
  from nemo.core.neural_types.neural_type import NeuralType
  from nemo.core.optim.lr_scheduler import compute_max_steps, prepare_lr_scheduler
  from nemo.utils import logging, model_utils
label_desc: Use image node_id 8 for calling the HifiGanModel obj's underlying member method code with example usage: obj.training_step(batch, batch_idx) without return types