Adding metal kernels for the gated delta nets. - #4020
Conversation
5810e68 to
8861d85
Compare
|
Hi @tpegolotti — thanks for this PR, and thanks @zcbenz for pointing me at it. The chunked WY-form kernels are a clear step up for batched prefill (the B ≥ 4 curves speak for themselves), and I'd be glad to see this land. @zcbenz asked me to look for possible improvements, so here are my notes. Everything below comes from reading the diff — I have not run the branch yet — so please take it as suggestions and correct me wherever I've misread something. I'm happy to help with any of it (patches against this branch, or measurements on an M5 Max).
Again, happy to turn any of these into patches or measurements — just say which would be most useful. (Also glad to help with the rebase onto current main if that's useful.) |
|
Hi @wyanzhao, thanks for the comments and suggestions! I've added most of them in the latest commits.
|
Adding kernel support for the Gated Delta Net rule. The math follows the ICLR paper: https://arxiv.org/abs/2412.06464.
Changes
Added three kernels for the forward gated delta rule:
Added benchmark and test scripts. The test script also compares against the naive FLA implementation of the gated delta rule using PyTorch ops.
Models Tested
Additionally to the tests added, I validated the kernels by running
mlx_lm.evaluate --model <model> --tasks wikitext --num-shots 5 --max-tokens 2048on the following modelsmlx-community/Qwen3.5-9B-MLX-4bit,mlx-community/Qwen3.5-35B-A3B-8bit, andmlx-community/Qwen3.5-27B-4bit. In the following table, I report the "word_perplexity" value.As expected, they all match.
Performance
I give micro benchmarks on M1 Max and M5 Max. These can be obtained by running
python benchmarks/python/gated_delta_bench.py.As well as full end to end prompt processing measurements over the 3 models used for validation on the M5 Max.

Future work