Repository navigation
feat(xla): add Youtu-VL vision and MLA inference (#872) - #919
Conversation
206566c to
7886a65
Compare
|
Rebased onto Post-rebase validation:
The runtime now uses the explicit |
7886a65 to
e36cb34
Compare
e36cb34 to
9171492
Compare
|
Published the bounded Youtu-VL follow-up at
Validation:
The real pinned checkpoint now reaches the unchanged intermediate gate quickly. An explicit BF16 contraction-input experiment produced byte-identical IREE |
20c2bff to
4f8547f
Compare
Implements the OpenXLA/IREE execution path for Youtu-VL (`youtu_vl` / `YoutuVLForConditionalGeneration`), covering SigLIP-style windowed vision encoding, `PatchMerger` 2x2 spatial reduction, `<|image_pad|>` token-feature replacement, and Multi-head Latent Attention (MLA) prefill/decode with compressed KV cache reuse. - Emits the 27-layer Youtu-VL SigLIP vision tower (`emit_youtu_vl_vision_mlir`) with bilinear 2D position-embedding interpolation, merged-patch window partitioning (`window_index` / `reverse_window_indices`), full-attention layer overrides (`fullatt_block_indexes`), and the 2x2 `PatchMerger` projection into language hidden size. - Implements `YoutuVlVisionRuntime` (`src/lib/mlxcel-xla/src/youtu_vl_runtime.rs`) with shape-bucketed IREE vision compilation and intermediate stage diagnostics (`patch_embeddings`, `position_embeddings`, `post_embed_hidden`, `window_packed_hidden`, `pre_merger_hidden`, `window_restored_hidden`, `merged_image_features`). - Emits MLA attention (`emit_mla_attention` in `src/lib/mlxcel-xla/src/emitter/model.rs`) with `q_a_proj` / `q_a_layernorm` / `q_b_proj`, `kv_a_proj_with_mqa` / `kv_a_layernorm`, per-head `kv_b_proj` key-nope and value latent expansion, interleaved rotary position embeddings (`rope_interleave`), and compressed KV cache storage (`kv_lora_rank` + `qk_rope_head_dim`). - Preserves `f32` carrier precision and disables `f16`-resident projection packing by default for MLA checkpoints (`config.mla.is_some()`) so 40-layer chained latent contractions stay within the 2e-2 reference tolerance on GPU and CPU backends. - Adds `xla_youtu_vl_reference_check`, `spike/openxla/youtu_vl_reference_oracle.py`, and `scripts/xla/validate_youtu_vl_reference.sh` for 27-stage actual-checkpoint verification against the pinned HuggingFace reference (`tencent/Youtu-VL-4B-Instruct` @ `8d30a0e49662a1d628a472b12df264dbcd768753`). Closes #872
4f8547f to
335993d
Compare
…loop (#2436) Closes #2420 The `xla-iree` serve loop never sent `GenerateEvent::Prefill` and reported the logical (placeholder) prompt length, so a media body's `usage`, `/v1/messages/count_tokens` and the streaming `message_start` that #2415 holds for the prefill report all carried the placeholder count. This makes the loop match the batch scheduler and `docs/llama-server-compat.md`. ## Changes - `ServeState` keeps one count, `effective_prefill_len` (the expanded prepared length for media, the prompt length for text), and a `prefill_reported` flag. `ServeState::report_prefill` sends `PrefillStats { prompt_tokens, cached_tokens: 0, processed, first_token: true, prompt_ms }` once, before the first `Token` or before `Done` when the engine finishes with no token (withheld EOS), and stamps the decode state's first-token instant as `sequence.rs` does. - `Done`, the stop-string finish and the zero-budget media finish report the expanded length. The count route follows, since the XLA worker answers it with a one-token generation. - Every XLA image family goes through `handle_preprocessed`, including the new Molmo (#918) and Youtu-VL (#919) producers, so they are covered too. So are the DeepStack (Qwen3-VL) and Phi4MM audio/image paths. The disaggregated coordinator stays out of scope, as the issue says. - No doc change: `docs/llama-server-compat.md` has no XLA-specific statement, and its general promise now holds on this loop. ## Tests The new and updated tests drive the real `admit`, preprocessing and `dispatch` path with a fake engine: text gets `Prefill(2)`, the image gets `Prefill(5)`, and Phi4MM audio and image each get `Prefill(6)`, every one sent before its `Token`, with `Done` reporting the same length. They also cover zero-budget image and audio, and a bare EOS finish. The fake Phi4MM producer now expands placeholders. Two existing assertions in this module were already failing on main because the error messages had changed (`structured` is now `constrained decoding`, and `refusing text fallback` is now `image resolution cardinality mismatch`). I updated them so the module runs green. - Fix: `server::batch::xla_worker`, 15 passed (`--release --features cuda,xla-iree`, `--test-threads=1`, under gpu-lock). - Revert check: with the production files restored to main, 9 failed. That is the 7 new or updated tests plus the 2 stale assertions. - `cargo clippy --release --features cuda,xla-iree --lib --tests -- -D warnings`, `cargo check --release --features cuda,xla-iree --all-targets`, `cargo fmt --check` and the repository check scripts pass. ## Real checkpoint `~/models/mlx/gemma-3-4b-it-4bit`, `MLXCEL_BACKEND=xla MLXCEL_XLA_DEVICE=cuda MLXCEL_XLA_CONTEXT_CAPACITY=512 mlxcel-server` on the GB10 (the default 256 capacity refuses a Gemma 3 image). I sent one body (`tests/fixtures/test_image.png` plus a short prompt) to `count_tokens`, non-streaming and streaming `/v1/messages`: | Body | Build | count_tokens | usage.input_tokens | message_start.input_tokens | |---|---|---|---|---| | image | main cadc636, XLA | 18 | 18 | 18 | | image | this PR, XLA | 277 | 277 | 277 | | image | this PR, MLX path | 277 | 277 | 277 | | text | both builds, XLA | 17 | 17 | 17 | In every stream `message_start` was the first event, and it was sent once. Phi4MM audio was not run on a real checkpoint (none is present locally), so the fake-producer test covers it.
Summary
Implements the OpenXLA / IREE execution path for Youtu-VL (
youtu_vl/YoutuVLForConditionalGeneration), covering SigLIP-style windowed vision encoding,PatchMerger2x2 spatial reduction,<|image_pad|>token-feature replacement, and Multi-head Latent Attention (MLA) prefill/decode with compressed KV cache reuse:mlxcel-xla::emitter::youtu_vl,youtu_vl_runtime):emit_youtu_vl_vision_mlir) with bilinear 2D position-embedding interpolation, merged-patch window partitioning (window_index/reverse_window_indices), full-attention layer overrides (fullatt_block_indexes = [7, 15, 23, 26]), and the 2x2PatchMergerMLP into the language model hidden dimension.patch_embeddings,position_embeddings,post_embed_hidden,window_packed_hidden,pre_merger_hidden,window_restored_hidden,merged_image_features) for boundary verification.multimodal::youtu_vl_prompt,host_preprocessor):<|vision_start|><|image_pad|><|vision_end|>placeholders to match merged visual token counts and replaces<|image_pad|>positions (151669) with projected visual features while preserving non-visual text embeddings bit-identically.mlxcel-xla::emitter::model,iree):emit_mla_attention) withq_a_proj->q_a_layernorm->q_b_proj,kv_a_proj_with_mqa->kv_a_layernorm, per-headkv_b_projkey-nope and value latent expansion, interleaved RoPE (rope_interleave = true), and compressed KV cache slabs (kv_lora_rank = 512,qk_rope_head_dim = 64).config.mla.is_some()) tof32carrier precision and disablesf16-resident projection packing unless explicitly overridden viaMLXCEL_XLA_PRECISION, keeping 40-layer chained latent contractions within the2e-2stage parity budget across GPU and CPU backends.xla_youtu_vl_reference_check,spike/openxla/youtu_vl_reference_oracle.py):tencent/Youtu-VL-4B-Instruct(8d30a0e49662a1d628a472b12df264dbcd768753) HuggingFace reference across vision, token replacement, prefill logits, MLA cache slices, 4-step greedy decode, and warm-cache reuse.Verification
pytest spike/openxla/test_youtu_vl_reference_oracle.py(14 passed)cargo test --features rocm -p mlxcel-xla --lib -- youtu_vl(12 passed)cargo test --features rocm -p mlxcel-xla --lib -- mla_runtime_defaults(1 passed)cargo test --features xla-diagnostics-rocm --lib -- youtu_vl(47 passed; 0 failed)cargo clippy --all-targets --features xla-diagnostics-rocm -- -D warnings(0 warnings)tencent/Youtu-VL-4B-Instruct@8d30a0e49662a1d628a472b12df264dbcd768753):--device hip,gfx1151AMD Radeon 8060S):"passed": true,"first_divergence": nullacross all 27 stages:pixel_values,grid_thw,window_index,cu_seqlens,cu_window_seqlens,reverse_window_indices,expanded_token_ids,image_token_mask,non_visual_embeddings:max_absolute = 0.0patch_embeddings:max_absolute = 6.914e-6(<= 1e-3)position_embeddings:max_absolute = 1.907e-6(<= 1e-3)post_embed_hidden:max_absolute = 6.795e-6(<= 1e-3)window_packed_hidden:max_absolute = 6.795e-6(<= 1e-3)pre_merger_hidden/window_restored_hidden:max_absolute = 5.479e-4(<= 1e-2)merged_image_features/replaced_Visual_embeddings/prepared_embeddings:max_absolute = 3.902e-3(<= 2e-2)prefill_logits/reuse_prefill_logits:max_absolute = 5.004e-3(<= 2e-2)selected_kv/reuse_selected_kv:max_absolute = 1.594e-3(<= 2e-2)greedy_tokens/reuse_greedy_tokens:[576, 2870, 21141, 261](max_absolute = 0.0)--device local-task):"passed": true,"first_divergence": nullacross all 27 stages (prepared_embeddingsmax_abs = 4.885e-3,prefill_logitsmax_abs = 4.118e-3,selected_kvmax_abs = 1.987e-3,greedy_tokens[576, 2870, 21141, 261]max_abs = 0.0).Closes #872