Repository navigation
feat: per-device default precision and a precision accuracy gate for the OpenXLA backend (#449) - #557
Merged
Merged
Conversation
…the OpenXLA backend (#449) Make f16 the default contraction precision on the GPU HAL devices (metal, cuda) and keep f32 on the CPU (local-task / local-sync), resolved per device at graph emission; MLXCEL_XLA_PRECISION (f16 | bf16 | f32) overrides the default on any device (f32 forces f32 even on a GPU whose default is f16). The emitter's emit_* gain _with(precision) variants that iree.rs drives with resolve_precision(device); the plain emit_* stay f32-default wrappers so the byte-exact regression tests are unchanged. Add the precision accuracy gate: a structural emitter test asserting the f16 graph demotes only the matmul inputs and keeps norm (rsqrt) and softmax (exponential) f32 -- the targeted, not blanket invariant that makes f16 token-exact, so a blanket demotion fails it -- plus a default_precision device decision-table test. Validated on an M1 Ultra (Llama-3.2-1B-Instruct, greedy): metal now defaults to f16 at 2.95 tok/s (vs f32 1.55, ~1.9x) with no env set; MLXCEL_XLA_PRECISION=f32 forces f32; default / f16 / f32 are all token-exact. 48 mlxcel-xla unit tests green; the byte-exact regression still passes; fmt and emitter clippy clean.
1 of 4 tasks
be-free-snowboy
pushed a commit
to freestylejs/snowbrain-mlxcel
that referenced
this pull request
Oct 27, 2026
…the OpenXLA backend (lablup#449) (lablup#557) Make f16 the default contraction precision on the GPU HAL devices (metal, cuda) and keep f32 on the CPU (local-task / local-sync), resolved per device at graph emission; MLXCEL_XLA_PRECISION (f16 | bf16 | f32) overrides the default on any device (f32 forces f32 even on a GPU whose default is f16). The emitter's emit_* gain _with(precision) variants that iree.rs drives with resolve_precision(device); the plain emit_* stay f32-default wrappers so the byte-exact regression tests are unchanged. Add the precision accuracy gate: a structural emitter test asserting the f16 graph demotes only the matmul inputs and keeps norm (rsqrt) and softmax (exponential) f32 -- the targeted, not blanket invariant that makes f16 token-exact, so a blanket demotion fails it -- plus a default_precision device decision-table test. Validated on an M1 Ultra (Llama-3.2-1B-Instruct, greedy): metal now defaults to f16 at 2.95 tok/s (vs f32 1.55, ~1.9x) with no env set; MLXCEL_XLA_PRECISION=f32 forces f32; default / f16 / f32 are all token-exact. 48 mlxcel-xla unit tests green; the byte-exact regression still passes; fmt and emitter clippy clean.
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.
Closes #515. Part of #513.
What
Per-device default precision for the OpenXLA backend plus a precision accuracy gate, building on the f16 emitter mode (#514).
f16on the GPU HAL devices (metal,cuda),f32on the CPU (local-task/local-sync), resolved per device at graph emission.MLXCEL_XLA_PRECISION(f16|bf16|f32) overrides on any device;f32forces f32 even on a GPU whose default is f16.rsqrt) and softmax (exponential) f32 -- the "targeted, not blanket" invariant that makes f16 token-exact. A blanket demotion (which regressed accuracy and was slower) fails it. Plus adefault_precisiondevice decision-table test.Changes
emitter/builder.rs:precision_env_override()(Option, now matchingf32too),default_precision(device),resolve_precision(device); decision-table test.emitter/model.rs:emit_*_with(precision)variants; the plainemit_*become f32-default wrappers (test API unchanged).emitter/mod.rs: re-exports; the structural f16-invariant gate test.iree.rs: both emit sites useresolve_precision(device)+ the_withvariants.mlxcel-xla/README.md: the per-device default.Validation (M1 Ultra, Llama-3.2-1B-Instruct, greedy)
MLXCEL_XLA_PRECISION=f32forces f32 (1.55);=f16forces f16 (2.91).mlxcel-xlaunit tests green (incl. the new gate + decision-table tests); the emitter byte-exact regression still passes;cargo fmt --checkand emitter clippy clean.xla-backend-only crate; the CPU default stays f32).A bug caught by validation and fixed here:
precision_env_overridepreviously did not matchf32, soMLXCEL_XLA_PRECISION=f32fell through to the GPU f16 default instead of forcing f32.