class_docstr: **Transformer** 的 Decoder 层
  
  :param d_model: 输入、输出的维度
  :param n_head: **多头注意力** head 的数目，需要能被 ``d_model`` 整除
  :param dim_ff:  FFN 中间映射的维度
  :param dropout: Dropout 的大小
  :param layer_idx: layer的编号
class_docstr_tok: ["*","*","Transformer","*","*","\u7684","Decoder","\u5c42",":","param","d_model",":","\u8f93\u5165\u3001\u8f93\u51fa\u7684\u7ef4\u5ea6",":","param","n_head",":","*","*","\u591a\u5934\u6ce8\u610f\u529b","*","*","head","\u7684\u6570\u76ee\uff0c\u9700\u8981\u80fd\u88ab","``","d_model","``","\u6574\u9664",":","param","dim_ff",":","FFN","\u4e2d\u95f4\u6620\u5c04\u7684\u7ef4\u5ea6",":","param","dropout",":","Dropout","\u7684\u5927\u5c0f",":","param","layer_idx",":","layer\u7684\u7f16\u53f7"]
code: def __init__(
      self,
      d_model: int = 512,
      n_head: int = 8,
      dim_ff: int = 2048,
      dropout: float = 0.1,
      layer_idx: int = None,
  ):
      super().__init__()
      self.d_model = d_model
      self.n_head = n_head
      self.dim_ff = dim_ff
      self.dropout = dropout
      self.layer_idx = layer_idx  # 记录layer的层索引，以方便获取state的信息
  
      self.self_attn = MultiHeadAttention(
          d_model, n_head, dropout, layer_idx
      )
      self.self_attn_layer_norm = nn.LayerNorm(d_model)
  
      self.encoder_attn = MultiHeadAttention(
          d_model, n_head, dropout, layer_idx
      )
      self.encoder_attn_layer_norm = nn.LayerNorm(d_model)
  
      self.ffn = nn.Sequential(
          nn.Linear(self.d_model, self.dim_ff),
          nn.ReLU(),
          nn.Dropout(dropout),
          nn.Linear(self.dim_ff, self.d_model),
          nn.Dropout(dropout),
      )
  
      self.final_layer_norm = nn.LayerNorm(self.d_model)
  
imports: from typing import Union, Tuple
  import math
  import torch
  from torch import nn
  import torch.nn.functional
  from ..attention import AttentionLayer, MultiHeadAttention
  from ....embeddings.torch.utils import get_embeddings
  from ....embeddings.torch.static_embedding import StaticEmbedding
  from .seq2seq_state import State, LSTMState, TransformerState
label_desc: Use image node_id 1 to create a new TransformerSeq2SeqDecoderLayer object from inherited base classes: nn with example: obj = TransformerSeq2SeqDecoderLayer(d_model, n_head, dim_ff, dropout, layer_idx)