docstr: :param hidden_states: [B, L, Hs]
  :param key_padding_mask: [B, S]                   为 1/True 的地方需要 mask
  :param attn_mask: [S] / [L, S] 指定位置 mask 掉，   为 1/True 的地方需要 mask
  :param head_mask: [N] / [L, N] 指定 head mask 掉， 为 1/True 的地方需要 mask
docstr_tok: [":","param","hidden_states",":","[","B",",","L",",","Hs","]",":","param","key_padding_mask",":","[","B",",","S","]","\u4e3a","1\/True","\u7684\u5730\u65b9\u9700\u8981","mask",":","param","attn_mask",":","[","S","]","\/","[","L",",","S","]","\u6307\u5b9a\u4f4d\u7f6e","mask","\u6389\uff0c","\u4e3a","1\/True","\u7684\u5730\u65b9\u9700\u8981","mask",":","param","head_mask",":","[","N","]","\/","[","L",",","N","]","\u6307\u5b9a","head","mask","\u6389\uff0c","\u4e3a","1\/True","\u7684\u5730\u65b9\u9700\u8981","mask"]
code: def forward(
      self,
      hidden_states,
      key_padding_mask=None,
      attention_mask=None,
      head_mask=None,
  ):
      """
      :param hidden_states: [B, L, Hs]
      :param key_padding_mask: [B, S]                   为 1/True 的地方需要 mask
      :param attn_mask: [S] / [L, S] 指定位置 mask 掉，   为 1/True 的地方需要 mask
      :param head_mask: [N] / [L, N] 指定 head mask 掉， 为 1/True 的地方需要 mask
      """
      if head_mask is not None:
          if head_mask.dim() == 1:
              head_mask = head_mask.expand(
                  (self.num_hidden_layers,) + head_mask.shape
              )
      else:
          head_mask = [None] * self.num_hidden_layers
  
      all_hidden_states = ()
      all_attentions = ()
      for i, layer_module in enumerate(self.layer):
          if self.output_hidden_states:
              all_hidden_states = all_hidden_states + (hidden_states,)
  
          layer_outputs = layer_module(
              hidden_states,
              key_padding_mask,
              attention_mask,
              head_mask[i],
          )
          hidden_states = layer_outputs[0]
  
          if self.output_attentions:
              all_attentions = all_attentions + (layer_outputs[1],)
  
      # Add last layer
      if self.output_hidden_states:
          all_hidden_states = all_hidden_states + (hidden_states,)
  
      outputs = (hidden_states,)
      if self.output_hidden_states:
          outputs = outputs + (all_hidden_states,)
      if self.output_attentions:
          outputs = outputs + (all_attentions,)
      return outputs
  
imports: import math
  import torch
  import torch.nn
  import torch.nn.functional
  from .Attention import MultiHeadAttention
label_desc: Use image node_id 2 for calling the Transformer obj's underlying member method code with example usage: obj.forward(hidden_states, key_padding_mask, attention_mask, head_mask) and returns: outputs