class_docstr: Refer Attention is All You Need for more details.
  
  This is a simplified implementation of multihead attention
  optimized for exporting using torchscript. Usage of nn.Linear() instead of
  F.Linear() helps to quantize the linear layers.
  
  Query represents the output from last decoder step. Key and Values are obtained from
  encoder. Attention weights are obtained from the dot product of query and key.
  Attention weights multiplied by the value gives output.
class_docstr_tok: ["Refer","Attention","is","All","You","Need","for","more","details",".","This","is","a","simplified","implementation","of","multihead","attention","optimized","for","exporting","using","torchscript",".","Usage","of","nn.Linear","(",")","instead","of","F.Linear","(",")","helps","to","quantize","the","linear","layers",".","Query","represents","the","output","from","last","decoder","step",".","Key","and","Values","are","obtained","from","encoder",".","Attention","weights","are","obtained","from","the","dot","product","of","query","and","key",".","Attention","weights","multiplied","by","the","value","gives","output","."]
code: def __init__(
      self,
      embed_dim,
      num_heads,
      dropout,
      kdim=None,
      vdim=None,
      bias=True,
  ):
      super().__init__()
      self.embed_dim = embed_dim
      self.kdim = embed_dim if kdim is None else kdim
      self.vdim = embed_dim if vdim is None else vdim
  
      self.q_proj = Linear(embed_dim, embed_dim, bias=bias)
      self.k_proj = Linear(self.kdim, embed_dim, bias=bias)
      self.v_proj = Linear(self.vdim, embed_dim, bias=bias)
  
      self.num_heads = num_heads
      self.dropout = nn.Dropout(dropout)
      self.head_dim = embed_dim // num_heads
      assert (
          self.head_dim * num_heads == self.embed_dim
      ), "embed_dim must be divisible by num_heads"
      self.scaling = self.head_dim**-0.5
  
      self.out_proj = Linear(embed_dim, embed_dim, bias=bias)
  
imports: from typing import Dict, Optional, Tuple
  import numpy
  import torch
  import torch.nn.functional
  from pytext.config import ConfigBase
  from pytext.utils.usage import log_class_usage
  from torch import nn, Tensor
  from .base import PyTextIncrementalDecoderComponent
  from .utils import Linear
label_desc: Use image node_id 2 to create a new MultiheadAttention object from inherited base classes: PyTextIncrementalDecoderComponent with example: obj = MultiheadAttention(embed_dim, num_heads, dropout, kdim, vdim, bias)