docstr: Args:
      hidden_states (`torch.FloatTensor`): input to the layer of shape *(seq_len, batch, embed_dim)*
      attention_mask (`torch.FloatTensor`): attention mask of size
          *(batch, 1, tgt_len, src_len)* where padding elements are indicated by very large negative values.
      encoder_hidden_states (`torch.FloatTensor`):
          cross attention input to the layer of shape *(seq_len, batch, embed_dim)*
      encoder_attention_mask (`torch.FloatTensor`): encoder attention mask of size
          *(batch, 1, tgt_len, src_len)* where padding elements are indicated by very large negative values.
      layer_head_mask (`torch.FloatTensor`): mask for attention heads in a given layer of size
          *(encoder_attention_heads,)*.
      cross_attn_layer_head_mask (`torch.FloatTensor`): mask for cross-attention heads in a given layer of
          size *(decoder_attention_heads,)*.
      past_key_value (`Tuple(torch.FloatTensor)`): cached past key and value projection states
      output_attentions (`bool`, *optional*):
          Whether or not to return the attentions tensors of all attention layers. See `attentions` under
          returned tensors for more detail.
docstr_tok: ["Args",":","hidden_states","(","`","torch.FloatTensor","`",")",":","input","to","the","layer","of","shape","*","(","seq_len",",","batch",",","embed_dim",")","*","attention_mask","(","`","torch.FloatTensor","`",")",":","attention","mask","of","size","*","(","batch",",","1",",","tgt_len",",","src_len",")","*","where","padding","elements","are","indicated","by","very","large","negative","values",".","encoder_hidden_states","(","`","torch.FloatTensor","`",")",":","cross","attention","input","to","the","layer","of","shape","*","(","seq_len",",","batch",",","embed_dim",")","*","encoder_attention_mask","(","`","torch.FloatTensor","`",")",":","encoder","attention","mask","of","size","*","(","batch",",","1",",","tgt_len",",","src_len",")","*","where","padding","elements","are","indicated","by","very","large","negative","values",".","layer_head_mask","(","`","torch.FloatTensor","`",")",":","mask","for","attention","heads","in","a","given","layer","of","size","*","(","encoder_attention_heads",",",")","*",".","cross_attn_layer_head_mask","(","`","torch.FloatTensor","`",")",":","mask","for","cross-attention","heads","in","a","given","layer","of","size","*","(","decoder_attention_heads",",",")","*",".","past_key_value","(","`","Tuple","(","torch.FloatTensor",")","`",")",":","cached","past","key","and","value","projection","states","output_attentions","(","`","bool","`",",","*","optional","*",")",":","Whether","or","not","to","return","the","attentions","tensors","of","all","attention","layers",".","See","`","attentions","`","under","returned","tensors","for","more","detail","."]
code: def forward(
      self,
      hidden_states: torch.Tensor,
      attention_mask: Optional[torch.Tensor] = None,
      encoder_hidden_states: Optional[torch.Tensor] = None,
      encoder_attention_mask: Optional[torch.Tensor] = None,
      layer_head_mask: Optional[torch.Tensor] = None,
      cross_attn_layer_head_mask: Optional[torch.Tensor] = None,
      past_key_value: Optional[Tuple[torch.Tensor]] = None,
      output_attentions: Optional[bool] = False,
      use_cache: Optional[bool] = True,
  ) -> torch.Tensor:
      """
      Args:
          hidden_states (`torch.FloatTensor`): input to the layer of shape *(seq_len, batch, embed_dim)*
          attention_mask (`torch.FloatTensor`): attention mask of size
              *(batch, 1, tgt_len, src_len)* where padding elements are indicated by very large negative values.
          encoder_hidden_states (`torch.FloatTensor`):
              cross attention input to the layer of shape *(seq_len, batch, embed_dim)*
          encoder_attention_mask (`torch.FloatTensor`): encoder attention mask of size
              *(batch, 1, tgt_len, src_len)* where padding elements are indicated by very large negative values.
          layer_head_mask (`torch.FloatTensor`): mask for attention heads in a given layer of size
              *(encoder_attention_heads,)*.
          cross_attn_layer_head_mask (`torch.FloatTensor`): mask for cross-attention heads in a given layer of
              size *(decoder_attention_heads,)*.
          past_key_value (`Tuple(torch.FloatTensor)`): cached past key and value projection states
          output_attentions (`bool`, *optional*):
              Whether or not to return the attentions tensors of all attention layers. See `attentions` under
              returned tensors for more detail.
      """
      residual = hidden_states
      hidden_states = self.self_attn_layer_norm(hidden_states)
  
      # Self Attention
      # decoder uni-directional self-attention cached key/values tuple is at positions 1,2
      self_attn_past_key_value = (
          past_key_value[:2] if past_key_value is not None else None
      )
      # add present self-attn cache to positions 1,2 of present_key_value tuple
      (
          hidden_states,
          self_attn_weights,
          present_key_value,
      ) = self.self_attn(
          hidden_states=hidden_states,
          past_key_value=self_attn_past_key_value,
          attention_mask=attention_mask,
          layer_head_mask=layer_head_mask,
          output_attentions=output_attentions,
      )
      hidden_states = nn.functional.dropout(
          hidden_states, p=self.dropout, training=self.training
      )
      hidden_states = residual + hidden_states
  
      # Cross-Attention Block
      cross_attn_present_key_value = None
      cross_attn_weights = None
      if encoder_hidden_states is not None:
          residual = hidden_states
          hidden_states = self.encoder_attn_layer_norm(hidden_states)
  
          # cross_attn cached key/values tuple is at positions 3,4 of present_key_value tuple
          cross_attn_past_key_value = (
              past_key_value[-2:]
              if past_key_value is not None
              else None
          )
          (
              hidden_states,
              cross_attn_weights,
              cross_attn_present_key_value,
          ) = self.encoder_attn(
              hidden_states=hidden_states,
              key_value_states=encoder_hidden_states,
              attention_mask=encoder_attention_mask,
              layer_head_mask=cross_attn_layer_head_mask,
              past_key_value=cross_attn_past_key_value,
              output_attentions=output_attentions,
          )
          hidden_states = nn.functional.dropout(
              hidden_states, p=self.dropout, training=self.training
          )
          hidden_states = residual + hidden_states
  
          # add cross-attn to positions 3,4 of present_key_value tuple
          present_key_value = (
              present_key_value + cross_attn_present_key_value
          )
  
      # Fully Connected
      residual = hidden_states
      hidden_states = self.final_layer_norm(hidden_states)
      hidden_states = self.activation_fn(self.fc1(hidden_states))
      hidden_states = nn.functional.dropout(
          hidden_states,
          p=self.activation_dropout,
          training=self.training,
      )
      hidden_states = self.fc2(hidden_states)
      hidden_states = nn.functional.dropout(
          hidden_states, p=self.dropout, training=self.training
      )
      hidden_states = residual + hidden_states
  
      outputs = (hidden_states,)
  
      if output_attentions:
          outputs += (self_attn_weights, cross_attn_weights)
  
      if use_cache:
          outputs += (present_key_value,)
  
      return outputs
  
imports: import math
  import random
  from typing import List, Optional, Tuple, Union
  import torch
  from torch import nn
  from torch.nn import CrossEntropyLoss
  from ...activations import ACT2FN
  from ...deepspeed import is_deepspeed_zero3_enabled
  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 M2M100DecoderLayer obj's underlying member method code with example usage: obj.forward(hidden_states, attention_mask, encoder_hidden_states, encoder_attention_mask, layer_head_mask, cross_attn_layer_head_mask, past_key_value, output_attentions, use_cache) and returns: outputs