class_docstr: Multiheaded Scaled Dot Product Attention
  
  Implements equation:
  MultiHead(Q, K, V) = Concat(head_1,...,head_h)W^O
      where head_i = Attention(QW_i^Q, KW_i^K, VW_i^V)
  
  Similarly to the above, d_k = d_v = d_model / h
  In this implementation, keys and values are both set to encoder output
  
  Inputs
    init:
      decoder_hidden_state_dim : dimensionality of decoder hidden state
      context_dim : dimensionality of encoder output
      kwargs :
        nheads : integer # of attention heads
        unseen_mask: if True, only attend to previous sequence positions
        src_lengths_mask: if True, mask padding based on src_lengths
  
    forward:
      decoder_state : [batch size, d_model]
      source_hids : [sequence length, batch size, d_model]
      src_lengths : [batch size]
  
    forward:
      query : [sequence length, batch size, d_model]
      key: [sequence length, batch size, d_model]
      value: [sequence length, batch size, d_model]
  
  Output
    result : [batch_size,  d_model]
code: def __init__(
      self,
      decoder_hidden_state_dim,
      context_dim,
      *,
      nheads=1,
      unseen_mask=False,
      src_length_mask=True,
  ):
      super().__init__(decoder_hidden_state_dim, context_dim)
      assert decoder_hidden_state_dim == context_dim
      d_model = decoder_hidden_state_dim  # for brevity
      assert d_model % nheads == 0
  
      if unseen_mask:
          raise NotImplementedError(
              "Unseen mask not supported with sequential decoding"
          )
      self._fair_attn = fair_multihead.MultiheadAttention(
          d_model, nheads
      )
      self.use_src_length_mask = src_length_mask
  
imports: from typing import Optional
  from fairseq.modules import multihead_attention
  from pytorch_translate.attention import attention_utils, BaseAttention, register_attention
  from torch import Tensor
label_desc: Use image node_id 1 to create a new MultiheadAttention object from inherited base classes: BaseAttention with example: obj = MultiheadAttention(decoder_hidden_state_dim, context_dim)