mlx-m5-kernels
by liuweid95-hash · Integration · Text & code
Adds hand-tuned Metal GPU kernels for MLX that shrink the attention memory cache and speed up long-context text generation on Apple silicon Macs.
Latest · Nov 28Open-source repo of three Metal kernels for MLX found by evolutionary search on an M5 MacBook Air, with one-command benchmark reproduction
AccessOpen codeLicenseMIT
Evidence
- Nov 28Fused 4-bit KV-cache FlashDecoding on Llama-3-8B (32:8 GQA, 32K): KV memory 128 MB to 36 MB (-71.9%), 1.171 ms, 8e-6 max errorHands-on test
liuweid95-hash - Nov 284-bit fused KV-cache kernel ran 2.405x faster than mx.dequantize plus SDPA at 32K context on Llama-3-8B shapesHands-on test
liuweid95-hash - Nov 284-bit fused KV-cache kernel ran 1.055x faster than uncompressed FP16 SDPA at 32K context while using 71.9% less KV memoryHands-on test
liuweid95-hash - Nov 28INT8 fused KV-cache kernel cut KV memory 46.9% and ran 2.334x faster than dequantize plus SDPA (1.239 ms), matching FP16 speed, 5.7e-5 errorHands-on test
liuweid95-hash - Nov 28FP16/BF16 GQA FlashDecoding kernel: 1.105x vs mx.fast.scaled_dot_product_attention at 4K (0.324 vs 0.358 ms), 1.005x at 16K (~129 GB/s)Hands-on test
liuweid95-hash
Show all 6
- Nov 28Fused residual add + RMSNorm reached 131.6 GB/s (0.510 ms/layer on 2048x4096) with 2x better fp16 precision than unfused add + mx.fast.rms_normHands-on test
liuweid95-hash