Skip to content

fix(xla): round the Molmo v1 vision tower at eager's F16 boundaries - #3399

Merged
inureyes merged 5 commits into
mainfrom
fix/issue-3390-molmo-vision-bound
Nov 25, 2026
Merged

inureyes merged 5 commits into
mainfrom
fix/issue-3390-molmo-vision-bound

Conversation

@inureyes

Copy link
Copy Markdown
Member

Summary

The XLA Molmo v1 vision graph now rounds to F16 wherever eager MLX stores an F16 tensor for the F16 checkpoint, instead of running the CLIP tower in f32. The xla_molmo_reference_check gate passes 14/14 on local-task and cuda with the VISION bound (atol 0.25, rtol 0.05) unchanged.

Root cause

  • Not a regression on CUDA. With the gate built at the feat(xla): support Molmo sparse additive visual embeddings #870 merge commit (3ba57b30, no digest patch needed: the double hash came in with fix(xla): repair the OpenXLA feature compile job after #2819 #2837), vision.selected_layer_21 already fails on this GB10 (4 elements, max_abs 1.56) and layer 14 passes (max_abs 1.59). feat(xla): support Molmo sparse additive visual embeddings #870 was qualified with eager on ROCm (gfx1151). Intermediate commits were not bisected further once the base itself failed.
  • Precision contract gap. The failing elements sit in channel 650, the tower's outlier channel (|x| up to about 200), plus channel 363 (the next-largest) in layer 21, at rows 68/117/309 and their duplicate-crop rows 645/694/886: e.g. layer 14 row 117, IREE 41.68 against eager 44.38. That is about 90 F16 steps at that size, so the error builds up across blocks rather than coming from one output rounding.
  • Rounding points (emitter/molmo_vision_f16.rs): dequantized weight; linear product and bias add (two roundings, as quantized_matmul then add); pixels, patch product and position add; LayerNorm with f32 statistics, F16 normalized value, then w*n+b rounded once (the CUDA kernel's half FMA; rounding the product and the sum separately measured worse, layer 21 max_abs 2.81 against 2.50); quick_gelu with the F16 coefficient and three roundings; the attention context; both residual adds. Ablations on local-task: dropping any one of linear, attention context, residual, quick_gelu or the pre-tower roundings fails the gate again (2 to 12 elements per stage); dequant was ablated against the two-rounding LayerNorm and also fails without it.
  • The Molmo operator numeric contract declares F16 output rounding on those operators, so the contract digest and the artifact identity change, and cached Molmo vision artifacts recompile once. Molmo2's contract and graph are unchanged.

Results (GB10, eager MLX on CUDA)

stage max_abs (failures) main local-task fix local-task fix cuda
vision.patch_embedding 1.34e-3 4.88e-4 4.88e-4
vision.selected_layer_21 2.80 (8) 2.50 (0) 1.81 (0)
vision.selected_layer_14 2.69 (4) 2.47 (0) 1.78 (0)
vision.projector 0.334 0.188 0.094
prepared.sparse_add_visual_rows 0.334 0.188 0.094
decoder.prefill_logits 2.07e-2 1.01e-2 1.10e-2

The issue reported identical failures on cuda before the fix (layer 21 max_abs 2.80, layer 14 2.69). After the fix the worst selected-layer element is 0.12 inside the bound on local-task (it was 0.69 over); the projector went from 0.004 inside the bound to 0.22 inside.

compare_stage now also prints the first failing elements (index, observed, reference).

Test plan

  • xla_molmo_reference_check, pinned revision 5c04b3a4, test_image.png: 14/14 on local-task and on cuda
  • mlxcel generate on molmo-7b-d-0924-4bit, --image tests/fixtures/test_image.png -n 16 --temp 0, eager (MLXCEL_SDPA_DETERMINISTIC=1) and MLXCEL_BACKEND=xla MLXCEL_XLA_DEVICE=cuda without a pinned capacity: identical 16 token ids
  • cargo test -p mlxcel-xla --lib -- molmo operator_numeric_contract (new emitter tests and the updated Molmo pins fail on main), cargo clippy -p mlxcel-xla --lib --tests -- -D warnings
  • cargo check --features cuda,xla-iree --all-targets, cargo check --no-default-features --features xla-diagnostics --all-targets, cargo fmt --check, python3 scripts/insert_apache_header.py --check
  • ROCm (hip) eager and IREE not run: no AMD host here

Closes #3390

@inureyes inureyes added status:review Under review type:bug Bug fixes, error corrections, or issue resolutions priority:high High priority area:inference Generation, sampling, decoding (incl. speculative, DRY) labels Nov 24, 2026
The Molmo-7B checkpoint stores its CLIP tower in F16, so eager MLX stores an F16 tensor after every operator, while the XLA graph ran the tower in f32. The difference concentrated in the outlier channel 650 (|x| up to about 200), which dominates each LayerNorm's variance, and the Molmo gate failed vision.selected_layer_21 (8 elements over VISION, max_abs 2.80) and vision.selected_layer_14 (4 elements, max_abs 2.69). Not a regression on CUDA: the #870 merge commit already fails selected_layer_21 here (4 elements, max_abs 1.56); #870 was qualified with eager on ROCm.

The graph now rounds to F16 at eager's materialisation points (new emitter/molmo_vision_f16.rs): dequantized weights, linear products and bias adds, pixels and patch embedding, the position add, LayerNorm (normalized value, then one fused affine), quick_gelu, the attention context and residual adds. Dropping any one of them fails the gate again. The Molmo operator numeric contract declares F16 output rounding on those operators, so the manifest digest changes. Molmo2 is unchanged. The VISION tolerance is unchanged.

compare_stage also lists the first failing elements so a failure can be traced to a row and channel.

Gate 14/14 on local-task (selected 21/14 max_abs 2.50/2.47) and cuda (1.81/1.78). Molmo CLI greedy 16 tokens on XLA cuda matches eager.

Closes #3390
docs/gelu-call-sites.md section 3 still said Molmo's XLA emitter calls numeric_ops::quick_gelu; #3390 switched Molmo to the F16-rounding quick_gelu_f16 in emitter/molmo_vision_f16.rs, so the inventory line now names that split and keeps Qwen2-VL on the shared helper.

Refs #3390
@inureyes
inureyes force-pushed the fix/issue-3390-molmo-vision-bound branch from 1ec83c2 to cdc649e Compare November 24, 2026 12:17
@inureyes inureyes added the area:architecture Architecture and code structure changes label Nov 24, 2026
@inureyes
inureyes marked this pull request as ready for review November 24, 2026 12:19
@inureyes
inureyes merged commit 36129eb into main Nov 25, 2026
15 checks passed
@inureyes
inureyes deleted the fix/issue-3390-molmo-vision-bound branch November 25, 2026 23:21
@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:architecture Architecture and code structure changes area:inference Generation, sampling, decoding (incl. speculative, DRY) priority:high High priority status:review Under review type:bug Bug fixes, error corrections, or issue resolutions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: Molmo v1 vision selected-layer stages exceed the VISION bound

1 participant