Titan-Llama: Retrofitting Pre-trained LLMs with External Neural Memory Modules
cs.CL, cs.AI
Submitted: 2026-10-13
Updated: 2026-10-13
Code: https://github.com/sarahpannn/titans-pytorch
License: http://creativecommons.org/licenses/by/4.0/
The gist: Transformers are efficient to pre-train at scale because attention permits parallel computation across sequence positions, but long-context inference requires increasingly large KV caches.
Abstract
Transformers are efficient to pre-train at scale because attention permits parallel computation across sequence positions, but long-context inference requires increasingly large KV caches. Efficient recurrent alternatives reduce the asymptotic complexity of inference, but their sequential dependence limits token-wise parallelism during training, making them harder to scale. Further, the current paradigm of extending long context tasks creates competing notions of retaining information precisely and keeping long-context inference efficient. To address this gap, we introduce Titan-Llama, a post-training method for retrofitting attention-based language models with a hierarchical memory architecture that updates parameters at test-time. Titan-Llama applies a blockwise attention mask and preserves full-fidelity attention over recent tokens while compressing historical context into recurrent, fixed-size neural memory modules (NMMs). Our formulation allows pre-trained attention layers to be replaced without training a new language model from scratch. On Llama-3.2-1B-Instruct, Titan-Llama raises accuracy over segmented attention windows from 23.87% to 40.51% on QuALITY and from 14.50% to 40.75% on LongHealth. Inference benchmarks show more than 20% faster prefill, 37% faster decode at medium context lengths, and 24% lower steady-state decode memory usage in the evaluated configurations. Together, these results demonstrate that incorporating memory architecture mechanisms that utilize test-time training effectively modulates long-context behavior of pre-trained models, offering a practical route to adapting pre-trained transformers for efficient long-context inference. Our code is released on Github GitHub
Sources
- ETC: Encoding Long and Structured Inputs in Transformers
- LongAlign: A Recipe for Long Context Alignment of Large Language Models
- Let's (not) just put things in Context: Test-Time Training for Long-Context LLMs
- Titans: Learning to Memorize at Test Time
- ATLAS: Learning to Optimally Memorize the Context at Test Time
- Longformer: The Long-Document Transformer
- Transformers to SSMs: Distilling Quadratic Knowledge to Subquadratic Models
- Recurrent Memory Transformer
- Transformers are SSMs: Generalized Models and Efficient Algorithms Through Structured State Space Duality
- FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness
- In-Place Test-Time Training
- Model-Agnostic Meta-Learning for Fast Adaptation of Deep Networks
- The Llama 3 Herd of Models
- Mamba: Linear-Time Sequence Modeling with Selective State Spaces
- RULER: What's the Real Context Size of Your Long-Context Language Models?
- Dynamic Chunking for End-to-End Hierarchical Sequence Modeling
- Reformer: The Efficient Transformer
- LoRA-TTT: Low-Rank Test-Time Training for Vision-Language Models
- GradMem: Learning to Write Context into Memory with Test-Time Gradient Descent
- Hierarchical Transformers Are More Efficient Language Models
Related papers
- Exploring Solution Divergence and Its Effect on Large Language Model Problem Solving
- Ishigaki-IDS-Bench: A Benchmark for Generating Information Delivery Specification from BIM Information Requirements
- Subliminal Steering: Stronger Encoding of Hidden Signals
- MedStruct-S: A Benchmark for Key Discovery, Key-Conditioned QA and Semi-Structured Extraction from OCR Clinical Reports
- The End of Transformers? On Challenging Attention and the Rise of Sub-Quadratic Architectures
- Untangling the Mechanisms of Misleading Context in Medical Question Answering