class_docstr: Takes model parameters (modelConfig) from config file to initialize radtts module.
  Specify the type of training in the include_modules parameter. "decatnvpred" for decoder training. and "decatnunvbiasdpmvpredapm" for feature training
  n_speakers (int): Number of speakers
  n_speaker_dim (int): number of speakers dimension
  n_text (int): Symbols embedding size
  n_text_dim (int):
  n_flows (int):
  n_conv_layers_per_step (int): number of convolution layers per step
  dummy_speaker_embedding (bool):
  include_modules (string): A string that describes what to train. "decatnvpred" for decoder training. and "decatnunvbiasdpmvpredapm" for feature training.
  scaling_fn (string): scaling function
  decoder_use_partial_padding (Bool): Set this to True to add partial padding
  learn_alignments (Bool): set this to true to learn alignments
  attn_use_CTC (Bool): set True to use CTC
  n_f0_dims (int): number of Pitch dimension
  n_early_size (int):
  n_early_every (int):
  n_group_size (int):
  decoder_use_unvoiced_bias (bool):
  context_lstm_w_f0_and_energy (bool):
  use_first_order_features (bool):
  ap_pred_log_f0 (bool):
  dur_model_config: model configuration for duration
  f0_model_config: model configuration for Pitch
  energy_model_config: model configuration for energy
class_docstr_tok: ["Takes","model","parameters","(","modelConfig",")","from","config","file","to","initialize","radtts","module",".","Specify","the","type","of","training","in","the","include_modules","parameter",".","``","decatnvpred","''","for","decoder","training",".","and","``","decatnunvbiasdpmvpredapm","''","for","feature","training","n_speakers","(","int",")",":","Number","of","speakers","n_speaker_dim","(","int",")",":","number","of","speakers","dimension","n_text","(","int",")",":","Symbols","embedding","size","n_text_dim","(","int",")",":","n_flows","(","int",")",":","n_conv_layers_per_step","(","int",")",":","number","of","convolution","layers","per","step","dummy_speaker_embedding","(","bool",")",":","include_modules","(","string",")",":","A","string","that","describes","what","to","train",".","``","decatnvpred","''","for","decoder","training",".","and","``","decatnunvbiasdpmvpredapm","''","for","feature","training",".","scaling_fn","(","string",")",":","scaling","function","decoder_use_partial_padding","(","Bool",")",":","Set","this","to","True","to","add","partial","padding","learn_alignments","(","Bool",")",":","set","this","to","true","to","learn","alignments","attn_use_CTC","(","Bool",")",":","set","True","to","use","CTC","n_f0_dims","(","int",")",":","number","of","Pitch","dimension","n_early_size","(","int",")",":","n_early_every","(","int",")",":","n_group_size","(","int",")",":","decoder_use_unvoiced_bias","(","bool",")",":","context_lstm_w_f0_and_energy","(","bool",")",":","use_first_order_features","(","bool",")",":","ap_pred_log_f0","(","bool",")",":","dur_model_config",":","model","configuration","for","duration","f0_model_config",":","model","configuration","for","Pitch","energy_model_config",":","model","configuration","for","energy"]
code: def __init__(
      self,
      n_speakers,
      n_speaker_dim,
      n_text,
      n_text_dim,
      n_flows,
      n_conv_layers_per_step,
      n_mel_channels,
      dummy_speaker_embedding,
      n_early_size,
      n_early_every,
      n_group_size,
      affine_model,
      dur_model_config,
      f0_model_config,
      energy_model_config,
      v_model_config=None,
      include_modules="dec",
      scaling_fn="exp",
      matrix_decomposition="",
      learn_alignments=False,
      affine_activation="softplus",
      attn_use_CTC=True,
      use_context_lstm=False,
      context_lstm_norm=None,
      n_f0_dims=0,
      n_energy_avg_dims=0,
      context_lstm_w_f0_and_energy=True,
      use_first_order_features=False,
      unvoiced_bias_activation="",
      ap_pred_log_f0=False,
      **kwargs,
  ):
      super(RadTTSModule, self).__init__()
      assert n_early_size % 2 == 0
      self.n_mel_channels = n_mel_channels
      self.n_f0_dims = n_f0_dims  # >= 1 to trains with f0
      self.n_energy_avg_dims = (
          n_energy_avg_dims  # >= 1 trains with energy
      )
      self.decoder_use_partial_padding = kwargs[
          "decoder_use_partial_padding"
      ]
      self.n_speaker_dim = n_speaker_dim
      assert self.n_speaker_dim % 2 == 0
      self.speaker_embedding = torch.nn.Embedding(
          n_speakers, self.n_speaker_dim
      )
      self.embedding = torch.nn.Embedding(n_text, n_text_dim)
      self.flows = torch.nn.ModuleList()
      self.encoder = get_radtts_encoder(
          encoder_embedding_dim=n_text_dim
      )
      self.dummy_speaker_embedding = dummy_speaker_embedding
      self.learn_alignments = learn_alignments
      self.affine_activation = affine_activation
      self.include_modules = include_modules
      self.attn_use_CTC = bool(attn_use_CTC)
      self.use_context_lstm = bool(use_context_lstm)
      self.context_lstm_norm = context_lstm_norm
      self.context_lstm_w_f0_and_energy = context_lstm_w_f0_and_energy
      self.use_first_order_features = bool(use_first_order_features)
      self.decoder_use_unvoiced_bias = kwargs[
          "decoder_use_unvoiced_bias"
      ]
      self.ap_pred_log_f0 = ap_pred_log_f0
      self.ap_use_unvoiced_bias = kwargs["ap_use_unvoiced_bias"]
  
      if "atn" in include_modules or "dec" in include_modules:
          if self.learn_alignments:
              self.attention = ConvAttention(
                  n_mel_channels, self.n_speaker_dim, n_text_dim
              )
  
          self.n_flows = n_flows
          self.n_group_size = n_group_size
  
          n_flowstep_cond_dims = (
              self.n_speaker_dim
              + (n_text_dim + n_f0_dims + n_energy_avg_dims)
              * n_group_size
          )
  
          if self.use_context_lstm:
              n_in_context_lstm = (
                  self.n_speaker_dim + n_text_dim * n_group_size
              )
              n_context_lstm_hidden = int(
                  (self.n_speaker_dim + n_text_dim * n_group_size) / 2
              )
  
              if self.context_lstm_w_f0_and_energy:
                  n_in_context_lstm = (
                      n_f0_dims + n_energy_avg_dims + n_text_dim
                  )
                  n_in_context_lstm *= n_group_size
                  n_in_context_lstm += self.n_speaker_dim
                  n_flowstep_cond_dims = (
                      self.n_speaker_dim + n_text_dim * n_group_size
                  )
  
              self.context_lstm = BiLSTM(
                  input_size=n_in_context_lstm,
                  hidden_size=n_context_lstm_hidden,
                  num_layers=1,
              )
  
          if self.n_group_size > 1:
              self.unfold_params = {
                  "kernel_size": (n_group_size, 1),
                  "stride": n_group_size,
                  "padding": 0,
                  "dilation": 1,
              }
              self.unfold_mod = nn.Unfold(**self.unfold_params)
  
          self.exit_steps = []
          self.n_early_size = n_early_size
          n_mel_channels = n_mel_channels * n_group_size
  
          for i in range(self.n_flows):
              if i > 0 and i % n_early_every == 0:  # early exiting
                  n_mel_channels -= self.n_early_size
                  self.exit_steps.append(i)
  
              self.flows.append(
                  FlowStep(
                      n_mel_channels,
                      n_flowstep_cond_dims,
                      n_conv_layers_per_step,
                      affine_model,
                      scaling_fn,
                      matrix_decomposition,
                      affine_activation=affine_activation,
                      use_partial_padding=self.decoder_use_partial_padding,
                  )
              )
  
      if "dpm" in include_modules:
          dur_model_config["hparams"]["n_speaker_dim"] = n_speaker_dim
          self.dur_pred_layer = get_attribute_prediction_model(
              dur_model_config
          )
  
      self.use_unvoiced_bias = False
      self.use_vpred_module = False
      self.ap_use_voiced_embeddings = kwargs["ap_use_voiced_embeddings"]
  
      if self.decoder_use_unvoiced_bias or self.ap_use_unvoiced_bias:
          assert unvoiced_bias_activation in {"relu", "exp"}
          self.use_unvoiced_bias = True
          if unvoiced_bias_activation == "relu":
              unvbias_nonlin = nn.ReLU()
          elif unvoiced_bias_activation == "exp":
              unvbias_nonlin = ExponentialClass()
          else:
              exit(1)  # we won't reach here anyway due to the assertion
          self.unvoiced_bias_module = nn.Sequential(
              LinearNorm(n_text_dim, 1), unvbias_nonlin
          )
  
      # all situations in which the vpred module is necessary
      if (
          self.ap_use_voiced_embeddings
          or self.use_unvoiced_bias
          or "vpred" in include_modules
      ):
          self.use_vpred_module = True
  
      if self.use_vpred_module:
          v_model_config["hparams"]["n_speaker_dim"] = n_speaker_dim
          self.v_pred_module = get_attribute_prediction_model(
              v_model_config
          )
          # 4 embeddings, first two are scales, second two are biases
          if self.ap_use_voiced_embeddings:
              self.v_embeddings = torch.nn.Embedding(4, n_text_dim)
          self.v_pred_threshold = 0.5
  
      if "apm" in include_modules:
          f0_model_config["hparams"]["n_speaker_dim"] = n_speaker_dim
          energy_model_config["hparams"][
              "n_speaker_dim"
          ] = n_speaker_dim
          if self.use_first_order_features:
              f0_model_config["hparams"]["n_in_dim"] = 2
              energy_model_config["hparams"]["n_in_dim"] = 2
              if (
                  "spline_flow_params" in f0_model_config["hparams"]
                  and f0_model_config["hparams"]["spline_flow_params"]
                  is not None
              ):
                  f0_model_config["hparams"]["spline_flow_params"][
                      "n_in_channels"
                  ] = 2
              if (
                  "spline_flow_params" in energy_model_config["hparams"]
                  and energy_model_config["hparams"][
                      "spline_flow_params"
                  ]
                  is not None
              ):
                  energy_model_config["hparams"]["spline_flow_params"][
                      "n_in_channels"
                  ] = 2
          else:
              if (
                  "spline_flow_params" in f0_model_config["hparams"]
                  and f0_model_config["hparams"]["spline_flow_params"]
                  is not None
              ):
                  f0_model_config["hparams"]["spline_flow_params"][
                      "n_in_channels"
                  ] = f0_model_config["hparams"]["n_in_dim"]
              if (
                  "spline_flow_params" in energy_model_config["hparams"]
                  and energy_model_config["hparams"][
                      "spline_flow_params"
                  ]
                  is not None
              ):
                  energy_model_config["hparams"]["spline_flow_params"][
                      "n_in_channels"
                  ] = energy_model_config["hparams"]["n_in_dim"]
  
          self.f0_pred_module = get_attribute_prediction_model(
              f0_model_config
          )
          self.energy_pred_module = get_attribute_prediction_model(
              energy_model_config
          )
  
imports: import torch
  import torch.nn.functional
  from torch import nn
  from nemo.collections.tts.modules.attribute_prediction_model import get_attribute_prediction_model
  from nemo.collections.tts.modules.common import AffineTransformationLayer, BiLSTM, ConvAttention, ExponentialClass, Invertible1x1Conv, Invertible1x1ConvLUS, LinearNorm, get_radtts_encoder
  from nemo.collections.tts.parts.utils.helpers import get_mask_from_lengths, mas_width1, regulate_len
  from nemo.core.classes import Exportable, NeuralModule
  from nemo.core.neural_types.elements import Index, LengthsType, MelSpectrogramType, TokenDurationType, TokenIndex
  from nemo.core.neural_types.neural_type import NeuralType
label_desc: Use image node_id 1 to create a new RadTTSModule object from inherited base classes: NeuralModule, Exportable with example: obj = RadTTSModule(n_speakers, n_speaker_dim, n_text, n_text_dim, n_flows, n_conv_layers_per_step, n_mel_channels, dummy_speaker_embedding, n_early_size, n_early_every, n_group_size, affine_model, dur_model_config, f0_model_config, energy_model_config, v_model_config, include_modules, scaling_fn, matrix_decomposition, learn_alignments, affine_activation, attn_use_CTC, use_context_lstm, context_lstm_norm, n_f0_dims, n_energy_avg_dims, context_lstm_w_f0_and_energy, use_first_order_features, unvoiced_bias_activation, ap_pred_log_f0)