Recall with Reasoning: Chain-of-Thought Distillation for Mamba’s Long-Context Memory and Extrapolation

Jun-Yu Ma, Tianqing Fang, Zhisong Zhang, Hongming Zhang, Haitao Mi, Dong Yu

TL;DR

This paper introduces "Recall with Reasoning" (RwR), a novel method to significantly improve Mamba's ability to recall and reason over extremely long contexts, a known limitation despite its linear complexity. By distilling chain-of-thought (CoT) summaries from a teacher model, RwR teaches Mamba to effectively extract and utilize crucial information from extended texts, outperforming existing methods on long-context benchmarks without altering Mamba's architecture.

What Problem Does This Paper Address?

Transformer-based Large Language Models (LLMs) have revolutionized NLP but struggle with quadratic complexity in handling long sequences, limiting their practical application. Mamba, a State Space Model (SSM), offers a compelling alternative with linear complexity and theoretically unlimited context. However, empirical studies reveal that Mamba's performance degrades significantly when input lengths exceed its training length, a phenomenon known as poor length extrapolation. Existing methods like DeciMamba and ReMamba attempt to address this by filtering or compressing tokens, but they often compromise Mamba's core language modeling capabilities and still fall short on very long contexts. This paper aims to unlock Mamba's inherent long-context memory potential without architectural changes, focusing on improving its ability to recall and reason over extended information.

Methods

The core of the proposed method, Recall with Reasoning (RwR), is a data-driven approach that leverages Chain-of-Thought (CoT) distillation. Instead of modifying Mamba's architecture, RwR augments its training data with CoT summaries.

Here's a breakdown of the process:

  • Summary-based CoT Construction:
    • Valid Summary Extraction: For a given context ($c$), query ($q$), and answer ($a$), a capable teacher model (e.g., Llama-3.1-8B-Instruct) is used to generate a summary ($s$) of the context that is relevant to the query. This summary is then paired with the original context and query, forming $(c, q, s)$ triples. GPT-4 is used to verify the consistency of these summaries with the ground-truth answers.
  • Empty Summary Construction: To prevent Mamba from overconfidently generating answers when information is insufficient, the authors create "empty summary" examples. This involves removing the paragraphs containing the correct answer from the context ($c$) to create a modified context ($c_r$). This teaches Mamba to recognize when information is missing.
  • The final training dataset ($D$) is a combination of these valid summary triples and empty summary triples.
  • Segmented Summarization for Answering: For extremely long contexts that might still pose challenges, RwR employs a strategy of segmenting the context into smaller pieces. Each segment is summarized, and these summaries are then fed into Mamba to answer the query. This approach keeps processing steps within manageable lengths while leveraging Mamba's linear complexity.

Datasets

  • Training:
    • OpenOrca: Used as the primary Supervised Fine-Tuning (SFT) dataset.
  • Constructed Summary Data: The dataset generated by the RwR method (combining valid and empty summary triples).
  • Evaluation:
    • LONGMEMEVAL: A benchmark designed to evaluate chat assistants' long-context memory across six tasks (single-session-user, single-session-assistant, single-session-preference, multi-session reasoning, knowledge update, temporal reasoning). It includes datasets of different lengths (10k and 100k).
  • HELMET: A comprehensive benchmark for long-context language models, with specific tasks evaluated at a 16k context length.
  • Short-context tasks: RTE, GSM8K, Natural Question, and SAMSum were used to verify that RwR does not negatively impact basic language modeling abilities.

Key Insights and Ideas

  • CoT Distillation as a Memory Enhancer: The paper demonstrates that distilling CoT reasoning, specifically in the form of summaries, is a powerful way to teach Mamba to recall and utilize information from long contexts. This is a more effective approach than simply filtering tokens.
  • Mamba's Untapped Potential: The results suggest that Mamba's architecture has a strong underlying capacity for long-context memory, which was previously hindered by its training methodology. RwR effectively unlocks this potential.
  • Importance of "Knowing What You Don't Know": The inclusion of "empty summary" examples is crucial. It teaches Mamba to identify when it lacks sufficient information, preventing it from fabricating answers and improving its robustness.
  • Architecture Agnostic Improvement: The method works by augmenting the training data, meaning it can be applied to existing Mamba models without requiring architectural modifications, making it highly practical.
  • Mamba's Extrapolation Advantage: The study highlights that Mamba, even without RwR, shows better length extrapolation capabilities compared to Transformer and hybrid models, suggesting SSMs are fundamentally better suited for very long sequences.

Key Results

  • LONGMEMEVAL: RwR significantly outperforms Mamba (Pre), Mamba (SFT), DeciMamba, and ReMamba on both 10k and 100k length settings. For example, on the 100k length setting, RwR achieved an average score of 11.4%, compared to Mamba (SFT) at 3.8% and ReMamba at 4.0%.
  • HELMET: RwR also shows superior performance on HELMET tasks, achieving 34.3% on average compared to ReMamba at 31.8% and Mamba (SFT) at 28.0%.
  • Short-context Tasks: RwR slightly improves performance on short-context tasks compared to Mamba (SFT), while DeciMamba and ReMamba show significant performance degradation. This indicates RwR preserves, and even slightly enhances, general language modeling abilities.
  • Efficiency Study: The paper notes that while Transformer models become significantly slower at 100k length, Mamba's efficiency is maintained, underscoring the advantage of SSMs for long sequences.

Limitations and Future Work

  • Model Specificity: Experiments were primarily conducted on Mamba-2.8b. The effectiveness of RwR on other SSM models (e.g., Mamba2, Falcon-mamba) is yet to be explored.
  • Maximum Context Length: The longest tested context length was 100k due to computational constraints. Exploring even longer sequences (e.g., 200k) remains an open question.
  • Pre-training Length: Mamba's pre-training length (2k) is shorter than some advanced Transformer models (e.g., Llama-3.3 at 128k). This limits direct comparability with state-of-the-art Transformers in certain scenarios.
  • Future Work: The authors suggest exploring the effectiveness of RwR on other SSM architectures and investigating its performance on even longer contexts. They also highlight the need for further research into Mamba's capabilities compared to larger Transformer models.

Summary updated

BibTeX
@inproceedings{ma2025recall,
  author = {Jun-Yu Ma and Tianqing Fang and Zhisong Zhang and Hongming Zhang and Haitao Mi and Dong Yu},
  title = {{Recall with Reasoning: Chain-of-Thought Distillation for Mamba’s Long-Context Memory and Extrapolation}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2025},
}
Figure