notes

Context Compaction in Transformers

exploring

Core Question

Human lifetime permanent memory is tiny compared to a single modern Transformer KV cache. Rather than mutating weights online at test time (e.g., Titans / TTT), can a 3-tier split win instead:

  1. Decoder self-attention — small, exact short-term working memory.
  2. Encoder latent memory (cross-attended) — pre-distilled, compact representations of learned context/priors (zero reading tax, activation-only).
  3. Plain text files + grep — lossless, human-auditable factual/episodic archive.

Back-of-the-Envelope Anchor

System Capacity / Footprint Notes
Human lifetime memory (Landauer, 1986) ~125 MB (~$10^9$ bits, ~2 bits/s) Permanent long-term retention across modalities
Human language acquisition (Mollica & Piantadosi, 2019) ~1.5 MB Structured linguistic knowledge
Raw text (1M tokens) ~4 MB (~1 MB gzipped) Information-theoretic baseline
Llama-3 70B KV cache (1M tokens, bf16, GQA-8) ~320 GiB (~320 KiB/tok) ~300,000× blowup over gzipped text; ~2,500× human lifetime
DeepSeek-V4.1-Flash CED + CSA2 + FP4 KV ~890 B/tok (~0.85 GiB @ 1M) ~360× smaller than standard decoder-only KV
Transformer weight memorization (Morris et al., 2025) ~3.6 bits / parameter Landauer’s 125 MB fits in ~300M params

Takeaway: A Transformer KV cache is not a memory system — it is an uncompressed, layer-by-layer random-access scratchpad.

Landscape & Trade-offs

Paradigm Representative Work Pros Core Limitation
Heuristic KV pruning H2O, SnapKV, Expected Attention Fast, drop-in Brittle when future queries target previously low-attention tokens
Latent KV compaction Cartridges, Attention Matching 38–50× smaller KV; swappable activations; preserves ICL Static-corpus focus; continual streaming updates still open
Test-time fast weights TTT, Titans, E2E-TTT Expressive continual compression; surprise-gated updates Per-session weight mutation breaks GPU batching; drift/rollback risk
Pointers / Virtual Memory MemGPT, DeepSeek NSA, grep + files Exact recall, inspectable, infinite durability “Folder tab” (pointer key = compression), hard RL credit assignment, serial foraging latency, reading tax
Encoder-Decoder / Conditional Memory YOCO, CEPE, DeepSeek CED / OCR / Engram Encodes context once; orders-of-magnitude smaller KV; clean separation of compute vs. memory Needs a clean long-horizon update rule for the distilled encoder state

Key Insights & Current Stance

Open Questions / Next Steps

  1. The update rule for encoder memory $Z$ over weeks/months:
    • Append ($[Z_1, \dots, Z_t]$) $\implies O(T)$ growth (eventually needs sparse/pointer routing anyway).
    • Recurrent overwrite ($Z_t = \text{Enc}(Z_{t-1}, x_t)$) $\implies$ fixed-size RNN bottleneck & drift.
    • Periodic offline re-distillation from text-file ground truth (“sleep-time” compilation into a fresh Cartridge / Attention-Matched KV / encoder state) $\implies$ most promising direction to explore next.
  2. Read Cartridges (arXiv:2506.06266) & Attention Matching (arXiv:2602.16284) in detail to compare iterative gradient distillation vs. closed-form KV compaction as the offline compiler for the 3-tier design.

Key References