class_docstr: Implements decoder layer in Conditional DETR transformer.
class_docstr_tok: ["Implements","decoder","layer","in","Conditional","DETR","transformer","."]
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`.
      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`.
      ref_sine_embed (Tensor): The positional encoding for query in
          cross attention, with the same shape as `x`. 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_masks (Tensor, optional): ByteTensor mask, has shape
          (num_queries, num_keys), Same in `nn.MultiheadAttention.
          forward`. Defaults to None.
      cross_attn_masks (Tensor, optional): ByteTensor mask, has shape
          (num_queries, num_keys), Same in `nn.MultiheadAttention.
          forward`. Defaults to None.
      key_padding_mask (Tensor, optional): ByteTensor, has shape
          (bs, num_keys). Defaults to None.
      is_first (bool): A indicator to tell whether the current layer
          is the first layer of the decoder. Defaults to False.
  
  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","`",".","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","`",".","ref_sine_embed","(","Tensor",")",":","The","positional","encoding","for","query","in","cross","attention",",","with","the","same","shape","as","`","x","`",".","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_masks","(","Tensor",",","optional",")",":","ByteTensor","mask",",","has","shape","(","num_queries",",","num_keys",")",",","Same","in","`","nn.MultiheadAttention",".","forward","`",".","Defaults","to","None",".","cross_attn_masks","(","Tensor",",","optional",")",":","ByteTensor","mask",",","has","shape","(","num_queries",",","num_keys",")",",","Same","in","`","nn.MultiheadAttention",".","forward","`",".","Defaults","to","None",".","key_padding_mask","(","Tensor",",","optional",")",":","ByteTensor",",","has","shape","(","bs",",","num_keys",")",".","Defaults","to","None",".","is_first","(","bool",")",":","A","indicator","to","tell","whether","the","current","layer","is","the","first","layer","of","the","decoder",".","Defaults","to","False",".","Returns",":","Tensor",":","Forwarded","results",",","has","shape","(","bs",",","num_queries",",","dim",")","."]
code: def forward(
      self,
      query: Tensor,
      key: Tensor = None,
      query_pos: Tensor = None,
      key_pos: Tensor = None,
      self_attn_masks: Tensor = None,
      cross_attn_masks: Tensor = None,
      key_padding_mask: Tensor = None,
      ref_sine_embed: Tensor = None,
      is_first: bool = False,
  ):
      """
      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`.
          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`.
          ref_sine_embed (Tensor): The positional encoding for query in
              cross attention, with the same shape as `x`. 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_masks (Tensor, optional): ByteTensor mask, has shape
              (num_queries, num_keys), Same in `nn.MultiheadAttention.
              forward`. Defaults to None.
          cross_attn_masks (Tensor, optional): ByteTensor mask, has shape
              (num_queries, num_keys), Same in `nn.MultiheadAttention.
              forward`. Defaults to None.
          key_padding_mask (Tensor, optional): ByteTensor, has shape
              (bs, num_keys). Defaults to None.
          is_first (bool): A indicator to tell whether the current layer
              is the first layer of the decoder. Defaults to False.
  
      Returns:
          Tensor: Forwarded results, has shape (bs, num_queries, dim).
      """
      query = self.self_attn(
          query=query,
          key=query,
          query_pos=query_pos,
          key_pos=query_pos,
          attn_mask=self_attn_masks,
      )
      query = self.norms[0](query)
      query = self.cross_attn(
          query=query,
          key=key,
          query_pos=query_pos,
          key_pos=key_pos,
          attn_mask=cross_attn_masks,
          key_padding_mask=key_padding_mask,
          ref_sine_embed=ref_sine_embed,
          is_first=is_first,
      )
      query = self.norms[1](query)
      query = self.ffn(query)
      query = self.norms[2](query)
  
      return query
  
file_path: mmdetection/mmdet/models/layers/transformer/conditional_detr_layers.py
imports: import torch
  from mmcv.cnn import build_norm_layer
  from mmcv.cnn.bricks.transformer import FFN
  from torch import Tensor
  from torch.nn import ModuleList
  from .detr_layers import DetrTransformerDecoder, DetrTransformerDecoderLayer
  from .utils import MLP, ConditionalAttention, coordinate_to_encoding
label_desc: Use image node_id 2 for calling the ConditionalDetrTransformerDecoderLayer obj's underlying member method code with example usage: obj.forward(query, key, query_pos, key_pos, _attn_masks, cross_attn_masks, key_padding_mask, ref_sine_embed, is_first) and returns: query