class_docstr: A wrapper of conditional attention, dropout and residual connection.
  
  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: A Dropout layer after `nn.MultiheadAttention`.
          Default: 0.0.
      cross_attn (bool): Whether the attention module is for cross attention.
          Default: False
      keep_query_pos (bool): Whether to transform query_pos before cross
          attention.
          Default: False.
      batch_first (bool): When it is True, Key, Query and Value are shape of
          (batch, n, embed_dim), otherwise (n, batch, embed_dim).
           Default: True.
      init_cfg (obj:`mmcv.ConfigDict`): The Config for initialization.
          Default: None.
class_docstr_tok: ["A","wrapper","of","conditional","attention",",","dropout","and","residual","connection",".","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",":","A","Dropout","layer","after","`","nn.MultiheadAttention","`",".","Default",":","0.0.","cross_attn","(","bool",")",":","Whether","the","attention","module","is","for","cross","attention",".","Default",":","False","keep_query_pos","(","bool",")",":","Whether","to","transform","query_pos","before","cross","attention",".","Default",":","False",".","batch_first","(","bool",")",":","When","it","is","True",",","Key",",","Query","and","Value","are","shape","of","(","batch",",","n",",","embed_dim",")",",","otherwise","(","n",",","batch",",","embed_dim",")",".","Default",":","True",".","init_cfg","(","obj",":","`","mmcv.ConfigDict","`",")",":","The","Config","for","initialization",".","Default",":","None","."]
code: def __init__(
      self,
      embed_dims: int,
      num_heads: int,
      attn_drop: float = 0.0,
      proj_drop: float = 0.0,
      cross_attn: bool = False,
      keep_query_pos: bool = False,
      batch_first: bool = True,
      init_cfg: OptMultiConfig = None,
  ):
      super().__init__(init_cfg=init_cfg)
  
      assert (
          batch_first is True
      ), "Set `batch_first`\
          to False is NOT supported in ConditionalAttention. \
          First dimension of all DETRs in mmdet is `batch`, \
          please set `batch_first` to True."
  
      self.cross_attn = cross_attn
      self.keep_query_pos = keep_query_pos
      self.embed_dims = embed_dims
      self.num_heads = num_heads
      self.attn_drop = Dropout(attn_drop)
      self.proj_drop = Dropout(proj_drop)
  
      self._init_layers()
  
imports: import math
  import warnings
  from typing import Optional, Sequence, Tuple, Union
  import torch
  import torch.nn.functional
  from mmcv.cnn import Linear, build_activation_layer, build_conv_layer, build_norm_layer
  from mmcv.cnn.bricks.drop import Dropout
  from mmengine.model import BaseModule, ModuleList
  from mmengine.utils import to_2tuple
  from torch import Tensor, nn
  from mmdet.registry import MODELS
  from mmdet.utils import OptConfigType, OptMultiConfig
label_desc: Use image node_id 1 to create a new ConditionalAttention object from inherited base classes: BaseModule with example: obj = ConditionalAttention(embed_dims, num_heads, attn_drop, proj_drop, cross_attn, keep_query_pos, batch_first, init_cfg)