Repository navigation
fix(xla): size CLI image requests from the processed media - #3388
Conversation
Since #2856 the OpenXLA CLI added a per-family worst-case image expansion to the text prompt before compiling its one context shape. Qwen2-VL and Qwen2.5-VL added the 16384-token maximum-pixel floor, so a 64-token 224x224 image compiled a 32768 shape that ran out of CUDA memory and was refused under MLXCEL_XLA_CONTEXT_CAPACITY=256. Gemma3, Molmo v1 and Phi4MM had no floor and compiled a 256 shape their expanded prompt (272, 325, 552 tokens) could not fit. The CLI now decodes and prepares the images (or the Phi4MM media) before it builds the session and sizes the shape and admission from PreparedPrefill::sequence_len, the expanded length the serve worker already routes on. The new multimodal::xla_image_prefill module holds that rule: PreparedImagePrefill and prepare_image_prefill (DeepStack first) are shared by the CLI, XlaBackendSession and the server preprocess stage. backend::xla::create_prepared_xla_session takes over the preprocessor that prepared the request so vision weights load once. The worst-case floor now only chooses the server's startup buckets and guards an unsized session. Family vision limits stay fail-closed, including the Qwen3-VL 512-patch IREE vision bound, which is documented. Verified on GB10 XLA cuda against eager for Qwen2-VL, Qwen2.5-VL (also pinned 256), Qwen3-VL, Gemma3, Molmo v1, Youtu-VL, Phi4MM and LLaVA-interleave; per-family expansion unit tests pin the sizing. Refs #3361
Implementation Review SummaryIntent
Findings AddressedNo CRITICAL or HIGH findings, so no fixes were pushed. Remaining Items
Verification
Server path: the stage now calls the shared Narrow tests: |
Apply the review findings on the request-sized XLA image path. The Qwen2-VL test asserted a 4096 shape for a 2048x1536 image that production refuses at the 256-patch vision bucket (QWEN2_VL_PATCH_BUCKETS), so it now asserts that refusal bound, and the module docs and environment-variables.md list the Qwen2-VL and Qwen2.5-VL cap next to the Qwen3-VL and Youtu-VL ones. A two-image Qwen2.5-VL test pins that sequence_len counts both expansions. The CLI preparation time no longer includes the one-time vision weight load and compile, so reported image throughput accounting matches the earlier behavior. The unpinned Phi4MM producer is bounded by the top of the context ladder, so an over-ladder prompt is refused before embeddings are computed. The stale create_session comment is corrected. Refs #3361
…age-sizing # Conflicts: # CHANGELOG.md
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_prefillholds the one rule:PreparedImagePrefill,prepare_image_prefill(DeepStack first) andxla_request_positions. The CLI,XlaBackendSession::generate_images_greedyand the server preprocess stage all use it.backend::xla::create_prepared_xla_sessionbuilds the request-sized session and takes over the preprocessor that prepared the images, so vision weights load once.xla_image_context_floornow 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 indocs/environment-variables.md.Verification (GB10, XLA cuda,
tests/fixtures/test_image.png,-n 16 --temp 0, eager withMLXCEL_SDPA_DETERMINISTIC=1)Each XLA run matched the same binary pinned at
MLXCEL_XLA_CONTEXT_CAPACITY=1024.llava-1.5-7b-4bitcannot load its XLA image preprocessor on main (text_config.hidden_sizemissing), 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; CLIpreparation_timeexcludes the one-time vision weight load and compile, as before; the unpinned Phi4MM producer is bounded bymin(window, context ladder top); a two-image test pins multi-image sizing.multimodal::xla_image_prefill::tests, including the large-image refusals for Qwen2-VL, Qwen3-VL and Youtu-VL and a two-image case), serverxla_preprocesstests, CLI sizing tests (18 pass)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 --checkCloses #3361