Why Qwen Kept Attention in 1 Layer Out of 4
As we explained in our breakdown of Qwen3.8-27B, the model replaces attention with Gated DeltaNet in 48 of its 64 layers. Gated DeltaNet compresses everything it has read into a fixed-size memory, so with attention left in only one layer in four, long contexts stay cheap.
This ratio of three Gated DeltaNet layers to one attention layer is a trade-off between memory, compute and recall. With no attention at all, the model would lose exact retrieval from its context. With attention in half of its layers, it would double its key-value cache and its attention compute for no measurable gain in quality.
This post answers the three questions behind the layout: why Qwen had to keep attention at all, why it didn't keep more of it, and why the trade-off settles at three to one. The answers come from linear algebra, from theoretical results on recurrent models and from the ablations that Qwen, Moonshot AI and others have published.
Two memories with opposite trade-offs
Attention stores a key and a value for every token it has seen, in what is called the KV cache. In Qwen3.8-27B, each attention layer has four key-value heads of 256 dimensions, so its KV cache grows by 2,048 numbers, or 4 KiB in 16-bit precision, for every token. For each new token, the layer compares that token's query with every stored key, and a softmax turns these scores into weights over the stored values. This is what gives attention exact recall: since every token is stored as is, a query can single out any earlier token and read it back unchanged. The price is that both the cache and the work for each new token grow in proportion to the context, so the total cost of a sequence grows with the square of its length.
Gated DeltaNet is a recurrent layer: it replaces this growing cache with a fixed-size matrix per head, the state . You can think of this matrix as a lookup table: multiply it by a key, and it returns the value stored under that key. Each new token updates the table in two steps:
- Forget gradually. The whole table is multiplied by , a number between 0 and 1 computed from the token. Close to 1, the memory keeps almost everything. Close to 0, it is nearly wiped, which helps when the context moves on to something new.
- Correct one entry. This is the delta rule. The layer looks up the token's key , compares what the table returns with the value it should store, and corrects the table so that this key returns a value closer to . A second number between 0 and 1, , sets the size of that correction: at 1, the key returns exactly , and at 0, nothing changes.
Written as one equation, with the correction in parentheses, the update is:
To produce its output, the layer then looks up the token's query in the updated table. In Qwen3.8-27B, each Gated DeltaNet layer has 48 heads with a state of 128 by 128, so it keeps 786,432 numbers, or 3 MiB in 32-bit precision, no matter how long the context is.
| Memory of one layer | After 1,000 tokens | After 262,144 tokens |
|---|---|---|
| Attention (KV cache) | 3.9 MiB | 1 GiB |
| Gated DeltaNet (state) | 3 MiB | 3 MiB |
At 1,000 tokens, the two layers need about the same memory. At the model's full window of 262,144 tokens, one attention layer needs 1 GiB for a single conversation, while a Gated DeltaNet layer still needs only 3 MiB, about 340 times less. Scaled to all 64 layers, attention everywhere would need 64 GiB per conversation, more than the model's 50 GiB of weights, while Gated DeltaNet everywhere would need about 200 MiB.
This gap also decides what each layer can recall. Attention keeps every one of those 262,144 tokens in full, at 2,048 numbers per token. Gated DeltaNet has to squeeze all of them into its 786,432 numbers, which leaves about 3 numbers per token.
Why not Gated DeltaNet in all four layers
The delta rule turns the state into a small regression model. At every token, the update takes one gradient step to make the state return for the key . These gradient steps happen at inference time, while the model processes your prompt and generates its answer, and they are separate from the training of the model itself: its weights stay fixed, and only the state changes, starting from zero for every new input.
The problem is capacity. Each key is a direction in a 128-dimensional space, and the state can give each direction its own value only as long as the keys are independent of one another. A 128-dimensional space has room for only 128 independent directions, so each head can store at most 128 key-value pairs exactly. Every key beyond that overlaps with keys already stored, and writing its value changes the values stored under those keys. A full-length context holds 262,144 tokens, 2,048 times more than that limit. The authors of Gated DeltaNet put it directly: the number of key-value pairs a state can hold "is bounded by the model's dimensionality," and beyond that, "memory collisions" become inevitable and exact retrieval degrades.
The decay helps by clearing out what is no longer needed, but it cannot restore a detail that has already been overwritten. And the model has to decide what to keep at the moment it reads each token, long before it knows which detail a later step will ask for. Attention never has to make that bet, because it keeps every token.
Theory shows that this limit is not specific to Gated DeltaNet. A 2024 paper, RNNs are not Transformers (Yet), proved it for associative recall, the task of finding the value paired with a given key earlier in the context. A transformer solves this task easily, but no recurrent model whose memory grows more slowly than its input can solve it once the context is long enough. The same paper proved that appending a single transformer layer is enough to give a recurrent model the retrieval ability it lacks.
Experiments confirm the theory. In the Gated DeltaNet paper, at 1.3 billion parameters, Gated DeltaNet predicts text better than a transformer of the same size and scores higher on commonsense reasoning. But on tasks that require pulling specific facts out of a document given in the prompt, such as extracting fields from web pages or answering questions about a passage, it falls well behind: 30.6 on average, against 37.0 for the transformer.
MiniMax's experience shows how costly too little attention can be. Its MiniMax-01 model had only one attention layer for every seven layers of a simpler linear attention, without the delta rule. In small-scale tests, this hybrid "looked just as good as pure full attention." At larger scale, however, the team found "clear deficits in complex, multi-hop reasoning tasks," where the model has to combine several facts spread across its context. MiniMax built targeted tests and narrowed the gap, but could not confirm that the fix would hold at scale, so its next model, MiniMax-M2, went back to full attention in every layer.
The cost of too little attention can stay hidden until the model is large and its tasks are hard, which is exactly the case for agentic coding. Qwen avoids that risk with a stronger recurrent layer and twice as many attention layers as MiniMax-01.
Why not Gated DeltaNet in only two
With Gated DeltaNet in only two layers of every four, attention would run in 32 layers instead of 16, and every attention layer costs memory and compute in proportion to the context. The KV cache would double, from 64 KiB to 128 KiB per token, or from 16 GiB to 32 GiB at the full window. With Qwen's layout, a single GPU with 80 GiB of memory can hold the model and one full-length conversation in 16-bit precision: 50 GiB of weights plus a 16 GiB cache. With a 32 GiB cache, the total would reach 82 GiB, more than the GPU can hold.
Compute grows the same way. Every time the model generates a token, each attention layer compares it with all the tokens in its cache. At the full window, comparing the new token with all 262,144 cached tokens costs twelve times as much compute as running it through the layer's feed-forward block. Across Qwen's 16 attention layers, these comparisons already cost three times as much as all 64 feed-forward blocks combined. With 32 attention layers, they would cost six times as much.
For that price, the extra attention buys nothing measurable. Moonshot AI ran the clearest comparison when it designed Kimi Linear, a hybrid of attention and a refined version of Gated DeltaNet: it trained models at five ratios on the same compute budget and compared their perplexity on held-out text.
| Recurrent layers per attention layer | Validation perplexity (lower is better) |
|---|---|
| 0 (attention in every layer) | 5.77 |
| 1 | 5.66 (second best) |
| 3 | 5.65 (best) |
| 7 | 5.70 |
| 15 | 5.82 |
Going from three-to-one to one-to-one doubled the attention layers and left perplexity essentially unchanged. The model with attention in every layer did worse than every hybrid except the sparsest. A 2025 study that trained 72 models with six types of recurrent layers found the same pattern for recall: it "rises steadily as full-attention layers are added and saturates around 3:1," where Gated DeltaNet hybrids match the recall of a full-attention transformer. Language-modeling quality, by contrast, barely moved across ratios.
The 2024 paper hints at why the gains stop so early: a single transformer layer on top was enough to restore retrieval. Once an attention layer retrieves a detail, it writes it into the token's residual stream, where every layer above can read it. The model therefore needs a retrieval step every few layers, not in every layer.
What Qwen's own experiments show
Qwen's own ablation shows that the layout doesn't just match a transformer but beats it. In its August 2026 paper on Qwen3.8-Next, a larger model with the same one-in-four layout, the team trained three 25-billion-parameter models on 400 billion tokens each. The Gated DeltaNet hybrid averaged 53.8 across nine benchmarks, against 49.9 for the full-attention transformer, and won on eight of the nine. A third model, which replaced Gated DeltaNet with sliding-window attention that sees only recent tokens, landed in between. The paper concludes that the one-in-four layout "strikes a favorable balance between efficiency and quality," and that "periodic full attention is particularly important for long-context performance."
What other labs chose
| Model | Recurrent layers per attention layer |
|---|---|
| Qwen3.8-27B (Alibaba) | 3 |
| Kimi Linear (Moonshot AI) | 3 |
| Jamba (AI21 Labs) | 7 |
| Granite 4.0-H (IBM) | 9 |
Labs that ship hybrids use between three and nine recurrent layers per attention layer, depending on how much they value exact recall over memory savings. Jamba's team, testing 1.3-billion-parameter models, found one attention layer in four and one in eight virtually identical and chose the cheaper option. IBM goes further with Granite 4.0-H, at nine to one, to cut memory for enterprise deployment. Qwen, built for long agentic sessions where exact recall matters most, sits with Kimi Linear at the attention-heavy end of the range.
Conclusion: three to one is the sweet spot
To sum up, the ratio balances two costs. Less attention costs quality: with no attention at all, the model would lose exact recall, which no fixed-size state can provide, and in Moonshot's comparison, perplexity already rises with one attention layer in eight. More attention costs memory and compute: with attention in half the layers, the KV cache and the attention compute would double for no measurable gain. Three to one is the cheapest layout that keeps full quality, and it is one reason a 27-billion-parameter model beats Claude Opus 4.6 Max at agentic coding while a full-length session still fits on a single GPU.
Common questions
Which layers of Qwen3.8-27B use attention?
Layers 4, 8, 12 and so on, up to 64. The other 48 use Gated DeltaNet. Every attention layer is global: it attends over the full window of 262,144 tokens, not a sliding window of recent tokens.
Could a larger Gated DeltaNet state replace attention?
A somewhat larger state helps, but only a little. Doubling the key dimension from 128 to 256 would let each head store 256 key-value pairs exactly instead of 128, at the cost of doubling the state's memory and the compute of every update. At the full window, each head would still see 1,024 times more tokens than it can store exactly. Closing that gap entirely would take a state at least as big as attention's KV cache, so a few attention layers are the cheaper way to get exact recall.
How much memory does a Gated DeltaNet layer need?
In Qwen3.8-27B, each Gated DeltaNet layer keeps 786,432 numbers per conversation, no matter how long the conversation gets. Across all 48 layers, stored in 32-bit precision, this comes to 144 MiB per conversation. The 16 attention layers, by contrast, need 16 GiB for a full-length conversation, more than 100 times as much.
Running long-context agents on open models? At Qubit Analytics, we deploy open models such as Qwen and DeepSeek, but our work goes deeper than integration: we work inside the model itself. We read the papers, reimplement architectures from scratch, adapt them to your problem and turn recent research into working prototypes.
Email contact@qubitanalytics.be with what you're building.
Sources
- Zihan Qiu et al., “On the Design of Qwen3.8-Next Architecture: Evaluation, Efficiency, and Training Stability” (2026).
- Qwen team, “Qwen3-Next: Towards Ultimate Training & Inference Efficiency” (2025).
- Songlin Yang, Jan Kautz and Ali Hatamizadeh, “Gated Delta Networks: Improving Mamba2 with Delta Rule” (2024).
- Kaiyue Wen, Xingyu Dang and Kaifeng Lyu, “RNNs are not Transformers (Yet): The Key Bottleneck on In-context Retrieval” (2024).
- Kimi Team, “Kimi Linear: An Expressive, Efficient Attention Architecture” (2025).
- Dustin Wang et al., “A Systematic Analysis of Hybrid Linear Attention” (2025).
- Opher Lieber et al., “Jamba: A Hybrid Transformer-Mamba Language Model” (2024).
- IBM, “IBM Granite 4.0: hyper-efficient, high performance hybrid models for enterprise” (2025).
- MiniMax, “Why Did M2 End Up as a Full Attention Model?” (2025).
- Qwen team, Qwen3.8-27B configuration file (2026).