Sparse Delta Memory

Scaling the State of Linear RNNs through Sparsity

An interactive companion to the paper

Paper: arxiv.org/abs/2607.07386  ·  Code: github.com/facebookresearch/sparse-delta-memory

Approaches to Sequence Memory

Five strategies, each at a different point in the memory–compute trade-off:

Local

Sliding Window

Constant KV cache size. Old tokens are evicted — no long-range memory.

Global Dense

Full Attention

Large memory but KV cache and compute grow with sequence length.

Global Sparse

DSA

Sparse reading, but KV cache still grows with sequence length.

Dense Recurrent

Gated DeltaNet

Constant cache size but dense update — limited memory capacity.

Sparse Recurrent

SDM

Constant cache size and large memory via sparse top-k access.

Background

Sequence models face a fundamental trade-off between memory capacity and computational cost. Sliding window attention (SWA) restricts context to a fixed window. Full attention retains the entire history but scales quadratically. Recurrent models like Gated DeltaNet (GDN) and Mamba compress all past context into a fixed-size dense state — typically on the order of 100K parameters — which bounds both cost and capacity.

Sparse Deltanet Memory (SDM) extends GDN by replacing its dense state matrix with a large explicit memory bank of N slots (230K at 1.4B scale). Each token reads from and writes to only W=64 of the N slots, selected via product key hashing. This yields a state roughly 1,000× larger than GDN with identical FLOPs per token.

Unlocking linear memory states through sparsity

Each rectangle represents the memory state one global layer maintains, shown for an 8B model (d=3840) in bf16. Proportions are up to scale. The attention KV-cache size assumes GQA with group size 2 (i.e. n_kv_heads = n_heads/2).

How does SDM work?

Each SDM layer maintains a memory bank M ∈ Rd×N — a matrix of N column vectors, each of dimension d. Processing a token involves three steps: select slots via product keys, write to selected slots with a gated delta rule, and read from (possibly different) selected slots.

Write & Read: slot selection, gated update, and retrieval

The token embedding is projected to write keys via product key hashing, selecting top-k memory slots. The memory is updated: selected columns are first decayed, then written with the delta rule. A separate query projection then selects (possibly different) slots for reading. The output is a weighted sum of the retrieved memory column vectors.

The SDM mechanism, end to end. The memory is a d×N matrix of slot-vectors. Product keys (two sub-keys → outer sum → top-k) select W=64 whole slot-vectors; a gated delta rule writes them (decay, then Δv); a softmax-weighted read gathers them into the output. Those 64 active vectors are exactly the size of GDN's entire dense state — drawn from N ≈ 230,400 slots, whose fixed footprint rivals a 256k-token KV-cache.

Memory Access Patterns on a Needle-in-a-Haystack Task

To see how SDM uses its memory in practice, we run the 1.4B model on a needle-in-a-haystack task: a key fact is inserted into filler text, and a query about it appears at the end. The visualization shows which memory slots are accessed at each token position.

Token 0
Filler writes
Needle writes
Query reads
Token sequence
Write Memory — cumulative writes
Read Memory — current token reads
Write–Read Bucket Overlap — do the same slots get written at the needle and read at the query?
Real model data. These heatmaps show actual memory access patterns from the SDM 1.4B model (128k post-trained) on a 256-token needle-in-a-haystack task. The needle (“The secret code for Project Alpha is 7392”) is inserted at token 61. The query appears at token 239. Try layer 7: the model concentrates writes into specific memory slots when it sees the code “7392”, and reads from the same slots when the query arrives — the addressing behavior emerges entirely from next-token prediction training.

SDM matches full attention scaling while outperforming GDN

SDM and baselines are trained across seven scales (160M–1.4B parameters) at 160 tokens per parameter using SWA (w=128) as the local layer in a 3:1 hybrid. SDM matches full attention training loss at 1.4B (2.055 vs. 2.048) while outperforming GDN at every scale.

Training loss vs. compute (scaling ladder)
Scaling ladder

Short-Context Benchmark Results

Downstream task accuracy across 15 benchmarks. All models use SWA as the local layer.

BenchmarkFullAttnGDNSDMΔ vs GDN
Val NLL ↓2.2852.2982.253-0.040
HellaSwag79.3379.1080.02+0.92
WinoGrande73.6473.2475.30+2.06
ARC easy78.1079.1578.52-0.63
ARC challenge50.8252.2753.05+0.78
PIQA79.9881.0180.47-0.54
OpenBookQA43.8043.0044.60+1.60
RACE mid64.8360.1762.05+1.88
RACE high47.9443.4044.97+1.57
CommonsenseQA68.8866.8370.60+3.77
BoolQ71.8374.9867.13-7.85
TriviaQA55.2355.3659.11+3.75
HumanEval+24.3918.2924.39+6.10
NaturalQuestions22.9422.6025.93+3.33
MMLU58.7357.2457.81+0.57
GSM8K29.3428.8128.66-0.15
Average accuracy56.6555.7056.84+1.14

SDM excels at long-context evaluation

After 128k post-training, SDM maintains low perplexity from 32K to 1M tokens, while full attention degrades beyond 128K (ppl rises from 1.98 to 4.17). On RULER (exact-match, avg over 4k–131k, all 13 tasks), SDM reaches 31.2% at 1.4B and 50.2% at 8B — far above the iso-FLOP GDN (20.0% and 34.2%), and at 1.4B on par with unbounded-cache full attention (32.5%).

Perplexity by token position (code, 1.4B)
Perplexity by token position
RULER accuracy by task (avg over 4k–131k)
RULER TaskFullAttnGDNSDMΔ vs GDN
single_199.3100.0100.0+0.0
single_289.445.171.5+26.4
single_370.132.674.9+42.3
multikey_175.332.959.3+26.4
multikey_258.01.04.7+3.7
multikey_329.80.11.2+1.1
multivalue74.331.166.1+35.0
multiquery73.031.268.6+37.4
vt67.246.272.3+26.1
cwe5.511.412.8+1.5
fwe77.862.765.0+2.4
qa_139.023.627.2+3.6
qa_238.428.230.4+2.3
Average61.234.250.2+16.0

Discussion

The memory access patterns and scaling results suggest that sparse, learned memory access is a viable path for long-range sequence modeling. The consistent slot assignment for storage and retrieval across hundreds of thousands of tokens emerges entirely from the next-token prediction objective.

The finite state is not a limitation. It is a feature. Just as humans cannot hold an entire book in working memory but can choose to re-read relevant passages, a model with finite state can benefit from agentic context engineering: selectively re-reading or searching through previous conversation to refresh its memory. A fixed-size state makes this practical at any context length, whereas full attention keeps a KV cache that grows with the sequence.

Open questions remain. SDM still trails full attention on some multi-key retrieval tasks. The Triton kernels reach lower MFU than GDN because slot access is memory-bound. And the interplay between state capacity and retrieval accuracy at very long contexts deserves further study.

Summary