docstr: Multi-Scale Deformable Attention Module.
  
  Args:
      d_model(int, optional): The hidden dimension. Default: 256
      n_levels(int, optional): The number of feature levels. Default: 4
      n_heads(int, optional): The number of attention heads. Default: 8
      n_points(int, optional): The number of sampling points per attention head per feature level. Default: 4
      ratio (float, optional): The ratio of channels for Linear. Default: 1.0
docstr_tok: ["Multi-Scale","Deformable","Attention","Module",".","Args",":","d_model","(","int",",","optional",")",":","The","hidden","dimension",".","Default",":","256","n_levels","(","int",",","optional",")",":","The","number","of","feature","levels",".","Default",":","4","n_heads","(","int",",","optional",")",":","The","number","of","attention","heads",".","Default",":","8","n_points","(","int",",","optional",")",":","The","number","of","sampling","points","per","attention","head","per","feature","level",".","Default",":","4","ratio","(","float",",","optional",")",":","The","ratio","of","channels","for","Linear",".","Default",":","1.0"]
code: def __init__(
      self, d_model=256, n_levels=4, n_heads=8, n_points=4, ratio=1.0
  ):
      """Multi-Scale Deformable Attention Module.
  
      Args:
          d_model(int, optional): The hidden dimension. Default: 256
          n_levels(int, optional): The number of feature levels. Default: 4
          n_heads(int, optional): The number of attention heads. Default: 8
          n_points(int, optional): The number of sampling points per attention head per feature level. Default: 4
          ratio (float, optional): The ratio of channels for Linear. Default: 1.0
      """
      super().__init__()
      if d_model % n_heads != 0:
          raise ValueError(
              "d_model must be divisible by n_heads, "
              "but got {} and {}".format(d_model, n_heads)
          )
      _d_per_head = d_model // n_heads
      # you'd better set _d_per_head to a power of 2
      # which is more efficient in our CUDA implementation
      if not self._is_power_of_2(_d_per_head):
          warnings.warn(
              "You'd better set d_model in MSDeformAttn to make "
              "the dimension of each attention head a power of 2 "
              "which is more efficient in our CUDA implementation."
          )
  
      self.im2col_step = 64
      self.d_model = d_model
      self.n_levels = n_levels
      self.n_heads = n_heads
      self.n_points = n_points
      self.ratio = ratio
  
      self.sampling_offsets = nn.Linear(
          d_model, n_heads * n_levels * n_points * 2
      )
      self.attention_weights = nn.Linear(
          d_model, n_heads * n_levels * n_points
      )
      self.value_proj = nn.Linear(d_model, int(d_model * ratio))
      self.output_proj = nn.Linear(int(d_model * ratio), d_model)
  
      self._reset_parameters()
  
file_path: PaddleSeg/paddleseg/models/layers/ms_deformable_attention.py
imports: import math
  import warnings
  import paddle
  import paddle.nn
  import paddle.nn.functional
  from paddleseg.cvlibs import param_init
  from paddleseg.cvlibs.param_init import constant_init, xavier_uniform
label_desc: Use image node_id 1 to create a new MSDeformAttn object from inherited base classes: nn with example: obj = MSDeformAttn(d_model, n_levels, n_heads, n_points, ratio)