Skip to content

Releases

mlx-exact 0.13.1

Choose a tag to compare

@audenvenn audenvenn released this 23 Nov 04:06

Fixes and stricter checks, prompted by an independent review of the technical report draft.

  • Bitwise comparison: mx.array_equal treats +0 and −0 as equal, so tests based on it could not establish bit-identical results. The new mlx_exact.testing.bits_equal compares the stored bit patterns, and every test and experiment now uses it.
    • The full suite passes under it.
    • The seven real checkpoints pass every check bit for bit: Llama-3.2-1B, Qwen2.5-1.5B, SmolLM3-3B, Phi-4-mini, Gemma-3-1B, Gemma-3-4B, and Gemma-2-2B for single sequences.
  • Gradients:
    • mxfp4 layers had no backward pass since 0.9.0, and Gemma 2's attention had none in 0.13.0 (the custom kernels had no VJP).
    • Full-prefill attention with sinks had none either, because stock MLX's backward pass rejects sinks.
    • All three now have one. Backward passes are correct gradients, not bit-exact ones.
  • mx.matmul(a, b, stream=...) raised TypeError while exact mode was on (0.13.0). The stream is now honoured.
  • Docs: MLX's dispatch boundaries are corrected.
    • split-K partitions go up to K/64;
    • head dim 192 is unfused at every query count;
    • head dim 256 switches to a fused kernel from 1,024 queries only with causal or array masks;
    • head dim 512's fused long-prefill kernel (Gemma 4's global layers) is listed as not validated.
    • The environment guard is described precisely: it checks the MLX version and GPU generation, not mlx-lm.
  • New tests: tests/test_gradients.py. 275 tests in all.

Install: pip install "mlx-exact[lm] @ git+https://github.com/audenvenn/mlx-exact@v0.13.1". Validated on Apple M6 with MLX 0.32.4 and mlx-lm 0.32.2.

Developed with AI assistance (Anthropic's Claude).

mlx-exact 0.13.0

Choose a tag to compare

@audenvenn audenvenn released this 21 Nov 10:58

Raw matmuls are rerouted in exact mode, and Gemma 2 is bit-exact.

  • Raw matmuls (a @ b, mx.matmul) used to stay schedule-dependent. MLX picks their kernel from the shape (gemv, gemv_wide, accelerator kernels, split-K for some unbatched shapes), so they rounded differently in decode and prefill. While exact mode is on:
    • a 2-D right operand (a weight applied as x @ w.T, such as MoE router gates and tied output layers) takes mlx-exact's dense Linear route;
    • batched products run on MLX's accelerator kernels with at least 16 rows and columns.
    • This applies to every @ in the process while exact mode is on.
  • Gemma 2 computes attention with raw matmuls (logit softcapping). It now also uses mlx-exact's softmax, because MLX's switches kernels above 4,096 keys.
    • With mlx-community/gemma-2-2b-it-4bit, decode after a 1,400-token prefill matches the full prefill at 100 of 100 positions (0.12.x and stock MLX: 0).
    • Speed: prefill 0.99×, decode 0.81× of stock.
    • Batching Gemma 2 fails in mlx-lm 0.32.2 itself (mask broadcasting).
  • The other real checkpoints (Llama-3.2-1B, Gemma-3-1B, Gemma-3-4B) are unchanged and bit-exact in every check.
  • Not covered: DeepSeek-V3's MLA, whose decode uses a different formulation than its prefill.
  • New tests: tests/test_raw_matmul.py, four tests that all fail without the change. 270 tests in all.

Install: pip install "mlx-exact[lm] @ git+https://github.com/audenvenn/mlx-exact@v0.13.0". Validated on Apple M6 with MLX 0.32.4 and mlx-lm 0.32.2.

Developed with AI assistance (Anthropic's Claude).

mlx-exact 0.12.1

Choose a tag to compare

@audenvenn audenvenn released this 21 Nov 07:48

Head dims 192/256 with several KV heads (Gemma 3 4B and larger) are bit-exact with sliding windows, decode and batches, checked on the real model.

  • What was wrong (0.6.0–0.12.0): on real mlx-community/gemma-3-4b-it-qat-4bit, decode once the sliding window had slid, and padded sequences in batches, were not bit-exact.

    • MLX's softmax on the unfused attention path, used for these head dims, sums each row in a tree over 128-key groups. Its bits depend on where the keys sit modulo 512 or more, and mlx-exact aligned them modulo 32.
    • The differences are rare (a few hundred in 26 million outputs), so the tiny-model tests passed, but each one changes every later token's logits.
  • Fix: mlx-exact composes this path itself: MLX's accelerator matmuls (at least 16 query rows), with its own softmax in between. Each SIMD lane sums the entries whose index ≡ lane (mod 32) in order, and the 32 lane sums are combined in a fixed order. So shifts by multiples of 32, and masked keys at the end, cannot change the bits.

  • Real Gemma 3 4B, 1,500-token prompt, bit-identical:

    Comparison 0.12.1 0.12.0 Stock
    chunks of 512 vs one chunk (checked rows) 109/109 109/109 1/109
    token-by-token decode after a 1,400-token prefill 100/100 0/100 0/100
    each sequence of a left-padded batch vs alone (padded by 300) 11/11 0/11 0/11
    greedy 64 tokens, prefill steps 2,048 vs 512 64/64 64/64 45/64
  • Speed (Apple M6): prefill 0.96×, decode 0.75× of stock. Decode pads each attention call's query to 16 rows.

  • New regression tests (tests/test_long_d256.py): the softmax's invariance, and a window's decode, shifted and prefill layouts at real sizes. Stock MLX attention gives 54 mismatching outputs in the same test. 266 tests.

Install: pip install "mlx-exact[lm] @ git+https://github.com/audenvenn/mlx-exact@v0.12.1". Validated on Apple M6 with MLX 0.32.4 and mlx-lm 0.32.2.

Developed with AI assistance (Anthropic's Claude).

mlx-exact 0.12.0

Choose a tag to compare

@audenvenn audenvenn released this 21 Nov 05:45

Correction (2026-11-21): on the real mlx-community/gemma-3-4b-it-qat-4bit, batched sliding windows and decode after the window has slid are not bit-exact for head dims 192/256 with several KV heads.

  • MLX's unfused attention softmax depends on the keys' offset modulo 512 or more, while mlx-exact aligns them modulo 32.
  • The long-prompt crash fix and chunked prefill are fine.
  • See the README's Limitations; a fix is in progress.

Head dims 192/256 with several KV heads (Gemma 3 4B and larger): two fixes, and batched sliding windows.

  • Fix (since 0.1.0): in exact mode, prompt chunks of 1,024 or more tokens with an array mask raised NotImplementedError.
    • This hit a single prompt over 1,024 tokens on a sliding-window layer (mlx-lm prefills in 2,048-token steps), and long left-padded batches.
    • Such chunks are now split into blocks of at most 1,008 rows on MLX's unfused attention path, which decode and shorter chunks use.
  • Fix (since 0.6.0): when a causal chunk of 1,024 or more tokens on a sliding-window layer was split, each block re-derived its key alignment from the cache and could shift its keys by up to 31 positions. Values were correct, but the bits could differ from other schedules.
  • Batched sliding windows are bit-exact for these head dims too: each sequence is placed at its absolute positions modulo 32. This was the last batched case the README listed as not covered.
  • New tests:
    • tests/test_long_d256.py: a 1,100-token prompt prefilled whole, in chunks of 300, or token by token gives bit-identical logits; a left-padded batch of 1,100- and 1,040-token prompts matches each sequence alone.
    • A Gemma 3 4B-like case in tests/test_batch_sliding.py, which fails with 0.11.0.
  • README: a related-work section (batch-invariant kernels on CUDA and MLX; LLM-42, CoRun, Vosti).
  • 264 tests.

Install: pip install "mlx-exact[lm] @ git+https://github.com/audenvenn/mlx-exact@v0.12.0". Validated on Apple M6 with MLX 0.32.4 and mlx-lm 0.32.2 (tiny random-weight models for these cases).

Developed with AI assistance (Anthropic's Claude).

mlx-exact 0.11.0

Choose a tag to compare

@audenvenn audenvenn released this 20 Nov 19:51

Attention sinks (gpt-oss) now run on the exact offsets kernel for head dims 64/96/128, through MLX's own sink path (one sink logit per query head). Batched and served gpt-oss, i.e. batched sliding windows with sinks, is now bit-exact.

  • Sink kernel: bit-identical to stock MLX's sink kernel for decode, short chunks and left-padded batches (head dims 64/128, bf16/fp16; tests/test_sinks.py).
  • Batched gpt-oss: a tiny gpt-oss (sinks, sliding windows, mxfp4 experts) in a left-padded batch gives every step's logits bit-identical to each sequence alone (tests/test_batch_sliding.py); with 0.10.0 it did not.
  • Gradients: the backward pass includes the sinks and gives them a gradient.
  • 259 tests.

Install: pip install "mlx-exact[lm] @ git+https://github.com/audenvenn/mlx-exact@v0.11.0". Validated on Apple M6 with MLX 0.32.4 and mlx-lm 0.32.2.

Developed with AI assistance (Anthropic's Claude).

mlx-exact 0.10.0

Choose a tag to compare

@audenvenn audenvenn released this 20 Nov 16:53

Batched generation with sliding windows is now bit-exact. This covers mlx-lm's BatchRotatingKVCache, which BatchGenerator and mlx_lm.server use for Gemma 3, Cohere 2, EXAONE 4 and similar models.

  • Scope: head dims 64/96/128 (bf16/fp16), and head dims 192/256 with one KV head.
  • How: the batch shares one ring buffer. mlx-exact puts it back in temporal order and shifts each sequence to its absolute positions modulo 32. The positions come from the per-sequence offsets that RoPE uses, so every sequence sees the 32-key blocks of its own full prefill.
  • Checks: new tests/test_batch_sliding.py runs a left-padded batch through tiny Gemma 3, Cohere 2 and EXAONE 4 models and a head-dim-256, one-KV-head Gemma 3. Prompts are prefilled whole or in chunks of 16, then decoded for 40 steps. Every step's logits are bit-identical to each sequence run alone; with 0.9.0 they were not. 251 tests.
  • Not yet covered in batches: attention sinks (gpt-oss), and head dims 192/256 with two or more KV heads (Gemma 3 4B and larger).

Install: pip install "mlx-exact[lm] @ git+https://github.com/audenvenn/mlx-exact@v0.10.0". Validated on Apple M6 with MLX 0.32.4 and mlx-lm 0.32.2.

Developed with AI assistance (Anthropic's Claude).

mlx-exact 0.9.0

Choose a tag to compare

@audenvenn audenvenn released this 20 Nov 11:18

mxfp4 (MX-format) layers are now exact, e.g. the experts of gpt-oss.

  • How: mlx-exact runs MLX v0.32.4's own mxfp4 accelerator implementation (vendored, unmodified arithmetic) with a 16-row tile for any row count, plus an expert-indexed variant for MoE layers.
  • Checks: both are bit-identical to stock MLX's long-prefill kernel and sorted expert kernel (gpt-oss-20b shapes, bf16 and fp16).
  • gpt-oss-20b (mlx-community/gpt-oss-20b-MXFP4-Q8: mxfp4 experts, attention sinks, 128-token sliding windows), 200-token prompt, single sequence:
    • decode and prefill in chunks of 7 match one full prefill at 200 / 200 positions (stock MLX: 0 / 200);
    • decode runs at 0.77× of stock.
  • Tests: new tests/test_mxfp4.py, including a tiny random gpt-oss with mxfp4 experts; 239 tests.
  • Still not exact: nvfp4 and mxfp8 fall back to stock MLX with a warning, and batched generation with sliding windows is not covered.

Install: pip install "mlx-exact[lm] @ git+https://github.com/audenvenn/mlx-exact@v0.9.0". Validated on Apple M6 with MLX 0.32.4 and mlx-lm 0.32.2.

Developed with AI assistance (Anthropic's Claude).

mlx-exact 0.8.1

Choose a tag to compare

@audenvenn audenvenn released this 20 Nov 08:18

Faster fixed-order attention for head dims 192/256 with one KV head (e.g. Gemma 3 1B / 270M):

  • Prefill attention is 2.4–3× faster: 0.95 vs 2.32 ms at 512 tokens and 11.8 vs 35.4 ms at 2,048 tokens, against stock MLX's 0.32 / 0.97 ms (Apple M6, causal, 4 query heads, 1 KV head, head dim 256).
  • Decode attention is the same or faster.
  • How: every output is still the same sequential fp32 chain. Each thread now computes a 4 × 4 block of outputs from tiles staged in threadgroup memory, and one SIMD group handles each softmax row; its sum stays sequential.
  • Results are bit-identical to 0.8.0. tests/test_fixed_order.py keeps the previous kernels as the reference; 232 tests.

Install: pip install "mlx-exact[lm] @ git+https://github.com/audenvenn/mlx-exact@v0.8.1". Validated on Apple M6 with MLX 0.32.4 and mlx-lm 0.32.2.

Developed with AI assistance (Anthropic's Claude).

mlx-exact 0.8.0

Choose a tag to compare

@audenvenn audenvenn released this 20 Nov 01:33

Exact attention for head dims 64/96/128 (bf16/fp16) now calls MLX's own fused attention kernel directly, with per-sequence key offsets: no query padding, no key copies, and the KV cache is read in place.

  • Batched exact decode is 2× faster: Qwen3-0.6B-4bit, 8 sequences, 1,125 generated tok/s vs 566 in 0.7.1 (stock 1,260; now 0.89× of stock). Single-sequence decode: 0.95× of stock.
  • Results are unchanged: bit-identical to 0.7.x in 552 kernel checks, and a GSM8K replay (120 problems × 3 schedules) is token-identical.
  • Fixes, found in an independent pre-release review and confirmed with regression tests (tests/test_attention_review.py):
    • NaN in left-padded batches in exact mode for head dims 192/256 with one KV head (e.g. Gemma 3 1B), since 0.7.0;
    • backward passes through every exact attention route (missing on the fixed-order, re-alignment and quantized-KV routes);
    • unrestricted attention (mask=None with several queries) was made causal on the padded fallback path; more queries than keys; masks broadcast along the key axis with rotating caches.

Install: pip install "mlx-exact[lm] @ git+https://github.com/audenvenn/mlx-exact@v0.8.0". Validated on Apple M6 with MLX 0.32.4 and mlx-lm 0.32.2. Full changelog, results and limitations: README.

Developed with AI assistance (Anthropic's Claude). This release also had an independent pre-release code review by another AI model (OpenAI's Codex).