Repository navigation
feat: add Gemma3 VLM OpenXLA path (#869) - #917
Conversation
002bb77 to
c4e5d22
Compare
|
Rebased onto Post-rebase validation:
The shared vision runtime inherited #934’s explicit |
c4e5d22 to
9ab1399
Compare
Rebase and bounded SigLIP evidence — 2026-07-27
|
TF32 reference policy checked here: immaterial, so the numbers above standI filed on #932 that MLX defaults Re-run at
This is consistent with the mechanism: the flag only reaches genuine f32 contractions, and So unlike #916, the divergence recorded here is a property of the emitted graph rather than For completeness, this run also reconfirms at current head the numbers the PR body carried |
9ab1399 to
63a4cfa
Compare
Add the Gemma3 VLM OpenXLA execution path with SigLIP 2D average-pool projection, one-time sqrt(hidden_size) text embedding scaling, and exact bidirectional image-block plus padding additive prefill masks: - Emit the Gemma3 SigLIP vision encoder and 2D average-pooling + RMSNorm + linear multi_modal_projector in StableHLO without the LLaVA 2-layer MLP contract. - Add the Gemma3 prepared-prefill boundary with one-time text embedding scaling, native projector rows, and the authoritative bidirectional image-block / padding additive mask for embeddings prefill. - Bind the prepared-prefill ABI, additive-mask mode/value, post-scale policy, wrapper tokens, SigLIP/projector configuration, and Gemma3 sliding/global attention settings into stable single-sequence and batched IREE bundle fingerprints while preserving existing dense text-only identities byte-for-byte. - Route CLI and continuous-batch server image requests through the filtered host embedding table and resident IREE vision projector. - Widen BF16 SigLIP and projector weights to F32 on the MLX reference side of xla_gemma3_reference_check to match IreeVisionProjector's F32 execution contract, and set --task_worker_stack_size=8388608 in the diagnostics-only local-task thread helper so IREE worker.c does not clamp 0 to 32 KiB below GPU runtime TLS size. Refs #869
63a4cfa to
49c2b32
Compare
Nightly verify run 38819880080 on main 93748aa failed `make verify-clippy` (`--workspace --all-targets -- -D warnings`) on code added by #917, while its test and video steps passed: - `Gemma3VlmCompatibilityContract`, its `new`/`stable_identity`, and `bind_gemma3_vlm_compatibility` (`prepared_gemma3.rs`) are only called from `iree.rs`, so they are dead without the `iree` feature. They now carry `#[cfg_attr(not(feature = "iree"), allow(dead_code))]`, the attribute `lib.rs` already uses for `prepared`. - Four `1 * 4 + col` / `1 * 8 + col` mask indices in the Gemma3 export test tripped `identity_op`. The test allows that lint so the indices keep their `row * width + col` form. - `mod gemma3_vlm_mask_tests` in `emitter/model.rs` sat before the MoE probe emitters (`items_after_test_module`); it now ends the file, unchanged. No behavior change. `cargo clippy -p mlxcel-xla --all-targets -- -D warnings`, `cargo clippy --workspace --all-targets --features cuda -- -D warnings` and fmt are clean, and the mlxcel-xla lib tests pass (308 passed). The `iree` feature build needs an IREE install that this host lacks; the attribute is a no-op there. Refs #917
…config (#2986) ## Summary The pinned Gemma 3 eager-MLX-versus-IREE boundary gate (`xla_gemma3_reference_check`, the #869 gate) fails on `main` at `siglip.hidden.block4.output`. Its eager reference builds the SigLIP tower on the erf GELU, while the loader and the OpenXLA graph have run the tanh GELU for this checkpoint since #2552. This moves the loader's config parse into one function that the loader and the gate both call. The gate then passes all 34 stages. ## Related issues Closes #2985. ## Type of change - [x] `fix` — bug fix ## Cause `run_gemma3_eager_mlx_iree_prepared_boundary` parsed the pinned config with `serde_json::from_value::<VLMConfig>` and built `SigLipVisionModel` from it. The pinned `config.json` has no `vision_config.hidden_act`, so the field stayed the serde default, `VisionHiddenActivation::ExactGelu`. #2552 resolved an omitted key to the tanh GELU in `load_gemma3_vlm` (`default_missing_hidden_act_to_siglip`) and in the OpenXLA vision config; the gate's own parse dates from #917 and was not part of that change. The gate has compared an erf tower with a tanh graph since. ## Change - `parse_gemma3_vlm_config` in `src/loading/vlm_gemma.rs`: the `VLMConfig` parse and the `default_missing_hidden_act_to_siglip` call that `load_gemma3_vlm` had inline, as one function. `load_gemma3_vlm` calls it. Generation does not change. - The gate calls the same function instead of parsing `VLMConfig` itself, so its reference is the tower the loader builds and cannot drift from it again. - Two unit tests in `src/loading/vlm_gemma_tests.rs`, which run in the default suite and need no checkpoint: an omitted or null `hidden_act` resolves to tanh while the direct parse stays erf, a declared name is kept, and a parse error keeps the loader's message. - Not changed: the gate's tolerances, stages and pinned hashes. `load_gemma3_iree_host_preprocessor` also parses `VLMConfig` directly, but it builds no host tower and never reads `hidden_act`, so it is left as it is. ## Before / after GB10 (sm_121, CUDA 13.0), IREE `3.12.0rc20260721` from `scripts/iree/setup-cuda.sh`, `mlx-community/gemma-3-4b-it-4bit` @ `93724907d4ed`. `main` is `ce6855bc8`. Same command on both: ```bash cargo run --locked --profile test-fast --features cuda,xla-reference-diagnostics \ --example xla_gemma3_reference_check -- \ --model models/gemma-3-4b-it-4bit --image tests/fixtures/test_image.png --device local-task ``` | | `main` | This PR | |---|---|---| | Exit code | 101 | 0 | | Stage lines PASS / FAIL | 23 / 11 | 34 / 0 | | Last line | `first divergence: siglip.hidden.block4.output at flat index 61889` | `PASS all pinned Gemma3 eager MLX/IREE boundary stages` | `max_abs` of the IREE output against the eager MLX reference: | Stage | `main` | This PR | |---|---|---| | `siglip.block0.mlp_fc1` | 3.058e-5 | 3.058e-5 | | `siglip.block0.mlp_activation` | 4.766e-4 | 1.274e-5 | | `siglip.block0.output` | 2.270e-2 | 1.669e-5 | | `siglip.hidden.block4.output` | 1.067e-1, FAIL | 7.629e-4 | | `siglip.hidden.block20.output` | 5.604, FAIL | 1.000e-2 | | `siglip.hidden.last_pre_layernorm` | 343.3, FAIL | 0.2395 | | `projector.avg_pool_projection` | 0.4582, FAIL | 4.331e-4 | Every stage up to `mlp_fc1` reads the same on both sides of the change. The first one that moves is the activation, by 4.766e-4 on `main`; the largest difference between the erf and the tanh GELU is 4.732e-4 (at |x| = 2.70). The stage lines are the same, on both sides, with `--features xla-diagnostics,xla-reference-diagnostics`. Generation, to confirm that the loader refactor moves nothing. `generate --image <fixture> -p "Describe the image." -n 48 --temp 0`, release builds of `ce6855bc8` and of this PR: | Checkpoint | Fixtures | `main` against this PR | |---|---|---| | `mlx-community/gemma-3-4b-it-4bit`, no `hidden_act` | `test_image_shapes.png`, `test_image.png` | identical replies | | A copy of it whose config declares `"hidden_act": "gelu"` | the same two | identical replies | The two checkpoints answer differently from each other on both fixtures, in both builds, so a declared key is still read. ## Test plan Run on this PR's commit (`752e7ad4d`, one commit on `ce6855bc8`) on a DGX Spark (GB10). - [x] `cargo fmt --all -- --check` - [x] `cargo clippy --workspace --all-targets --features cuda -- -D warnings` (the Linux spelling of the template's line) - [x] `cargo build --release --features cuda` - [x] The gate, as in the tables above: exit 101 on `main`, exit 0 with 34 of 34 stages on this PR. Its retained libtest wrapper passes as well (`MLXCEL_GEMMA3_FIXTURE=<checkpoint> cargo test --profile test-fast --features xla-diagnostics,xla-reference-diagnostics --lib pinned_gemma3_eager_mlx_matches_iree_prepared_boundary -- --include-ignored`) - [x] `cargo test --profile test-fast --features xla-diagnostics,xla-reference-diagnostics --lib reference_boundary -- --test-threads=1`: 11 passed, which are the 10 unit tests of the gate module and one audio test whose name the filter also matches - [x] `cargo test --profile test-fast --features cuda --lib loading::vlm::gemma -- --test-threads=1`: 18 passed, the two new tests among them. With the resolution removed from `parse_gemma3_vlm_config`, `gemma3_vlm_config_resolves_an_omitted_hidden_act_to_the_siglip_tanh_gelu` fails (`left: ExactGelu`, `right: GeluPytorchTanh`) - [x] `make verify-test-cuda` (`cargo test --workspace --profile test-fast --features cuda --no-fail-fast -- --test-threads=1`): 186 of 187 test binaries pass (15488 tests passed, 1 failed, 496 ignored). The one failure is `native_env_tests::the_cuda_cache_defaults_reach_mlx`, which fails the same way on a clean `main` (it is order-dependent; described in the notes of #2967) - [x] The self-hosted `ci.yml` jobs a pull request from a fork does not get, run by hand: `clippy` (`cargo clippy -p mlxcel --lib --tests -- -D warnings`, default features), `cpu-link` (both commands; 13 tests passed), `xla-compile` (`cargo check --features cuda,xla-iree --all-targets`, `cargo check --no-default-features --features xla-diagnostics --all-targets`): all pass - [x] `cargo check --features xla-diagnostics,xla-reference-diagnostics --all-targets`, the feature set that compiles the gate: passes - [ ] `cargo clippy -p mlxcel --lib --tests --example xla_gemma3_reference_check --features xla-diagnostics,xla-reference-diagnostics -- -D warnings`: the lib test target stops at one finding, `field_reassign_with_default` in `src/server/batch/xla_worker_tests.rs:1417`. A clean `main` stops at the same single finding, and it is not in a file this PR touches - [x] `python3 -m unittest discover -s tests -p 'test_*.py'` (the command of `make verify-python-tooling`), `scripts/insert_apache_header.py --check`, `scripts/ci/check_cross_repo_refs.py`: 219 Python tests OK, license headers OK, cross-repo refs OK - [x] Validated with a real checkpoint: the gate and the replies above, `mlx-community/gemma-3-4b-it-4bit` - [ ] Traced per "Judging a change that moves the numbers": not applicable. Generation does not move (identical replies); what moves is the gate's reference, on purpose - [ ] `cargo deny check`: not run and not applicable (no manifest, lockfile or `deny.toml` change) - [ ] Metal: not built or run here. The gate's example needs CUDA; the new unit tests are backend-neutral and first run on Metal in the nightly `make verify` ## Notes for reviewers - **CI does not build this gate.** `reference_boundary` is compiled only with `xla-reference-diagnostics`, which no workflow turns on, and running it needs the pinned checkpoint. That is why the failure went unreported, and it is why I ran the gate by hand here. This PR does not add a job for it. - **The unit tests pin the function, not the gate.** They fail if the resolution is removed from `parse_gemma3_vlm_config`. The gate itself is covered only by running it, which is the table above. - **"Since #2552" is read from the diff.** #2552 changed the loader and the OpenXLA vision config and did not touch `vlm_gemma_xla_tests.rs`. I did not run the gate on an older commit. - **The other reference gates were not run** (`xla_molmo_reference_check`, `xla_llava_reference_check`, `xla_youtu_vl_reference_check`): I do not have their checkpoints on this host. - This is the gate failure that the description of #2967 records as the behaviour of `main` on this host. ## Checklist - [x] PR title uses a Conventional Commits prefix - [x] One logical change per PR - [ ] Updated `docs/`: no user-facing behavior or supported-model change - [x] Updated `// Used by: ...` comments: `parse_gemma3_vlm_config` is new and carries one - [x] No secrets, credentials, or `.env` files committed
Summary
multi_modal_projectorin StableHLO without the LLaVA 2-layer MLP contract.sqrt(hidden_size)), native projector rows, and the authoritative bidirectional image-block and padding mask used by embeddings prefill.Gemma3Processor's exact newline, BOI, image-token, EOI, newline block for both existing placeholders and bare CLI/server prompts, with checked capacity accounting for every wrapper token.xla_gemma3_reference_checkexample capturing processor pixels, twelve block-0 sub-stages, ordered intermediate/final SigLIP states, post-layernorm, average-pool projection, prepared image rows, one-timesqrt(hidden)scaling, and the exact bidirectional padding mask.vision_tower.*andmulti_modal_projector.*weights to F32 on the MLX reference side ofxla_gemma3_reference_checkto matchIreeVisionProjector's F32 execution contract, resolving the previous BF16 mantissa drift across the 27-block4096 x 4096SigLIP encoder without changing tolerances.--task_topology_group_count=1and--task_worker_stack_size=8388608(8 MiB, preventingworker.cfrom clamping0to32 KiBbelow GPU runtime TLS size).Validation
cargo test -p mlxcel-xla --lib --features iree,diagnostics -- gemma3cargo test -p mlxcel-xla --lib --features iree,diagnostics -- diagnostic_flagscargo test --lib --features rocm,xla-reference-diagnostics -- vlm_gemma_xla_testscargo test --lib --features rocm,xla-iree -- host_preprocessor(30 passed)cargo fmt --all -- --checkcargo clippy --lib --bins --tests -- -D warningscargo clippy --lib --bins --tests --examples --features rocm,xla-reference-diagnostics -- -D warningsxla_gemma3_reference_check --model models/mlx/gemma-3-4b-it-4bit --image tests/fixtures/test_image.png --device hip:PASSacross all stages (processor.pixel_valuesmax_abs=0.0,siglip.hidden.embeddingmax_abs=7.63e-6, all 12siglip.block0.*stagesmax_abs<=5.53e-5,siglip.hidden.block1..26PASSwith 0 failures,siglip.selected.post_layernormmax_abs=2.56e-3,projector.avg_pool_projectionmax_abs=5.03e-4,prepared.mlx_vs_iree_image_rowsmax_abs=5.03e-4,prepared.mask.*max_abs=0.0, 0 failures).xla_gemma3_reference_check --model models/mlx/gemma-3-4b-it-4bit --image tests/fixtures/test_image.png --device local-task:PASSacross all stages (projector.avg_pool_projectionmax_abs=7.64e-4,prepared.mask.*max_abs=0.0, 0 failures).models/mlx/gemma-3-4b-it-4bit(tests/fixtures/test_image.png,MLXCEL_XLA_CONTEXT_CAPACITY=512,--device hip): XLA CLI and XLA/v1/chat/completionsserver match token-for-token ("This is an image of a solid, bright-orange color.", 13 tokens,finish_reason="stop"), and repeated image + follow-up text-only requests on the same server slot verify clean additive prefill mask reset and slot reuse.Runtime notes
xla-ireefeature and rejectsMLXCEL_XLA_VISION_BACKEND=hostexplicitly.Closes #869