Abstract
The training and inference of large language models (LLMs) are together a costly process that transports knowledge from raw data to meaningful computation. Inspired by the memory hierarchy of the human brain, we reduce this cost by equipping LLMs with explicit memory, a memory format cheaper than model parameters and text retrieval-augmented generation (RAG). Conceptually, with most of its knowledge externalized to explicit memories, the LLM can enjoy a smaller parameter size, training cost, and inference cost, all proportional to the amount of remaining "abstract knowledge". As a preliminary proof of concept, we train from scratch a 2.4B LLM, which achieves better performance than much larger LLMs as well as RAG models, and maintains higher decoding speed than RAG. The model is named $\text{Memory}^3$, since explicit memory is the third form of memory in LLMs after implicit memory (model parameters) and working memory (context key-values). We introduce a memory circuitry theory to support the externalization of knowledge, and present novel techniques including a memory sparsification mechanism that makes storage tractable and a two-stage pretraining scheme that facilitates memory formation.
Introduction: The Efficiency Gap in LLM Memory
Current Large Language Models (LLMs) primarily store knowledge in two ways, each representing an extreme in the cost-efficiency spectrum. Implicit memory, stored within model parameters, is extremely expensive to "write" (requiring massive compute during pretraining) but very efficient to "read" during inference via matrix multiplications. Conversely, working memory (often utilized via Retrieval-Augmented Generation or RAG) treats knowledge as raw text. While it has near-zero "write" cost, its "read" cost is high because the model must re-encode the text from scratch for every use.
$\text{Memory}^3$ addresses this gap by introducing a "third way": explicit memory. This format mimics the human brain's ability to separate abstract reasoning from stored facts, providing a middle ground that is cheaper to update than weights but more efficient to retrieve than raw text.
The $\text{Memory}^3$ Architecture
The $\text{Memory}^3$ framework externalizes factual knowledge into a specialized "AI database" of pre-computed Key-Value (KV) states.
Explicit Memory as Sparse KV Pairs
Unlike RAG, which stores plain text, $\text{Memory}^3$ stores knowledge as sparse attention KV pairs. This allows the model to bypass the expensive re-encoding step required for raw text. To ensure the database remains manageable, a memory sparsification mechanism identifies and retains only the most critical information, making the storage tractable.
Training for Memory Formation
The model is trained from scratch using a two-stage pretraining scheme:
- Abstract Knowledge Acquisition: The model first learns language structure and logic.
- Memory Formation: The model learns to effectively recall and integrate externalized explicit memories from the database.
This process is guided by Memory Circuitry Theory, a framework that determines which knowledge should be externalized versus kept within the internal weights.
Cost-Benefit Analysis and the "Sweet Spot"
A central contribution of this work is the analysis of the total cost (write + read) relative to the expected usage count ($n_k$) of a piece of knowledge.
As shown in the analysis, explicit memory becomes the most cost-effective format for knowledge that is used moderately often—specifically between approximately 0.5 and 13,400 times over the model's lifespan. For very rare knowledge, RAG (external information) is cheaper; for extremely common knowledge, implicit memory (model parameters) is superior. By targeting this middle ground, $\text{Memory}^3$ optimizes the overall computational budget.
Key Results
The researchers evaluated a 2.4B parameter $\text{Memory}^3$ model trained from scratch. Key findings include:
- Performance: The 2.4B model outperformed significantly larger traditional LLMs on standard benchmarks.
- Efficiency: It surpassed RAG-based models in both accuracy and decoding speed, as it avoids the overhead of encoding text on the fly.
- Scalability: By moving facts out of the parameters, the "core" model can remain small, reducing the overhead for "abstract knowledge" processing.
Conclusion and Future Directions
$\text{Memory}^3$ serves as a proof of concept for a more efficient memory hierarchy in AI. While current results are promising, future work will focus on scaling the architecture to 70B+ parameter models and refining the infrastructure for managing massive external KV databases. Additionally, the ability to update or "unlearn" specific explicit memories in real-time without retraining the core model presents a significant opportunity for future research.
Summary updated