class_docstr: Mixer-TTS and Mixer-TTS-X models (https://arxiv.org/abs/2110.03584) that is used to generate mel spectrogram from text.
class_docstr_tok: ["Mixer-TTS","and","Mixer-TTS-X","models","(","https",":","\/\/arxiv.org\/abs\/2110.03584",")","that","is","used","to","generate","mel","spectrogram","from","text","."]
code: def training_step(self, batch, batch_idx):
      attn_prior, lm_tokens = None, None
      if self.cond_on_lm_embeddings:
          (
              audio,
              audio_len,
              text,
              text_len,
              attn_prior,
              pitch,
              _,
              lm_tokens,
          ) = batch
      else:
          audio, audio_len, text, text_len, attn_prior, pitch, _ = batch
  
      spect, spect_len = self.preprocessor(
          input_signal=audio, length=audio_len
      )
  
      # pitch normalization
      zero_pitch_idx = pitch == 0
      pitch = (pitch - self.pitch_mean) / self.pitch_std
      pitch[zero_pitch_idx] = 0.0
  
      (
          pred_spect,
          _,
          pred_log_durs,
          pred_pitch,
          attn_soft,
          attn_logprob,
          attn_hard,
          attn_hard_dur,
      ) = self(
          text=text,
          text_len=text_len,
          pitch=pitch,
          spect=spect,
          spect_len=spect_len,
          attn_prior=attn_prior,
          lm_tokens=lm_tokens,
      )
  
      (
          loss,
          durs_loss,
          acc,
          acc_dist_1,
          acc_dist_3,
          pitch_loss,
          mel_loss,
          ctc_loss,
          bin_loss,
      ) = self._metrics(
          pred_durs=pred_log_durs,
          pred_pitch=pred_pitch,
          true_durs=attn_hard_dur,
          true_text_len=text_len,
          true_pitch=pitch,
          true_spect=spect,
          pred_spect=pred_spect,
          true_spect_len=spect_len,
          attn_logprob=attn_logprob,
          attn_soft=attn_soft,
          attn_hard=attn_hard,
          attn_hard_dur=attn_hard_dur,
      )
  
      train_log = {
          "train_loss": loss,
          "train_durs_loss": durs_loss,
          "train_pitch_loss": torch.tensor(1.0).to(durs_loss.device)
          if pitch_loss is None
          else pitch_loss,
          "train_mel_loss": mel_loss,
          "train_durs_acc": acc,
          "train_durs_acc_dist_3": acc_dist_3,
          "train_ctc_loss": torch.tensor(1.0).to(durs_loss.device)
          if ctc_loss is None
          else ctc_loss,
          "train_bin_loss": torch.tensor(1.0).to(durs_loss.device)
          if bin_loss is None
          else bin_loss,
      }
  
      return {
          "loss": loss,
          "progress_bar": {k: v.detach() for k, v in train_log.items()},
          "log": train_log,
      }
  
imports: import contextlib
  from typing import List, Optional
  import numpy
  import omegaconf
  import torch
  import transformers
  import wandb
  from hydra.utils import instantiate
  from omegaconf import DictConfig
  from pytorch_lightning import Trainer
  from pytorch_lightning.loggers import WandbLogger
  from torch import nn
  from torch.nn import functional
  from transformers import AlbertTokenizer
  from nemo.collections.common.tokenizers.text_to_speech.tts_tokenizers import EnglishCharsTokenizer, EnglishPhonemesTokenizer
  from nemo.collections.tts.losses.aligner_loss import BinLoss, ForwardSumLoss
  from nemo.collections.tts.models.base import SpectrogramGenerator
  from nemo.collections.tts.modules.fastpitch import average_features, regulate_len
  from nemo.collections.tts.parts.utils.helpers import binarize_attention_parallel, g2p_backward_compatible_support, get_mask_from_lengths, plot_pitch_to_numpy, plot_spectrogram_to_numpy
  from nemo.core import Exportable
  from nemo.core.classes.common import PretrainedModelInfo, typecheck
  from nemo.core.neural_types.elements import LengthsType, LogprobsType, MelSpectrogramType, ProbsType, RegressionValuesType, TokenDurationType, TokenIndex, TokenLogDurationType
  from nemo.core.neural_types.neural_type import NeuralType
  from nemo.utils import logging, model_utils
label_desc: Use image node_id 12 for calling the MixerTTSModel obj's underlying member method code with example usage: obj.training_step(batch, batch_idx) and returns: dict