notes
← back to notes

kimi delta attn from first principles

+ linear attention, delta net, and gated delta net

some reference material:

https://arxiv.org/pdf/2510.26692

https://haileyschoelkopf.github.io/blog/2024/linear-attn/

The idea is to have a small memory matrix to continuously learn and forget information as it arrives. KDA builds upon linear attention, DeltaNet and gated DeltaNet and adds fine-grained gating mechanism

Let’s go from first principles.

Self attention

$$\mathrm{out}=\operatorname{softmax}\!\left(\frac{QK^\top}{\sqrt{d}}\right)V$$

What’s wrong with regular softmax attention?

Linear Attention

To linearize attention, we can replace softmax with a similarity function

$$\operatorname{Softmax}(QK^\top)V=\frac{\exp(QK^\top)}{\sum_{i=1}^{L}\exp(QK_i^\top)}V$$
$$\frac{\operatorname{sim}(Q,K)}{\sum_{i=1}^{L}\operatorname{sim}(Q,K_i)}V$$
$$\operatorname{sim}(Q,K)=\phi(Q)\cdot\phi(K)=\phi(Q)\phi(K)^\top$$
$$\frac{\phi(Q)\phi(K)^\top}{\sum_{i=1}^{L}\phi(Q)\phi(K_i)^\top}V=\frac{\phi(Q)(\phi(K)^\top V)}{\phi(Q)\sum_{i=1}^{L}\phi(K_i)^\top}$$
Q (N × d) times K transpose (d × N) equals QK transpose (N × N). K transpose (d × N) times V (N × d) equals K transpose V (d × d).

Why can’t we just reorder this in self attn?

$$S_t=S_{t-1}+k_tv_t^\top$$ $$o_t=S_t^\top q_t$$

Associative memory

So what’s wrong with Linear attention?

DeltaNet

$$\hat{v}_t=S_{t-1}^\top k_t$$
$$e_t=v_t-\hat{v}_t$$
$$S_t=S_{t-1}+\beta_t k_t e_t^\top$$

Online gradient descent on a reconstruction objective:

$$\mathcal{L}_t(S)=\frac{1}{2}\lVert S^\top k_t-v_t\rVert^2$$
$$\nabla_S\mathcal{L}_t=k_t(S^\top k_t-v_t)^\top$$
$$S_t=S_{t-1}-\beta_t\nabla_S\mathcal{L}_t$$
$$S_t=S_{t-1}+\beta_t k_t(v_t-S_{t-1}^\top k_t)^\top$$
$$S_t=S_{t-1}+\beta_t k_t e_t^\top$$

Gated DeltaNet

$$S_t=\alpha_t S_{t-1}+\beta_t k_t(v_t-\alpha_t S_{t-1}^\top k_t)^\top$$
$$\alpha_t\in[0,1]$$

Problems with GDN

KDA

$$\alpha_t=\begin{bmatrix}1.0\\0.9\\0.2\\0.0\end{bmatrix}\qquad\operatorname{Diag}(\alpha_t)=\begin{bmatrix}1&0&0&0\\0&0.9&0&0\\0&0&0.2&0\\0&0&0&0\end{bmatrix}$$

Breaking down the KDA equation from the paper:

$$S_t=(I-\beta_t k_t k_t^\top)\operatorname{Diag}(\alpha_t)S_{t-1}+\beta_t k_t v_t^\top$$ $$o_t=S_t^\top q_t$$
  1. Each row of the memory matrix $S$ gets its own decay factor to forget memory
    $$\bar{S}_t=\operatorname{Diag}(\alpha_t)S_{t-1}$$
  2. starting with the delta net update rule
    $$S_t=S_{t-1}+\beta_t k_t(v_t-S_{t-1}^\top k_t)^\top$$
    • can be expanded to
      $$S_t=S_{t-1}+\beta_t k_t v_t^\top-\beta_t k_t k_t^\top S_{t-1}$$
    • factor out $S_{t-1}$ using an identity matrix $I$
      $$S_t=(I-\beta_t k_t k_t^\top)S_{t-1}+\beta_t k_t v_t^\top$$
    • putting this together we get the KDA equation

KDA has three gates actually, forget gate $\alpha_t$, update gate $\beta_t$ and output gate $g_t$:

$$\alpha_t=f(W_\alpha^\uparrow W_\alpha^\downarrow x_t)$$
$$o_t=S_t^\top q_t$$
$$g_t=\sigma(W_g^\uparrow W_g^\downarrow x_t)$$ $$o_t=W_o(g_t\odot\tilde{o}_t)$$

What is low rank parameterization:

KDA Architecture:

$$q_t=\operatorname{L2Norm}\bigl(\operatorname{Swish}(\operatorname{ShortConv}(W_qx))\bigr)_t$$ $$k_t=\operatorname{L2Norm}\bigl(\operatorname{Swish}(\operatorname{ShortConv}(W_kx))\bigr)_t$$ $$v_t=\operatorname{Swish}(\operatorname{ShortConv}(W_vx))_t$$
Kimi Linear architecture: hybrid MLA and KDA layers with MoE, and the Kimi Delta Attention projections, convolutions, normalization, and gates.