class_docstr: Base class for TransformerEncoder and TransformerDecoder in vision
  transformer.
  
  As base-class of Encoder and Decoder in vision transformer.
  Support customization such as specifying different kind
  of `transformer_layer` in `transformer_coder`.
  
  Args:
      transformerlayer (list[obj:`mmcv.ConfigDict`] |
          obj:`mmcv.ConfigDict`): Config of transformerlayer
          in TransformerCoder. If it is obj:`mmcv.ConfigDict`,
           it would be repeated `num_layer` times to a
           list[`mmcv.ConfigDict`]. Default: None.
      num_layers (int): The number of `TransformerLayer`. Default: None.
      init_cfg (obj:`mmcv.ConfigDict`): The Config for initialization.
          Default: None.
class_docstr_tok: ["Base","class","for","TransformerEncoder","and","TransformerDecoder","in","vision","transformer",".","As","base-class","of","Encoder","and","Decoder","in","vision","transformer",".","Support","customization","such","as","specifying","different","kind","of","`","transformer_layer","`","in","`","transformer_coder","`",".","Args",":","transformerlayer","(","list","[","obj",":","`","mmcv.ConfigDict","`","]","|","obj",":","`","mmcv.ConfigDict","`",")",":","Config","of","transformerlayer","in","TransformerCoder",".","If","it","is","obj",":","`","mmcv.ConfigDict","`",",","it","would","be","repeated","`","num_layer","`","times","to","a","list","[","`","mmcv.ConfigDict","`","]",".","Default",":","None",".","num_layers","(","int",")",":","The","number","of","`","TransformerLayer","`",".","Default",":","None",".","init_cfg","(","obj",":","`","mmcv.ConfigDict","`",")",":","The","Config","for","initialization",".","Default",":","None","."]
docstr: Forward function for `TransformerCoder`.
  
  Args:
      query (Tensor): Input query with shape
          `(num_queries, bs, embed_dims)`.
      key (Tensor): The key tensor with shape
          `(num_keys, bs, embed_dims)`.
      value (Tensor): The value tensor with shape
          `(num_keys, bs, embed_dims)`.
      query_pos (Tensor): The positional encoding for `query`.
          Default: None.
      key_pos (Tensor): The positional encoding for `key`.
          Default: None.
      attn_masks (List[Tensor], optional): Each element is 2D Tensor
          which is used in calculation of corresponding attention in
          operation_order. Default: None.
      query_key_padding_mask (Tensor): ByteTensor for `query`, with
          shape [bs, num_queries]. Only used in self-attention
          Default: None.
      key_padding_mask (Tensor): ByteTensor for `query`, with
          shape [bs, num_keys]. Default: None.
  
  Returns:
      Tensor:  results with shape [num_queries, bs, embed_dims].
docstr_tok: ["Forward","function","for","`","TransformerCoder","`",".","Args",":","query","(","Tensor",")",":","Input","query","with","shape","`","(","num_queries",",","bs",",","embed_dims",")","`",".","key","(","Tensor",")",":","The","key","tensor","with","shape","`","(","num_keys",",","bs",",","embed_dims",")","`",".","value","(","Tensor",")",":","The","value","tensor","with","shape","`","(","num_keys",",","bs",",","embed_dims",")","`",".","query_pos","(","Tensor",")",":","The","positional","encoding","for","`","query","`",".","Default",":","None",".","key_pos","(","Tensor",")",":","The","positional","encoding","for","`","key","`",".","Default",":","None",".","attn_masks","(","List","[","Tensor","]",",","optional",")",":","Each","element","is","2D","Tensor","which","is","used","in","calculation","of","corresponding","attention","in","operation_order",".","Default",":","None",".","query_key_padding_mask","(","Tensor",")",":","ByteTensor","for","`","query","`",",","with","shape","[","bs",",","num_queries","]",".","Only","used","in","self-attention","Default",":","None",".","key_padding_mask","(","Tensor",")",":","ByteTensor","for","`","query","`",",","with","shape","[","bs",",","num_keys","]",".","Default",":","None",".","Returns",":","Tensor",":","results","with","shape","[","num_queries",",","bs",",","embed_dims","]","."]
code: def forward(
      self,
      query,
      key,
      value,
      query_pos=None,
      key_pos=None,
      attn_masks=None,
      query_key_padding_mask=None,
      key_padding_mask=None,
      **kwargs,
  ):
      """Forward function for `TransformerCoder`.
  
      Args:
          query (Tensor): Input query with shape
              `(num_queries, bs, embed_dims)`.
          key (Tensor): The key tensor with shape
              `(num_keys, bs, embed_dims)`.
          value (Tensor): The value tensor with shape
              `(num_keys, bs, embed_dims)`.
          query_pos (Tensor): The positional encoding for `query`.
              Default: None.
          key_pos (Tensor): The positional encoding for `key`.
              Default: None.
          attn_masks (List[Tensor], optional): Each element is 2D Tensor
              which is used in calculation of corresponding attention in
              operation_order. Default: None.
          query_key_padding_mask (Tensor): ByteTensor for `query`, with
              shape [bs, num_queries]. Only used in self-attention
              Default: None.
          key_padding_mask (Tensor): ByteTensor for `query`, with
              shape [bs, num_keys]. Default: None.
  
      Returns:
          Tensor:  results with shape [num_queries, bs, embed_dims].
      """
      for layer in self.layers:
          query = layer(
              query,
              key,
              value,
              query_pos=query_pos,
              key_pos=key_pos,
              attn_masks=attn_masks,
              query_key_padding_mask=query_key_padding_mask,
              key_padding_mask=key_padding_mask,
              **kwargs,
          )
      return query
  
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 2 for calling the TransformerLayerSequence obj's underlying member method code with example usage: obj.forward(query, key, value, query_pos, key_pos, attn_masks, query_key_padding_mask, key_padding_mask) and returns: query