Repository navigation
feat(xla): support Molmo sparse additive visual embeddings (#870) - #918
Conversation
ac54a07 to
2c6c9d4
Compare
|
Bounded actual-checkpoint follow-up on commit 6481443: all pinned processor boundaries passed exactly (677,376 patch values, 1,152 mask values, image token IDs, sparse image_input_idx, and grid metadata). The staged eager capture then materialized the patch embedding successfully and entered selected ViT layer 14. That named stage produced no completion marker within the five-minute no-output limit and was interrupted once with exit 130. The CPU run will not be repeated unchanged; the remaining numeric oracle requires a small GPU eager diagnostic runner or a cached/staged equivalent. No parity result is claimed, and the PR remains draft. |
2dc2866 to
d20b06e
Compare
|
Rebased onto Post-rebase validation:
The Molmo runtime now uses the explicit |
d20b06e to
a4047b2
Compare
|
Rebased #918 onto The actual-run assets are present and pinned: the 5.0 GB checkpoint, image and config hashes, GB10 CUDA device, and local-task IREE distribution all match. The local fixture lacks Hugging Face metadata, so the runner documentation now supplies its already-supported pinned revision environment value. One Validation completed: default |
|
Additional bounded linker audit after the rebase evidence:
This does not alter the qualification result: #918 remains draft/fail-closed pending a reproducible cached release runner and the original intermediate/KV/token/lifecycle gates. |
First completed actual for this gate, at
|
| stage | status | elements | max_abs | failures |
|---|---|---|---|---|
processor.patches |
PASS | 677376 | 0.0 exact | 0 |
processor.patch_masks |
PASS | 1152 | 0.0 exact | 0 |
processor.image_token_ids |
PASS | 316 | 0 | |
processor.image_input_idx |
PASS | 288 | 0 | |
processor.grid |
PASS | 3 | 0 | |
vision.patch_embedding |
PASS | 1179648 | 1.336575e-3 | 0 |
vision.selected_layer_14 |
PASS | 1181696 | 2.258102 | 0 |
vision.selected_layer_21 |
FAIL | 1181696 | 2.317841 | 4 |
vision.projector |
PASS | 1032192 | 2.251205e-1 | 0 |
prepared.non_visual_rows |
PASS | 132608 | 0.0 exact (atol=0, rtol=0) | 0 |
prepared.sparse_add_visual_rows |
PASS | 1032192 | 2.500000e-1 | 0 |
decoder.layer0_kv |
PASS | 128 | 0.0 exact | 0 |
decoder.all_layer_kv |
PASS | 3584 | 5.212402e-2 | 0 |
decoder.prefill_logits |
PASS | 152064 | 1.176004e-1 | 0 |
Exit 101 is the intended first-divergence panic on the single failing stage.
Four values out of 1,181,696, and the divergence does not propagate: the projector that
consumes the ViT output, the authoritative sparse-add merge, all-layer KV and the prefill
logits all pass downstream of it. elements=1181696 is 2 crops times 577 tokens times
1024 hidden, so flat index 514613 is crop 0, token 502, channel 565.
The 4 values are deterministic, and the gate is cross-device by construction
Re-running with MLXCEL_MOLMO_IREE_DEVICE=local-sync, which is single-threaded and
deterministic, reproduces the failure identically: same max_abs=2.317841, same
max_rel=5.661761e3, same 4 failures, same first_failure=514613. So this is not a
local-task worker or reduction-order artifact.
MLXCEL_MOLMO_IREE_DEVICE=cuda is rejected by the gate itself
(the #870 reference gate requires IREE local-task or local-sync), so the comparison is
by design MLX on CUDA against IREE on CPU. The two selected layers straddle the threshold
narrowly under atol + rtol*|expected|:
selected_layer_14max difference 2.258102 passes, its worst element sitting where
|expected|is at least about 40.2selected_layer_21max difference 2.317841 fails, its worst element sitting where
|expected|is below about 41.4
Both layers differ by roughly the same amount; layer 21's worst element simply lands at a
slightly smaller |expected|. That looks like the residual of a GPU reference against a
CPU candidate rather than a semantic mismatch, especially since every downstream production
stage including the prefill logits passes. Deciding it properly needs the comparison to run
with both sides on the same device, which this gate currently forbids.
No tolerance was changed and no production arithmetic was touched. Greedy token exactness,
CLI and server paths, cancellation and slot reuse, and mixed batching were not reached
because the strict first-divergence panic stands. This PR stays draft.
Correction to the numbers above: the reference was TF32, not F32The results I posted earlier were collected with MLX's default
True F32 removes about 12 percent of the drift at both selected ViT layers and 25 to 27 It does not close the gate. The same four elements at flat index 514613 still exceed Two further observations on that residual, both from runs at this head:
Filed the reference-policy issue and the two |
|
Reopening to retrigger CI. The red |
|
Correction to my previous comment: this red cannot be cleared by re-running, and I have now measured why.
Only a push to the branch (a The useful part for whoever picks the branch up: there is nothing to fix in the formatting. |
a954d21 to
fa3e1d8
Compare
Wire Molmo v1 (`MolmoVLM` / `model_type: "molmo"`) sparse additive visual embeddings through the OpenXLA / IREE path: - Emit the Molmo v1 dual-layer CLIP ViT (`selected_layers = [-2, -9]`), 2x2 attention pooling, and SwiGLU MLP projector in `mlxcel-xla`, plus diagnostic outputs for patch embedding, selected layers 21 and 14, and projector output. - Implement `MolmoSparseAddPlan` to validate and apply sparse additive visual features (`target = round_bf16(text + round_bf16(projected))`) indexed by `image_input_idx` while preserving sentinel (`< 0`) skips. - Map Molmo v1 fused OLMo decoder weights (`wte`, `att_proj`, `ff_proj` value-then-gate SwiGLU halves, `ff_out`), enable `f16` resident row-sliced projections on `WeightScheme::Molmo`, and default `rope_impl` to `"llama"` (non-interleaved rotate-half) unless `"interleave"` is explicitly set. - Stream decoder weights shard-by-shard into IREE device buffers via `xla_llama_upload_weight` so 7B checkpoints do not double-materialize all weights in host RAM during load. - Add `xla_molmo_reference_check` actual-checkpoint boundary verification across `local-task` and GPU (`hip` / `cuda`) backends. Refs #870
fa3e1d8 to
641d5e2
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 Molmo v1 (
MolmoVLM/model_type: "molmo") sparse additive visual embeddings on the OpenXLA / IREE execution path:selected_layers = [-2, -9], indices 21 and 14 of 23 layers), 2x2 attention pooling (image_pooling_2d), and SwiGLU MLP (image_projector) inmlxcel-xla, along with intermediate diagnostic boundaries (patch_embedding,selected_layer_21,selected_layer_14,projector).MolmoSparseAddPlaninmlxcel-xla::prepared_molmoto validate and apply sparse additive visual features (target = round_bf16(text + round_bf16(projected))) indexed byimage_input_idxwhile preserving sentinel (< 0) skips and rejecting duplicate or out-of-range indices.language_model.model.wte.embedding,att_proj,ff_projvalue-then-gate SwiGLU halves,ff_out), enablesf16resident row-sliced projections forWeightScheme::Molmo, and defaultsrope_implto"llama"(non-interleaved rotate-half) unless"interleave"is explicitly configured.xla_llama_upload_weightso 7B checkpoints do not double-materialize all dequantized weights in host RAM during load.xla_molmo_reference_checkfor actual-checkpoint boundary verification acrosslocal-taskand GPU (hip/cuda) backends.Verification
cargo test -p mlxcel-xla --lib(323 passed; 0 failed)cargo test --lib multimodal --features rocm,xla-reference-diagnosticsxla_molmo_reference_checkonmlx-community/Molmo-7B-D-0924-4bitrevision5c04b3a418979597b1968e41414ad799c87533e8,tests/fixtures/test_image.png):MLXCEL_MOLMO_IREE_DEVICE=local-task: all 14 stagesPASSwithfailures=0(vision.patch_embeddingmax_abs=1.336575e-3,vision.selected_layer_21max_abs=2.002304e0,vision.selected_layer_14max_abs=2.016567e0,vision.projectormax_abs=3.934250e-1,prepared.non_visual_rowsmax_abs=0.0,prepared.sparse_add_visual_rowsmax_abs=3.750000e-1,decoder.layer0_kvmax_abs=0.0,decoder.all_layer_kvmax_abs=4.089439e-2,decoder.prefill_logitsmax_abs=1.099339e-1).MLXCEL_MOLMO_IREE_DEVICE=hip(gfx1151, AMD Radeon 8060S): all 14 stagesPASSwithfailures=0(vision.patch_embeddingmax_abs=1.336575e-3,vision.selected_layer_21max_abs=2.002304e0,vision.selected_layer_14max_abs=2.016567e0,vision.projectormax_abs=3.934250e-1,prepared.non_visual_rowsmax_abs=0.0,prepared.sparse_add_visual_rowsmax_abs=3.750000e-1,decoder.layer0_kvmax_abs=0.0,decoder.all_layer_kvmax_abs=3.109646e-2,decoder.prefill_logitsmax_abs=6.121254e-2)./v1/chat/completions16-token greedy parity ongfx1151(MLXCEL_BACKEND=xla MLXCEL_XLA_DEVICE=hip MLXCEL_XLA_CONTEXT_CAPACITY=512across 2 sequential image requests vs MLX reference serve):hip, Requests 1 and 2) produce exact 16-token greedy match:"A vibrant, solid orange square dominates the image, filling the entire frame with its".Closes #870