class_docstr: Decoder layer implemented by fairseq.
  This version only removes the "args" parameter, no other changes
class_docstr_tok: ["Decoder","layer","implemented","by","fairseq",".","This","version","only","removes","the","``","args","''","parameter",",","no","other","changes"]
docstr: Args:
      x (Tensor): input to the layer of shape `(batch, seq_len, embed_dim)`
      encoder_padding_mask (ByteTensor, optional): binary
          ByteTensor of shape `(batch, src_len)` where padding
          elements are indicated by ``1``.
      need_attn (bool, optional): return attention weights
      need_head_weights (bool, optional): return attention weights
          for each head (default: return average over heads).
  
  Returns:
      encoded output of shape `(seq_len, batch, embed_dim)`
code: def forward(
      self,
      x,
      encoder_out: Optional[torch.Tensor] = None,
      encoder_padding_mask: Optional[torch.Tensor] = None,
      incremental_state: Optional[
          Dict[str, Dict[str, Optional[Tensor]]]
      ] = None,
      prev_self_attn_state: Optional[List[torch.Tensor]] = None,
      prev_attn_state: Optional[List[torch.Tensor]] = None,
      self_attn_mask: Optional[torch.Tensor] = None,
      self_attn_padding_mask: Optional[torch.Tensor] = None,
      need_attn: bool = False,
      need_head_weights: bool = False,
  ):
      """
      Args:
          x (Tensor): input to the layer of shape `(batch, seq_len, embed_dim)`
          encoder_padding_mask (ByteTensor, optional): binary
              ByteTensor of shape `(batch, src_len)` where padding
              elements are indicated by ``1``.
          need_attn (bool, optional): return attention weights
          need_head_weights (bool, optional): return attention weights
              for each head (default: return average over heads).
  
      Returns:
          encoded output of shape `(seq_len, batch, embed_dim)`
      """
      if need_head_weights:
          need_attn = True
      x = x.transpose(0, 1)
      residual = x
      if self.normalize_before:
          x = self.self_attn_layer_norm(x)
      if prev_self_attn_state is not None:
          prev_key, prev_value = prev_self_attn_state[:2]
          saved_state: Dict[str, Optional[Tensor]] = {
              "prev_key": prev_key,
              "prev_value": prev_value,
          }
          if len(prev_self_attn_state) >= 3:
              saved_state[
                  "prev_key_padding_mask"
              ] = prev_self_attn_state[2]
          assert incremental_state is not None
          self.self_attn._set_input_buffer(
              incremental_state, saved_state
          )
  
      x, attn = self.self_attn(
          query=x,
          key=x,
          value=x,
          key_padding_mask=self_attn_padding_mask,
          incremental_state=incremental_state,
          need_weights=False,
          attn_mask=self_attn_mask,
      )
      x = self.dropout_module(x)
      x = self.residual_connection(x, residual)
      if not self.normalize_before:
          x = self.self_attn_layer_norm(x)
  
      if self.has_cross_attn and encoder_out is not None:
          if (
              encoder_out.shape[1] != x.shape[1]
              and x.shape[1] % encoder_out.shape[1] == 0
          ):
              beam_size = int(x.shape[1] / encoder_out.shape[1])
              encoder_out = encoder_out.repeat_interleave(beam_size, 1)
              encoder_padding_mask = (
                  encoder_padding_mask.repeat_interleave(beam_size, 0)
              )
  
          residual = x
          if self.normalize_before:
              x = self.encoder_attn_layer_norm(x)
          if prev_attn_state is not None:
              prev_key, prev_value = prev_attn_state[:2]
              saved_state: Dict[str, Optional[Tensor]] = {
                  "prev_key": prev_key,
                  "prev_value": prev_value,
              }
              if len(prev_attn_state) >= 3:
                  saved_state[
                      "prev_key_padding_mask"
                  ] = prev_attn_state[2]
              assert incremental_state is not None
              self.encoder_attn._set_input_buffer(
                  incremental_state, saved_state
              )
  
          x, attn = self.encoder_attn(
              query=x,
              key=encoder_out,
              value=encoder_out,
              key_padding_mask=encoder_padding_mask,
              incremental_state=incremental_state,
              static_kv=True,
              need_weights=need_attn
              or (not self.training and self.need_attn),
              need_head_weights=need_head_weights,
          )
          x = self.dropout_module(x)
          x = self.residual_connection(x, residual)
          if not self.normalize_before:
              x = self.encoder_attn_layer_norm(x)
  
      residual = x
      if self.normalize_before:
          x = self.final_layer_norm(x)
  
      x = self.activation_fn(self.fc1(x))
      x = self.activation_dropout_module(x)
      x = self.fc2(x)
      x = self.dropout_module(x)
      x = self.residual_connection(x, residual)
      if not self.normalize_before:
          x = self.final_layer_norm(x)
      if self.onnx_trace and incremental_state is not None:
          saved_state = self.self_attn._get_input_buffer(
              incremental_state
          )
          assert saved_state is not None
          if self_attn_padding_mask is not None:
              self_attn_state = [
                  saved_state["prev_key"],
                  saved_state["prev_value"],
                  saved_state["prev_key_padding_mask"],
              ]
          else:
              self_attn_state = [
                  saved_state["prev_key"],
                  saved_state["prev_value"],
              ]
          return x, attn, self_attn_state
      x = x.transpose(0, 1)
      return x, attn, None
  
imports: import __init__
  import math
  import uuid
  from typing import Dict, Optional, List
  import torch
  from torch import Tensor, nn
  from torch.nn import Parameter, LayerNorm, Dropout
  from csrc.pytorch import util
  from csrc.pytorch.layer_base import TransformerEmbeddingLayerBase, TransformerEncoderLayerBase, TransformerDecoderLayerBase
  from csrc.pytorch.quantization import QuantLinear, TensorQuantizer, act_quant_config, weight_quant_config, out_quant_config, emb_quant_config
label_desc: Use image node_id 6 for calling the TransformerDecoderLayer obj's underlying member method code with example usage: obj.forward(x, encoder_out, encoder_padding_mask, incremental_state, prev__attn_state, prev_attn_state, _attn_mask, _attn_padding_mask, need_attn, need_head_weights) and returns: x,  attn,  None, x,  attn,  self_attn_state