class_docstr: Tacotron 2 Model that is used to generate mel spectrograms from text
code: def forward(self, *, tokens, token_len, audio=None, audio_len=None):
      if audio is not None and audio_len is not None:
          (
              spec_target,
              spec_target_len,
          ) = self.audio_to_melspec_precessor(audio, audio_len)
      else:
          if self.training or self.calculate_loss:
              raise ValueError(
                  f"'audio' and 'audio_len' can not be None when either 'self.training' or 'self.calculate_loss' is True."
              )
  
      token_embedding = self.text_embedding(tokens).transpose(1, 2)
      encoder_embedding = self.encoder(
          token_embedding=token_embedding, token_len=token_len
      )
  
      if self.training:
          spec_pred_dec, gate_pred, alignments = self.decoder(
              memory=encoder_embedding,
              decoder_inputs=spec_target,
              memory_lengths=token_len,
          )
      else:
          (
              spec_pred_dec,
              gate_pred,
              alignments,
              pred_length,
          ) = self.decoder(
              memory=encoder_embedding, memory_lengths=token_len
          )
  
      spec_pred_postnet = self.postnet(mel_spec=spec_pred_dec)
  
      if not self.calculate_loss and not self.training:
          return (
              spec_pred_dec,
              spec_pred_postnet,
              gate_pred,
              alignments,
              pred_length,
          )
  
      return (
          spec_pred_dec,
          spec_pred_postnet,
          gate_pred,
          spec_target,
          spec_target_len,
          alignments,
      )
  
imports: import contextlib
  from dataclasses import dataclass, field
  from typing import Any, Dict, List, Optional
  import torch
  from hydra.utils import instantiate
  from omegaconf import MISSING, DictConfig, OmegaConf, open_dict
  from omegaconf.errors import ConfigAttributeError
  from pytorch_lightning.loggers import TensorBoardLogger, WandbLogger
  from torch import nn
  from nemo.collections.common.parts.preprocessing import parsers
  from nemo.collections.tts.losses.tacotron2loss import Tacotron2Loss
  from nemo.collections.tts.models.base import SpectrogramGenerator
  from nemo.collections.tts.parts.utils.helpers import g2p_backward_compatible_support, get_mask_from_lengths, tacotron2_log_to_tb_func, tacotron2_log_to_wandb_func
  from nemo.core.classes.common import PretrainedModelInfo, typecheck
  from nemo.core.neural_types.elements import AudioSignal, EmbeddedTextType, LengthsType, LogitsType, MelSpectrogramType, SequenceToSequenceAlignmentType
  from nemo.core.neural_types.neural_type import NeuralType
  from nemo.utils import logging, model_utils
label_desc: Use image node_id 6 for calling the Tacotron2Model obj's underlying member method code with example usage: obj.forward() and returns: spec_pred_dec,  spec_pred_postnet,  gate_pred,  spec_target,  spec_target_len,  alignments, spec_pred_dec,  spec_pred_postnet,  gate_pred,  alignments,  pred_length