Repository navigation
Closed
Labels
area:architectureArchitecture and code structure changesarea:inferenceGeneration, sampling, decoding (incl. speculative, DRY)priority:mediumMedium prioritystatus:doneCompletedtype:enhancementNew features, capabilities, or significant additions
Description
Parent and dependency
- Parent epic: epic: OpenXLA multimodal / VLM architecture support (Qwen2-VL, Gemma3n, Phi4MM, Molmo, and more) #566
- Blocked by feat(xla): seed single and batched IREE sessions from embeddings #860
- Existing Qwen position construction:
src/multimodal/qwen_vl.rs,src/models/qwen2_vl.rs, andsrc/models/qwen_vl_position_tests.rs - Existing XLA RoPE/decode emitter:
src/lib/mlxcel-xla/src/emitter/model.rs
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_deltaper 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_deltathrough 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.
Metadata
Metadata
Assignees
Labels
area:architectureArchitecture and code structure changesarea:inferenceGeneration, sampling, decoding (incl. speculative, DRY)priority:mediumMedium prioritystatus:doneCompletedtype:enhancementNew features, capabilities, or significant additions
Activity
fix(xla): reject incomplete explicit M-RoPE configs
feat(xla): add multimodal RoPE position state (#894)
feat(xla): add multimodal RoPE position state (lablup#894)