Skip to content

vllm.model_executor.layers.rotary_embedding.mrope

Classes:

Functions:

MRotaryEmbedding

Bases: RotaryEmbeddingBase

Rotary Embedding with Multimodal Sections.

Methods:

  • forward_native –

    PyTorch-native implementation equivalent to forward().

forward_native(positions, query, key=None, offsets=None)

PyTorch-native implementation equivalent to forward().

Parameters:

  • positions

    (Tensor) –

    [num_tokens,] (text only) or [3, num_tokens] (T/H/W positions with multimodal inputs)

  • query

    (Tensor) –

    [num_tokens, num_heads * head_size]

  • key

    (Tensor | None, default: None ) –

    [num_tokens, num_kv_heads * head_size]

  • offsets

    (Tensor | None, default: None ) –

    Optional per-token position offsets added to positions.

apply_interleaved_rope(x, mrope_section)

Apply interleaved MRoPE to 3D rotary embeddings. Reorganizes frequency layout from chunked [TTT...HHH...WWW] to interleaved [THWTHWTHW...TT], preserving frequency continuity.

triton_mrope(q, k, cos, sin, mrope_section, head_size, rotary_dim, mrope_interleaved, is_neox_style)

Qwen2VL mrope kernel.

Parameters:

  • q

    (Tensor) –

    [num_tokens, num_heads * head_size]

  • k

    (Tensor) –

    [num_tokens, num_kv_heads * head_size]

  • cos

    (Tensor) –

    [3, num_tokens, rotary_dim // 2] (T/H/W positions with multimodal inputs)

  • sin

    (Tensor) –

    [3, num_tokens, rotary_dim // 2] (T/H/W positions with multimodal inputs)

  • mrope_section

    (list[int]) –

    [t, h, w]

  • head_size

    (int) –

    int

  • rotary_dim

    (int) –

    Number of leading dimensions rotary is applied to.

  • mrope_interleaved

    (bool) –

    Whether the T/H/W sections are interleaved rather than concatenated.

  • is_neox_style

    (bool) –

    Whether rotary pairs use split-half (NeoX) or adjacent (GPT-J) layout.