Skip to content

Adding metal kernels for the gated delta nets. - #4020

Open
tpegolotti wants to merge 56 commits into
mainfrom
gated-delta-update
Open

Adding metal kernels for the gated delta nets.#4020
tpegolotti wants to merge 56 commits into
mainfrom
gated-delta-update

Conversation

@tpegolotti

Copy link
Copy Markdown
Collaborator

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:

  • Sequential: straightforward recurrence
  • Simdgroup: chunk parallel implementation using 8x8 simdgroup_matrix operations
  • NAX: chunk parallel implementation using 16x16 tiles available on the neural accelerator

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 2048 on the following models mlx-community/Qwen3.5-9B-MLX-4bit, mlx-community/Qwen3.5-35B-A3B-8bit, and mlx-community/Qwen3.5-27B-4bit. In the following table, I report the "word_perplexity" value.

Sequential Simdgroup NAX
Qwen3.5-9B 9.82 9.82 9.82
Qwen3.5-35B 7.45 7.45 7.45
Qwen3.5-27B 7.87 7.87 7.87

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.

m1_max_micro m5_max_micro

As well as full end to end prompt processing measurements over the 3 models used for validation on the M5 Max.
m5_max_tps

Future work

  • Add backward pass
  • Add to mlx-lm
  • Add masking to kernels
  • Make kernel general in chunk parameter

@tpegolotti
tpegolotti marked this pull request as draft August 5, 2026 21:20
@tpegolotti
tpegolotti marked this pull request as ready for review August 7, 2026 11:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant