class_docstr: Conformer encoder module.
  
  Args:
      input_size (int): Input dimension.
      output_size (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.
      attention_dropout_rate (float): Dropout rate in attention.
      positional_dropout_rate (float): Dropout rate after adding positional encoding.
      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.
      rel_pos_type (str): Whether to use the latest relative positional encoding or
          the legacy one. The legacy relative positional encoding will be deprecated
          in the future. More Details can be found in
          https://github.com/espnet/espnet/pull/2816.
      encoder_pos_enc_layer_type (str): Encoder positional encoding layer type.
      encoder_attn_layer_type (str): Encoder attention layer type.
      activation_type (str): Encoder activation function type.
      macaron_style (bool): Whether to use macaron style for positionwise layer.
      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.
class_docstr_tok: ["Conformer","encoder","module",".","Args",":","input_size","(","int",")",":","Input","dimension",".","output_size","(","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",".","attention_dropout_rate","(","float",")",":","Dropout","rate","in","attention",".","positional_dropout_rate","(","float",")",":","Dropout","rate","after","adding","positional","encoding",".","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",".","rel_pos_type","(","str",")",":","Whether","to","use","the","latest","relative","positional","encoding","or","the","legacy","one",".","The","legacy","relative","positional","encoding","will","be","deprecated","in","the","future",".","More","Details","can","be","found","in","https",":","\/\/github.com\/espnet\/espnet\/pull\/2816",".","encoder_pos_enc_layer_type","(","str",")",":","Encoder","positional","encoding","layer","type",".","encoder_attn_layer_type","(","str",")",":","Encoder","attention","layer","type",".","activation_type","(","str",")",":","Encoder","activation","function","type",".","macaron_style","(","bool",")",":","Whether","to","use","macaron","style","for","positionwise","layer",".","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","."]
docstr: Calculate forward propagation.
  
  Args:
      xs_pad (torch.Tensor): Input tensor (#batch, L, input_size).
      ilens (torch.Tensor): Input length (#batch).
      prev_states (torch.Tensor): Not to be used now.
      ctc (CTC): ctc module for intermediate CTC loss
      return_all_hs (bool): whether to return all hidden states
  
  Returns:
      torch.Tensor: Output tensor (#batch, L, output_size).
      torch.Tensor: Output length (#batch).
      torch.Tensor: Not to be used now.
docstr_tok: ["Calculate","forward","propagation",".","Args",":","xs_pad","(","torch.Tensor",")",":","Input","tensor","(","#","batch",",","L",",","input_size",")",".","ilens","(","torch.Tensor",")",":","Input","length","(","#","batch",")",".","prev_states","(","torch.Tensor",")",":","Not","to","be","used","now",".","ctc","(","CTC",")",":","ctc","module","for","intermediate","CTC","loss","return_all_hs","(","bool",")",":","whether","to","return","all","hidden","states","Returns",":","torch.Tensor",":","Output","tensor","(","#","batch",",","L",",","output_size",")",".","torch.Tensor",":","Output","length","(","#","batch",")",".","torch.Tensor",":","Not","to","be","used","now","."]
code: def forward(
      self,
      xs_pad: torch.Tensor,
      ilens: torch.Tensor,
      prev_states: torch.Tensor = None,
      ctc: CTC = None,
      return_all_hs: bool = False,
  ) -> Tuple[torch.Tensor, torch.Tensor, Optional[torch.Tensor]]:
      """Calculate forward propagation.
  
      Args:
          xs_pad (torch.Tensor): Input tensor (#batch, L, input_size).
          ilens (torch.Tensor): Input length (#batch).
          prev_states (torch.Tensor): Not to be used now.
          ctc (CTC): ctc module for intermediate CTC loss
          return_all_hs (bool): whether to return all hidden states
  
      Returns:
          torch.Tensor: Output tensor (#batch, L, output_size).
          torch.Tensor: Output length (#batch).
          torch.Tensor: Not to be used now.
  
      """
      masks = (~make_pad_mask(ilens)[:, None, :]).to(xs_pad.device)
  
      if (
          isinstance(self.embed, Conv2dSubsampling)
          or isinstance(self.embed, Conv2dSubsampling1)
          or isinstance(self.embed, Conv2dSubsampling2)
          or isinstance(self.embed, Conv2dSubsampling6)
          or isinstance(self.embed, Conv2dSubsampling8)
      ):
          short_status, limit_size = check_short_utt(
              self.embed, xs_pad.size(1)
          )
          if short_status:
              raise TooShortUttError(
                  f"has {xs_pad.size(1)} frames and is too short for subsampling "
                  + f"(it needs more than {limit_size} frames), return empty results",
                  xs_pad.size(1),
                  limit_size,
              )
          xs_pad, masks = self.embed(xs_pad, masks)
      else:
          xs_pad = self.embed(xs_pad)
  
      intermediate_outs = []
      if len(self.interctc_layer_idx) == 0:
          for layer_idx, encoder_layer in enumerate(self.encoders):
              xs_pad, masks = encoder_layer(xs_pad, masks)
              if return_all_hs:
                  if isinstance(xs_pad, tuple):
                      intermediate_outs.append(xs_pad[0])
                  else:
                      intermediate_outs.append(xs_pad)
      else:
          for layer_idx, encoder_layer in enumerate(self.encoders):
              xs_pad, masks = encoder_layer(xs_pad, masks)
  
              if layer_idx + 1 in self.interctc_layer_idx:
                  encoder_out = xs_pad
                  if isinstance(encoder_out, tuple):
                      encoder_out = encoder_out[0]
  
                  # intermediate outputs are also normalized
                  if self.normalize_before:
                      encoder_out = self.after_norm(encoder_out)
  
                  intermediate_outs.append((layer_idx + 1, encoder_out))
  
                  if self.interctc_use_conditioning:
                      ctc_out = ctc.softmax(encoder_out)
  
                      if isinstance(xs_pad, tuple):
                          x, pos_emb = xs_pad
                          x = x + self.conditioning_layer(ctc_out)
                          xs_pad = (x, pos_emb)
                      else:
                          xs_pad = xs_pad + self.conditioning_layer(
                              ctc_out
                          )
  
                  if self.ctc_trim and ctc is not None:
                      ctc_out = ctc.softmax(encoder_out)
  
                      if isinstance(xs_pad, tuple):
                          x, pos_emb = xs_pad
                          x, masks, pos_emb = trim_by_ctc_posterior(
                              x, ctc_out, masks, pos_emb
                          )
                          xs_pad = (x, pos_emb)
                      else:
                          x, masks, _ = trim_by_ctc_posterior(
                              x, ctc_out, masks
                          )
  
      if isinstance(xs_pad, tuple):
          xs_pad = xs_pad[0]
      if self.normalize_before:
          xs_pad = self.after_norm(xs_pad)
  
      olens = masks.squeeze(1).sum(1)
      if len(intermediate_outs) > 0:
          return (xs_pad, intermediate_outs), olens, None
      return xs_pad, olens, None
  
imports: import logging
  from typing import List, Optional, Tuple, Union
  import torch
  from typeguard import check_argument_types
  from espnet2.asr.ctc import CTC
  from espnet2.asr.encoder.abs_encoder import AbsEncoder
  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, make_pad_mask, trim_by_ctc_posterior
  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, Conv2dSubsampling1, Conv2dSubsampling2, Conv2dSubsampling6, Conv2dSubsampling8, TooShortUttError, check_short_utt
label_desc: Use image node_id 3 for calling the ConformerEncoder obj's underlying member method code with example usage: obj.forward(xs_pad, ilens, prev_states, ctc, return_all_hs) and returns: xs_pad,  olens,  None, xs_pad,  intermediate_outs,  olens,  None