class_docstr: Transformer encoder consisting of *config.encoder_layers* self attention layers. Each layer is a
  [`Speech2TextEncoderLayer`].
  
  Args:
      config: Speech2TextConfig
      embed_tokens (nn.Embedding): output embedding
class_docstr_tok: ["Transformer","encoder","consisting","of","*","config.encoder_layers","*","self","attention","layers",".","Each","layer","is","a","[","`","Speech2TextEncoderLayer","`","]",".","Args",":","config",":","Speech2TextConfig","embed_tokens","(","nn.Embedding",")",":","output","embedding"]
docstr: Args:
      input_features (`torch.LongTensor` of shape `(batch_size, sequence_length, feature_size)`):
          Float values of fbank features extracted from the raw speech waveform. Raw speech waveform can be
          obtained by loading a `.flac` or `.wav` audio file into an array of type `List[float]` or a
          `numpy.ndarray`, *e.g.* via the soundfile library (`pip install soundfile`). To prepare the array into
          `input_features`, the [`AutoFeatureExtractor`] should be used for extracting the fbank features,
          padding and conversion into a tensor of type `torch.FloatTensor`. See
          [`~Speech2TextFeatureExtractor.__call__`]
      attention_mask (`torch.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
          Mask to avoid performing convolution and attention on padding token indices. Mask values selected in
          `[0, 1]`:
  
          - 1 for tokens that are **not masked**,
          - 0 for tokens that are **masked**.
  
          [What are attention masks?](../glossary#attention-mask)
      head_mask (`torch.Tensor` of shape `(encoder_layers, encoder_attention_heads)`, *optional*):
          Mask to nullify selected heads of the attention modules. Mask values selected in `[0, 1]`:
  
          - 1 indicates the head is **not masked**,
          - 0 indicates the head is **masked**.
  
      output_attentions (`bool`, *optional*):
          Whether or not to return the attentions tensors of all attention layers. See `attentions` under
          returned tensors for more detail.
      output_hidden_states (`bool`, *optional*):
          Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors
          for more detail.
      return_dict (`bool`, *optional*):
          Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
docstr_tok: ["Args",":","input_features","(","`","torch.LongTensor","`","of","shape","`","(","batch_size",",","sequence_length",",","feature_size",")","`",")",":","Float","values","of","fbank","features","extracted","from","the","raw","speech","waveform",".","Raw","speech","waveform","can","be","obtained","by","loading","a","`",".flac","`","or","`",".wav","`","audio","file","into","an","array","of","type","`","List","[","float","]","`","or","a","`","numpy.ndarray","`",",","*","e.g",".","*","via","the","soundfile","library","(","`","pip","install","soundfile","`",")",".","To","prepare","the","array","into","`","input_features","`",",","the","[","`","AutoFeatureExtractor","`","]","should","be","used","for","extracting","the","fbank","features",",","padding","and","conversion","into","a","tensor","of","type","`","torch.FloatTensor","`",".","See","[","`","~Speech2TextFeatureExtractor.__call__","`","]","attention_mask","(","`","torch.Tensor","`","of","shape","`","(","batch_size",",","sequence_length",")","`",",","*","optional","*",")",":","Mask","to","avoid","performing","convolution","and","attention","on","padding","token","indices",".","Mask","values","selected","in","`","[","0",",","1","]","`",":","-","1","for","tokens","that","are","*","*","not","masked","*","*",",","-","0","for","tokens","that","are","*","*","masked","*","*",".","[","What","are","attention","masks","?","]","(","..","\/glossary","#","attention-mask",")","head_mask","(","`","torch.Tensor","`","of","shape","`","(","encoder_layers",",","encoder_attention_heads",")","`",",","*","optional","*",")",":","Mask","to","nullify","selected","heads","of","the","attention","modules",".","Mask","values","selected","in","`","[","0",",","1","]","`",":","-","1","indicates","the","head","is","*","*","not","masked","*","*",",","-","0","indicates","the","head","is","*","*","masked","*","*",".","output_attentions","(","`","bool","`",",","*","optional","*",")",":","Whether","or","not","to","return","the","attentions","tensors","of","all","attention","layers",".","See","`","attentions","`","under","returned","tensors","for","more","detail",".","output_hidden_states","(","`","bool","`",",","*","optional","*",")",":","Whether","or","not","to","return","the","hidden","states","of","all","layers",".","See","`","hidden_states","`","under","returned","tensors","for","more","detail",".","return_dict","(","`","bool","`",",","*","optional","*",")",":","Whether","or","not","to","return","a","[","`","~utils.ModelOutput","`","]","instead","of","a","plain","tuple","."]
code: def forward(
      self,
      input_features,
      attention_mask=None,
      head_mask=None,
      output_attentions=None,
      output_hidden_states=None,
      return_dict=None,
  ):
      r"""
      Args:
          input_features (`torch.LongTensor` of shape `(batch_size, sequence_length, feature_size)`):
              Float values of fbank features extracted from the raw speech waveform. Raw speech waveform can be
              obtained by loading a `.flac` or `.wav` audio file into an array of type `List[float]` or a
              `numpy.ndarray`, *e.g.* via the soundfile library (`pip install soundfile`). To prepare the array into
              `input_features`, the [`AutoFeatureExtractor`] should be used for extracting the fbank features,
              padding and conversion into a tensor of type `torch.FloatTensor`. See
              [`~Speech2TextFeatureExtractor.__call__`]
          attention_mask (`torch.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
              Mask to avoid performing convolution and attention on padding token indices. Mask values selected in
              `[0, 1]`:
  
              - 1 for tokens that are **not masked**,
              - 0 for tokens that are **masked**.
  
              [What are attention masks?](../glossary#attention-mask)
          head_mask (`torch.Tensor` of shape `(encoder_layers, encoder_attention_heads)`, *optional*):
              Mask to nullify selected heads of the attention modules. Mask values selected in `[0, 1]`:
  
              - 1 indicates the head is **not masked**,
              - 0 indicates the head is **masked**.
  
          output_attentions (`bool`, *optional*):
              Whether or not to return the attentions tensors of all attention layers. See `attentions` under
              returned tensors for more detail.
          output_hidden_states (`bool`, *optional*):
              Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors
              for more detail.
          return_dict (`bool`, *optional*):
              Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
      """
      output_attentions = (
          output_attentions
          if output_attentions is not None
          else self.config.output_attentions
      )
      output_hidden_states = (
          output_hidden_states
          if output_hidden_states is not None
          else self.config.output_hidden_states
      )
      return_dict = (
          return_dict
          if return_dict is not None
          else self.config.use_return_dict
      )
      inputs_embeds = self.conv(input_features)
      inputs_embeds = self.embed_scale * inputs_embeds
  
      # subsample attention mask if necessary
      if attention_mask is not None:
          attention_mask = self._get_feature_vector_attention_mask(
              inputs_embeds.shape[1], attention_mask
          )
          padding_mask = attention_mask.ne(1).long()
      else:
          padding_mask = torch.zeros(
              inputs_embeds.shape[:2],
              dtype=torch.long,
              device=inputs_embeds.device,
          )
  
      embed_pos = self.embed_positions(padding_mask)
  
      hidden_states = inputs_embeds + embed_pos
      hidden_states = nn.functional.dropout(
          hidden_states, p=self.dropout, training=self.training
      )
  
      # expand attention_mask
      if attention_mask is not None:
          # [bsz, seq_len] -> [bsz, 1, tgt_seq_len, src_seq_len]
          attention_mask = _prepare_4d_attention_mask(
              attention_mask, inputs_embeds.dtype
          )
  
      encoder_states = () if output_hidden_states else None
      all_attentions = () if output_attentions else None
  
      # check if head_mask has a correct number of layers specified if desired
      if head_mask is not None:
          assert head_mask.size()[0] == (
              len(self.layers)
          ), f"The head_mask should be specified for {len(self.layers)} layers, but it is for {head_mask.size()[0]}."
  
      for idx, encoder_layer in enumerate(self.layers):
          if output_hidden_states:
              encoder_states = encoder_states + (hidden_states,)
          # add LayerDrop (see https://arxiv.org/abs/1909.11556 for description)
          to_drop = False
          if self.training:
              dropout_probability = torch.rand([])
              if dropout_probability < self.layerdrop:  # skip the layer
                  to_drop = True
  
          if to_drop:
              layer_outputs = (None, None)
          else:
              if self.gradient_checkpointing and self.training:
                  layer_outputs = self._gradient_checkpointing_func(
                      encoder_layer.__call__,
                      hidden_states,
                      attention_mask,
                      (
                          head_mask[idx]
                          if head_mask is not None
                          else None
                      ),
                      output_attentions,
                  )
              else:
                  layer_outputs = encoder_layer(
                      hidden_states,
                      attention_mask,
                      layer_head_mask=(
                          head_mask[idx]
                          if head_mask is not None
                          else None
                      ),
                      output_attentions=output_attentions,
                  )
  
              hidden_states = layer_outputs[0]
  
          if output_attentions:
              all_attentions = all_attentions + (layer_outputs[1],)
  
      hidden_states = self.layer_norm(hidden_states)
      if output_hidden_states:
          encoder_states = encoder_states + (hidden_states,)
  
      if not return_dict:
          return tuple(
              v
              for v in [hidden_states, encoder_states, all_attentions]
              if v is not None
          )
      return BaseModelOutput(
          last_hidden_state=hidden_states,
          hidden_states=encoder_states,
          attentions=all_attentions,
      )
  
imports: import math
  from typing import Optional, Tuple, Union
  import torch
  from torch import nn
  from torch.nn import CrossEntropyLoss
  from ...activations import ACT2FN
  from ...modeling_attn_mask_utils import _prepare_4d_attention_mask, _prepare_4d_causal_attention_mask
  from ...modeling_outputs import BaseModelOutput, BaseModelOutputWithPastAndCrossAttentions, Seq2SeqLMOutput, Seq2SeqModelOutput
  from ...modeling_utils import PreTrainedModel
  from ...utils import add_start_docstrings, add_start_docstrings_to_model_forward, logging, replace_return_docstrings
  from .configuration_speech_to_text import Speech2TextConfig
label_desc: Use image node_id 2 for calling the Speech2TextEncoder obj's underlying member method code with example usage: obj.forward(input_features, attention_mask, head_mask, output_attentions, output_hidden_states, return_dict) and returns: BaseModelOutput, tuple