class_docstr: Conformer Encoder for speech translation based on https://arxiv.org/abs/2005.08100
docstr: Args:
      src_tokens: Input source tokens Tensor of shape B X T X C
      src_lengths: Lengths Tensor corresponding to input source tokens
      return_all_hiddens: If true will append the self attention states to the encoder states
  Returns:
      encoder_out: Tensor of shape B X T X C
      encoder_padding_mask: Optional Tensor with mask
      encoder_embedding: Optional Tensor. Always empty here
      encoder_states: List of Optional Tensors wih self attention states
      src_tokens: Optional Tensor. Always empty here
      src_lengths: Optional Tensor. Always empty here
docstr_tok: ["Args",":","src_tokens",":","Input","source","tokens","Tensor","of","shape","B","X","T","X","C","src_lengths",":","Lengths","Tensor","corresponding","to","input","source","tokens","return_all_hiddens",":","If","true","will","append","the","self","attention","states","to","the","encoder","states","Returns",":","encoder_out",":","Tensor","of","shape","B","X","T","X","C","encoder_padding_mask",":","Optional","Tensor","with","mask","encoder_embedding",":","Optional","Tensor",".","Always","empty","here","encoder_states",":","List","of","Optional","Tensors","wih","self","attention","states","src_tokens",":","Optional","Tensor",".","Always","empty","here","src_lengths",":","Optional","Tensor",".","Always","empty","here"]
code: def _forward(self, src_tokens, src_lengths, return_all_hiddens=False):
      """
      Args:
          src_tokens: Input source tokens Tensor of shape B X T X C
          src_lengths: Lengths Tensor corresponding to input source tokens
          return_all_hiddens: If true will append the self attention states to the encoder states
      Returns:
          encoder_out: Tensor of shape B X T X C
          encoder_padding_mask: Optional Tensor with mask
          encoder_embedding: Optional Tensor. Always empty here
          encoder_states: List of Optional Tensors wih self attention states
          src_tokens: Optional Tensor. Always empty here
          src_lengths: Optional Tensor. Always empty here
      """
      x, input_lengths = self.subsample(
          src_tokens, src_lengths
      )  # returns T X B X C
      encoder_padding_mask = lengths_to_padding_mask(input_lengths)
      x = self.embed_scale * x
      if self.pos_enc_type == "rel_pos":
          positions = self.embed_positions(x)
  
      elif self.pos_enc_type == "rope":
          positions = None
  
      else:
          positions = self.embed_positions(
              encoder_padding_mask
          ).transpose(0, 1)
          x += positions
          positions = None
  
      x = self.linear(x)
      x = self.dropout(x)
      encoder_states = []
  
      # x is T X B X C
      for layer in self.conformer_layers:
          x, _ = layer(x, encoder_padding_mask, positions)
          if return_all_hiddens:
              encoder_states.append(x)
  
      return {
          "encoder_out": [x],  # T x B x C
          "encoder_padding_mask": [encoder_padding_mask]
          if encoder_padding_mask.any()
          else [],  # B x T
          "encoder_embedding": [],  # B x T x C
          "encoder_states": encoder_states,  # List[T x B x C]
          "src_tokens": [],
          "src_lengths": [],
      }
  
imports: import logging
  import math
  from pathlib import Path
  import torch
  from fairseq import checkpoint_utils
  from fairseq.data.data_utils import lengths_to_padding_mask
  from fairseq.models import FairseqEncoder, register_model, register_model_architecture
  from fairseq.models.speech_to_text.modules.convolution import Conv1dSubsampler, Conv2dSubsampler
  from fairseq.models.speech_to_text.s2t_transformer import S2TTransformerEncoder, S2TTransformerModel
  from fairseq.models.speech_to_text.s2t_transformer import base_architecture
  from fairseq.modules import PositionalEmbedding, RelPositionalEncoding
  from fairseq.modules.conformer_layer import ConformerEncoderLayer
label_desc: Use image node_id 2 for calling the S2TConformerEncoder obj's underlying member method code with example usage: obj._forward(src_tokens, src_lengths, return_all_hiddens) and returns: dict