Raindrop lab · Glossary

linear attention

How to explain it

Some of the model's layers let tokens share notes through a whiteboard. The board is handed along the text, from each token to the next. Each token fades what is on it a little, writes a note of its own, and then reads the board. The board never gets bigger, however long the text.

A kind of layer in which each token learns about the tokens before it from a memory of fixed size that is passed along the text. In Qwen3.5-4B, 24 of the 32 layers work this way. At each token the layer fades the memory a little, writes a note for this token in a spot chosen by what the note is about, replacing what was there, and then reads the memory; what it reads becomes the update the layer adds to that token's residual stream. The memory is 524,288 numbers on each of these layers, whether the text is 16 tokens long or 200,000, so every token costs the same.

A layer that mixes information between positions through a recurrent state of fixed size, instead of comparing each position with every earlier one. The state is a matrix that stores key-value associations: each position writes a value (lesson 4's note) under a key (the spot it goes in), and reads with a query (what the token looks for). Because the state does not grow, the cost of each token is constant and the total cost grows in a straight line with the text - the "linear" in the name - where full attention costs more for every token already read. Qwen3.5's linear-attention layers are Gated DeltaNet: at each position the whole state is first decayed by a gate, then the value stored under this position's key is replaced by the new one (the delta rule), and then the state is read. Qwen3.5-4B has 24 such layers among its 32, each with a state of 524,288 numbers.

Gated DeltaNet (Yang, Kautz and Hatamizadeh, 2024, Gated Delta Networks: Improving Mamba2 with Delta Rule): per head, St=St−1 αt (I−βtktkt⊤)+βtvtkt⊤S_t = S_{t-1}\,\alpha_t\,(I - \beta_t k_t k_t^\top) + \beta_t v_t k_t^\top and ot=Stqto_t = S_t q_t, with a data-dependent decay αt\alpha_t and write strength βt\beta_t, and keys and queries normalised. In mlx_lm's implementation the order at each token is: decay the state, look up SktS k_t, write βt(vt−Skt)kt⊤\beta_t (v_t - S k_t) k_t^\top, then read with qtq_t, so a position's output includes its own write. Qwen3.5-4B's config gives 24 of its 32 layers this type (the other 8 are full attention), each with 16 key heads and 32 value heads of 128 (the lesson's 32 panels), so each layer's state is 32 × 128 × 128 = 524,288 numbers, 12,582,912 over the 24 layers. Lesson 4's probe read those sizes off the model's cache: the same after 16 tokens as after 1,000, and by construction the same at 200,000. A causal convolution over the last 4 tokens sits in front of the keys, queries and values, and its 3 remembered tokens travel with the state.

Lesson 4 pictures this memory as a whiteboard. Like a whiteboard it has a fixed size, so to take new notes it has to let old ones go, and it cannot keep every detail of a long text.

Lesson 4 pictures this memory as a whiteboard: a fixed surface that is wiped and rewritten as the text goes by. Because it never grows, it cannot keep every detail of a long text: each new note goes over part of what was there, so older notes fade and blur. In Qwen3.5-4B, exact details seem to be kept mostly by the model's other kind of layer, the archive (full attention).

Where the whiteboard picture breaks. There is a board on every one of the 24 layers, not one for the whole model, and each of its 32 panels is a separate memory that no other panel reads. A board holds blended numbers, not words: notes whose keys overlap disturb one another, so a panel 128 numbers wide can hold at most 128 notes cleanly, and past that they blur together. And the fading is even across a panel; it is not aimed at stale notes. What these layers carry depends on the model around them: in models built only from such layers, exact details have to be kept in the state, while in a hybrid model they are left to full attention.

Capacity: the number of key-value pairs a state holds without interference is bounded by the key dimension, 128 here, and beyond it "memory collisions" are unavoidable (Yang et al., 2024). Lesson 4's probe of Qwen3.5-4B's gates, on three texts: at a sentence's first token 21 to 27% of a layer's 32 states decay by more than half, against 8 to 13% in mid-sentence.

Raindrop's split-prefill runs (the method of Afendulev et al., 2026, What Attention Recalls and Recurrence Controls in Hybrid Language Models): with the recurrent states from one context and the full-attention layers' keys and values from another, the language to answer in followed the recurrent states in 52 of 52 cases and a planted tag followed the keys and values in 30 of 30; from the recurrent states alone the tag was recalled in 0 of 30 cases, at every distance from 0 to 2,048 tokens. Lee et al. (2026, How Linear Attention Remembers) find the same on this hybrid, and that in purely recurrent models the state does carry the recalled item. For a fact stored in the weights, Raindrop's studies 2.10 to 2.12 found two overlapping routes to the answer, one of them through the 24 linear-attention layers.