ggml-gated-delta-net

The gated delta rule from llama.cpp as a single kernel (gated_delta_net) — the linear-attention recurrence behind Qwen3-Next and Qwen3.5, which eager torch spells out in ~200 ops per layer. l2_norm is exposed alongside it.

q and k carry one head per value head rather than being pre-expanded, and the recurrent state is indexed [value][key] — store what the op returns rather than transposing it. Ask supports_gated_delta_net for the head dims it covers.

Usage

import torch
from kernels import get_kernel

gdn = get_kernel("marcsun13/ggml-gated-delta-net", version=1)

n_seqs, n_tokens, n_heads, head_dim = 1, 1, 32, 128
q = torch.randn(n_seqs, n_tokens, n_heads, head_dim, device="mps")
k = torch.randn_like(q)                                    # one head per value head, not expanded
v = torch.randn_like(q)
g = torch.randn(n_seqs, n_tokens, n_heads, device="mps")   # log-domain gate
beta = torch.rand(n_seqs, n_tokens, n_heads, device="mps")
state = torch.zeros(n_seqs, n_heads, head_dim, head_dim, device="mps")

out, state = gdn.gated_delta_net(q, k, v, g, beta, state)  # (1, 1, 32, 128), (1, 32, 128, 128)
Downloads last month
-
kernel
mit
Supported hardwares new
Metal
Apple Silicon
Apple MacBook Neo
8GB
Apple Silicon
Apple M1
8GB
Apple Silicon Pro
Apple M1 Pro
16GB
Apple Silicon Max
Apple M1 Max
16GB
Apple Silicon Ultra
Apple M1 Ultra
16GB
Apple Silicon
Apple M2
8GB
Apple Silicon Pro
Apple M2 Pro
16GB
Apple Silicon Max
Apple M2 Max
32GB
Apple Silicon Ultra
Apple M2 Ultra
64GB
Apple Silicon
Apple M3
8GB
Apple Silicon Pro
Apple M3 Pro
18GB
Apple Silicon Max
Apple M3 Max
36GB
Apple Silicon Ultra
Apple M3 Ultra
96GB
Apple Silicon
Apple M4
16GB
Apple Silicon Pro
Apple M4 Pro
24GB
Apple Silicon Max
Apple M4 Max
36GB
Apple Silicon
Apple M5
16GB
Apple Silicon Pro
Apple M5 Pro
24GB
Apple Silicon Max
Apple M5 Max
36GB
OS
macos
Arch
aarch64
Kernel Builder
81f55ea