---
title: "ClikaRT::ops::mrope_rotary_embedding_qk_varlen"
sidebar_label: "mrope_rotary_embedding_qk_varlen"
description: "Multi-axis RoPE over a packed q/k pair: ONE per-token angle table serves both projections in a single call, the media-prefill pre-rotation shape."
---

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

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

## mrope\_rotary\_embedding\_qk\_varlen() {#mrope_rotary_embedding_qk_varlen}

<div class="api-signature">

`std::array<`[`Tensor`](../Tensor.md) `2>` **`mrope_rotary_embedding_qk_varlen`**(<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`Tensor`](../Tensor.md) `query`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`Tensor`](../Tensor.md) `key`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`Tensor`](../Tensor.md) `position_ids`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`ClikaRT::Span`](../Span.md)`<const std::int64_t>` `mrope_sections`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`std::optional<bool>` `interleaved_sections` `=` `std::nullopt`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`std::optional<double>` `theta` `=` `std::nullopt`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`std::optional<`[`RopeScaling`](./index.md#RopeScaling)`>` `scaling` `=` `std::nullopt`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`std::optional<`[`RotaryMode`](./index.md#RotaryMode)`>` `mode` `=` `std::nullopt`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`std::optional<int64_t>` `rotary_dim` `=` `std::nullopt`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`std::optional<double>` `scale` `=` `std::nullopt`<br />
)

</div>

Multi-axis RoPE over a packed q/k pair: ONE per-token angle table serves both projections in a single call, the media-prefill pre-rotation shape. `query`/`key` are head-exposed `[n_tokens, heads, head_dim]` (a flat `[n_tokens, heads·head_dim]` projection reshapes to it as a free view; the rotation spans the TRAILING dim, so a flat row would rotate across head boundaries); `position_ids` is `[n_axes, n_tokens]` with `n_axes == mrope_sections.size()` (strip any trailing zero sections a checkpoint's metadata pads; the axis count follows the section list); `rotary_dim` bounds the rotated span (dims beyond it pass through) and defaults to the trailing dim. Rows whose per-axis positions are all EQUAL rotate exactly as the plain ops do; serve pure-text calls through `rotary_embedding*` (cheaper: no per-token table), and use this form for packs whose rows carry genuinely multi-axis positions, then attend with the rope inputs ABSENT so the attention op consumes (and appends) q/k exactly as given.

**Returns:** a 2-element array \{q, k\}.

<div class="api-declared">

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

</div>
