class_docstr: General forward TTS model implementation that uses an encoder-decoder architecture with an optional alignment
  network and a pitch predictor.
  
  If the alignment network is used, the model learns the text-to-speech alignment
  from the data instead of using pre-computed durations.
  
  If the pitch predictor is used, the model trains a pitch predictor that predicts average pitch value for each
  input character as in the FastPitch model.
  
  `ForwardTTS` can be configured to one of these architectures,
  
      - FastPitch
      - SpeedySpeech
      - FastSpeech
      - FastSpeech2 (requires average speech energy predictor)
  
  Args:
      config (Coqpit): Model coqpit class.
      speaker_manager (SpeakerManager): Speaker manager for multi-speaker training. Only used for multi-speaker models.
          Defaults to None.
  
  Examples:
      >>> from TTS.tts.models.fast_pitch import ForwardTTS, ForwardTTSArgs
      >>> config = ForwardTTSArgs()
      >>> model = ForwardTTS(config)
class_docstr_tok: ["General","forward","TTS","model","implementation","that","uses","an","encoder-decoder","architecture","with","an","optional","alignment","network","and","a","pitch","predictor",".","If","the","alignment","network","is","used",",","the","model","learns","the","text-to-speech","alignment","from","the","data","instead","of","using","pre-computed","durations",".","If","the","pitch","predictor","is","used",",","the","model","trains","a","pitch","predictor","that","predicts","average","pitch","value","for","each","input","character","as","in","the","FastPitch","model",".","`","ForwardTTS","`","can","be","configured","to","one","of","these","architectures",",","-","FastPitch","-","SpeedySpeech","-","FastSpeech","-","FastSpeech2","(","requires","average","speech","energy","predictor",")","Args",":","config","(","Coqpit",")",":","Model","coqpit","class",".","speaker_manager","(","SpeakerManager",")",":","Speaker","manager","for","multi-speaker","training",".","Only","used","for","multi-speaker","models",".","Defaults","to","None",".","Examples",":",">",">",">","from","TTS.tts.models.fast_pitch","import","ForwardTTS",",","ForwardTTSArgs",">",">",">","config","=","ForwardTTSArgs","(",")",">",">",">","model","=","ForwardTTS","(","config",")"]
docstr: Model's forward pass.
  
  Args:
      x (torch.LongTensor): Input character sequences.
      x_lengths (torch.LongTensor): Input sequence lengths.
      y_lengths (torch.LongTensor): Output sequnce lengths. Defaults to None.
      y (torch.FloatTensor): Spectrogram frames. Only used when the alignment network is on. Defaults to None.
      dr (torch.IntTensor): Character durations over the spectrogram frames. Only used when the alignment network is off. Defaults to None.
      pitch (torch.FloatTensor): Pitch values for each spectrogram frame. Only used when the pitch predictor is on. Defaults to None.
      energy (torch.FloatTensor): energy values for each spectrogram frame. Only used when the energy predictor is on. Defaults to None.
      aux_input (Dict): Auxiliary model inputs for multi-speaker training. Defaults to `{"d_vectors": 0, "speaker_ids": None}`.
  
  Shapes:
      - x: :math:`[B, T_max]`
      - x_lengths: :math:`[B]`
      - y_lengths: :math:`[B]`
      - y: :math:`[B, T_max2]`
      - dr: :math:`[B, T_max]`
      - g: :math:`[B, C]`
      - pitch: :math:`[B, 1, T]`
code: def forward(
      self,
      x: torch.LongTensor,
      x_lengths: torch.LongTensor,
      y_lengths: torch.LongTensor,
      y: torch.FloatTensor = None,
      dr: torch.IntTensor = None,
      pitch: torch.FloatTensor = None,
      energy: torch.FloatTensor = None,
      aux_input: Dict = {
          "d_vectors": None,
          "speaker_ids": None,
      },  # pylint: disable=unused-argument
  ) -> Dict:
      """Model's forward pass.
  
      Args:
          x (torch.LongTensor): Input character sequences.
          x_lengths (torch.LongTensor): Input sequence lengths.
          y_lengths (torch.LongTensor): Output sequnce lengths. Defaults to None.
          y (torch.FloatTensor): Spectrogram frames. Only used when the alignment network is on. Defaults to None.
          dr (torch.IntTensor): Character durations over the spectrogram frames. Only used when the alignment network is off. Defaults to None.
          pitch (torch.FloatTensor): Pitch values for each spectrogram frame. Only used when the pitch predictor is on. Defaults to None.
          energy (torch.FloatTensor): energy values for each spectrogram frame. Only used when the energy predictor is on. Defaults to None.
          aux_input (Dict): Auxiliary model inputs for multi-speaker training. Defaults to `{"d_vectors": 0, "speaker_ids": None}`.
  
      Shapes:
          - x: :math:`[B, T_max]`
          - x_lengths: :math:`[B]`
          - y_lengths: :math:`[B]`
          - y: :math:`[B, T_max2]`
          - dr: :math:`[B, T_max]`
          - g: :math:`[B, C]`
          - pitch: :math:`[B, 1, T]`
      """
      g = self._set_speaker_input(aux_input)
      # compute sequence masks
      y_mask = torch.unsqueeze(
          sequence_mask(y_lengths, None), 1
      ).float()
      x_mask = torch.unsqueeze(
          sequence_mask(x_lengths, x.shape[1]), 1
      ).float()
      # encoder pass
      o_en, x_mask, g, x_emb = self._forward_encoder(x, x_mask, g)
      # duration predictor pass
      if self.args.detach_duration_predictor:
          o_dr_log = self.duration_predictor(o_en.detach(), x_mask)
      else:
          o_dr_log = self.duration_predictor(o_en, x_mask)
      o_dr = torch.clamp(torch.exp(o_dr_log) - 1, 0, self.max_duration)
      # generate attn mask from predicted durations
      o_attn = self.generate_attn(o_dr.squeeze(1), x_mask)
      # aligner
      o_alignment_dur = None
      alignment_soft = None
      alignment_logprob = None
      alignment_mas = None
      if self.use_aligner:
          (
              o_alignment_dur,
              alignment_soft,
              alignment_logprob,
              alignment_mas,
          ) = self._forward_aligner(x_emb, y, x_mask, y_mask)
          alignment_soft = alignment_soft.transpose(1, 2)
          alignment_mas = alignment_mas.transpose(1, 2)
          dr = o_alignment_dur
      # pitch predictor pass
      o_pitch = None
      avg_pitch = None
      if self.args.use_pitch:
          (
              o_pitch_emb,
              o_pitch,
              avg_pitch,
          ) = self._forward_pitch_predictor(o_en, x_mask, pitch, dr)
          o_en = o_en + o_pitch_emb
      # energy predictor pass
      o_energy = None
      avg_energy = None
      if self.args.use_energy:
          (
              o_energy_emb,
              o_energy,
              avg_energy,
          ) = self._forward_energy_predictor(o_en, x_mask, energy, dr)
          o_en = o_en + o_energy_emb
      # decoder pass
      o_de, attn = self._forward_decoder(
          o_en, dr, x_mask, y_lengths, g=None
      )  # TODO: maybe pass speaker embedding (g) too
      outputs = {
          "model_outputs": o_de,  # [B, T, C]
          "durations_log": o_dr_log.squeeze(1),  # [B, T]
          "durations": o_dr.squeeze(1),  # [B, T]
          "attn_durations": o_attn,  # for visualization [B, T_en, T_de']
          "pitch_avg": o_pitch,
          "pitch_avg_gt": avg_pitch,
          "energy_avg": o_energy,
          "energy_avg_gt": avg_energy,
          "alignments": attn,  # [B, T_de, T_en]
          "alignment_soft": alignment_soft,
          "alignment_mas": alignment_mas,
          "o_alignment_dur": o_alignment_dur,
          "alignment_logprob": alignment_logprob,
          "x_mask": x_mask,
          "y_mask": y_mask,
      }
      return outputs
  
imports: from dataclasses import dataclass, field
  from typing import Dict, List, Tuple, Union
  import torch
  from coqpit import Coqpit
  from torch import nn
  from torch.cuda.amp.autocast_mode import autocast
  from TTS.tts.layers.feed_forward.decoder import Decoder
  from TTS.tts.layers.feed_forward.encoder import Encoder
  from TTS.tts.layers.generic.aligner import AlignmentNetwork
  from TTS.tts.layers.generic.pos_encoding import PositionalEncoding
  from TTS.tts.layers.glow_tts.duration_predictor import DurationPredictor
  from TTS.tts.models.base_tts import BaseTTS
  from TTS.tts.utils.helpers import average_over_durations, generate_path, maximum_path, sequence_mask
  from TTS.tts.utils.speakers import SpeakerManager
  from TTS.tts.utils.text.tokenizer import TTSTokenizer
  from TTS.tts.utils.visual import plot_alignment, plot_avg_energy, plot_avg_pitch, plot_spectrogram
  from TTS.utils.io import load_fsspec
label_desc: Use image node_id 12 for calling the ForwardTTS obj's underlying member method code with example usage: obj.forward(x, x_lengths, y_lengths, y, dr, pitch, energy, aux_input) and returns: outputs