Skip to content

fix(xla): build the Gemma 3 gate's eager reference from the loader's config - #2986

Merged
inureyes merged 1 commit into
lablup:mainfrom
Jaeyeong-CHOI:fix/gemma3-xla-gate-reference-activation
Nov 15, 2026
Merged

inureyes merged 1 commit into
lablup:mainfrom
Jaeyeong-CHOI:fix/gemma3-xla-gate-reference-activation

Conversation

@Jaeyeong-CHOI

@Jaeyeong-CHOI Jaeyeong-CHOI commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

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

  • 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:

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).

  • cargo fmt --all -- --check
  • cargo clippy --workspace --all-targets --features cuda -- -D warnings (the Linux spelling of the template's line)
  • cargo build --release --features cuda
  • 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)
  • 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
  • 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)
  • 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 perf(cuda): fuse the f32 tanh GELU into one bit-exact kernel (#2780) #2967)
  • 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
  • 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
  • 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
  • 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 fix(vision): add GELU selector, use tanh where checkpoints declare it #2552" is read from the diff. fix(vision): add GELU selector, use tanh where checkpoints declare it #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 perf(cuda): fuse the f32 tanh GELU into one bit-exact kernel (#2780) #2967 records as the behaviour of main on this host.

Checklist

  • PR title uses a Conventional Commits prefix
  • One logical change per PR
  • Updated docs/: no user-facing behavior or supported-model change
  • Updated // Used by: ... comments: parse_gemma3_vlm_config is new and carries one
  • No secrets, credentials, or .env files committed

…config

The pinned eager-MLX-versus-IREE boundary gate for Gemma 3
(`xla_gemma3_reference_check`, lablup#869) fails on main at
`siglip.hidden.block4.output`. Its eager reference parsed `VLMConfig`
directly, so the `vision_config.hidden_act` that the pinned config omits
stayed the serde default, exact erf. The loader and the OpenXLA emitter
have resolved that omitted key to the tanh GELU since lablup#2552, so the gate
compared an erf tower with a tanh graph.

`parse_gemma3_vlm_config` is the loader's parse and resolution moved into
one function. `load_gemma3_vlm` and the gate both call it, so the gate's
reference is the tower the loader builds.
@inureyes inureyes added area:inference Generation, sampling, decoding (incl. speculative, DRY) modeltype:vlm Vision-language model priority:medium Medium priority status:review Under review type:bug Bug fixes, error corrections, or issue resolutions labels Nov 15, 2026
@inureyes

Copy link
Copy Markdown
Member

Implementation hardening for #2986.

Reviewed #2985: the eager reference now shares Gemma3 config parsing with the production loader, including omitted/null tanh activation defaults, explicit activation values, and error context. No additional security or performance defect was found.

Validation: Both new Gemma3 config tests passed in the combined CUDA candidate suite. The recorded 34-boundary checkpoint evidence was reviewed; that complete checkpoint gate was not re-run.

Commands: cargo test --workspace --profile test-fast --features cuda --no-fail-fast -- --test-threads=1 on the combined candidate tree has passed the affected module tests noted above; the broader run is still finishing. cargo fmt --all -- --check and python3 scripts/ci/check_kernel_dtype_keys.py passed. Required GitHub checks are checked again immediately before merge.

@inureyes
inureyes merged commit 4a5bb51 into lablup:main Nov 15, 2026
31 checks passed
@inureyes inureyes added status:done Completed and removed status:review Under review labels Nov 15, 2026
@inureyes inureyes added this to the 0.9 milestone Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:inference Generation, sampling, decoding (incl. speculative, DRY) modeltype:vlm Vision-language model priority:medium Medium priority status:done Completed type:bug Bug fixes, error corrections, or issue resolutions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(xla): Gemma 3 eager-MLX/IREE boundary gate fails on main from a stale reference activation

2 participants