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: Aligner forward pass.
  
  1. Compute a mask to apply to the attention map.
  2. Run the alignment network.
  3. Apply MAS to compute the hard alignment map.
  4. Compute the durations from the hard alignment map.
  
  Args:
      x (torch.FloatTensor): Input sequence.
      y (torch.FloatTensor): Output sequence.
      x_mask (torch.IntTensor): Input sequence mask.
      y_mask (torch.IntTensor): Output sequence mask.
  
  Returns:
      Tuple[torch.IntTensor, torch.FloatTensor, torch.FloatTensor, torch.FloatTensor]:
          Durations from the hard alignment map, soft alignment potentials, log scale alignment potentials,
          hard alignment map.
  
  Shapes:
      - x: :math:`[B, T_en, C_en]`
      - y: :math:`[B, T_de, C_de]`
      - x_mask: :math:`[B, 1, T_en]`
      - y_mask: :math:`[B, 1, T_de]`
  
      - o_alignment_dur: :math:`[B, T_en]`
      - alignment_soft: :math:`[B, T_en, T_de]`
      - alignment_logprob: :math:`[B, 1, T_de, T_en]`
      - alignment_mas: :math:`[B, T_en, T_de]`
code: def _forward_aligner(
      self,
      x: torch.FloatTensor,
      y: torch.FloatTensor,
      x_mask: torch.IntTensor,
      y_mask: torch.IntTensor,
  ) -> Tuple[
      torch.IntTensor,
      torch.FloatTensor,
      torch.FloatTensor,
      torch.FloatTensor,
  ]:
      """Aligner forward pass.
  
      1. Compute a mask to apply to the attention map.
      2. Run the alignment network.
      3. Apply MAS to compute the hard alignment map.
      4. Compute the durations from the hard alignment map.
  
      Args:
          x (torch.FloatTensor): Input sequence.
          y (torch.FloatTensor): Output sequence.
          x_mask (torch.IntTensor): Input sequence mask.
          y_mask (torch.IntTensor): Output sequence mask.
  
      Returns:
          Tuple[torch.IntTensor, torch.FloatTensor, torch.FloatTensor, torch.FloatTensor]:
              Durations from the hard alignment map, soft alignment potentials, log scale alignment potentials,
              hard alignment map.
  
      Shapes:
          - x: :math:`[B, T_en, C_en]`
          - y: :math:`[B, T_de, C_de]`
          - x_mask: :math:`[B, 1, T_en]`
          - y_mask: :math:`[B, 1, T_de]`
  
          - o_alignment_dur: :math:`[B, T_en]`
          - alignment_soft: :math:`[B, T_en, T_de]`
          - alignment_logprob: :math:`[B, 1, T_de, T_en]`
          - alignment_mas: :math:`[B, T_en, T_de]`
      """
      attn_mask = torch.unsqueeze(x_mask, -1) * torch.unsqueeze(
          y_mask, 2
      )
      alignment_soft, alignment_logprob = self.aligner(
          y.transpose(1, 2), x.transpose(1, 2), x_mask, None
      )
      alignment_mas = maximum_path(
          alignment_soft.squeeze(1).transpose(1, 2).contiguous(),
          attn_mask.squeeze(1).contiguous(),
      )
      o_alignment_dur = torch.sum(alignment_mas, -1).int()
      alignment_soft = alignment_soft.squeeze(1).transpose(1, 2)
      return (
          o_alignment_dur,
          alignment_soft,
          alignment_logprob,
          alignment_mas,
      )
  
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 10 for calling the ForwardTTS obj's underlying member method code with example usage: obj._forward_aligner(x, y, x_mask, y_mask) and returns: o_alignment_dur,  alignment_soft,  alignment_logprob,  alignment_mas