class_docstr: Multi-scale Deformable Attention used in Deformable DETR.
  
  Described in https://arxiv.org/abs/2010.04159.
class_docstr_tok: ["Multi-scale","Deformable","Attention","used","in","Deformable","DETR",".","Described","in","https",":","\/\/arxiv.org\/abs\/2010.04159","."]
docstr: Args:
      query: shape (N, Lq, C)
      reference_points: shape (N, Lq, n_levels, 4)
      value: shape (N, Lv, C)
      value_spatial_shapes: [(H0, W0), (H1, W1), ...]
  
  Returns:
      output, shape (N, Lq, C)
docstr_tok: ["Args",":","query",":","shape","(","N",",","Lq",",","C",")","reference_points",":","shape","(","N",",","Lq",",","n_levels",",","4",")","value",":","shape","(","N",",","Lv",",","C",")","value_spatial_shapes",":","[","(","H0",",","W0",")",",","(","H1",",","W1",")",",","...","]","Returns",":","output",",","shape","(","N",",","Lq",",","C",")"]
code: def forward(
      self,
      query: Tensor,
      reference_points: Tensor,
      value: Tensor,
      value_spatial_shapes: list[tuple[int, int]],
  ) -> Tensor:
      """
      Args:
          query: shape (N, Lq, C)
          reference_points: shape (N, Lq, n_levels, 4)
          value: shape (N, Lv, C)
          value_spatial_shapes: [(H0, W0), (H1, W1), ...]
  
      Returns:
          output, shape (N, Lq, C)
      """
      N, Lenq, _ = query.shape
      _, Len_v, _ = value.shape
  
      sampling_offsets = self.sampling_offsets(query).reshape(
          N, Lenq, self.num_heads, self.num_levels, self.num_points, 2
      )
      attention_weights = self.attention_weights(query).reshape(
          N, Lenq, self.num_heads, self.num_levels * self.num_points
      )
      attention_weights = attention_weights.softmax(-1).reshape(
          N, Lenq, self.num_heads, self.num_levels, self.num_points
      )
  
      # prepare the spatial sampling grid
      reference_points_cxcy = reference_points[:, :, None, :, None, :2]
      reference_points_wh = reference_points[:, :, None, :, None, 2:]
      sampling_locations = (
          reference_points_cxcy
          + sampling_offsets
          / self.num_points
          * reference_points_wh
          * 0.5
      )
  
      value_buf = self.value_proj(value).reshape(
          N, Len_v, self.num_heads, self.head_dim
      )
  
      out = _deformable_attention_kernel(
          value_buf,
          value_spatial_shapes,
          sampling_locations,
          attention_weights,
      )
  
      # final projection
      out = self.output_proj(out)
  
      return out
  
imports: from __future__ import annotations
  from typing import Optional
  import torch
  from torch import nn
  from kornia.contrib.models.common import MLP, ConvNormAct
  from kornia.core import Module, Tensor, concatenate
label_desc: Use image node_id 2 for calling the MultiScaleDeformableAttention obj's underlying member method code with example usage: obj.forward(query, reference_points, value, value_spatial_shapes) and returns: out