State Space Models for Language › Two Memory Systems

Michael BrenndoerferNovember 17, 20262 min read
Language AI HandbookAll chapters
Part 19 of 67Alternative Sequence and Generative Architectures
Chapter 133State Space Models for Language › Two Memory Systems
Reading section 2 of 13 · Two Memory Systems · 2 minSection 2 of 13 · 2 min

Section 2 of 13 · 2 min read

Reading settings

Definitions

Choose how many terms have tooltips.

Article links

Make inline references clickable

Notes & comments

Efficient Attention introduced methods for evaluating attention more cheaply. Here we compare one conventional full causal attention layer to a recurrent state space layer.

Key-Value Cache

For one attention head, let qk∈Rdkq_k \in \mathbb{R}^{d_k} be the query at position kk. The cache holds the matching keys kj∈Rdkk_j \in \mathbb{R}^{d_k} and values vj∈Rdvv_j \in \mathbb{R}^{d_v} for already processed positions. A causal attention output is ∑j≤kαkjvj\sum_{j\le k} \alpha_{kj} v_j, with αkj=softmaxj(qk⊤kj/dk)\alpha_{kj} = \mathrm{softmax}_j(q_k^\top k_j / \sqrt{d_k}). For a completed prefix of length LL, the cache of this head uses L(dk+dv)L(d_k + d_v) scalars. With equal key and value widths dd, that becomes 2Ld2Ld.

Recurrent State

A scalar-input state space layer updates xk∈RNx_k \in \mathbb{R}^N from xk−1x_{k-1} and its input at position kk. It reads an output from the resulting state. With HH parallel channels of this type, the recurrent state uses HNHN scalars per sequence.

An attention query can assign different weights to two occurrences of a name if their keys give it different scores. A recurrent state can track a statistic such as how often a specified name appears. That count alone cannot tell you where a particular occurrence appeared.

The recurrence introduces another practical question. Evaluating one update at a time creates a dependency chain of length LL. When the transition, write, readout, and direct-path coefficients are fixed and the initial state is zero, the layer's input contribution can be evaluated as a causal convolution. The rest of this chapter develops that equivalence and shows what to compute when the weights vary with the input.

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