Repository navigation
fix: restore Phi4MM audio on the XLA and eager CLI paths - #3380
Merged
Merged
Conversation
OpenXLA: since #2861 the loader transposes every `Proj` spec for the single-sequence `InOut` layout, but the Phi4MM speech/vision LoRA A/B tensors were pushed as `Proj` while the emitter declares them in the checkpoint layout (`[rank, in]`, `[out, rank]`) and contracts them with the untransposed helpers. Prefill failed with `expected 320x3072, actual 3072x320`. The pairs are now `Whole` specs, which the loader never transposes in any layout and keeps f32-resident (the declared element type), so the ragged `OutIn` path is unchanged. A `WeightSpec::uploads_transposed` helper now drives the loader's `Proj` branch, and a new test checks the declared LoRA shapes of the prefill, embeddings-prefill, decode and ragged graphs against what the loader uploads in both layouts (it fails with the old `Proj` push). Eager: since #874 `materialize_phi4mm_ordered_prompt` refused a prompt without ordered-media markers, which is what the CLI renders through the Phi4MM template. Mirroring the Gemma3n fallback from #922, such a prompt now passes through to `prepare_phi4mm_prompt_tokens`, which inserts the audio tag at the start of the user turn (as the OpenXLA CLI does) and still rejects a placeholder count that disagrees with the request. Verified on microsoft/Phi-4-multimodal-instruct@93f923e1 with the official WAV: eager, XLA cuda and XLA local-task all produce `13347 382 10147 306 495 3621`. Closes #3362
6 tasks done
Member
Author
Implementation Review SummaryIntent
Findings AddressedNo CRITICAL or HIGH findings, so no commits were added. Remaining Items
Checks
Verification
|
inureyes
marked this pull request as ready for review
November 24, 2026 03:07
…-audio # Conflicts: # CHANGELOG.md
This was referenced Nov 24, 2026
5 tasks done
inureyes
added a commit
that referenced
this pull request
Nov 24, 2026
## Summary The OpenXLA CLI now prepares a request's images (or Phi4MM media) before it compiles its one context shape. It sizes the shape and admission from `PreparedPrefill::sequence_len`, the expanded prompt the family preprocessor actually produced. The serve worker already routes on that same length. The per-family worst-case floor is no longer added on top, so Qwen2-VL stops compiling 32768 for a 64-token image, and Gemma3, Molmo v1 and Phi4MM no longer get a 256 shape they cannot fit. - `multimodal::xla_image_prefill` holds the one rule: `PreparedImagePrefill`, `prepare_image_prefill` (DeepStack first) and `xla_request_positions`. The CLI, `XlaBackendSession::generate_images_greedy` and the server preprocess stage all use it. - `backend::xla::create_prepared_xla_session` builds the request-sized session and takes over the preprocessor that prepared the images, so vision weights load once. - `xla_image_context_floor` now only picks the server's startup buckets and guards an unsized session. Family vision limits still fail closed, and the Qwen3-VL 512-patch IREE vision bound is documented in the module docs and in `docs/environment-variables.md`. ## Verification (GB10, XLA cuda, `tests/fixtures/test_image.png`, `-n 16 --temp 0`, eager with `MLXCEL_SDPA_DETERMINISTIC=1`) | Model | Old shape | New shape (prompt) | Tokens vs eager | |---|---|---|---| | qwen2-vl-2b-instruct-4bit | 32768 (OOM) | 256 (89) | 11/11 match | | qwen2.5-vl-3b-instruct-4bit | 32768 (OOM), pinned 256 refused | 256 (89), pinned 256 admitted | 16/16 match | | qwen3-vl-2b-instruct-4bit | 256 | 256 (78) | 16/16 match | | gemma-3-4b-it-4bit | 256, refused | 512 (272) | 15/16, known token-16 divergence | | molmo-7b-d-0924-4bit | 256, refused | 512 (325) | 16/16 match | | youtu-vl-4b-instruct | 256 | 256 (74) | admitted; output broken by #3364 | | phi-4-multimodal-instruct | 256, refused | 1024 (552) | 16/16 match with #3380's fix applied locally; on main prefill fails with the #3362 LoRA transpose | | llava-interleave-qwen-0.5b-bf16 | 1024 | 1024 (742) | 16/16 match | Each XLA run matched the same binary pinned at `MLXCEL_XLA_CONTEXT_CAPACITY=1024`. `llava-1.5-7b-4bit` cannot load its XLA image preprocessor on main (`text_config.hidden_size` missing), and that is unrelated to sizing. After review: the Qwen2-VL/Qwen2.5-VL 256-patch vision cap (`QWEN2_VL_PATCH_BUCKETS`) is documented next to the Qwen3-VL 512 and Youtu-VL 256 caps and pinned by a refusal test; CLI `preparation_time` excludes the one-time vision weight load and compile, as before; the unpinned Phi4MM producer is bounded by `min(window, context ladder top)`; a two-image test pins multi-image sizing. - [x] Per-family expansion and sizing unit tests (`multimodal::xla_image_prefill::tests`, including the large-image refusals for Qwen2-VL, Qwen3-VL and Youtu-VL and a two-image case), server `xla_preprocess` tests, CLI sizing tests (18 pass) - [x] `cargo check --features cuda,xla-iree --all-targets`, `cargo check --no-default-features --features xla-diagnostics --all-targets`, `cargo clippy --features cuda,xla-iree --lib --bins -D warnings`, `scripts/insert_apache_header.py --check` Closes #3361
This was referenced Nov 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
WeightSpec::Whole, notProj. Since perf(xla): load single-sequence graphs with transposed weights (#2859) #2861 the loader transposesProjspecs for the single-sequenceInOutlayout, while the emitter declares the LoRA pairs in the checkpoint layout ([rank, in],[out, rank]) and contracts them untransposed, so prefill failed withexpected 320x3072, actual 3072x320.Wholeis never transposed and stays f32-resident (the declared element type) in every layout, so the raggedOutInpath uploads exactly what it did before. I chose this over flipping the declarations because the LoRA branch is shared by single and ragged graphs. Flipping the declarations would have meant changing the LoRA branch per layout, and the f16-residentProjrule would also have needed an exemption.WeightSpec::uploads_transposednow drives the loader'sProjbranch. The new testphi4mm_lora_declared_shapes_match_uploaded_shapes_in_every_layoutcompares the declared LoRA shapes in the prefill, embeddings-prefill, decode and ragged graphs against what the loader uploads, in both layouts. With the oldProjpush it fails:prefill (InOut) declares ...qkv.lora_A.speech as [3, 8] but the loader uploads [8, 3].materialize_phi4mm_ordered_promptnow passes a prompt without ordered-media markers through toprepare_phi4mm_prompt_tokens, as the Gemma3n path does since feat(xla): add Gemma3n audio execution #922. That function inserts the audio tag at the start of the user turn, which is the same normalization the OpenXLA CLI applies, and it still rejects a placeholder count that disagrees with the request.Test plan
Checkpoint: microsoft/Phi-4-multimodal-instruct@93f923e1. Input: the official
what_is_shown_in_this_image.wavwith "Transcribe the audio exactly." and-n 8 --temp 0.MLXCEL_SDPA_DETERMINISTIC=1), XLA cuda and XLA local-task all produce13347 382 10147 306 495 3621("what is shown in this image")xla_phi4_audio_checkpasses on local-task and cudacargo test -p mlxcel-xla --lib -- phi4andcargo test --features cuda --lib -- phi4mm_passcargo check --features cuda,xla-iree --all-targets,cargo check --no-default-features --features xla-diagnostics --all-targets,insert_apache_header.py --checkandcargo fmt --checkpassCloses #3362