Skip to content

fix(xla): repair the OpenXLA feature compile job after #2819 - #2837

Merged
inureyes merged 1 commit into
mainfrom
fix/issue-2820-safetensors-name-as-str
Nov 2, 2026
Merged

inureyes merged 1 commit into
mainfrom
fix/issue-2820-safetensors-name-as-str

Conversation

@inureyes

@inureyes inureyes commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

Summary

The OpenXLA feature compile job has been red on main since #2819 (the safetensors 0.8 and sha2 0.11 upgrades). It hid two independent breaks, because cargo stops at the first one.

  • SafeTensors::names() returns &str in safetensors 0.8, so the name.as_str() left in the Youtu-VL runtime resolved to the unstable str_as_str feature in the cuda,xla-iree step.
  • sha2 0.11 returns a hybrid_array::Array without LowerHex, so four format!("{:x}", digest) sites fail in the xla-diagnostics step. A fifth copy sits behind xla-reference-diagnostics, which this job does not compile; it is fixed too.

Both now use the forms the rest of the crate already uses: a borrowed name for the set lookup, and the existing sha256_hex helper for digests.

Validation

cargo check --all-targets with RUSTFLAGS=-D warnings for cuda,xla-iree, xla-diagnostics, and xla-reference-diagnostics against the provisioned IREE runtime on spark-102, all exit 0. CI runs the first two.

Closes #2820

safetensors 0.8 returns `&str` from `SafeTensors::names()`, so the `name.as_str()` left in the Youtu-VL runtime resolved to the unstable `str_as_str` library feature and broke `cargo check --features cuda,xla-iree`, the first of the OpenXLA job's two steps. `required` is a `BTreeSet<&str>`, so it takes the borrowed name directly.

The second step, `xla-diagnostics`, then failed on four `format!("{:x}", Sha256::digest(..))` sites: sha2 0.11 returns a `hybrid_array::Array` that no longer implements `LowerHex`. Three are reachable in that job (Gemma3n diagnostics, the Molmo diagnostics support module) and one sits behind `xla-reference-diagnostics`, which CI does not compile; all now call the `sha256_hex` helper #2819 added for exactly this reason.

Validation: `cargo check --features cuda,xla-iree --all-targets`, `cargo check --no-default-features --features xla-diagnostics --all-targets`, and `cargo check --features xla-reference-diagnostics --all-targets` against the provisioned IREE runtime on spark-102, all exit 0.

Closes #2820
@inureyes inureyes changed the title fix(xla): drop as_str on the safetensors 0.8 tensor name fix(xla): repair the OpenXLA feature compile job after #2819 Nov 2, 2026
@inureyes
inureyes force-pushed the fix/issue-2820-safetensors-name-as-str branch from 20f0904 to 4488fd4 Compare November 2, 2026 16:23
@inureyes
inureyes merged commit e07082e into main Nov 2, 2026
31 of 32 checks passed
@inureyes
inureyes deleted the fix/issue-2820-safetensors-name-as-str branch November 2, 2026 16:49
inureyes added a commit that referenced this pull request Nov 24, 2026
## Summary

- The Molmo and Gemma3n diagnostic digests were hashed twice since #2837 (`sha256_hex(digest.finalize())`). A new `hex_lower` encodes the finished digest at the three sites, so the pinned values (`0a1bef50...`) match again and none changed. A unit test pins `digest_f32` and `digest_i32` to a single SHA-256.
- The Molmo gate now reaches its vision stages and fails 2 of 14: `vision.selected_layer_21` on 4 of 1,181,696 elements (max_abs 2.80) and `vision.selected_layer_14` on 2 elements (max_abs 2.69), identical on local-task and cuda. No tolerance is relaxed. This is tracked separately.
- The Gemma3n canonical lib test now clears its checkpoint hashes and reaches its numerics, then fails the pinned prefix-decode top1 (854 pinned, 236798 observed on this GB10). Tracked separately.
- `llava_cli_server_check.py`: strips the CLI's leading newline, and expects the server's `usage.prompt_tokens` to be the expanded sequence (743), not the unexpanded prompt (15). Passes on cuda.
- Oracle venv: `requirements.lock` gains `torchvision`; the new `requirements-youtu.lock` pins transformers 4.57.1 for the Youtu-VL oracle. Both resolve from a clean venv.
- Docs: `xla_qwen25_vl_window_check` needs non-uniform multi-image input. The `mlxcel-xla` `iree` lib tests fail to link under `test-fast` because the IREE runtime link recipe lives only in the root `build.rs`; release links only because fat LTO drops the unreferenced shim calls. The README records this and the working `--release` command.

## Test plan

- [x] new unit tests `digest_helpers_hash_the_little_endian_bytes_once` and `hex_lower_encodes_a_finished_digest_without_rehashing`
- [x] `llava_cli_server_check.py` on cuda: RESULT PASS
- [x] `cargo test --release -p mlxcel-xla --lib --features iree --no-run` links
- [x] `cargo fmt --check`, `cargo check --features cuda,xla-iree --all-targets`, `cargo check --no-default-features --features xla-diagnostics --all-targets`, `python3 scripts/insert_apache_header.py --check`
- [ ] Molmo v1 gate 14/14: currently 12/14 (see above)
- [ ] Gemma3n canonical lib test passes: reaches numerics, fails the pinned top1

Closes #3365
inureyes added a commit that referenced this pull request Nov 25, 2026
…3399)

## 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 #870 merge commit (`3ba57b30`, no digest patch needed: the double hash came in with #2837), `vision.selected_layer_21` already fails on this GB10 (4 elements, max_abs 1.56) and layer 14 passes (max_abs 1.59). #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

- [x] `xla_molmo_reference_check`, pinned revision `5c04b3a4`, `test_image.png`: 14/14 on `local-task` and on `cuda`
- [x] `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
- [x] `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`
- [x] `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:done Completed type:bug Bug fixes, error corrections, or issue resolutions priority:medium Medium priority labels Nov 30, 2026
@inureyes inureyes added this to the 0.8 milestone Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

1 participant