class_docstr: Implements decoder layer in DAB-DETR transformer.
docstr: Args:
      query (Tensor): The input query with shape [bs, num_queries,
          dim].
      key (Tensor): The key tensor with shape [bs, num_keys,
          dim].
      query_pos (Tensor): The positional encoding for query in self
          attention, with the same shape as `x`.
      key_pos (Tensor): The positional encoding for `key`, with the
          same shape as `key`.
      ref_sine_embed (Tensor): The positional encoding for query in
          cross attention, with the same shape as `x`.
          Defaults to None.
      self_attn_masks (Tensor): ByteTensor mask with shape [num_queries,
          num_keys]. Same in `nn.MultiheadAttention.forward`.
          Defaults to None.
      cross_attn_masks (Tensor): ByteTensor mask with shape [num_queries,
          num_keys]. Same in `nn.MultiheadAttention.forward`.
          Defaults to None.
      key_padding_mask (Tensor): ByteTensor with 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 with shape
      [bs, num_queries, dim].
docstr_tok: ["Args",":","query","(","Tensor",")",":","The","input","query","with","shape","[","bs",",","num_queries",",","dim","]",".","key","(","Tensor",")",":","The","key","tensor","with","shape","[","bs",",","num_keys",",","dim","]",".","query_pos","(","Tensor",")",":","The","positional","encoding","for","query","in","self","attention",",","with","the","same","shape","as","`","x","`",".","key_pos","(","Tensor",")",":","The","positional","encoding","for","`","key","`",",","with","the","same","shape","as","`","key","`",".","ref_sine_embed","(","Tensor",")",":","The","positional","encoding","for","query","in","cross","attention",",","with","the","same","shape","as","`","x","`",".","Defaults","to","None",".","self_attn_masks","(","Tensor",")",":","ByteTensor","mask","with","shape","[","num_queries",",","num_keys","]",".","Same","in","`","nn.MultiheadAttention.forward","`",".","Defaults","to","None",".","cross_attn_masks","(","Tensor",")",":","ByteTensor","mask","with","shape","[","num_queries",",","num_keys","]",".","Same","in","`","nn.MultiheadAttention.forward","`",".","Defaults","to","None",".","key_padding_mask","(","Tensor",")",":","ByteTensor","with","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","with","shape","[","bs",",","num_queries",",","dim","]","."]
code: def forward(
      self,
      query: Tensor,
      key: Tensor,
      query_pos: Tensor,
      key_pos: Tensor,
      ref_sine_embed: Tensor = None,
      self_attn_masks: Tensor = None,
      cross_attn_masks: Tensor = None,
      key_padding_mask: Tensor = None,
      is_first: bool = False,
      **kwargs,
  ) -> Tensor:
      """
      Args:
          query (Tensor): The input query with shape [bs, num_queries,
              dim].
          key (Tensor): The key tensor with shape [bs, num_keys,
              dim].
          query_pos (Tensor): The positional encoding for query in self
              attention, with the same shape as `x`.
          key_pos (Tensor): The positional encoding for `key`, with the
              same shape as `key`.
          ref_sine_embed (Tensor): The positional encoding for query in
              cross attention, with the same shape as `x`.
              Defaults to None.
          self_attn_masks (Tensor): ByteTensor mask with shape [num_queries,
              num_keys]. Same in `nn.MultiheadAttention.forward`.
              Defaults to None.
          cross_attn_masks (Tensor): ByteTensor mask with shape [num_queries,
              num_keys]. Same in `nn.MultiheadAttention.forward`.
              Defaults to None.
          key_padding_mask (Tensor): ByteTensor with 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 with 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,
          **kwargs,
      )
      query = self.norms[0](query)
      query = self.cross_attn(
          query=query,
          key=key,
          query_pos=query_pos,
          key_pos=key_pos,
          ref_sine_embed=ref_sine_embed,
          attn_mask=cross_attn_masks,
          key_padding_mask=key_padding_mask,
          is_first=is_first,
          **kwargs,
      )
      query = self.norms[1](query)
      query = self.ffn(query)
      query = self.norms[2](query)
  
      return query
  
imports: from typing import List
  import torch
  import torch.nn
  from mmcv.cnn import build_norm_layer
  from mmcv.cnn.bricks.transformer import FFN
  from mmengine.model import ModuleList
  from torch import Tensor
  from .detr_layers import DetrTransformerDecoder, DetrTransformerDecoderLayer, DetrTransformerEncoder, DetrTransformerEncoderLayer
  from .utils import MLP, ConditionalAttention, coordinate_to_encoding, inverse_sigmoid
label_desc: Use image node_id 2 for calling the DABDetrTransformerDecoderLayer obj's underlying member method code with example usage: obj.forward(query, key, query_pos, key_pos, ref_sine_embed, _attn_masks, cross_attn_masks, key_padding_mask, is_first) and returns: query