class_docstr: Represents a Transformer decoder as described in
  :cite:t:`https://doi.org/10.48550/arxiv.1706.03762`.
class_docstr_tok: ["Represents","a","Transformer","decoder","as","described","in",":","cite",":","t",":","`","https",":","\/\/doi.org\/10.48550\/arxiv.1706.03762","`","."]
code: def forward(
      self,
      seqs: Tensor,
      padding_mask: Optional[PaddingMask],
      encoder_output: Optional[Tensor] = None,
      encoder_padding_mask: Optional[PaddingMask] = None,
      *,
      state_bag: Optional[IncrementalStateBag] = None,
  ) -> Tuple[Tensor, Optional[PaddingMask]]:
      if self._layer_output_hooks and self.layers.drop_p > 0.0:
          raise RuntimeError(
              "The layer output hooks cannot be run when LayerDrop is enabled."
          )
  
      num_layers = len(self.layers)
  
      if self.self_attn_mask_factory is None:
          self_attn_mask = None
      else:
          self_attn_mask = self.self_attn_mask_factory(
              seqs,
              keys=seqs,
              training=self.training,
              state_bag=state_bag,
          )
  
      for layer_idx, layer in enumerate(self.layers.drop_iter()):
          seqs, padding_mask = layer(
              seqs,
              padding_mask,
              self_attn_mask,
              encoder_output,
              encoder_padding_mask,
              state_bag=state_bag,
          )
  
          for hook in self._layer_output_hooks.values():
              if not hook(layer_idx, seqs, padding_mask, num_layers):
                  break
  
      if self.layer_norm is not None:
          seqs = self.layer_norm(seqs)
  
      return seqs, padding_mask
  
imports: from __future__ import annotations
  from abc import ABC, abstractmethod
  from collections import OrderedDict
  from typing import Dict, Iterable, Optional, Protocol, Tuple, final
  from torch import Tensor
  from torch.nn import Module
  from torch.utils.hooks import RemovableHandle
  from fairseq2.nn.incremental_state import IncrementalStateBag
  from fairseq2.nn.module_list import ModuleList
  from fairseq2.nn.normalization import LayerNorm
  from fairseq2.nn.padding import PaddingMask
  from fairseq2.nn.transformer.attention_mask import AttentionMaskFactory, CausalAttentionMaskFactory
  from fairseq2.nn.transformer.decoder_layer import TransformerDecoderLayer
  from fairseq2.nn.transformer.layer_norm import LayerNormFactory, create_standard_layer_norm
  from fairseq2.nn.transformer.norm_order import TransformerNormOrder
  from fairseq2.typing import DataType, Device, finaloverride
label_desc: Use image node_id 2 for calling the StandardTransformerDecoder obj's underlying member method code with example usage: obj.forward(seqs, padding_mask, encoder_output, encoder_padding_mask) and returns: seqs,  padding_mask