State Space Attention: Learning Context-Dependent Memory Retention

Ege Çakar, Cengiz PehlevanarXiv 2026

TL;DR

Transformers have photographic memories that grow infinitely expensive as text gets longer, while recurrent State Space Models (SSMs) use fixed-size memories that blur exact details together. State Space Attention (SSA) bridges this divide by giving a Transformer a strict, constant-sized memory budget and teaching it which exact chunks of the past are worth keeping—before it even knows what questions will be asked later. It achieves near-full-attention retrieval and multi-hop reasoning using a fraction of the inference memory.

What Problem Does This Paper Address?

Long-context sequence modeling currently forces an uncomfortable trade-off:

  1. Standard Transformers store exact key–value (KV) representations for every past token. Recall is razor-sharp, but memory grows linearly with sequence length.
  2. State Space Models (SSMs) and linear attention compress history into a fixed-size recurrent state. Inference memory stays constant, but successive inputs overwrite and blur into one another, ruining precise recall and multi-hop reasoning.

Think of a fixed-window Transformer—one that only looks at the most recent $R$ tokens—as already having a bounded state, governed by a naive "first-in, first-out" eviction rule. The authors ask: What if we keep exact token representations and standard softmax attention, cap the memory at $R$ tokens, and let the model learn what to keep and what to throw away?

Methods

SSA splits sequence processing into two jointly trained Transformers: a main language backbone (reader) and a lightweight scorer (just ~3.5% of parameters at the 400M scale).

Incoming text is sliced into fixed-size chunks. At any moment, the reader attends over a bounded set of $R$ tokens: a tiny local window of recent chunks plus $M$ retained memory slots. When a chunk ages out of the local window, it becomes a candidate for long-term storage. The scorer looks at the token embeddings (not hidden states, which keeps training parallelizable) of all $M$ resident chunks alongside the new candidate, re-evaluates everyone in light of the new context, and evicts the lowest-scoring chunk.

Figure 1: The bounded attention state at chunk step t, for a toy configuration with M = 4, w = 1, and C = 4. Top: the input, with each chunk colored by its role. Middle: the accessible set St, shared by all layers and heads. Bottom: the scorer rescores the candidate and the M residents and evicts the lowest-scoring chunk (here chunk 5).

Training discrete, irreversible evictions from scratch is notoriously difficult—if you throw away a vital clue at step 10, you won't realize your mistake until step 1,000, and hard drops yield zero gradients. SSA solves credit assignment with two tools:

  • Counterfactual Recovery (New & Essential): When the model fails a training prediction, it replays the example while forcing a previously evicted chunk back into memory. If that chunk fixes the error, the scorer gets direct supervised credit to keep it next time.
  • Soft Retention Warmup: An optional early phase where low-scoring chunks are smoothly down-weighted in attention rather than deleted, acting as a differentiable approximation of recovery.

Datasets

  • Pretraining: SlimPajama (15B tokens for 400M-parameter models) and TinyStories (for smaller character-level prose experiments).
  • Evaluation & Post-Training:
  • Synthetic & Standard Benchmarks: Long-context cued copying, $k$-hop induction (multi-hop reasoning over random strings), MQAR (associative recall), and RULER (a 13-task long-context suite).
  • MKVT (Multi-Key Variable Tracking): A newly adapted benchmark embedding RULER-style key–value bindings and distractors inside TinyStories prose, testing query-dependent retrieval alongside language modeling.

Key Insights and Ideas

  • Exact representations beat compressed states for composition: On multi-hop reasoning ($k$-hop induction), recurrent baselines (Gated DeltaNet and HOLA) collapse to near-chance (~26%) at 400M scale despite having similar byte-sized memory budgets, while SSA matches full attention (>99.5%). How memory is stored matters just as much as its size.
  • Counterfactual recovery is the secret sauce: In 400M-scale ablations, zero runs learned long-context retrieval without the recovery mechanism, whereas skipping the soft warmup phase worked fine. Explicitly testing "what if I hadn't forgotten that?" is what makes end-to-end discrete retention trainable.
  • Pretraining alone starves the scorer: Left solely to next-token language modeling, the scorer defaults to a lazy positional rule (hoarding a few early chunks and the most recent ones). It only learns sharp, content-aware selection during long-context post-training.
  • Indirect "lossy" memory hops: Even when a source chunk is evicted, deeper Transformer layers hold contextualized keys/values computed while that chunk was still alive—allowing SSA to occasionally answer questions via 1-hop or 2-hop echoes.

Key Results

At the 400M parameter scale (with a strict readable budget of $R = 576$ tokens evaluated out to 8K context):

  • Long-Context Retrieval (8K MKVT): SSA hits 96.57%–97.53% exact match, crushing a 576-window Transformer (8.13%), beating a 2K-window Transformer (34.73%—nearly 4$\times$ the budget), and trailing full 8K attention by just ~3 points (99.90%).
  • Multi-Hop Reasoning: On 16-hop induction, SSA reaches 99.54% token accuracy, tied with full 8K attention (99.46%) while Gated DeltaNet (25.59%) and learned-eviction baseline DMS (38.61%) struggle.
  • Efficiency: SSA uses a constant 54 MiB KV cache at 64K context vs. 6.0 GiB for a comparable Transformer, decoding per-token in 0.24$\times$–0.56$\times$ the time at 64K.

Limitations and Future Work

  • Training & Prefill Overhead: Because eviction decisions run sequentially across chunks and recovery replays failed examples, SSA trains 2.3$\times$ to 13$\times$ slower per update than a standard Transformer and reads initial prompts 2$\times$–6$\times$ slower (only winning on wall-clock speed after generating a few hundred tokens).
  • RULER & Perplexity Gaps: At 8K, SSA trails full attention on the broad RULER suite (56.4% vs. 76.9%) and shows higher language modeling perplexity (largely because its aggressive retrieval policy leaves a tiny 1-chunk local window; widening the local window at inference fixes most of the perplexity hit).
  • Single-Seed Scale & Future Directions: All 400M runs used a single seed, and smaller pilots showed bimodal seed sensitivity. Future work includes stacking SSA with post-hoc KV-cache compression methods, scaling to larger models, and using recovery at inference time as a tunable compute-vs.-memory knob.

Summary updated

Abstract

Standard attention's key-value cache grows linearly with context length. Bounding it raises the question of what a sequence model should retain for long-context reasoning. We argue this choice should be learned, and introduce State Space Attention (SSA), which learns to keep a bounded set of past representations and reads them with standard attention. A learned scorer rescores every chunk against newly arriving context and the rest of memory. A fixed-context Transformer is then the special case that always keeps the most recent tokens. We train the scorer and reader jointly, either moving gradually from a differentiable soft weighting of memories to hard retention, or with hard retention from the start. To produce signal for the scorer, we generate supervised samples during training, a technique we call recovery. We compare SSA with recurrent models, bounded-memory attention methods, and full-attention Transformers across retrieval, variable tracking, multi-hop reasoning, and language modeling. On our retrieval and reasoning benchmarks, SSA matches or comes within a few points of full attention on most tasks, far outperforms a Transformer with the same readable budget on every long-context retrieval task we evaluate, and matches or outperforms one with about 4 times that budget, while using constant inference memory. The largest remaining gap to full attention at small language model scale is on RULER. SSA makes a fixed number of tokens useful over a longer context, and since it reads memory with standard attention, we propose that it can be stacked with KV cache eviction methods. We also pretrain and post-train 400M-parameter models and measure how SSA's training and inference costs scale with context length and model size. Together, these experiments examine the capabilities and limitations of learned memory retention for long-context sequence modeling.
BibTeX
@misc{cakar2026state,
  author = {Ege Çakar and Cengiz Pehlevan},
  title = {{State Space Attention: Learning Context-Dependent Memory Retention}},
  year = {2026},
  eprint = {2611.33625},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2611.33625},
}
Figure