class_docstr: Transformer encoder consisting of *config.encoder_layers* self attention layers. Each layer is a
  [`M2M100EncoderLayer`].
  
  Args:
      config: M2M100Config
      embed_tokens (nn.Embedding): output embedding
class_docstr_tok: ["Transformer","encoder","consisting","of","*","config.encoder_layers","*","self","attention","layers",".","Each","layer","is","a","[","`","M2M100EncoderLayer","`","]",".","Args",":","config",":","M2M100Config","embed_tokens","(","nn.Embedding",")",":","output","embedding"]
docstr: Args:
      input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
          Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you
          provide it.
  
          Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
          [`PreTrainedTokenizer.__call__`] for details.
  
          [What are input IDs?](../glossary#input-ids)
      attention_mask (`torch.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
          Mask to avoid performing 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**.
  
      inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
          Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation.
          This is useful if you want more control over how to convert `input_ids` indices into associated vectors
          than the model's internal embedding lookup matrix.
      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_ids","(","`","torch.LongTensor","`","of","shape","`","(","batch_size",",","sequence_length",")","`",")",":","Indices","of","input","sequence","tokens","in","the","vocabulary",".","Padding","will","be","ignored","by","default","should","you","provide","it",".","Indices","can","be","obtained","using","[","`","AutoTokenizer","`","]",".","See","[","`","PreTrainedTokenizer.encode","`","]","and","[","`","PreTrainedTokenizer.__call__","`","]","for","details",".","[","What","are","input","IDs","?","]","(","..","\/glossary","#","input-ids",")","attention_mask","(","`","torch.Tensor","`","of","shape","`","(","batch_size",",","sequence_length",")","`",",","*","optional","*",")",":","Mask","to","avoid","performing","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","*","*",".","inputs_embeds","(","`","torch.FloatTensor","`","of","shape","`","(","batch_size",",","sequence_length",",","hidden_size",")","`",",","*","optional","*",")",":","Optionally",",","instead","of","passing","`","input_ids","`","you","can","choose","to","directly","pass","an","embedded","representation",".","This","is","useful","if","you","want","more","control","over","how","to","convert","`","input_ids","`","indices","into","associated","vectors","than","the","model","'s","internal","embedding","lookup","matrix",".","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_ids: Optional[torch.Tensor] = None,
      attention_mask: Optional[torch.Tensor] = None,
      head_mask: Optional[torch.Tensor] = None,
      inputs_embeds: Optional[torch.Tensor] = None,
      output_attentions: Optional[bool] = None,
      output_hidden_states: Optional[bool] = None,
      return_dict: Optional[bool] = None,
  ):
      r"""
      Args:
          input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
              Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you
              provide it.
  
              Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
              [`PreTrainedTokenizer.__call__`] for details.
  
              [What are input IDs?](../glossary#input-ids)
          attention_mask (`torch.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
              Mask to avoid performing 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**.
  
          inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
              Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation.
              This is useful if you want more control over how to convert `input_ids` indices into associated vectors
              than the model's internal embedding lookup matrix.
          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
      )
  
      # retrieve input_ids and inputs_embeds
      if input_ids is not None and inputs_embeds is not None:
          raise ValueError(
              "You cannot specify both input_ids and inputs_embeds at the same time"
          )
      elif input_ids is not None:
          self.warn_if_padding_and_no_attention_mask(
              input_ids, attention_mask
          )
          input_shape = input_ids.size()
          input_ids = input_ids.view(-1, input_shape[-1])
      elif inputs_embeds is not None:
          input_shape = inputs_embeds.size()[:-1]
      else:
          raise ValueError(
              "You have to specify either input_ids or inputs_embeds"
          )
  
      if inputs_embeds is None:
          inputs_embeds = (
              self.embed_tokens(input_ids) * self.embed_scale
          )
  
      embed_pos = self.embed_positions(input_ids, inputs_embeds)
      embed_pos = embed_pos.to(inputs_embeds.device)
  
      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:
          if head_mask.size()[0] != len(self.layers):
              raise ValueError(
                  f"The head_mask should be specified for {len(self.layers)} layers, but it is for"
                  f" {head_mask.size()[0]}."
              )
      deepspeed_zero3_is_enabled = is_deepspeed_zero3_enabled()
  
      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)
          dropout_probability = torch.rand([])
  
          skip_the_layer = (
              True
              if self.training
              and (dropout_probability < self.layerdrop)
              else False
          )
          if not skip_the_layer or deepspeed_zero3_is_enabled:
              # under deepspeed zero3 all gpus must run in sync
  
              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 skip_the_layer:
              layer_outputs = (None, None)
  
          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 List, Optional, Tuple, Union
  import torch
  from torch import nn
  from torch.nn import CrossEntropyLoss
  from ...activations import ACT2FN
  from ...integrations.deepspeed import is_deepspeed_zero3_enabled
  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_code_sample_docstrings, add_end_docstrings, add_start_docstrings, add_start_docstrings_to_model_forward, logging, replace_return_docstrings
  from .configuration_m2m_100 import M2M100Config
label_desc: Use image node_id 2 for calling the M2M100Encoder obj's underlying member method code with example usage: obj.forward(input_ids, attention_mask, head_mask, inputs_embeds, output_attentions, output_hidden_states, return_dict) and returns: BaseModelOutput, tuple