Repository navigation
feat(xla): fail fast on MLXCEL_XLA_PRECISION=bf16 for Metal targets - #615
Merged
Merged
Conversation
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.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #612 (follow-up to #575). On the OpenXLA/IREE Metal target,
MLXCEL_XLA_PRECISION=bf16cannot lower: themetal-spirvGPU target advertises no bf16 compute (compute = fp32|fp16|int*), so the emitter'sf32-to-bf16vector.bitcastfails to legalize insideiree-compile. Before this change that surfaced mid-run as a raw multi-lineiree-compilelegalization 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 atf16. It is backed by a pure, env-freeprecision_lowers_on(device, precision)predicate so the guard logic is unit-tested directly.compile_vmfbs(single-seq) and the batchXlaRaggedEngineload. The guard fires at the emit/compile boundary, beforeiree-compileand before weights upload.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, noiree-compiledump)f16: still generates (metal default, token-exact per feat: extend the fused low-precision path to the Metal target #575).f32: still generates.bf16on CUDA / CPU targets is unaffected (guard only fires onmetal).precision_lowers_on_rejects_only_bf16_on_metalpasses;cargo fmt --all -- --checkclean.