---
title: "ClikaRT::ops::ms_deform_attention"
sidebar_label: "ms_deform_attention"
description: "Multi-scale deformable attention (2-D): per query and head, gather P bilinear samples from each of L flattened feature-map levels and combine them with the given weights."
---

<!-- Generated by tools/doxygen2mdx from Doxygen XML. Do not edit. -->

<span class="api-kind api-kind--function">function</span>

## ms\_deform\_attention() {#ms_deform_attention}

<div class="api-signature">

[`Tensor`](../Tensor.md) **`ms_deform_attention`**(<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`Tensor`](../Tensor.md) `value`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`Tensor`](../Tensor.md) `spatial_shapes`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`Tensor`](../Tensor.md) `level_start_index`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`Tensor`](../Tensor.md) `sampling_locations`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`Tensor`](../Tensor.md) `attention_weights`<br />
)

</div>

Multi-scale deformable attention (2-D): per query and head, gather `P` bilinear samples from each of `L` flattened feature-map levels and combine them with the given weights. `value [N, S, M, D]` with `S = Σ_l H_l·W_l`; `spatial_shapes [L, 2]` = per-level `(H_l, W_l)` and `level_start_index [L]` (both Int32 or Int64); `sampling_locations [N, Lq, M, L, P, 2]`; last dim `(x, y)`, normalized to `[0, 1]` per level, sampled at `loc·size − 0.5` (bilinear; out-of-bounds reads 0); `attention_weights [N, Lq, M, L, P]` are consumed AS GIVEN (apply softmax beforehand if wanted). Returns `[N, Lq, M, D]` at `value`'s dtype; accumulation is fp32. The float inputs must share `value`'s dtype (f32/f64/f16/bf16; no silent promotion).

<div class="api-declared">

Declared in `ClikaRT/compute/ops.h`, line 3906

</div>
