class_docstr: Represents a Transformer decoder layer as described in
  :cite:t:`https://doi.org/10.48550/arxiv.1706.03762`.
class_docstr_tok: ["Represents","a","Transformer","decoder","layer","as","described","in",":","cite",":","t",":","`","https",":","\/\/doi.org\/10.48550\/arxiv.1706.03762","`","."]
docstr: :param self_attn:
      The self attention layer.
  :param encoder_decoder_attn:
      The encoder-decoder attention layer.
  :param ffn:
      The feed-forward network.
  :param scale_residual:
      If ``True``, scales residuals before adding them to the output of
      the feed-forward network as described in
      :cite:t:`https://doi.org/10.48550/arxiv.2110.09456`.
  :param dropout_p:
      The dropout probability on outputs of the attention layers and the
      feed-forward network.
  :param norm_order:
      The Layer Normalization order.
  :param layer_norm_factory:
      The factory to construct the Layer Normalization modules.
docstr_tok: [":","param","self_attn",":","The","self","attention","layer",".",":","param","encoder_decoder_attn",":","The","encoder-decoder","attention","layer",".",":","param","ffn",":","The","feed-forward","network",".",":","param","scale_residual",":","If","``","True","``",",","scales","residuals","before","adding","them","to","the","output","of","the","feed-forward","network","as","described","in",":","cite",":","t",":","`","https",":","\/\/doi.org\/10.48550\/arxiv.2110.09456","`",".",":","param","dropout_p",":","The","dropout","probability","on","outputs","of","the","attention","layers","and","the","feed-forward","network",".",":","param","norm_order",":","The","Layer","Normalization","order",".",":","param","layer_norm_factory",":","The","factory","to","construct","the","Layer","Normalization","modules","."]
code: def __init__(
      self,
      self_attn: MultiheadAttention,
      encoder_decoder_attn: Optional[MultiheadAttention],
      ffn: FeedForwardNetwork,
      *,
      scale_residual: bool = False,
      dropout_p: float = 0.1,
      norm_order: TransformerNormOrder = TransformerNormOrder.POST,
      layer_norm_factory: Optional[LayerNormFactory] = None,
      device: Optional[Device] = None,
      dtype: Optional[DataType] = None,
  ) -> None:
      """
      :param self_attn:
          The self attention layer.
      :param encoder_decoder_attn:
          The encoder-decoder attention layer.
      :param ffn:
          The feed-forward network.
      :param scale_residual:
          If ``True``, scales residuals before adding them to the output of
          the feed-forward network as described in
          :cite:t:`https://doi.org/10.48550/arxiv.2110.09456`.
      :param dropout_p:
          The dropout probability on outputs of the attention layers and the
          feed-forward network.
      :param norm_order:
          The Layer Normalization order.
      :param layer_norm_factory:
          The factory to construct the Layer Normalization modules.
      """
      model_dim = self_attn.model_dim
  
      super().__init__(model_dim)
  
      if layer_norm_factory is None:
          layer_norm_factory = create_standard_layer_norm
  
      self_attn_layer_norm = layer_norm_factory(
          model_dim, device=device, dtype=dtype
      )
  
      if norm_order != TransformerNormOrder.POST:
          self.self_attn_layer_norm = self_attn_layer_norm
  
      self.self_attn = self_attn
  
      if norm_order == TransformerNormOrder.PRE_WITH_NORMFORMER:
          self.self_attn_norm = layer_norm_factory(
              model_dim, device=device, dtype=dtype
          )
      else:
          self.register_module("self_attn_norm", None)
  
      if dropout_p > 0.0:
          self.self_attn_dropout = Dropout(dropout_p)
      else:
          self.register_module("self_attn_dropout", None)
  
      if norm_order == TransformerNormOrder.POST:
          self.self_attn_layer_norm = self_attn_layer_norm
  
      if encoder_decoder_attn is None:
          self.register_module("encoder_decoder_attn", None)
          self.register_module("encoder_decoder_attn_layer_norm", None)
      else:
          encoder_decoder_attn_layer_norm = layer_norm_factory(
              model_dim, device=device, dtype=dtype
          )
  
          if norm_order != TransformerNormOrder.POST:
              self.encoder_decoder_attn_layer_norm = (
                  encoder_decoder_attn_layer_norm
              )
  
          self.encoder_decoder_attn = encoder_decoder_attn
  
          if dropout_p > 0.0:
              self.encoder_decoder_attn_dropout = Dropout(dropout_p)
          else:
              self.register_module("encoder_decoder_attn_dropout", None)
  
          if norm_order == TransformerNormOrder.POST:
              self.encoder_decoder_attn_layer_norm = (
                  encoder_decoder_attn_layer_norm
              )
  
      ffn_layer_norm = layer_norm_factory(
          model_dim, device=device, dtype=dtype
      )
  
      if norm_order != TransformerNormOrder.POST:
          self.ffn_layer_norm = ffn_layer_norm
  
      self.ffn = ffn
  
      if dropout_p > 0.0:
          self.ffn_dropout = Dropout(dropout_p)
      else:
          self.register_module("ffn_dropout", None)
  
      if scale_residual:
          self.residual_scale = Parameter(
              torch.empty((model_dim,), device=device, dtype=dtype)
          )
      else:
          self.register_parameter("residual_scale", None)
  
      if norm_order == TransformerNormOrder.POST:
          self.ffn_layer_norm = ffn_layer_norm
  
      self.norm_order = norm_order
  
      self.reset_parameters()
  
imports: from abc import ABC, abstractmethod
  from typing import Optional, Tuple, cast, final
  import torch
  import torch.nn
  from torch import Tensor
  from torch.nn import Dropout, Module
  from torch.nn.parameter import Parameter
  from fairseq2.nn.incremental_state import IncrementalStateBag
  from fairseq2.nn.normalization import LayerNorm
  from fairseq2.nn.padding import PaddingMask
  from fairseq2.nn.transformer.attention_mask import AttentionMask
  from fairseq2.nn.transformer.ffn import FeedForwardNetwork
  from fairseq2.nn.transformer.layer_norm import LayerNormFactory, create_standard_layer_norm
  from fairseq2.nn.transformer.multihead_attention import MultiheadAttention
  from fairseq2.nn.transformer.norm_order import TransformerNormOrder
  from fairseq2.typing import DataType, Device, finaloverride
label_desc: Use image node_id 1 to create a new StandardTransformerDecoderLayer object from inherited base classes: TransformerDecoderLayer with example: obj = StandardTransformerDecoderLayer(_attn, encoder_decoder_attn, ffn)