Skip to content

feat(xla): support multimodal 3D RoPE positions and decode deltas #864

Closed

Description

@inureyes

Parent and dependency

Problem

The XLA language-model path assumes one scalar position per token and derives incremental decode positions from cache length. Qwen2-VL, Qwen2.5-VL, and Qwen3-VL use multimodal 3D position IDs for temporal, height, and width axes during prefill, then carry a per-sequence RoPE delta into incremental decoding. Cache offsets and RoPE coordinates are related but not interchangeable.

Without a dedicated state contract, an implementation can appear correct on text-only prompts while rotating image tokens or post-prefill decode tokens at the wrong coordinates.

Goal

Add explicit 3-axis M-RoPE prefill and per-slot decode-delta support to XLA single and continuous-batch language-model execution, while leaving ordinary 1D RoPE behavior unchanged.

Position-state contract

  • Extend the backend-neutral prepared-prefill representation with an explicit position variant: 1D positions or 3-axis positions. Do not infer the variant from tensor rank after crossing the C ABI.
  • Canonicalize M-RoPE prefill positions as [3, Lp] for one request and [B, 3, Lp] for ragged batches, with documented axis ordering matching the existing MLX Qwen implementation.
  • Store one signed rope_delta per active slot. Cache length remains the physical KV offset; RoPE decode coordinates are derived from the Qwen family rule and the stored delta.
  • For one-token decode, provide the three coordinates explicitly to the graph even when all axes currently share the same value.

Required implementation

  • Generalize the StableHLO RoPE helper and argument schemas to accept the position variant without regressing architectures that use 1D RoPE, partial rotary dimensions, scaling, or sliding attention.
  • Implement Qwen M-RoPE section splitting and axis selection from model configuration. Validate section sums, rotary dimension, axis count, dtype/range, and sequence length during model loading.
  • Thread 3D positions and rope_delta through embeddings prefill, single-session state, XlaBatchEngine::Pending, active slot state, ragged batching, cancellation, and slot reset.
  • Keep cache position, logical token count, expanded multimodal length, and RoPE position as distinct named values. Avoid unsigned conversions until bounds have been validated.
  • Include position mode and M-RoPE configuration in module/artifact compatibility fingerprints.
  • Preserve the exact existing schema/module for non-M-RoPE text models when possible; otherwise provide golden-IR and token-exact regression evidence.
  • Return typed errors for missing/extra axes, wrong position length, invalid section config, overflow, and a prepared payload whose position mode disagrees with the loaded model.

Non-goals

  • Vision encoder, processor, placeholder expansion, or Qwen checkpoint loading.
  • Deepstack vision feature injection.
  • General video scheduling beyond representing the temporal coordinate supplied by a preprocessor.

Validation

  • Port the existing Qwen position fixtures to the backend-neutral contract and compare every prefill coordinate and computed decode coordinate with the MLX implementation.
  • Cover text-only Qwen prompts, one image, multiple images, a video-shaped temporal grid, left/right padding as supported, long prompts, negative and positive deltas, cancellation, and slot reuse.
  • Compare RoPE-transformed Q/K tensors for selected layers against an independent eager oracle before comparing logits and tokens.
  • Interleave 1D and M-RoPE requests in continuous batching and prove per-slot deltas cannot bleed across requests.
  • Run a real IREE prefill/decode sequence using synthetic 3D positions and the existing text model weights before family integration.
  • Run all existing XLA architecture/token-exact tests.

Acceptance criteria

  • Position mode is explicit from prepared input through the C ABI and StableHLO entry.
  • M-RoPE section/axis semantics match the existing MLX Qwen implementation.
  • Each slot owns and resets its signed decode delta independently.
  • Cache offsets are never reused as M-RoPE coordinates without the documented transformation.
  • Mixed 1D/M-RoPE batching and cancellation are covered.
  • Synthetic real-IREE execution and Q/K/logit oracle comparisons pass.
  • Non-M-RoPE text models remain token-exact.

Activity

  1. added
    status:blocked
    type:enhancement
    priority:medium
    area:architecture
    area:inference
    on Jul 22, 2026
  2. added
    status:in-progress
    status:review
    and removed
    status:blocked
    status:in-progress
    on Jul 23, 2026
  3. added
    status:done
    and removed
    status:review
    on Jul 23, 2026
  4. self-assigned this
    on Aug 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:architecturearea:inferencepriority:mediumstatus:donetype:enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions