Expand description
Gated DeltaNet lowered to CUDA — the mechanism behind 48 of Qwen3.8-27B’s 64 layers.
Each value head carries a fixed D×D associative memory S and rewrites it per token:
u = S·k what the memory predicts for this key
S = α·S + β·(v − α·u)·kᵀ decay, then correct by the prediction error
o = S·q read the UPDATED memory
o = rmsnorm(o ⊙ silu(z))·GN gate FIRST, then normalize§The fusion
Written literally that is three passes over S — one for S·k, one for the rank-1 update, one for S·q.
A dataflow graph of separate operators (ggml’s shape) cannot do better, because each operator’s output is
a materialized tensor. But the update is affine in S, so the second matvec expands:
o[a] = Σ_b S_new[a][b]·q[b]
= Σ_b (α·S_old[a][b] + coef[a]·k[b])·q[b]
= α·(S_old·q)[a] + coef[a]·(k·q)(k·q) is ONE SCALAR per head. So a single pass that loads S_old[a][b] into a register accumulates
S·k, S·q and k·q together, and the register is still live for the write-back — one read and one
write of the memory per token, with the post-update read costing nothing extra. That is the whole reason
this op is a first-class LOGOS block rather than a composition of smaller ones.
Constants§
- GDN_
KERNELS - One block per
(value head, row)computes that row’su,wand the sharedk·qin a single pass over the memory, then rewrites the row from the register it already holds.olands in scratch; the gated RMSNorm needs the whole head, so it is a second (tiny) kernel. - QWEN38_
KERNELS - The rest of the Qwen3.8-specific device code: the pieces of a GDN layer that surround the recurrence, plus the two things gated attention needs that a plain transformer does not (a partial rotary and an output gate). Each is deliberately fused past what a per-operator graph could do — the conv carries silu, the gate kernel computes both gates from one launch, and the norm+rope stay one pass over the head.
Functions§
- emit_
gated_ delta_ forward - Emit a self-contained CUDA program for ONE Gated DeltaNet step with every input inlined, so the fused
kernels above can be checked against the LOGOS
gated deltaop on the VM at small shapes on any GPU — the same shape of proofemit_moe_forwardgives the MoE block. PrintsOthen the mutated memoryS, because a desugar that ignored the memory would otherwise pass.