class_docstr: Implements decoder layer in DETR transformer.
  
  Args:
      self_attn_cfg (:obj:`ConfigDict` or dict, optional): Config for self
          attention.
      cross_attn_cfg (:obj:`ConfigDict` or dict, optional): Config for cross
          attention.
      ffn_cfg (:obj:`ConfigDict` or dict, optional): Config for FFN.
      norm_cfg (:obj:`ConfigDict` or dict, optional): Config for
          normalization layers. All the layers will share the same
          config. Defaults to `LN`.
      init_cfg (:obj:`ConfigDict` or dict, optional): Config to control
          the initialization. Defaults to None.
class_docstr_tok: ["Implements","decoder","layer","in","DETR","transformer",".","Args",":","self_attn_cfg","(",":","obj",":","`","ConfigDict","`","or","dict",",","optional",")",":","Config","for","self","attention",".","cross_attn_cfg","(",":","obj",":","`","ConfigDict","`","or","dict",",","optional",")",":","Config","for","cross","attention",".","ffn_cfg","(",":","obj",":","`","ConfigDict","`","or","dict",",","optional",")",":","Config","for","FFN",".","norm_cfg","(",":","obj",":","`","ConfigDict","`","or","dict",",","optional",")",":","Config","for","normalization","layers",".","All","the","layers","will","share","the","same","config",".","Defaults","to","`","LN","`",".","init_cfg","(",":","obj",":","`","ConfigDict","`","or","dict",",","optional",")",":","Config","to","control","the","initialization",".","Defaults","to","None","."]
docstr: Args:
      query (Tensor): The input query, has shape (bs, num_queries, dim).
      key (Tensor, optional): The input key, has shape (bs, num_keys,
          dim). If `None`, the `query` will be used. Defaults to `None`.
      value (Tensor, optional): The input value, has the same shape as
          `key`, as in `nn.MultiheadAttention.forward`. If `None`, the
          `key` will be used. Defaults to `None`.
      query_pos (Tensor, optional): The positional encoding for `query`,
          has the same shape as `query`. If not `None`, it will be added
          to `query` before forward function. Defaults to `None`.
      key_pos (Tensor, optional): The positional encoding for `key`, has
          the same shape as `key`. If not `None`, it will be added to
          `key` before forward function. If None, and `query_pos` has the
          same shape as `key`, then `query_pos` will be used for
          `key_pos`. Defaults to None.
      self_attn_mask (Tensor, optional): ByteTensor mask, has shape
          (num_queries, num_keys), as in `nn.MultiheadAttention.forward`.
          Defaults to None.
      cross_attn_mask (Tensor, optional): ByteTensor mask, has shape
          (num_queries, num_keys), as in `nn.MultiheadAttention.forward`.
          Defaults to None.
      key_padding_mask (Tensor, optional): The `key_padding_mask` of
          `self_attn` input. ByteTensor, has shape (bs, num_value).
          Defaults to None.
  
  Returns:
      Tensor: forwarded results, has shape (bs, num_queries, dim).
docstr_tok: ["Args",":","query","(","Tensor",")",":","The","input","query",",","has","shape","(","bs",",","num_queries",",","dim",")",".","key","(","Tensor",",","optional",")",":","The","input","key",",","has","shape","(","bs",",","num_keys",",","dim",")",".","If","`","None","`",",","the","`","query","`","will","be","used",".","Defaults","to","`","None","`",".","value","(","Tensor",",","optional",")",":","The","input","value",",","has","the","same","shape","as","`","key","`",",","as","in","`","nn.MultiheadAttention.forward","`",".","If","`","None","`",",","the","`","key","`","will","be","used",".","Defaults","to","`","None","`",".","query_pos","(","Tensor",",","optional",")",":","The","positional","encoding","for","`","query","`",",","has","the","same","shape","as","`","query","`",".","If","not","`","None","`",",","it","will","be","added","to","`","query","`","before","forward","function",".","Defaults","to","`","None","`",".","key_pos","(","Tensor",",","optional",")",":","The","positional","encoding","for","`","key","`",",","has","the","same","shape","as","`","key","`",".","If","not","`","None","`",",","it","will","be","added","to","`","key","`","before","forward","function",".","If","None",",","and","`","query_pos","`","has","the","same","shape","as","`","key","`",",","then","`","query_pos","`","will","be","used","for","`","key_pos","`",".","Defaults","to","None",".","self_attn_mask","(","Tensor",",","optional",")",":","ByteTensor","mask",",","has","shape","(","num_queries",",","num_keys",")",",","as","in","`","nn.MultiheadAttention.forward","`",".","Defaults","to","None",".","cross_attn_mask","(","Tensor",",","optional",")",":","ByteTensor","mask",",","has","shape","(","num_queries",",","num_keys",")",",","as","in","`","nn.MultiheadAttention.forward","`",".","Defaults","to","None",".","key_padding_mask","(","Tensor",",","optional",")",":","The","`","key_padding_mask","`","of","`","self_attn","`","input",".","ByteTensor",",","has","shape","(","bs",",","num_value",")",".","Defaults","to","None",".","Returns",":","Tensor",":","forwarded","results",",","has","shape","(","bs",",","num_queries",",","dim",")","."]
code: def forward(
      self,
      query: Tensor,
      key: Tensor = None,
      value: Tensor = None,
      query_pos: Tensor = None,
      key_pos: Tensor = None,
      self_attn_mask: Tensor = None,
      cross_attn_mask: Tensor = None,
      key_padding_mask: Tensor = None,
      **kwargs,
  ) -> Tensor:
      """
      Args:
          query (Tensor): The input query, has shape (bs, num_queries, dim).
          key (Tensor, optional): The input key, has shape (bs, num_keys,
              dim). If `None`, the `query` will be used. Defaults to `None`.
          value (Tensor, optional): The input value, has the same shape as
              `key`, as in `nn.MultiheadAttention.forward`. If `None`, the
              `key` will be used. Defaults to `None`.
          query_pos (Tensor, optional): The positional encoding for `query`,
              has the same shape as `query`. If not `None`, it will be added
              to `query` before forward function. Defaults to `None`.
          key_pos (Tensor, optional): The positional encoding for `key`, has
              the same shape as `key`. If not `None`, it will be added to
              `key` before forward function. If None, and `query_pos` has the
              same shape as `key`, then `query_pos` will be used for
              `key_pos`. Defaults to None.
          self_attn_mask (Tensor, optional): ByteTensor mask, has shape
              (num_queries, num_keys), as in `nn.MultiheadAttention.forward`.
              Defaults to None.
          cross_attn_mask (Tensor, optional): ByteTensor mask, has shape
              (num_queries, num_keys), as in `nn.MultiheadAttention.forward`.
              Defaults to None.
          key_padding_mask (Tensor, optional): The `key_padding_mask` of
              `self_attn` input. ByteTensor, has shape (bs, num_value).
              Defaults to None.
  
      Returns:
          Tensor: forwarded results, has shape (bs, num_queries, dim).
      """
  
      query = self.self_attn(
          query=query,
          key=query,
          value=query,
          query_pos=query_pos,
          key_pos=query_pos,
          attn_mask=self_attn_mask,
          **kwargs,
      )
      query = self.norms[0](query)
      query = self.cross_attn(
          query=query,
          key=key,
          value=value,
          query_pos=query_pos,
          key_pos=key_pos,
          attn_mask=cross_attn_mask,
          key_padding_mask=key_padding_mask,
          **kwargs,
      )
      query = self.norms[1](query)
      query = self.ffn(query)
      query = self.norms[2](query)
  
      return query
  
imports: from typing import Union
  import torch
  from mmcv.cnn import build_norm_layer
  from mmcv.cnn.bricks.transformer import FFN, MultiheadAttention
  from mmengine import ConfigDict
  from mmengine.model import BaseModule, ModuleList
  from torch import Tensor
  from mmdet.utils import ConfigType, OptConfigType
label_desc: Use image node_id 3 for calling the DetrTransformerDecoderLayer obj's underlying member method code with example usage: obj.forward(query, key, value, query_pos, key_pos, _attn_mask, cross_attn_mask, key_padding_mask) and returns: query