class_docstr: `Attention is all you need <https://arxiv.org/abs/1706.03762>`_ 中提到的多头注意力
  
  :param d_model:
  :param n_head:
  :param dropout:
  :param layer_idx:
class_docstr_tok: ["`","Attention","is","all","you","need","<","https",":","\/\/arxiv.org\/abs\/1706.03762",">","`","_","\u4e2d\u63d0\u5230\u7684\u591a\u5934\u6ce8\u610f\u529b",":","param","d_model",":",":","param","n_head",":",":","param","dropout",":",":","param","layer_idx",":"]
code: def __init__(
      self,
      d_model: int = 512,
      n_head: int = 8,
      dropout: float = 0.0,
      layer_idx: int = None,
  ):
      super(MultiHeadAttention, self).__init__()
      self.d_model = d_model
      self.n_head = n_head
      self.dropout = dropout
      self.head_dim = d_model // n_head
      self.layer_idx = layer_idx
      assert (
          d_model % n_head == 0
      ), "d_model should be divisible by n_head"
      self.scaling = self.head_dim**-0.5
  
      self.q_proj = nn.Linear(d_model, d_model)
      self.k_proj = nn.Linear(d_model, d_model)
      self.v_proj = nn.Linear(d_model, d_model)
      self.out_proj = nn.Linear(d_model, d_model)
  
      self.reset_parameters()
  
imports: import math
  import torch
  import torch.nn.functional
  from torch import nn
  from .decoder.seq2seq_state import TransformerState
label_desc: Use image node_id 1 to create a new MultiHeadAttention object from inherited base classes: nn with example: obj = MultiHeadAttention(d_model, n_head, dropout, layer_idx)