class_docstr: A wrapper for ``torch.nn.MultiheadAttention``.
  
  This module implements MultiheadAttention with identity connection,
  and positional encoding  is also passed as input.
  
  Args:
      embed_dims (int): The embedding dimension.
      num_heads (int): Parallel attention heads.
      attn_drop (float): A Dropout layer on attn_output_weights.
          Default: 0.0.
      proj_drop (float): A Dropout layer after `nn.MultiheadAttention`.
          Default: 0.0.
      dropout_layer (obj:`ConfigDict`): The dropout_layer used
          when adding the shortcut.
      init_cfg (obj:`mmcv.ConfigDict`): The Config for initialization.
          Default: None.
      batch_first (bool): When it is True,  Key, Query and Value are shape of
          (batch, n, embed_dim), otherwise (n, batch, embed_dim).
           Default to False.
class_docstr_tok: ["A","wrapper","for","``","torch.nn.MultiheadAttention","``",".","This","module","implements","MultiheadAttention","with","identity","connection",",","and","positional","encoding","is","also","passed","as","input",".","Args",":","embed_dims","(","int",")",":","The","embedding","dimension",".","num_heads","(","int",")",":","Parallel","attention","heads",".","attn_drop","(","float",")",":","A","Dropout","layer","on","attn_output_weights",".","Default",":","0.0.","proj_drop","(","float",")",":","A","Dropout","layer","after","`","nn.MultiheadAttention","`",".","Default",":","0.0.","dropout_layer","(","obj",":","`","ConfigDict","`",")",":","The","dropout_layer","used","when","adding","the","shortcut",".","init_cfg","(","obj",":","`","mmcv.ConfigDict","`",")",":","The","Config","for","initialization",".","Default",":","None",".","batch_first","(","bool",")",":","When","it","is","True",",","Key",",","Query","and","Value","are","shape","of","(","batch",",","n",",","embed_dim",")",",","otherwise","(","n",",","batch",",","embed_dim",")",".","Default","to","False","."]
code: def __init__(
      self,
      embed_dims,
      num_heads,
      attn_drop=0.0,
      proj_drop=0.0,
      dropout_layer=dict(type="Dropout", drop_prob=0.0),
      init_cfg=None,
      batch_first=False,
      **kwargs,
  ):
      super(MultiheadAttention, self).__init__(init_cfg)
      if "dropout" in kwargs:
          warnings.warn(
              "The arguments `dropout` in MultiheadAttention "
              "has been deprecated, now you can separately "
              "set `attn_drop`(float), proj_drop(float), "
              "and `dropout_layer`(dict) "
          )
          attn_drop = kwargs["dropout"]
          dropout_layer["drop_prob"] = kwargs.pop("dropout")
  
      self.embed_dims = embed_dims
      self.num_heads = num_heads
      self.batch_first = batch_first
  
      self.attn = nn.MultiheadAttention(
          embed_dims, num_heads, attn_drop, **kwargs
      )
  
      self.proj_drop = nn.Dropout(proj_drop)
      self.dropout_layer = (
          build_dropout(dropout_layer)
          if dropout_layer
          else nn.Identity()
      )
  
imports: import copy
  import warnings
  import torch
  import torch.nn
  from annotator.uniformer.mmcv import ConfigDict, deprecated_api_warning
  from annotator.uniformer.mmcv.cnn import Linear, build_activation_layer, build_norm_layer
  from annotator.uniformer.mmcv.runner.base_module import BaseModule, ModuleList, Sequential
  from annotator.uniformer.mmcv.utils import build_from_cfg
  from .drop import build_dropout
  from .registry import ATTENTION, FEEDFORWARD_NETWORK, POSITIONAL_ENCODING, TRANSFORMER_LAYER, TRANSFORMER_LAYER_SEQUENCE
label_desc: Use image node_id 1 to create a new MultiheadAttention object from inherited base classes: BaseModule with example: obj = MultiheadAttention(embed_dims, num_heads, attn_drop, proj_drop, dropout_layer, init_cfg, batch_first)