class_docstr: **Self-Attention** 的 Layer，
  
  :param int d_model: input和output的输出维度
  :param int n_head: 多少个head，每个head的维度为d_model/n_head
  :param int dim_ff: FFN的维度大小
  :param float dropout: Self-attention和FFN的dropout大小，0表示不drop
class_docstr_tok: ["*","*","Self-Attention","*","*","\u7684","Layer\uff0c",":","param","int","d_model",":","input\u548coutput\u7684\u8f93\u51fa\u7ef4\u5ea6",":","param","int","n_head",":","\u591a\u5c11\u4e2ahead\uff0c\u6bcf\u4e2ahead\u7684\u7ef4\u5ea6\u4e3ad_model\/n_head",":","param","int","dim_ff",":","FFN\u7684\u7ef4\u5ea6\u5927\u5c0f",":","param","float","dropout",":","Self-attention\u548cFFN\u7684dropout\u5927\u5c0f\uff0c0\u8868\u793a\u4e0ddrop"]
docstr: :param x: batch_size, src_seq, d_model
  :param mask: batch_size, src_seq，为0的地方为padding
  :return:
docstr_tok: [":","param","x",":","batch_size",",","src_seq",",","d_model",":","param","mask",":","batch_size",",","src_seq\uff0c\u4e3a0\u7684\u5730\u65b9\u4e3apadding",":","return",":"]
code: def forward(self, x, mask):
      """
  
      :param x: batch_size, src_seq, d_model
      :param mask: batch_size, src_seq，为0的地方为padding
      :return:
      """
      # attention
      residual = x
      x = self.attn_layer_norm(x)
      x, _ = self.self_attn(query=x, key=x, value=x, key_mask=mask)
      x = F.dropout(x, p=self.dropout, training=self.training)
      x = residual + x
  
      # ffn
      residual = x
      x = self.ffn_layer_norm(x)
      x = self.ffn(x)
      x = residual + x
  
      return x
  
imports: import torch.nn
  import torch
  from torch.nn import LayerNorm
  import torch.nn.functional
  from typing import Union, Tuple
  from ....core.utils import seq_len_to_mask
  import math
  from .lstm import LSTM
  from ..attention import MultiHeadAttention
  from ....embeddings.torch import StaticEmbedding
  from ....embeddings.torch.utils import get_embeddings
label_desc: Use image node_id 2 for calling the TransformerSeq2SeqEncoderLayer obj's underlying member method code with example usage: obj.forward(x, mask) and returns: x