Rúben GalvãoThe Rabbit Hole

The Rabbit Hole / AI and machine learning / Language models / Alternative language-model architectures

Hybrid attention and SSM models: different kinds of memory

Combine attention with state-space models (SSMs): some layers retain separate cache entries, while others carry a fixed-size state.

Linear attention, Gated DeltaNet and Mamba keep a fixed-size state. That saves memory as the conversation grows, but many tokens share the same storage. Their writes can interfere, and some information can be lost.

Attention keeps a separate key/value entry for each token. A later query can request information from those entries, at the cost of a growing KV cache.

Could we keep that cache in only some layers?

Mix the layers

Use fixed-state layers for most of the stack, with attention layers between them. Each reads the current token representation and adds its update to the residual stream:

hybridToken vectorsEarlier context is dimmed; outlined columns are current.Current token computation.NormFixed-state mixer+NormAttention+84
Both mixer types update the same residual stream. Their histories stay separate: fixed states for recurrent mixers, stored keys and values for attention. Feed-forward branches are omitted here.

Each layer keeps its own history: a fixed state or a KV cache. The token representation passes between layers; their memories stay with them.

For example, Qwen3-Next repeats three Gated DeltaNet layers followed by one full-attention layer. Only 12 of its 48 layers need a growing KV cache. With the same KV dimensions, that is a quarter of the cache an all-attention stack would need. The other layers still need their fixed states.

Attention gives the model places to consult separate history entries. It cannot recover information that was never preserved in its own cached representations. Adding more attention layers increases both those opportunities and the growing cache; the useful balance depends on the model and task.

Could both paths work in one layer?

Instead of alternating layers, we could give attention and a fixed-state mixer the same input, then combine their updates:

parallelToken vectorsEarlier context is dimmed; outlined columns are current.Current token computation.NormAttentionMamba++84
Two mixer paths read the same token representation; combine their updates before adding to the residual stream.

Falcon-H1 uses this arrangement. Both designs let a model use fixed-state memory and separately stored history; they differ in where those paths meet.

Explore how the layer mix changes the KV cache

Which layers keep the growing cache?

Interactive
AttentionMambaLinear attention

Hybrid KV cache
Attention in every layer

KV cache only, in stored numbers. The dashed line keeps the same KV dimensions but gives every layer attention.

Model architecture ↗ · Config ↗

The layer strips show each model’s actual order. The dotted line gives every layer attention with the same KV dimensions, to compare only the growing cache. It does not include fixed states, model weights or other memory, and it is not a speed comparison.

Sources and assumptions

The layer strip comes from the published architecture entries; KV head widths come from the shared model-dimension registry. The graph counts only full-attention KV values for one sequence. Recurrent state, convolution buffers, model weights, allocator overhead and numerical storage formats are not included in that count. The all-attention line is a same-dimension comparison, not a released checkpoint or a speed estimate.

← Browse all subjectsBack to the beginning ↑