Hybrid Attention and State Space Models › What Flows Through a Hybrid Stack

Michael BrenndoerferNovember 17, 20263 min read
Language AI HandbookAll chapters
Part 19 of 67Alternative Sequence and Generative Architectures
Chapter 134Hybrid Attention and State Space Models › What Flows Through a Hybrid Stack
Reading section 4 of 12 · What Flows Through a Hybrid Stack · 3 minSection 4 of 12 · 3 min

Section 4 of 12 · 3 min read

Reading settings

Definitions

Choose how many terms have tooltips.

Article links

Make inline references clickable

Notes & comments

To reason about hybrids at all, you need a precise picture of the data path. Using pre-norm residual blocks (see Pre-Norm vs Post-Norm), a hybrid stack looks like this. At a state space layer ℓ\ell:

u(ℓ)=x(ℓ)+SSM(ℓ) ⁣(LN(x(ℓ)))u^{(\ell)} = x^{(\ell)} + \mathrm{SSM}^{(\ell)}\!\left(\mathrm{LN}(x^{(\ell)})\right)

and at an attention layer ℓ\ell:

u(ℓ)=x(ℓ)+Attn(ℓ) ⁣(LN(x(ℓ)))u^{(\ell)} = x^{(\ell)} + \mathrm{Attn}^{(\ell)}\!\left(\mathrm{LN}(x^{(\ell)})\right)

followed in both cases by the feed-forward sublayer,

x(ℓ+1)=u(ℓ)+FFN(ℓ)(LN(u(ℓ)))x^{(\ell+1)} = u^{(\ell)} + \mathrm{FFN}^{(\ell)}(\mathrm{LN}(u^{(\ell)}))

where:

  • x(ℓ)x^{(\ell)}: the residual stream entering layer ℓ\ell, a matrix of shape L×dmodelL \times d_{\text{model}}
  • LN(⋅)\mathrm{LN}(\cdot): layer normalization applied across the model dimension
  • SSM(ℓ)\mathrm{SSM}^{(\ell)}: the state space sequence-mixing sublayer at layer ℓ\ell
  • Attn(ℓ)\mathrm{Attn}^{(\ell)}: the attention sequence-mixing sublayer at layer ℓ\ell
  • u(ℓ)u^{(\ell)}: the intermediate residual stream after the sequence-mixing sublayer
  • FFN(ℓ)\mathrm{FFN}^{(\ell)}: the feed-forward sublayer at layer ℓ\ell
  • x(ℓ+1)x^{(\ell+1)}: the residual stream passed to the next layer, of shape L×dmodelL \times d_{\text{model}}

Both mixer choices preserve the shape of the residual stream. That lets a hybrid interleave them in a stack with a common interface.

The two mixer types keep different state between decode steps.

  • An attention layer reads its own input stream. It projects the vector at each position to a key and a value. At layer 20, those vectors can depend on the prior 19 layers. A deep attention layer works with these learned representations. Each decode step reads from that layer's cache of earlier projections.
  • Each state-space layer carries its own recurrent state. That state depends on the prefix of its input stream. Its state slots correspond to features, while the input stream gives the layer a representation per position. Replacing a mixer can change the representations and state in the layers above it.
  • A recurrence can merge two prefixes at the current position while an earlier position still differs. During prefill, later layers see the per-position stream. During decoding, they consult the keys and values kept by their attention layers. An earlier token can still affect the answer if a projection retained the distinguishing information. The example below makes the distinction precise.

A hybrid gives selected layers the ability to combine representations from different positions through attention. Increasing the attention count gives more layers that ability and adds a separate cache for each full-attention layer.

Gradients

Both mixers have a shortcut around their computation in a residual block. The derivative of each residual update includes the identity and a contribution from the mixer branch. The mixers can have different backward implementations. The Mamba paper describes a selective scan and recomputation to limit intermediate storage, while the Jamba report describes additional normalization used to stabilize its larger hybrid. Evaluate training stability alongside loss and compute when 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!

Newsletter

Stay up to date

Get new articles, book updates, and notes on AI and technology.

Unsubscribe at any time. Privacy policy