class_docstr: Glow-TTS encoder module.
  
  embedding -> <prenet> -> encoder_module -> <postnet> --> proj_mean
                                                       |
                                                       |-> proj_var
                                                       |
                                                       |-> concat -> duration_predictor
                                                              ↑
                                                        speaker_embed
  Args:
      num_chars (int): number of characters.
      out_channels (int): number of output channels.
      hidden_channels (int): encoder's embedding size.
      hidden_channels_ffn (int): transformer's feed-forward channels.
      kernel_size (int): kernel size for conv layers and duration predictor.
      dropout_p (float): dropout rate for any dropout layer.
      mean_only (bool): if True, output only mean values and use constant std.
      use_prenet (bool): if True, use pre-convolutional layers before transformer layers.
      c_in_channels (int): number of channels in conditional input.
  
  Shapes:
      - input: (B, T, C)
  
  Notes:
      suggested encoder params...
  
      for encoder_type == 'rel_pos_transformer'
          encoder_params={
              'kernel_size':3,
              'dropout_p': 0.1,
              'num_layers': 6,
              'num_heads': 2,
              'hidden_channels_ffn': 768,  # 4 times the hidden_channels
              'input_length': None
          }
  
      for encoder_type == 'gated_conv'
          encoder_params={
              'kernel_size':5,
              'dropout_p': 0.1,
              'num_layers': 9,
          }
  
      for encoder_type == 'residual_conv_bn'
          encoder_params={
              "kernel_size": 4,
              "dilations": [1, 2, 4, 1, 2, 4, 1, 2, 4, 1, 2, 4, 1],
              "num_conv_blocks": 2,
              "num_res_blocks": 13
          }
  
       for encoder_type == 'time_depth_separable'
          encoder_params={
              "kernel_size": 5,
              'num_layers': 9,
          }
class_docstr_tok: ["Glow-TTS","encoder","module",".","embedding","-",">","<","prenet",">","-",">","encoder_module","-",">","<","postnet",">","--",">","proj_mean","|","|-",">","proj_var","|","|-",">","concat","-",">","duration_predictor","\u2191","speaker_embed","Args",":","num_chars","(","int",")",":","number","of","characters",".","out_channels","(","int",")",":","number","of","output","channels",".","hidden_channels","(","int",")",":","encoder","'s","embedding","size",".","hidden_channels_ffn","(","int",")",":","transformer","'s","feed-forward","channels",".","kernel_size","(","int",")",":","kernel","size","for","conv","layers","and","duration","predictor",".","dropout_p","(","float",")",":","dropout","rate","for","any","dropout","layer",".","mean_only","(","bool",")",":","if","True",",","output","only","mean","values","and","use","constant","std",".","use_prenet","(","bool",")",":","if","True",",","use","pre-convolutional","layers","before","transformer","layers",".","c_in_channels","(","int",")",":","number","of","channels","in","conditional","input",".","Shapes",":","-","input",":","(","B",",","T",",","C",")","Notes",":","suggested","encoder","params","...","for","encoder_type","==","'rel_pos_transformer'","encoder_params=","{","'kernel_size':3",",","'dropout_p","'",":","0.1",",","'num_layers","'",":","6",",","'num_heads","'",":","2",",","'hidden_channels_ffn","'",":","768",",","#","4","times","the","hidden_channels","'input_length","'",":","None","}","for","encoder_type","==","'gated_conv'","encoder_params=","{","'kernel_size':5",",","'dropout_p","'",":","0.1",",","'num_layers","'",":","9",",","}","for","encoder_type","==","'residual_conv_bn'","encoder_params=","{","``","kernel_size","''",":","4",",","``","dilations","''",":","[","1",",","2",",","4",",","1",",","2",",","4",",","1",",","2",",","4",",","1",",","2",",","4",",","1","]",",","``","num_conv_blocks","''",":","2",",","``","num_res_blocks","''",":","13","}","for","encoder_type","==","'time_depth_separable'","encoder_params=","{","``","kernel_size","''",":","5",",","'num_layers","'",":","9",",","}"]
docstr: Shapes:
      x: [B, C, T]
      x_lengths: [B]
      g (optional): [B, 1, T]
docstr_tok: ["Shapes",":","x",":","[","B",",","C",",","T","]","x_lengths",":","[","B","]","g","(","optional",")",":","[","B",",","1",",","T","]"]
code: def forward(self, x, x_lengths, g=None):
      """
      Shapes:
          x: [B, C, T]
          x_lengths: [B]
          g (optional): [B, 1, T]
      """
      # embedding layer
      # [B ,T, D]
      x = self.emb(x) * math.sqrt(self.hidden_channels)
      # [B, D, T]
      x = torch.transpose(x, 1, -1)
      # compute input sequence mask
      x_mask = torch.unsqueeze(
          sequence_mask(x_lengths, x.size(2)), 1
      ).to(x.dtype)
      # prenet
      if hasattr(self, "prenet") and self.use_prenet:
          x = self.prenet(x, x_mask)
      # encoder
      x = self.encoder(x, x_mask)
      # postnet
      if hasattr(self, "postnet"):
          x = self.postnet(x) * x_mask
      # set duration predictor input
      if g is not None:
          g_exp = g.expand(-1, -1, x.size(-1))
          x_dp = torch.cat([torch.detach(x), g_exp], 1)
      else:
          x_dp = torch.detach(x)
      # final projection layer
      x_m = self.proj_m(x) * x_mask
      if not self.mean_only:
          x_logs = self.proj_s(x) * x_mask
      else:
          x_logs = torch.zeros_like(x_m)
      # duration predictor
      logw = self.duration_predictor(x_dp, x_mask)
      return x_m, x_logs, logw, x_mask
  
file_path: TTS/TTS/tts/layers/glow_tts/encoder.py
imports: import math
  import torch
  from torch import nn
  from TTS.tts.layers.glow_tts.transformer import RelativePositionTransformer
  from TTS.tts.layers.generic.gated_conv import GatedConvBlock
  from TTS.tts.utils.generic_utils import sequence_mask
  from TTS.tts.layers.glow_tts.glow import ResidualConv1dLayerNormBlock
  from TTS.tts.layers.glow_tts.duration_predictor import DurationPredictor
  from TTS.tts.layers.generic.time_depth_sep_conv import TimeDepthSeparableConvBlock
  from TTS.tts.layers.generic.res_conv_bn import ResidualConv1dBNBlock
label_desc: Use image node_id 2 for calling the Encoder obj's underlying member method code with example usage: obj.forward(x, x_lengths, g) and returns: x_m,  x_logs,  logw,  x_mask