Abstract
Large Language Models (LLMs) face significant challenges in maintaining coherence over long contexts due to the quadratic complexity of standard attention mechanisms. We present MELODI (MEmory with LOw DImension), a hierarchical architecture designed to process massive documents by compressing information across both network layers and time steps. MELODI utilizes a "sandwich" structure that combines recurrent short-term memory with a specialized long-term memorization layer. Our results demonstrate that MELODI achieves state-of-the-art performance on long-context benchmarks like PG-19 while reducing the memory footprint by a factor of 8 compared to uncompressed baselines like the Memorizing Transformer.
Introduction
The effective context window of a model determines its ability to utilize historical information. While recent advancements have expanded these windows, the associated computational and memory costs remain prohibitive. Standard sliding window approaches often suffer from "forgetting" once information leaves the active window. Existing solutions either cache previous activations (Transformer-XL) or store all raw Key-Value (KV) pairs (Memorizing Transformer), with the latter being extremely memory-intensive. MELODI addresses this by introducing a hierarchical compression scheme that bridges the gap between local processing and long-term history without the overhead of storing uncompressed data.
Methodology: Hierarchical Memory Architecture
MELODI’s architecture is organized into a "sandwich" configuration, consisting of $M$ short-term layers, a single long-term layer, and $N-M-1$ subsequent short-term layers.
Short-Term Memory
Short-term memory is managed through recurrent compression using two types of auxiliary tokens: summary tokens ($u$) and memory tokens ($z$). Summary tokens condense information vertically through the layers, while memory tokens facilitate horizontal information flow between consecutive context windows. A "linear token mixer" is employed to branch the information flow, updating both the subsequent layer and the memory for the next window.
Long-Term Memory
The long-term memory layer, positioned in the middle of the network, further compresses the short-term tokens. These hyper-compressed KV pairs are stored in a First-In-First-Out (FIFO) queue. The model accesses this historical archive via cross-attention, allowing it to reference distant information with minimal memory overhead.
Experimental Results
We evaluated MELODI on several long-context datasets, including PG-19 (English books), arXiv Math, and C4(4K+).
Performance and Efficiency
MELODI achieved a perplexity of 10.44 on the PG-19 dataset, outperforming the Memorizing Transformer (10.62) and the Block Recurrent Transformer (10.98). Crucially, it achieved these results with an 8x reduction in memory usage compared to the Memorizing Transformer. The model also demonstrated robustness to smaller window sizes; when the context window was reduced from 512 to 128 tokens, MELODI maintained significantly better performance than models relying solely on short-term memory.
Conclusion
MELODI demonstrates that treating memory as a hierarchy of compression is a highly effective strategy for long-context modeling. By utilizing a single long-term memory layer in a "sandwich" structure and employing summary branching, the model captures the essence of long histories with high efficiency. Future work includes adapting this architecture for pre-trained models and exploring its application in multi-modal domains such as video and audio.
Summary updated