Abstract
Mamba's theoretical infinite-context potential is limited in practice when sequences far exceed training lengths. This work explores unlocking Mamba's long-context memory ability by a simple-yet-effective method, Recall with Reasoning (RwR), by distilling chain-of-thought (CoT) summarization from a teacher model. Specifically, RwR prepends these summarization as CoT prompts during fine-tuning, teaching Mamba to actively recall and reason over long contexts. Experiments on LONGMEMEVAL and HELMET show RwR boosts Mamba's long-context performance against comparable Transformer/hybrid baselines under similar pretraining conditions, while preserving short-context capabilities, all without architectural changes.
Introduction
Transformer-based models dominate the current Large Language Model (LLM) landscape but face $O(n^2)$ complexity, making long-sequence processing computationally prohibitive. State Space Models (SSMs) like Mamba offer a linear-time alternative with theoretically unlimited context. However, empirical evidence suggests Mamba models struggle to maintain performance when input lengths exceed their pre-training context (typically 2k tokens). Existing solutions often rely on architectural modifications or input compression, which can degrade general language capabilities. This paper proposes Recall with Reasoning (RwR), a data-driven approach that leverages Chain-of-Thought (CoT) distillation to unlock Mamba's latent long-context memory.
Methodology
RwR treats long-context retrieval as a reasoning task. Instead of simply predicting the next token, the model is trained to "look back" into its internal state and generate a query-aware summary before answering.
The core components of the RwR pipeline include:
- Summary-based CoT Construction: A teacher model (Llama-3.1-8B-Instruct) generates query-specific summaries from long contexts.
- Verification & Filtering: GPT-4o verifies that generated summaries contain sufficient information to answer the query, ensuring high data quality.
- Empty Summary Training: To mitigate hallucinations, the model is trained on "empty summary" examples where the context lacks the necessary information, teaching it to recognize its own knowledge boundaries.
- Segmented Summarization for Answering (SSA): For sequences up to 100k tokens, RwR employs a segmented approach where the model aggregates summaries from different text portions to derive a final answer.
Experimental Results
The effectiveness of RwR was evaluated on LONGMEMEVAL (up to 100k tokens) and the HELMET benchmark (16k tokens).
Long-Context Performance
On the HELMET benchmark, RwR significantly outperformed standard Mamba SFT and compression-based baselines like ReMamba and DeciMamba, particularly in Retrieval-Augmented Generation (RAG) and In-Context Learning (ICL) tasks. In LONGMEMEVAL (10k), RwR achieved an average score of 27.6%, compared to 18.6% for the SFT baseline. Crucially, RwR demonstrated superior length extrapolation; at 100k tokens, it maintained an 11.4% average score while standard models dropped significantly.
Short-Context and Efficiency
RwR preserves and even slightly enhances performance on short-context benchmarks like GSM8K (Reasoning) and SAMSum (Dialogue). Furthermore, Mamba (RwR) maintains the architectural efficiency of SSMs, performing inference on 100k token sequences approximately 3x faster than Transformer-based models like Phi-2 (10.8s vs 30.6s per sample).
Conclusion
Recall with Reasoning (RwR) effectively bridges the gap between Mamba's theoretical potential and its practical long-context performance. By distilling reasoning-based summarization, RwR enables Mamba to actively recall distant information without architectural changes. Future work will explore scaling RwR to larger Mamba-based architectures and even longer context windows.
Summary updated