Jamba — Hybrid SSM-Transformer
State space models (SSMs) and transformers pull in opposite directions. Attention buys quality at quadratic cost. An SSM buys linear-time inference and constant memory through a recurrence, and gives up some quality for it. AI21's Jamba (March 2024) and Jamba 1.5 (August 2024) put both in one model: 1 Transformer layer for every 7 Mamba layers, MoE on every other layer, and a 256k context window that fits on a single 80GB GPU. Mamba-3 (ICLR 2026) tightens the SSM side with complex-valued state updates and MIMO projections. This lesson reads both architectures end to end and works out why the hybrid recipe is a reasonable bet for long context.
Learning Objectives
- Explain the three primitives in a Jamba block (Transformer layers, Mamba layers, MoE) and the 1:7 interleaving with MoE on every other layer.
- State what an SSM's recurrence looks like at a high level and why it gives constant-memory inference.
- Compute the KV cache footprint of a Jamba-shaped model at 256k context and compare it to a pure-Transformer model of the same shape.
- Name the three Mamba-3 innovations (exponential-trapezoidal discretization, complex-valued state update, MIMO) and the problem each one targets.
The Problem
Attention is quadratic in sequence length, and state space models are linear. The gap widens fast: at 256k tokens a single attention map has about 65B entries per head, while an SSM's recurrent state stays the same size at any sequence length.
Pure-SSM models (Mamba, Mamba-2) match Transformer perplexity at small scale but lag on state-tracking tasks and on some kinds of in-context retrieval. My read is that an SSM compresses history into a fixed state, so when the history is long, some of it gets lost. Attention keeps the keys and values of past tokens around and pays quadratic cost for the privilege.
So use both. Put Transformer layers where exact recall matters, use SSM layers for the rest, and tune the ratio. Jamba is a production-scale model that ships this hybrid recipe (52B total, 12B active, 256k context, single 80GB GPU). Jamba 1.5 extends the family to 398B total and 94B active. Mamba-3 (ICLR 2026) is a recent pure-SSM design that a future hybrid could be rebuilt around.
This lesson reads the three papers and builds the mental model for picking the right ratio.
The Concept
An SSM in one page
A state space model processes a sequence x_1, ..., x_N via a fixed-size state h:
h_t = A h_{t-1} + B x_t
y_t = C h_t
At each step the state evolves via a linear dynamics A, takes input B x_t, and emits output C h_t. A, B, C can be learned. The property that matters: computing y_t needs only h_{t-1} and x_t, not any earlier x. Memory is constant and inference is O(1) per token.
Modeling quality comes down to the structure of A. S4 (Gu 2021) used a highly structured matrix that could be evaluated as a long convolution during training. Mamba (Gu, Dao 2023) replaced the fixed A, B, C with data-dependent ones, which is the "selective" part. Mamba-2 (2024) simplified the structure further, and Mamba-3 (2026) adds complexity back in specific places.
For a decoder LLM, an SSM layer can take the place of an attention layer, with a fixed-size per-layer state instead of a growing KV cache.
The Jamba block
A Jamba block interleaves layers according to two numbers:
l: the attention-to-Mamba ratio. Jamba usesl = 8, meaning 1 Transformer layer for every 7 Mamba layers (7 Mamba + 1 Attention = 8 layers per group).e: the MoE frequency. Jamba usese = 2, meaning every other layer applies MoE.
The layer sequence within a block:
M M M M M M M A (7 Mamba + 1 Attention)
| M | M | M | M (where | marks MoE applied)
Each Jamba block is 8 layers. Stack 4 blocks (32 layers) and you get 28 Mamba layers and 4 attention layers, with MoE on 16 of the 32.
Why the 1:7 ratio
AI21 ran ablations to find the attention-to-Mamba ratio with the best perplexity per parameter and the best in-context recall on their long-context evals.
- Too much attention (1:1): quality improves, but memory and speed degrade.
- Too little attention (1:15): memory looks great, but in-context retrieval suffers.
- Sweet spot: 1:7 or 1:8.
The intuition is that the Transformer layers handle exact recall and state tracking while the Mamba layers do the cheap bulk of the processing.
Positional encoding
Mamba layers are position-aware through the recurrence, so the attention layers in the original Mamba-based hybrids did not use RoPE. The SSM layers supplied position information. Jamba 1.5 adds RoPE to the attention layers to generalize to longer context, a refinement based on long-context evaluation.
The memory budget
For a Jamba-1 shape (32 layers: 28 Mamba + 4 Attention, hidden 4096, 32 attention heads):
- KV cache (attention layers only):
2 * 4 * 32 * 128 * 256k * 2 = 16 GBat 256k BF16. Only the 4 attention layers contribute. - SSM state:
28 * hidden * state_size, fixed per layer and independent of sequence length. With a state of 16 per feature and hidden 4096, that is28 * 4096 * 16 * 2 = 3.7 MBtotal.
Compare to a pure Transformer at 32 layers, same hidden, full MHA at 32 heads: 2 * 32 * 32 * 128 * 256k * 2 = 128 GB at 256k BF16. That is an 8x reduction in KV cache. Even against a GQA(8) baseline (2 * 32 * 8 * 128 * 256k * 2 = 32 GB), the 1:7 hybrid at 16 GB is 2x smaller.
This is the arithmetic behind "256k context on a single 80GB GPU." The full-MHA KV cache of a pure Transformer would not fit, and a GQA baseline leaves little room for weights and activations. The hybrid's cache is small enough to leave that room.
Mamba-3: the pure-SSM baseline in 2026
Mamba-3 (ICLR 2026, arXiv:2603.15569) introduces three innovations on the pure-SSM side:
-
Exponential-trapezoidal discretization. Replaces the Euler-method discretization in Mamba-2 with a more expressive recurrence. A convolution-like operation is applied to the state-input inside the core recurrence, instead of as an outer convolution on
x_t. -
Complex-valued state update. Earlier Mambas simplified the state matrix from complex (S4) to real diagonal (Mamba) to scaled identity (Mamba-2). Mamba-3 brings complex values back, which is equivalent to a data-dependent rotary embedding on the state. That restores the state-tracking ability the real-valued simplifications cost.
-
Multi-input multi-output (MIMO) projections. Replaces per-feature scalar projections with matrix-valued ones. This improves modeling power and hardware utilization at inference without increasing decode latency.
At 1.5B parameters, Mamba-3 improves average downstream accuracy by 0.6 points over Gated DeltaNet; the MIMO variant adds 1.2 more for a total 1.8-point gain. At the same state size, Mamba-3 matches Mamba-2 with half the state.
Mamba-3 is not yet in a production hybrid at scale, but it is a natural candidate for the SSM side of the next Jamba-class model.
When to reach for a hybrid
Hybrids win when:
- Context is long enough that a pure-Transformer KV cache becomes painful (64k and up).
- Tasks mix short-range structure (good for SSM) with long-range recall (needs attention).
- You deploy on a single-GPU memory budget where the Transformer KV cache alone would not fit.
Hybrids lose when:
- Context is short (under 16k). The SSM machinery buys little, and a pure Transformer is fine.
- Tasks need dense attention across the whole input, such as deep reasoning or multi-document cross-reference. Having few attention layers in the hybrid hurts there.
- You are scaling toward frontier models. Pure-Transformer + MoE + MLA (DeepSeek-V3 style) is the recipe I see doing best on capability right now.
The competitive landscape
| Model | Family | Scale | Unique claim |
|---|---|---|---|
| Mamba-2 | pure SSM | 3B | linear time, constant memory |
| Jamba | hybrid | 52B/12B | 256k on 80GB |
| Jamba 1.5 Large | hybrid | 398B/94B | enterprise-grade long-context |
| Mamba-3 | pure SSM | 1.5B (paper) | state-tracking restored |
| DeepSeek-V3 | pure Transformer + MoE | 671B/37B | frontier capability |
In this landscape, pure-Transformer MoE leads at the frontier and hybrids look strongest in the 256k-plus context niche. Mamba-3's state-tracking gains may push hybrid ratios toward more SSM and less attention in the next generation.
Use It
code/main.py is a memory calculator for hybrid architectures. Given the number of attention layers, a hidden size, a head config, and an SSM state size, it computes:
- KV cache at a target context length.
- SSM state memory.
- The sum of the two at 8k, 65k, 131k, and 262k context (8192, 65536, 131072, and 262144 tokens), for each configuration.
It covers these configurations:
- A pure-Transformer baseline (full MHA and GQA 8), where the KV cache grows with context.
- Jamba-style hybrids at 1:7, 1:3, and 1:15.
- A pure SSM with no KV cache.
The numbers are illustrative. They count KV cache and SSM state only, with no weights or activations, so treat them as a way to compare shapes and not as a deployment budget. The closing takeaway is computed from the same functions as the table, so it prints the same numbers: 128 GB for the full-MHA Transformer and 16 GB for the 1:7 hybrid at 256k.
Integration considerations for a real deployment:
- Production inference servers such as vLLM and SGLang support Jamba and Mamba. Check the specific version.
- At 256k context, Jamba's memory advantage shows up in concurrent-request throughput, because the same VRAM holds more Jamba sequences than Transformer sequences.
- Mamba-3 as a standalone model is a research preview at 1.5B.
Ship It
This lesson produces outputs/skill-hybrid-picker.md. Given a workload specification (context length profile, task mix, memory budget), it recommends between a pure Transformer, a Jamba-style hybrid, and a pure SSM, with explicit reasoning about the memory and quality tradeoffs.
I'd run main.py first and read the table before the prose. It prints total cache memory at 8k, 65k, 131k, and 262k context for six configurations, so you can see the 1:7 hybrid land at 16.00GB against 128.00GB for full-MHA at 256k, with the GQA 8 baseline at 32.00GB in between. The ratio argument gets a lot more concrete once those numbers are in front of you.
The part I'd poke at is how little the SSM side contributes. In the script the pure Mamba row stays at 4.00MB from 8k to 262k, because its state does not depend on context length. Nearly all of the memory in the hybrid rows comes from the attention layers, so the memory question reduces to how many attention layers you keep. The 1:3 and 1:15 rows are the quickest way to feel that.
I'd also keep the calculator in proportion. It counts KV cache and SSM state and nothing else, so weights, activations, and MoE expert memory are missing, and the 1:7 row gives the attention layers full MHA heads. Before trusting a ratio for a real workload I'd want a quality eval at that ratio, since memory is only half of what the ablations were measuring.
Exercises
-
Run
code/main.pyto compute KV cache at 256k context for a 32-layer pure Transformer (hidden 4096, 32 heads) and for a Jamba-1 hybrid of the same shape. Verify the ~8x memory reduction the AI21 paper claims. -
Modify the calculator to model a 1:3 hybrid (3 Mamba : 1 Attention) and a 1:15 hybrid (15 Mamba : 1 Attention). Plot KV cache vs ratio. At what ratio does the KV cache equal the SSM state memory?
-
Read Section 3 of the Jamba paper (arXiv:2403.19887). Explain why AI21 uses Mamba-1 rather than Mamba-2 despite Mamba-2 being faster. Hint: the hybrid ablation section documents this.
-
Compute the parameter overhead of MoE-every-other-layer in Jamba 1.5 Large (398B total, 94B active). Compare the active ratio to DeepSeek-V3 (37B/671B) and explain why Jamba's architecture pushes the active ratio higher.
-
Read Section 3 of the Mamba-3 paper (arXiv:2603.15569). Explain in three sentences why a complex-valued state update is equivalent to a data-dependent rotary embedding. Tie the answer to Phase 7 · Lesson 04's RoPE derivation.
Key Terms
| Term | What people say | What it actually means |
|---|---|---|
| State space model (SSM) | "Recurrence with a fixed state" | A layer with a learned recurrence h_t = A h_{t-1} + B x_t; constant memory per token |
| Selective SSM | "Mamba's trick" | Data-dependent A, B, C parameters that give the model gating-like selectivity at linear time |
| Attention-to-Mamba ratio | "How many attention layers" | In Jamba, l = 8 means 1 attention layer per 7 Mamba layers |
| Jamba block | "The 8-layer group" | One attention + seven Mamba + MoE on alternate positions |
| SSM state | "The hidden buffer" | Fixed-size per-layer state that replaces the KV cache for Mamba layers |
| 256k context | "Jamba's flagship number" | The sequence length Jamba-1 fits on a single 80GB GPU; pure Transformer cannot at that size |
| Mamba-3 | "2026 pure SSM" | Current-best pure-SSM architecture with complex state + MIMO; the baseline hybrids rebuild around |
| MIMO | "Multi-input multi-output" | Mamba-3 innovation using matrix-valued projections instead of scalar per-feature |
| Exponential-trapezoidal discretization | "Mamba-3's recurrence" | More expressive recurrence that subsumes Mamba-2's Euler-method discretization |
| Hybrid architecture | "Mix attention and SSM" | Any model that interleaves Transformer and SSM layers; Jamba is the production archetype |
Further Reading
- Lieber et al. - Jamba: A Hybrid Transformer-Mamba Language Model (arXiv:2403.19887): the original Jamba paper, with ratio ablations and the 256k context claim
- AI21 - Jamba 1.5: Hybrid Transformer-Mamba at Scale (arXiv:2408.12570): the scaled-up family, 398B/94B and 12B/52B public releases
- Gu, Dao - Mamba: Linear-Time Sequence Modeling with Selective State Spaces (arXiv:2312.00752): the selective SSM paper Jamba builds on
- Dao, Gu - Mamba-2 (arXiv:2405.21060): the simplified structured-state-space successor
- Lahoti et al. - Mamba-3 (arXiv:2603.15569, ICLR 2026): complex-valued state and MIMO, a recent pure-SSM design
- Gu et al. - Efficiently Modeling Long Sequences with Structured State Spaces (arXiv:2111.00396): the S4 paper, where the SSM line for LLMs starts
Code
- main.py (python, 156 lines)