Hybrid Attention and State Space Models
Language AI HandbookAll chapters A long prompt can ask a decoder to keep track of a discussion and then recover a number mentioned early in it. A full-context attention layer can consult a separate representation of each earlier position. The layer stores keys and values for those positions, so its cache grows as the prompt gets longer.
A Mamba-1-style layer carries two fixed-shape buffers from one decode step to the next: the recurrent state and the short convolution history. The recurrence summarizes the prefix in its updated state. Two prefixes that leave the same complete carried state cannot be distinguished by its later updates when they receive the same subsequent inputs at the same positions.
A longer prompt increases the number of positions in a full-attention layer’s cache. In the Mamba-1-style layer modeled here, the recurrent state and convolution buffer keep the same shapes as the prompt grows.
A hybrid stack puts both mixers in the same residual stream. A few layers attend over token positions, while the remaining state-space layers use recurrent updates whose work grows linearly with sequence length at fixed width and state size. The architecture reduces the number of layers with a position-indexed cache while retaining attention at selected depths.
Jamba provides a concrete architecture to examine. Its first released model has 32 sequence-mixing layers arranged in four groups. Each group has one attention layer and seven Mamba layers, and some layers use a mixture of experts for their feed-forward computation. The released configuration supports 256K tokens. We use its 1:7 ratio to illustrate how the attention count affects cache capacity.
We will work through the following:
- why the two layer types fail in complementary ways, and what "capacity" means for a recurrent state;
- the three design axes (ratio, placement, and feed-forward type) and why the last one is independent of the first two;
- what actually flows through a hybrid residual stack, and what that implies about where attention layers can help;
- the prefill regime and the incremental decode regime, which have completely different cost structures;
- what the Jamba, Jamba-1.5, and Waleffe et al. studies measured, with their denominators and controls made explicit;
- a hand-checkable example where two sequences produce an identical recurrent state but are separated by one attention layer;
- an executable cache model that finds when the key-value cache equals and then exceeds the combined recurrent and convolution state.
A measured result describes one evaluated model and workload. An arithmetic estimate describes the operation count or state capacity under stated assumptions. The chapter uses both to examine the effects of changing the mixer schedule.
Comments
Add to the conversation
A question, a correction, or an example from your own work.
No comments yet. Be the first to share your thoughts!