class_docstr: Conformer encoder module.
  
  Args:
      idim (int): Input dimension.
      attention_dim (int): Dimension of attention.
      attention_heads (int): The number of heads of multi head attention.
      linear_units (int): The number of units of position-wise feed forward.
      num_blocks (int): The number of decoder blocks.
      dropout_rate (float): Dropout rate.
      positional_dropout_rate (float): Dropout rate after adding positional encoding.
      attention_dropout_rate (float): Dropout rate in attention.
      input_layer (Union[str, torch.nn.Module]): Input layer type.
      normalize_before (bool): Whether to use layer_norm before the first block.
      concat_after (bool): Whether to concat attention layer's input and output.
          if True, additional linear will be applied.
          i.e. x -> x + linear(concat(x, att(x)))
          if False, no additional linear will be applied. i.e. x -> x + att(x)
      positionwise_layer_type (str): "linear", "conv1d", or "conv1d-linear".
      positionwise_conv_kernel_size (int): Kernel size of positionwise conv1d layer.
      macaron_style (bool): Whether to use macaron style for positionwise layer.
      pos_enc_layer_type (str): Encoder positional encoding layer type.
      selfattention_layer_type (str): Encoder attention layer type.
      activation_type (str): Encoder activation function type.
      use_cnn_module (bool): Whether to use convolution module.
      zero_triu (bool): Whether to zero the upper triangular part of attention matrix.
      cnn_module_kernel (int): Kernerl size of convolution module.
      padding_idx (int): Padding idx for input_layer=embed.
      stochastic_depth_rate (float): Maximum probability to skip the encoder layer.
      intermediate_layers (Union[List[int], None]): indices of intermediate CTC layer.
          indices start from 1.
          if not None, intermediate outputs are returned (which changes return type
          signature.)
class_docstr_tok: ["Conformer","encoder","module",".","Args",":","idim","(","int",")",":","Input","dimension",".","attention_dim","(","int",")",":","Dimension","of","attention",".","attention_heads","(","int",")",":","The","number","of","heads","of","multi","head","attention",".","linear_units","(","int",")",":","The","number","of","units","of","position-wise","feed","forward",".","num_blocks","(","int",")",":","The","number","of","decoder","blocks",".","dropout_rate","(","float",")",":","Dropout","rate",".","positional_dropout_rate","(","float",")",":","Dropout","rate","after","adding","positional","encoding",".","attention_dropout_rate","(","float",")",":","Dropout","rate","in","attention",".","input_layer","(","Union","[","str",",","torch.nn.Module","]",")",":","Input","layer","type",".","normalize_before","(","bool",")",":","Whether","to","use","layer_norm","before","the","first","block",".","concat_after","(","bool",")",":","Whether","to","concat","attention","layer","'s","input","and","output",".","if","True",",","additional","linear","will","be","applied",".","i.e",".","x","-",">","x","+","linear","(","concat","(","x",",","att","(","x",")",")",")","if","False",",","no","additional","linear","will","be","applied",".","i.e",".","x","-",">","x","+","att","(","x",")","positionwise_layer_type","(","str",")",":","``","linear","''",",","``","conv1d","''",",","or","``","conv1d-linear","''",".","positionwise_conv_kernel_size","(","int",")",":","Kernel","size","of","positionwise","conv1d","layer",".","macaron_style","(","bool",")",":","Whether","to","use","macaron","style","for","positionwise","layer",".","pos_enc_layer_type","(","str",")",":","Encoder","positional","encoding","layer","type",".","selfattention_layer_type","(","str",")",":","Encoder","attention","layer","type",".","activation_type","(","str",")",":","Encoder","activation","function","type",".","use_cnn_module","(","bool",")",":","Whether","to","use","convolution","module",".","zero_triu","(","bool",")",":","Whether","to","zero","the","upper","triangular","part","of","attention","matrix",".","cnn_module_kernel","(","int",")",":","Kernerl","size","of","convolution","module",".","padding_idx","(","int",")",":","Padding","idx","for","input_layer=embed",".","stochastic_depth_rate","(","float",")",":","Maximum","probability","to","skip","the","encoder","layer",".","intermediate_layers","(","Union","[","List","[","int","]",",","None","]",")",":","indices","of","intermediate","CTC","layer",".","indices","start","from","1.","if","not","None",",","intermediate","outputs","are","returned","(","which","changes","return","type","signature",".",")"]
docstr: Encode input sequence.
  
  Args:
      xs (torch.Tensor): Input tensor (#batch, time, idim).
      masks (torch.Tensor): Mask tensor (#batch, 1, time).
  
  Returns:
      torch.Tensor: Output tensor (#batch, time, attention_dim).
      torch.Tensor: Mask tensor (#batch, 1, time).
docstr_tok: ["Encode","input","sequence",".","Args",":","xs","(","torch.Tensor",")",":","Input","tensor","(","#","batch",",","time",",","idim",")",".","masks","(","torch.Tensor",")",":","Mask","tensor","(","#","batch",",","1",",","time",")",".","Returns",":","torch.Tensor",":","Output","tensor","(","#","batch",",","time",",","attention_dim",")",".","torch.Tensor",":","Mask","tensor","(","#","batch",",","1",",","time",")","."]
code: def forward(self, xs, masks):
      """Encode input sequence.
  
      Args:
          xs (torch.Tensor): Input tensor (#batch, time, idim).
          masks (torch.Tensor): Mask tensor (#batch, 1, time).
  
      Returns:
          torch.Tensor: Output tensor (#batch, time, attention_dim).
          torch.Tensor: Mask tensor (#batch, 1, time).
  
      """
      if isinstance(self.embed, (Conv2dSubsampling, VGG2L)):
          xs, masks = self.embed(xs, masks)
      else:
          xs = self.embed(xs)
  
      if self.intermediate_layers is None:
          xs, masks = self.encoders(xs, masks)
      else:
          intermediate_outputs = []
          for layer_idx, encoder_layer in enumerate(self.encoders):
              xs, masks = encoder_layer(xs, masks)
  
              if (
                  self.intermediate_layers is not None
                  and layer_idx + 1 in self.intermediate_layers
              ):
                  # intermediate branches also require normalization.
                  encoder_output = xs
                  if isinstance(encoder_output, tuple):
                      encoder_output = encoder_output[0]
  
                  if self.normalize_before:
                      encoder_output = self.after_norm(encoder_output)
  
                  intermediate_outputs.append(encoder_output)
  
                  if self.use_conditioning:
                      intermediate_result = self.ctc_softmax(
                          encoder_output
                      )
  
                      if isinstance(xs, tuple):
                          x, pos_emb = xs[0], xs[1]
                          x = x + self.conditioning_layer(
                              intermediate_result
                          )
                          xs = (x, pos_emb)
                      else:
                          xs = xs + self.conditioning_layer(
                              intermediate_result
                          )
  
      if isinstance(xs, tuple):
          xs = xs[0]
  
      if self.normalize_before:
          xs = self.after_norm(xs)
  
      if self.intermediate_layers is not None:
          return xs, masks, intermediate_outputs
      return xs, masks
  
file_path: espnet/espnet/nets/pytorch_backend/conformer/encoder.py
imports: import logging
  import torch
  from espnet.nets.pytorch_backend.conformer.convolution import ConvolutionModule
  from espnet.nets.pytorch_backend.conformer.encoder_layer import EncoderLayer
  from espnet.nets.pytorch_backend.nets_utils import get_activation
  from espnet.nets.pytorch_backend.transducer.vgg2l import VGG2L
  from espnet.nets.pytorch_backend.transformer.attention import LegacyRelPositionMultiHeadedAttention, MultiHeadedAttention, RelPositionMultiHeadedAttention
  from espnet.nets.pytorch_backend.transformer.embedding import LegacyRelPositionalEncoding, PositionalEncoding, RelPositionalEncoding, ScaledPositionalEncoding
  from espnet.nets.pytorch_backend.transformer.layer_norm import LayerNorm
  from espnet.nets.pytorch_backend.transformer.multi_layer_conv import Conv1dLinear, MultiLayeredConv1d
  from espnet.nets.pytorch_backend.transformer.positionwise_feed_forward import PositionwiseFeedForward
  from espnet.nets.pytorch_backend.transformer.repeat import repeat
  from espnet.nets.pytorch_backend.transformer.subsampling import Conv2dSubsampling
label_desc: Use image node_id 2 for calling the Encoder obj's underlying member method code with example usage: obj.forward(xs, masks) and returns: xs,  masks, xs,  masks,  intermediate_outputs