Skip to content

feat: per-device default precision and a precision accuracy gate for the OpenXLA backend (#449) - #557

Merged
inureyes merged 1 commit into
mainfrom
feat/515-xla-precision-default
Jul 1, 2026
Merged

inureyes merged 1 commit into
mainfrom
feat/515-xla-precision-default

Conversation

@inureyes

@inureyes inureyes commented Jul 1, 2026

Copy link
Copy Markdown
Member

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).

  • Per-device default: f16 on the GPU HAL devices (metal, cuda), f32 on the CPU (local-task / local-sync), resolved per device at graph emission. MLXCEL_XLA_PRECISION (f16 | bf16 | f32) overrides on any device; f32 forces f32 even on a GPU whose default is f16.
  • 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. A blanket demotion (which regressed accuracy and was slower) fails it. Plus a default_precision device decision-table test.

Changes

  • emitter/builder.rs: precision_env_override() (Option, now matching f32 too), default_precision(device), resolve_precision(device); decision-table test.
  • emitter/model.rs: emit_*_with(precision) variants; the plain emit_* become f32-default wrappers (test API unchanged).
  • emitter/mod.rs: re-exports; the structural f16-invariant gate test.
  • iree.rs: both emit sites use resolve_precision(device) + the _with variants.
  • mlxcel-xla/README.md: the per-device default.

Validation (M1 Ultra, Llama-3.2-1B-Instruct, greedy)

  • Metal with no env now defaults to f16: 2.95 tok/s vs 1.55 (f32) = ~1.9x.
  • MLXCEL_XLA_PRECISION=f32 forces f32 (1.55); =f16 forces f16 (2.91).
  • default / f16 / f32 are all token-exact with each other.
  • 48 mlxcel-xla unit tests green (incl. the new gate + decision-table tests); the emitter byte-exact regression still passes; cargo fmt --check and emitter clippy clean.
  • Default / non-macOS builds unaffected (change is in the xla-backend-only crate; the CPU default stays f32).

A bug caught by validation and fixed here: precision_env_override previously did not match f32, so MLXCEL_XLA_PRECISION=f32 fell through to the GPU f16 default instead of forcing f32.

…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.
@inureyes inureyes added type:enhancement New features, capabilities, or significant additions area:inference Generation, sampling, decoding (incl. speculative, DRY) labels Jul 1, 2026
@inureyes
inureyes merged commit df9001a into main Jul 1, 2026
4 checks passed
@inureyes
inureyes deleted the feat/515-xla-precision-default branch July 1, 2026 00:47
@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
…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.
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) status:done Completed type:enhancement New features, capabilities, or significant additions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test: precision accuracy gate and per-device default precision for the OpenXLA backend (#449)

1 participant