Shows an approach for using AI search to port hard-won CUDA kernel optimizations to MLX on Apple Silicon, rather than rediscovering them from scratch. Relevant to anyone targeting non-NVIDIA hardware.
Key takeaways · AI-distilled
IBM Research extended Berkeley's K-Search, an evolutionary kernel optimizer, with an MLX backend and a CUDA-to-MLX translation layer: concept mapping tables, Metal-specific code patterns, and expert kernel behaviors restated as properties the search must preserve.
On attentionThe mechanism that lets a model weigh which earlier words matter for the word it's currently processing — the core operation of a transformer.Full definition →, the authors report a jump from 0.26x to 0.97x the speed of Apple's native MLX attention kernel with the full translation layer, whose evolved kernel found FlashAttention-2 techniques such as online softmax and the exp2 trick.
The translation tables encode hard limits that change which optimizations pay off, such as Metal threadgroup memory capped at 32 KB versus 48 KB of NVIDIA shared memory, and roughly 400 GB/s on an M3 Max versus about 3.35 TB/s of HBM3 on an H100.
On mamba-370m on an M1 Max, the evolved SSM kernel reached about 5,750-6,740 TokenA piece of text, such as a word, part of a word or a punctuation mark, that a language model represents as numbers and handles as a unit.Full definition →/s of prefill versus about 330 for mlx-lm, roughly 20x, because it applies an associative parallel scan. Decode stayed close (152 vs 116 tok/s), since one new token gives no scan to parallelize.
The authors conclude the bottleneck was not the Large language modelA model trained on large amounts of data to process and generate language.Full definition →'s ability to write Metal code but the quality of Context and context windowContext is the information available for a generation; the context window is the capacity available to hold it.Full definition → and constraints it received. They caution they do not yet know how far the result generalizes beyond the two kernels studied.
Terms in this piece · Glossary
attention — The mechanism that lets a model weigh which earlier words matter for the word it's currently processing — the core operation of a transformer.
Token — A piece of text, such as a word, part of a word or a punctuation mark, that a language model represents as numbers and handles as a unit.
Large language model — A model trained on large amounts of data to process and generate language.
Context and context window — Context is the information available for a generation; the context window is the capacity available to hold it.