class_docstr: Collection of Tacotron set-up based on provided config.
code: def forward(
      self,
      postnet_output,
      decoder_output,
      mel_input,
      linear_input,
      stopnet_output,
      stopnet_target,
      output_lens,
      decoder_b_output,
      alignments,
      alignment_lens,
      alignments_backwards,
      input_lens,
  ):
      return_dict = {}
      # remove lengths if no masking is applied
      if not self.config.loss_masking:
          output_lens = None
      # decoder and postnet losses
      if self.config.loss_masking:
          if self.decoder_alpha > 0:
              decoder_loss = self.criterion(
                  decoder_output, mel_input, output_lens
              )
          if self.postnet_alpha > 0:
              if self.config.model in ["Tacotron", "TacotronGST"]:
                  postnet_loss = self.criterion(
                      postnet_output, linear_input, output_lens
                  )
              else:
                  postnet_loss = self.criterion(
                      postnet_output, mel_input, output_lens
                  )
      else:
          if self.decoder_alpha > 0:
              decoder_loss = self.criterion(decoder_output, mel_input)
          if self.postnet_alpha > 0:
              if self.config.model in ["Tacotron", "TacotronGST"]:
                  postnet_loss = self.criterion(
                      postnet_output, linear_input
                  )
              else:
                  postnet_loss = self.criterion(
                      postnet_output, mel_input
                  )
      loss = (
          self.decoder_alpha * decoder_loss
          + self.postnet_alpha * postnet_loss
      )
      return_dict["decoder_loss"] = decoder_loss
      return_dict["postnet_loss"] = postnet_loss
  
      # stopnet loss
      stop_loss = (
          self.criterion_st(stopnet_output, stopnet_target, output_lens)
          if self.config.stopnet
          else torch.zeros(1)
      )
      if not self.config.separate_stopnet and self.config.stopnet:
          loss += stop_loss
      return_dict["stopnet_loss"] = stop_loss
  
      # backward decoder loss (if enabled)
      if self.config.bidirectional_decoder:
          if self.config.loss_masking:
              decoder_b_loss = self.criterion(
                  torch.flip(decoder_b_output, dims=(1,)),
                  mel_input,
                  output_lens,
              )
          else:
              decoder_b_loss = self.criterion(
                  torch.flip(decoder_b_output, dims=(1,)), mel_input
              )
          decoder_c_loss = torch.nn.functional.l1_loss(
              torch.flip(decoder_b_output, dims=(1,)), decoder_output
          )
          loss += self.decoder_alpha * (decoder_b_loss + decoder_c_loss)
          return_dict["decoder_b_loss"] = decoder_b_loss
          return_dict["decoder_c_loss"] = decoder_c_loss
  
      # double decoder consistency loss (if enabled)
      if self.config.double_decoder_consistency:
          if self.config.loss_masking:
              decoder_b_loss = self.criterion(
                  decoder_b_output, mel_input, output_lens
              )
          else:
              decoder_b_loss = self.criterion(
                  decoder_b_output, mel_input
              )
          # decoder_c_loss = torch.nn.functional.l1_loss(decoder_b_output, decoder_output)
          attention_c_loss = torch.nn.functional.l1_loss(
              alignments, alignments_backwards
          )
          loss += self.decoder_alpha * (
              decoder_b_loss + attention_c_loss
          )
          return_dict["decoder_coarse_loss"] = decoder_b_loss
          return_dict["decoder_ddc_loss"] = attention_c_loss
  
      # guided attention loss (if enabled)
      if self.config.ga_alpha > 0:
          ga_loss = self.criterion_ga(
              alignments, input_lens, alignment_lens
          )
          loss += ga_loss * self.ga_alpha
          return_dict["ga_loss"] = ga_loss
  
      # decoder differential spectral loss
      if self.config.decoder_diff_spec_alpha > 0:
          decoder_diff_spec_loss = self.criterion_diff_spec(
              decoder_output, mel_input, output_lens
          )
          loss += decoder_diff_spec_loss * self.decoder_diff_spec_alpha
          return_dict["decoder_diff_spec_loss"] = decoder_diff_spec_loss
  
      # postnet differential spectral loss
      if self.config.postnet_diff_spec_alpha > 0:
          postnet_diff_spec_loss = self.criterion_diff_spec(
              postnet_output, mel_input, output_lens
          )
          loss += postnet_diff_spec_loss * self.postnet_diff_spec_alpha
          return_dict["postnet_diff_spec_loss"] = postnet_diff_spec_loss
  
      # decoder ssim loss
      if self.config.decoder_ssim_alpha > 0:
          decoder_ssim_loss = self.criterion_ssim(
              decoder_output, mel_input, output_lens
          )
          loss += decoder_ssim_loss * self.postnet_ssim_alpha
          return_dict["decoder_ssim_loss"] = decoder_ssim_loss
  
      # postnet ssim loss
      if self.config.postnet_ssim_alpha > 0:
          postnet_ssim_loss = self.criterion_ssim(
              postnet_output, mel_input, output_lens
          )
          loss += postnet_ssim_loss * self.postnet_ssim_alpha
          return_dict["postnet_ssim_loss"] = postnet_ssim_loss
  
      return_dict["loss"] = loss
  
      # check if any loss is NaN
      for key, loss in return_dict.items():
          if torch.isnan(loss):
              raise RuntimeError(f" [!] NaN loss with {key}.")
      return return_dict
  
imports: import math
  import numpy
  import torch
  from torch import nn
  from inspect import signature
  from torch.nn import functional
  from TTS.tts.utils.generic_utils import sequence_mask
  from TTS.tts.utils.ssim import ssim
label_desc: Use image node_id 2 for calling the TacotronLoss obj's underlying member method code with example usage: obj.forward(postnet_output, decoder_output, mel_input, linear_input, stopnet_output, stopnet_target, output_lens, decoder_b_output, alignments, alignment_lens, alignments_backwards, input_lens) and returns: return_dict