Memory as a cache: Exact context reuse and deletion by construction
Abstract
The KV cache of a transformer entangles every token's representation with its entire prefix: a passage encoded once cannot be reused under a different prefix or removed without recomputing everything after it, so exact cache reuse is limited to shared prefixes. We present SMem, an architecture whose context representation is a cache by construction. A block-local encoder maps each block to memory rows independently of other blocks, and a reader conditions generation on their union through cross-attention. For every parameter setting, memory composes exactly at fixed block indices, deleting a block is an exact update for -token blocks, and the memory state is independent of the edit path. At the training context, under the shared recipe, SMem retrieves planted needles beyond any trained-length window (exact match 0.14-0.28 at distances of 31 and 63 blocks), where learned-position, RoPE, and Block-Attention-style transformers all score at most 0.02. A fully cached context is served by computing one block alone at a near-constant 3.1-6.2 ms, whereas cold prefill grows with context; batched decode stores 34-38% fewer KV rows and runs 1.4-1.7 faster when bandwidth-bound; and deletion beats suffix recomputation by 8.5 at 512 blocks and 452 at 4096 blocks (32-256 the trained length, probing the cost model rather than a served regime). The cost is a perplexity gap of -4.7% to +2.8% (negative favors SMem) against a parameter-matched transformer with the same positional scheme, at 160M-1.5B on FineWeb-Edu across two recipes and a learning-rate search. SMem also composes with RoPE: at 160M and 410M the composite matches or leads the matched transformer and closes 29-59% of SMem's gap to a RoPE transformer. Dropping prefix entanglement thus keeps perplexity comparable while making the cache exactly composable and editable.
Figures & tables
| arm | runs | 1 | 3 | 7 | 15 | 31 | 63 |
|---|---|---|---|---|---|---|---|
| SMem | R1 s0 | .71 | .57 | .42 | .18 | .13 | .12 |
| SMem | R2, 3 seeds | .46–.74 | .24–.65 | .13–.43 | .01–.13 | .01–.11 | .01–.11 |
| SMem+RoPE, sat. | R1+R2, 6 runs | .65–.73 | .47–.60 | .24–.42 | .07–.11 | .03–.12 | .05–.10 |
| SMem | 410M R2, 2 seeds | .55–.60 | .38–.42 | .13–.20 | .01–.05 | .00–.04 | .00–.03 |
| SMem+RoPE, sat. | 410M R2 s0 | .75 | .77 | .59 | .15 | .14 | .14 |
| transformer (learned pos.) | R1 s0, R2 3 seeds | .00–.02 | .00–.01 | .00 | .00–.01 | .00–.01 | .00 |
| scale | regime | transf. | SMem | |
|---|---|---|---|---|
| 160M | 1 (no warmup) | 29.72 | 28.32 | |
| 160M | 2 (warmup) | 26.51 | 26.96 | |
| 410M | 1 (no warmup) | 21.26 | 20.32 | |
| 410M | 2 (warmup) | 19.10 | 19.50 | |
| 1.5B | 1 (no warmup) | 14.46 | 14.26 |
Appendix figures & tables1 asset
Supplementary material from the paper’s appendix.
Appendix
KV Caching
Key-value (KV) caching reuses Transformer states to speed generation while managing memory and data movement.
See all 281 papers