docstr: Multi-Scale Deformable Attention Module
docstr_tok: ["Multi-Scale","Deformable","Attention","Module"]
code: def __init__(
      self,
      embed_dim=256,
      num_heads=8,
      num_levels=4,
      num_points=4,
      lr_mult=0.1,
  ):
      """
      Multi-Scale Deformable Attention Module
      """
      super(MSDeformableAttention, self).__init__()
      self.embed_dim = embed_dim
      self.num_heads = num_heads
      self.num_levels = num_levels
      self.num_points = num_points
      self.total_points = num_heads * num_levels * num_points
  
      self.head_dim = embed_dim // num_heads
      assert (
          self.head_dim * num_heads == self.embed_dim
      ), "embed_dim must be divisible by num_heads"
  
      self.sampling_offsets = nn.Linear(
          embed_dim,
          self.total_points * 2,
          weight_attr=ParamAttr(learning_rate=lr_mult),
          bias_attr=ParamAttr(learning_rate=lr_mult),
      )
  
      self.attention_weights = nn.Linear(embed_dim, self.total_points)
      self.value_proj = nn.Linear(embed_dim, embed_dim)
      self.output_proj = nn.Linear(embed_dim, embed_dim)
      try:
          # use cuda op
          print("use deformable_detr_ops in ms_deformable_attn")
          from deformable_detr_ops import ms_deformable_attn
      except:
          # use paddle func
          from .utils import (
              deformable_attention_core_func as ms_deformable_attn,
          )
      self.ms_deformable_attn_core = ms_deformable_attn
  
      self._reset_parameters()
  
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 1 to create a new MSDeformableAttention object from inherited base classes: nn with example: obj = MSDeformableAttention(embed_dim, num_heads, num_levels, num_points, lr_mult)