class_docstr: An attention module used in PETR. `End-to-End Multi-Person
  Pose Estimation with Transformers`.
  
  Args:
      embed_dims (int): The embedding dimension of Attention.
          Default: 256.
      num_heads (int): Parallel attention heads. Default: 8.
      num_levels (int): The number of feature map used in
          Attention. Default: 4.
      num_points (int): The number of sampling points for
          each query in each head. Default: 17.
      im2col_step (int): The step used in image_to_column.
          Default: 64.
      dropout (float): A Dropout layer on `inp_residual`.
          Default: 0.1.
      init_cfg (obj:`mmcv.ConfigDict`): The Config for initialization.
          Default: None.
class_docstr_tok: ["An","attention","module","used","in","PETR",".","`","End-to-End","Multi-Person","Pose","Estimation","with","Transformers","`",".","Args",":","embed_dims","(","int",")",":","The","embedding","dimension","of","Attention",".","Default",":","256.","num_heads","(","int",")",":","Parallel","attention","heads",".","Default",":","8.","num_levels","(","int",")",":","The","number","of","feature","map","used","in","Attention",".","Default",":","4.","num_points","(","int",")",":","The","number","of","sampling","points","for","each","query","in","each","head",".","Default",":","17.","im2col_step","(","int",")",":","The","step","used","in","image_to_column",".","Default",":","64.","dropout","(","float",")",":","A","Dropout","layer","on","`","inp_residual","`",".","Default",":","0.1.","init_cfg","(","obj",":","`","mmcv.ConfigDict","`",")",":","The","Config","for","initialization",".","Default",":","None","."]
docstr: Forward Function of MultiScaleDeformAttention.
  
  Args:
      query (Tensor): Query of Transformer with shape
          (num_query, bs, embed_dims).
      key (Tensor): The key tensor with shape (num_key, bs, embed_dims).
      value (Tensor): The value tensor with shape
          (num_key, bs, embed_dims).
      residual (Tensor): The tensor used for addition, with the
          same shape as `x`. Default None. If None, `x` will be used.
      reference_points (Tensor):  The normalized reference points with
          shape (bs, num_query, num_levels, K*2), all elements is range
          in [0, 1], top-left (0,0), bottom-right (1, 1), including
          padding area.
      attn_mask (Tensor): ByteTensor for `query`, with
          shape [bs, num_key].
      value_spatial_shapes (Tensor): Spatial shape of features in
          different level. With shape  (num_levels, 2),
          last dimension represent (h, w).
      value_level_start_index (Tensor): The start index of each level.
          A tensor has shape (num_levels) and can be represented
          as [0, h_0*w_0, h_0*w_0+h_1*w_1, ...].
  
  Returns:
      Tensor: forwarded results with shape [num_query, bs, embed_dims].
docstr_tok: ["Forward","Function","of","MultiScaleDeformAttention",".","Args",":","query","(","Tensor",")",":","Query","of","Transformer","with","shape","(","num_query",",","bs",",","embed_dims",")",".","key","(","Tensor",")",":","The","key","tensor","with","shape","(","num_key",",","bs",",","embed_dims",")",".","value","(","Tensor",")",":","The","value","tensor","with","shape","(","num_key",",","bs",",","embed_dims",")",".","residual","(","Tensor",")",":","The","tensor","used","for","addition",",","with","the","same","shape","as","`","x","`",".","Default","None",".","If","None",",","`","x","`","will","be","used",".","reference_points","(","Tensor",")",":","The","normalized","reference","points","with","shape","(","bs",",","num_query",",","num_levels",",","K","*","2",")",",","all","elements","is","range","in","[","0",",","1","]",",","top-left","(","0,0",")",",","bottom-right","(","1",",","1",")",",","including","padding","area",".","attn_mask","(","Tensor",")",":","ByteTensor","for","`","query","`",",","with","shape","[","bs",",","num_key","]",".","value_spatial_shapes","(","Tensor",")",":","Spatial","shape","of","features","in","different","level",".","With","shape","(","num_levels",",","2",")",",","last","dimension","represent","(","h",",","w",")",".","value_level_start_index","(","Tensor",")",":","The","start","index","of","each","level",".","A","tensor","has","shape","(","num_levels",")","and","can","be","represented","as","[","0",",","h_0","*","w_0",",","h_0","*","w_0+h_1","*","w_1",",","...","]",".","Returns",":","Tensor",":","forwarded","results","with","shape","[","num_query",",","bs",",","embed_dims","]","."]
code: def forward(
      self,
      query,
      key,
      value,
      residual=None,
      attn_mask=None,
      reference_points=None,
      value_spatial_shapes=None,
      value_level_start_index=None,
      **kwargs,
  ):
      """Forward Function of MultiScaleDeformAttention.
  
      Args:
          query (Tensor): Query of Transformer with shape
              (num_query, bs, embed_dims).
          key (Tensor): The key tensor with shape (num_key, bs, embed_dims).
          value (Tensor): The value tensor with shape
              (num_key, bs, embed_dims).
          residual (Tensor): The tensor used for addition, with the
              same shape as `x`. Default None. If None, `x` will be used.
          reference_points (Tensor):  The normalized reference points with
              shape (bs, num_query, num_levels, K*2), all elements is range
              in [0, 1], top-left (0,0), bottom-right (1, 1), including
              padding area.
          attn_mask (Tensor): ByteTensor for `query`, with
              shape [bs, num_key].
          value_spatial_shapes (Tensor): Spatial shape of features in
              different level. With shape  (num_levels, 2),
              last dimension represent (h, w).
          value_level_start_index (Tensor): The start index of each level.
              A tensor has shape (num_levels) and can be represented
              as [0, h_0*w_0, h_0*w_0+h_1*w_1, ...].
  
      Returns:
          Tensor: forwarded results with shape [num_query, bs, embed_dims].
      """
  
      if key is None:
          key = query
      if value is None:
          value = key
  
      bs, num_query, _ = query.shape
      bs, num_key, _ = value.shape
      assert (
          value_spatial_shapes[:, 0].numpy()
          * value_spatial_shapes[:, 1].numpy()
      ).sum() == num_key
  
      value = self.value_proj(value)
      if attn_mask is not None:
          # value = value.masked_fill(attn_mask[..., None], 0.0)
          value *= attn_mask.unsqueeze(-1)
      value = value.reshape([bs, num_key, self.num_heads, -1])
      sampling_offsets = self.sampling_offsets(query).reshape(
          [
              bs,
              num_query,
              self.num_heads,
              self.num_levels,
              self.num_points,
              2,
          ]
      )
      attention_weights = self.attention_weights(query).reshape(
          [
              bs,
              num_query,
              self.num_heads,
              self.num_levels * self.num_points,
          ]
      )
      attention_weights = F.softmax(attention_weights, axis=-1)
  
      attention_weights = attention_weights.reshape(
          [
              bs,
              num_query,
              self.num_heads,
              self.num_levels,
              self.num_points,
          ]
      )
      if reference_points.shape[-1] == self.num_points * 2:
          reference_points_reshape = reference_points.reshape(
              (bs, num_query, self.num_levels, -1, 2)
          ).unsqueeze(2)
          x1 = reference_points[:, :, :, 0::2].min(
              axis=-1, keepdim=True
          )
          y1 = reference_points[:, :, :, 1::2].min(
              axis=-1, keepdim=True
          )
          x2 = reference_points[:, :, :, 0::2].max(
              axis=-1, keepdim=True
          )
          y2 = reference_points[:, :, :, 1::2].max(
              axis=-1, keepdim=True
          )
          w = paddle.clip(x2 - x1, min=1e-4)
          h = paddle.clip(y2 - y1, min=1e-4)
          wh = paddle.concat([w, h], axis=-1)[:, :, None, :, None, :]
  
          sampling_locations = (
              reference_points_reshape + sampling_offsets * wh * 0.5
          )
      else:
          raise ValueError(
              f"Last dim of reference_points must be"
              f" 2K, but get {reference_points.shape[-1]} instead."
          )
  
      output = self.ms_deformable_attn_core(
          value,
          value_spatial_shapes,
          value_level_start_index,
          sampling_locations,
          attention_weights,
      )
  
      output = self.output_proj(output)
      return output
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import math
  import numpy
  import paddle
  import paddle.nn
  import paddle.nn.functional
  from paddle import ParamAttr
  from ppdet.core.workspace import register
  from ..layers import MultiHeadAttention, _convert_attention_mask
  from .utils import _get_clones
  from ..initializer import linear_init_, normal_, constant_, xavier_uniform_
label_desc: Use image node_id 3 for calling the MultiScaleDeformablePoseAttention obj's underlying member method code with example usage: obj.forward(query, key, value, residual, attn_mask, reference_points, value_spatial_shapes, value_level_start_index) and returns: output