AI State of the Art
SOTA/Post-Transformer Architectures/24 min
Section 71

Hybrid Architectures: The Best of Both Worlds

Listen as a podcast →

Neither one nor the other: both at once

A chef who only knows how to make salads misses all the hot dishes. A chef who only knows how to fry misses all the salads. The truly versatile chef knows when to use each technique.

That's exactly the philosophy of hybrid architectures: attention for what it does better than any other technique, SSMs (Mamba, RWKV...) for what they do better than attention. Neither one alone is optimal. Both together, placed in the right spot in the network, give the best result.

Why hybridization is necessary

Pure Transformers excel at precise recall (retrieving exact information from the context, like a name or date mentioned 10,000 tokens earlier) and few-shot learning (learning from examples provided in the prompt). But their KV cache grows linearly with context, and memory quickly becomes limiting beyond a few tens of thousands of tokens.

Pure SSMs (Mamba, RWKV, RetNet) offer constant-cost inference and fixed memory, regardless of context length. But they compress the entire history into a fixed-size state vector, it's like trying to find an exact sentence in a novel's summary. The information is there in substance, but the details are lost.

The guiding principle

Attention is a powerful but expensive tool, to be used sparingly, only for operations that truly need it. SSMs are efficient and scalable, to be used for the majority of routine sequential processing. The central design question: where to place attention layers in the network, and how many to include?

Vertical diagram of a hybrid model. An arrow enters an Embed box, then passes through a dashed frame labelled hidden layers. Inside the frame, a Linear Attention box repeated N times, then an ellipsis, then a Full Attention box. The output goes down to a Head box. On the left, two callout boxes give the corresponding formulas: for the linear layer, S sub t equals S sub t minus 1 plus v sub t times k sub t transposed; for the full layer, Attention of Q, K, V equals softmax of Q K transposed divided by the square root of d sub k, multiplied by V.
The skeleton shared by every hybrid architecture, whatever efficient mechanism is chosen. The stack of hidden layers is mostly made of recurrent-state layers (whose update, shown on the left, merely adds a term to the previous state) with a few full-attention layers inserted among them, the ones carrying the quadratic softmax. All the design work consists of choosing N and where to place the latter.Source : Paper A Systematic Analysis of Hybrid Linear Attention (arXiv 2507.06457)

The major hybrid architectures

Jamba (AI21 Labs)

Jamba is the first hybrid SSM+Attention+MoE model deployed at scale, published by AI21 Labs in early 2024 (covered in detail in the Mamba-2 and Jamba lesson).

Its architecture alternates Mamba blocks and attention blocks with a 7:1 ratio, seven Mamba layers for a single attention layer. In parallel, every other layer replaces its feed-forward network with a Mixture of Experts block, for more capacity at constant cost. Why this ratio? Because attention layers are the most resource-hungry: they contribute to the KV cache and perform quadratic computations. By rationing them, you preserve their unique capabilities while benefiting from Mamba's efficiency for the bulk of the processing.

  • Context: 256,000 tokens processed efficiently
  • KV cache: divided by 8 (only the attention layers, one in eight, contribute)
  • Parameters: 52B total, ~12B active via MoE
  • Performance: comparable to similarly-sized Transformer MoE models

Griffin and RecurrentGemma (Google)

Google proposed Griffin, which combines linear recurrence layers called RG-LRU (Real-Gated Linear Recurrent Unit: the recurrence and its gate work in real numbers, whereas the LRU it derives from, like S4, relied on complex numbers, which are trickier to implement) with local attention (window limited to 2,048 tokens).

The RG-LRU is deliberately simpler than Mamba: a linear recurrence with gating, without the complexity of the selective scan. Less expressive, but faster and easier to optimize on hardware.

Three-part figure. Part a, Residual block: a block repeated N times containing, bottom to top, RMSNorm, a Temporal mixing block, a residual addition, then RMSNorm, an MLP block and a second residual addition. An annotation notes that the temporal mixing block can be, for example, MQA or a recurrent block. Part b, Gated MLP block: two linear branches, one passing through a GeLU, multiplied together then projected by a linear layer. Part c, Recurrent block: two linear branches, one through a GeLU, the other through a 1D temporal convolution then an RG-LRU, multiplied together then projected by a linear layer.
What Griffin changes fits inside the orange box. The residual block on the left is a standard Transformer one: the temporal mixing block is the slot where you plug in either attention (MQA) or the recurrent block on the right. Inside that recurrent block, the 1D convolution followed by the RG-LRU replaces the attention computation. Alternating the two possible fillings of that same slot is what produces a hybrid model.Source : Griffin paper (figure 2), Google DeepMind
What Griffin demonstrates

Griffin demonstrates a counterintuitive result: local attention (2,048-token window) combined with recurrent layers is as performant as global attention on the majority of benchmarks, while being much more efficient. Why? Because when a recurrent mechanism already handles long-range dependencies, attention doesn't need to see the entire sequence, it can focus on fine interactions between nearby tokens. It's like reading a novel: you don't need to reread the first chapter to understand the current sentence, if you have a good mental summary of what happened before.

RecurrentGemma is the official Griffin instantiation by Google, open-sourced in 2B and 9B parameter versions.

Zamba (Zyphra)

Zamba takes an original approach: more attention layers than Jamba, but the attention layers share their weights between them. Concretely, a single set of learned matrices is reused at multiple points in the network, instead of learning distinct weights per layer. This drastically reduces the total number of parameters while maintaining recall capabilities, each attention layer "sees" the context differently thanks to the different intermediate representations produced by the interleaved Mamba layers. Excellent parameter efficiency for small models.

StripedHyena (Together AI)

StripedHyena alternates Hyena layers (long convolutions via FFT) with standard attention layers. It's proof that the hybrid principle isn't limited to SSMs, any sub-quadratic mechanism can play the role of "efficient layer" combined with a few attention layers.

Samba (Microsoft)

Samba combines Mamba with Sliding Window Attention in an interleaved arrangement. Local attention with a window of a few thousand tokens complements the Mamba recurrence: it handles fine short-range interactions while Mamba takes care of propagating information over long distances, all without the constraints of a global KV cache.

Key hybrid design questions

Attention layer placement

Where to put the precious attention layers? It's an open design question, but clear trends are emerging:

  • Regular: one attention layer every N SSM layers (Jamba, 7:1 ratio). Simple and effective.
  • Beginning and end: more attention in the first layers (which form initial representations) and the last ones (which make final decisions).
  • Adaptive: placement determined by automatic architecture search (NAS), letting the algorithm find the best configuration.
Figure 2 from the Nemotron-H paper, showing two layer stacks. On top, Nemotron-H-8B: a Mamba-2 then FFN group repeated 3 times, followed by a group repeated 4 times containing Mamba-2, Attention, FFN, then several Mamba-2 and FFN pairs, and finally a Mamba-2 then FFN group repeated once. Below, Nemotron-H-56B: the same structure with the central group repeated 10 times instead of 4. The caption states that roughly 8 percent of the model's layers are self-attention layers, evenly dispersed throughout the model, the rest alternating Mamba-2 and FFN layers.
Regular placement, applied at two model sizes. The red Attention boxes are rare (about 8% of layers) and spaced at a constant interval; everything else alternates Mamba-2 and FFN. Going from 8B to 56B, NVIDIA does not change the pattern, only how many times it is repeated (4 then 10): the attention-to-SSM ratio stays the same as the model grows.Source : Nemotron-H paper (figure 2), NVIDIA, via The Salt
What empirical studies suggest

Placing attention layers regularly throughout the network, with a ratio between 1:4 and 1:8 (one attention layer for every 4 to 8 SSM layers), offers a good general trade-off. Studies also show that the first and last layers benefit more from attention than middle layers, which makes sense, as these are the ones that must encode inputs and make output decisions.

Global or local attention in the hybrid?

In a hybrid context, SSM layers already handle long-range dependencies via their recurrent state. Attention therefore doesn't necessarily need to be global, it can focus on what it does best: fine interactions between nearby tokens.

Attention typeRangeKV cacheTypical use
GlobalEntire sequenceO(L)Very long-range recall
Local (window)Last W tokensO(W)Precise local interactions
DilatedOne token in kO(L/k)Wide coverage at low cost

Griffin demonstrates that local attention (2,048-token window) is sufficient in the vast majority of cases when SSMs handle the long term. The KV cache is then bounded by the window size, not the total context length.

The triple MoE + SSM + Attention combination

Jamba proves that all three technologies (MoE, SSM, Attention) are compatible and complementary, each optimizing a different aspect:

  • SSMs reduce computational cost compared to pure attention (sequential processing in O(1) per token)
  • Attention preserves recall and few-shot learning capabilities (exact access to context)
  • MoE increases model capacity without increasing per-token cost (only a few experts are activated)

Trade-off analysis

Impact on inference memory

ArchitectureKV cacheSize for 100K tokens, 32 layers, d=4096
Pure TransformerAll layers~105 GB
7:1 Hybrid1/8 of layers~13 GB
Pure SSMNone0 GB (fixed state ~a few MB)

Where does the ~105 GB come from? From the product: 2 bytes (float16 precision) × 2 (both K and V are stored) × 100,000 tokens × 4,096 dimensions × 32 layers ≈ 105 GB. One attention layer in eight, and the total is divided by 8.

The 8x KV cache reduction is transformative for large-context deployments. A model that required 4 A100 GPUs (80 GB each) for the KV cache alone can now run on a single GPU.

The hidden cost of SSM state

SSM layers don't require a KV cache but maintain a hidden state. For Mamba, this state is N x d per layer (N state dimensions for each of the d channels). For RetNet, it's a matrix per head, on the order of the head dimension squared. These states are generally much more compact than the KV cache, but they're not negligible, especially if the state is matrix-valued (RetNet) or if you have many SSM layers. You need to count this "hidden state" in the total memory budget.

Impact on model quality

Empirical results show that hybrids preserve the essentials of pure Transformer capabilities, with nuances:

  • Perplexity: comparable to same-size Transformers, no measurable degradation
  • Recall: slight degradation on exact long-range recall (the few attention layers don't cover everything)
  • Few-shot learning: preserved thanks to attention layers that maintain exact access to examples
  • Very long sequences: superior to pure Transformers, as SSM layers handle extended context efficiently

Adaptive hybridization

Research is exploring architectures that dynamically choose between attention and SSM depending on the nature of the current token. The idea: allocate more attention computation to critical tokens (complex terms, recall references, logical connectors) and use SSMs for ordinary tokens. It's the computational equivalent of slowing down when the text is complex and speeding up when it's predictable.

Theoretical unification

Mamba-2's SSD (Structured State Space Duality) framework, see the dedicated lesson suggests that attention and SSM are special cases of a more general mechanism, a semi-separable matrix parameterized differently. Future architectures could exploit a unified operator that dynamically adapts along this spectrum, eliminating the artificial distinction between "SSM layer" and "attention layer."

The industrial convergence

There's a clear convergence in the industry toward hybrid architectures. Most major labs are actively exploring SSM+Attention combinations for their next-generation models. Hybrid architectures aren't a tepid compromise, they're a synthesis that offers the best of both worlds: SSM efficiency for routine processing and attention power for operations that truly need it.

Check your understanding0 / 5

1. In Jamba, why use only one attention layer for every seven Mamba layers, rather than half and half?

2. In Jamba, where does the Mixture of Experts block go?

3. Griffin combines recurrence with attention limited to a 2,048-token window. Why is this local attention enough?

4. A pure 32-layer Transformer on a 100,000-token context drags around a KV cache of roughly 105 GB. What does that figure become in a 7:1 hybrid like Jamba?

5. The SSM layers of a hybrid have no KV cache. Does that mean their inference memory is zero?