TL;DR
This paper introduces a novel method for LLMs to understand longer contexts by generating their own synthetic training data and using it to train specialized "compression experts." These experts, implemented as LoRA adapters, condense the LLM's internal representations, effectively extending its context window without altering the base model's parameters. This approach offers a scalable and copyright-friendly way to improve long-context understanding.
What Problem Does This Paper Address?
Large Language Models (LLMs) are increasingly expected to process and understand long sequences of text, from lengthy documents for question-answering to entire code repositories. However, the core transformer architecture, with its self-attention mechanism, faces a quadratic scaling problem with input length, making it computationally expensive and memory-intensive to handle very long contexts. While many solutions exist, a key challenge is extending LLMs' context length while preserving their original capabilities and avoiding issues like licensing or copyright concerns that arise when using external "teacher" models to generate training data. This paper tackles this by exploring whether an LLM can learn to compress its own context using self-generated data.
Methods
The authors propose a two-pronged approach:
- Self-Generated Synthetic Data: They create a diverse set of six synthetic tasks designed to train LLMs for long-context instruction following. These tasks leverage a base LLM to generate passages about nouns, then prompt it to perform tasks like single-document QA, summarization of multiple passages, identifying similarities/differences between similar passages, multi-document QA requiring cross-passage reasoning, and even generating and explaining Python code. Crucially, distracting passages are mixed in to simulate real-world long contexts. This method allows for scalable data generation at arbitrary lengths, avoiding reliance on external data sources.
- LoRA Compression Experts: Instead of modifying the LLM's core architecture or using a single compression model, they employ a battery of Low-Rank Adaptation (LoRA) adapters. Each LoRA adapter is trained to specialize in compressing activations at a specific compression rate (e.g., 2x, 4x, up to 1024x). During inference, the appropriate LoRA expert is dynamically selected based on the input length. This "context compression" technique condenses the LLM's internal representations into a compact set of "memory tokens," allowing the LLM to "see" a longer context within its original, limited window. This approach is parameter-efficient compared to cloning entire attention modules.
Datasets
- Training Data:
- 6K synthetic training samples generated by the proposed method, with context lengths ranging from 1K to 8K tokens.
- 150K pretraining samples from RedPajama.
- 10K human-annotated instruction-tuning samples from LongAlpaca (to mitigate forgetting).
- Evaluation Data:
- LongBench dataset, comprising 3,350 test samples across five real-world long-context tasks: single-document QA, multi-document QA, summarization, few-shot learning, and code completion. Samples are truncated to 16K tokens for evaluation.
The paper introduces a novel set of synthetic tasks for generating long-context instruction-following data, which will be publicly released with context lengths up to 10 million tokens.
Key Insights and Ideas
- Self-Sufficiency in Data Generation: LLMs can be trained to generate their own high-quality, long-context instruction-following data, bypassing the need for external, potentially licensed, datasets. This is a significant step towards more independent and adaptable LLM training.
- Specialized Compression Experts are Better: Using multiple, specialized LoRA adapters (compression experts) for different compression rates yields better performance than a single, general-purpose compression model. This suggests that tailoring compression to specific needs is more effective.
- Parameter Efficiency: LoRA adapters offer a much more memory-efficient way to implement context compression compared to methods that clone and fine-tune large parts of the LLM's architecture, making deployment more feasible.
- Synthetic Data's Impact: Carefully designed synthetic data can significantly improve an LLM's performance on real-world long-context tasks, particularly those requiring reasoning across multiple documents.
Key Results
- The proposed method, using multiple LoRA compression experts trained on synthetic data, significantly improves performance across most LongBench tasks compared to a baseline using cloned Multi-Head Attention (MHA) parameters.
- For example, on the Llama-2-13B-chat model, the "Experts+Synth." approach achieved an "All Dataset Avg." accuracy of 42.97%, compared to 40.47% for the MHA baseline.
- Performance gains were particularly notable for multi-document QA tasks, indicating the synthetic tasks effectively trained the model to reason across longer, more complex inputs.
- The LoRA approach requires only a few hundred million additional parameters, a substantial reduction compared to the ~2B additional parameters needed by MHA cloning for Llama-2-7B.
Limitations and Future Work
- Limitations: The paper acknowledges that while their synthetic tasks are diverse, further exploration of more varied synthetic tasks could yield even greater performance gains. The current evaluation truncates samples to 16K tokens, so the ultimate limits of their method beyond this are not fully explored in the evaluation setup.
- Future Work: The authors plan to explore using their generated data for model fine-tuning and extending their approach to multiple modalities. They also intend to release the generated long-context instruction data to the community.
Summary updated