Skip to content

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