Skip to content

feat(xla): fail fast on MLXCEL_XLA_PRECISION=bf16 for Metal targets - #615

Merged
inureyes merged 1 commit into
mainfrom
fix/612-bf16-metal-guard
Jul 2, 2026
Merged

inureyes merged 1 commit into
mainfrom
fix/612-bf16-metal-guard

Conversation

@inureyes

@inureyes inureyes commented Jul 2, 2026

Copy link
Copy Markdown
Member

Summary

Closes #612 (follow-up to #575). On the OpenXLA/IREE Metal target, MLXCEL_XLA_PRECISION=bf16 cannot lower: the metal-spirv GPU target advertises no bf16 compute (compute = fp32|fp16|int*), so the emitter's f32-to-bf16 vector.bitcast fails to legalize inside iree-compile. Before this change that surfaced mid-run as a raw multi-line iree-compile legalization dump, after model load, which is a confusing failure for an operator who just set the env var.

Change

  • resolve_precision_checked(device) (builder.rs) resolves the precision and rejects the one pair the target cannot lower, returning an actionable message pointing at f16. It is backed by a pure, env-free precision_lowers_on(device, precision) predicate so the guard logic is unit-tested directly.
  • Both compile entry points use it: compile_vmfbs (single-seq) and the batch XlaRaggedEngine load. The guard fires at the emit/compile boundary, before iree-compile and before weights upload.
  • Docs: ADR 0004 and the mlxcel-xla README updated to describe the fail-fast behavior.

Validation (M1 Ultra, MLXCEL_XLA_DEVICE=metal)

  • bf16: Error: MLXCEL_XLA_PRECISION=bf16 is not supported on the Metal target: the metal-spirv GPU target has no bf16 compute, so the graph fails to legalize. Use f16 (the Metal default) or f32. (clean, no iree-compile dump)
  • f16: still generates (metal default, token-exact per feat: extend the fused low-precision path to the Metal target #575).
  • f32: still generates.
  • bf16 on CUDA / CPU targets is unaffected (guard only fires on metal).
  • Unit test precision_lowers_on_rejects_only_bf16_on_metal passes; cargo fmt --all -- --check clean.

The metal-spirv GPU target has no bf16 compute, so a bf16 graph fails deep inside iree-compile with an opaque vector.bitcast legalization dump after model load (found in #575). Add resolve_precision_checked, which rejects bf16 on a metal device at the emit/compile boundary with an actionable message pointing at f16 (the Metal default), before iree-compile runs and before weights upload.

Both single-seq (compile_vmfbs) and batch (XlaRaggedEngine load) compile paths use the checked resolver; f16 and f32 on Metal, and bf16 on CUDA and the CPU targets, are unaffected. The guard logic is a pure precision_lowers_on(device, precision) predicate with a unit test; validated on an M1 Ultra (bf16 errors cleanly, f16 and f32 still generate).

Closes #612.
@inureyes inureyes added area:inference Generation, sampling, decoding (incl. speculative, DRY) type:enhancement New features, capabilities, or significant additions priority:low Low priority labels Jul 2, 2026
@inureyes
inureyes merged commit e096ac8 into main Jul 2, 2026
4 checks passed
@inureyes
inureyes deleted the fix/612-bf16-metal-guard branch July 2, 2026 05:16
@inureyes inureyes self-assigned this Aug 31, 2026
@inureyes inureyes added the status:done Completed label Sep 6, 2026
be-free-snowboy pushed a commit to freestylejs/snowbrain-mlxcel that referenced this pull request Oct 27, 2026
…ablup#615)

The metal-spirv GPU target has no bf16 compute, so a bf16 graph fails deep inside iree-compile with an opaque vector.bitcast legalization dump after model load (found in lablup#575). Add resolve_precision_checked, which rejects bf16 on a metal device at the emit/compile boundary with an actionable message pointing at f16 (the Metal default), before iree-compile runs and before weights upload.

Both single-seq (compile_vmfbs) and batch (XlaRaggedEngine load) compile paths use the checked resolver; f16 and f32 on Metal, and bf16 on CUDA and the CPU targets, are unaffected. The guard logic is a pure precision_lowers_on(device, precision) predicate with a unit test; validated on an M1 Ultra (bf16 errors cleanly, f16 and f32 still generate).

Closes lablup#612.
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) priority:low Low priority status:done Completed type:enhancement New features, capabilities, or significant additions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(xla): fail fast when MLXCEL_XLA_PRECISION=bf16 targets a Metal device

1 participant