Abstract
While large language models (LLMs) excel in generating coherent and contextually rich outputs, their capacity to efficiently handle long-form contexts is limited by fixed-length position embeddings and quadratic computational costs. We propose Long-form Context Injection with Recurrent Compression (LCIRC), a framework that enables efficient processing of long sequences beyond standard limits through recurrent compression. By introducing query-dependent context modeling, LCIRC selectively retains information pertinent to the user's query. Empirical results show that Query Dependent LCIRC (QD-LCIRC) significantly improves performance on ultra-long benchmarks while reducing computational complexity by up to 99% at 128k tokens.
Introduction
Modern LLMs face two primary obstacles when handling extensive contexts: the Architectural Wall, where fixed position embeddings limit the visible token range, and the Computational Wall, where self-attention's $O(n^2)$ scaling makes processing 100k+ tokens prohibitively expensive. Existing solutions like sparse attention often lose critical information or fail to adapt to specific user queries. LCIRC addresses these by recurrently compressing context into compact representations and using a query-dependent mechanism to prioritize relevant data.
Methodology
The LCIRC framework introduces a decoupled approach to context management, keeping core LLM weights frozen while training auxiliary compression modules.
Recurrent Context Compression
LCIRC processes long contexts in segments. A Perceiver module compresses each segment into latent embeddings. This process is recurrent: the compressed state of the previous segment serves as the query for the next, allowing the model to maintain a continuous summary across the entire document without the memory overhead of full attention.
Query Dependent (QD) Modeling
To ensure the compressed representation captures the most relevant information, LCIRC employs a Gated Cross-Attention (GCA) block. This block injects the user's query into the compression pipeline, allowing the model to "compress away" noise and focus on the specific information required to answer the prompt.
Selective State BPTT
Training recurrent models on extremely long sequences is computationally demanding. LCIRC utilizes Selective State Backpropagation Through Time (BPTT), which randomly selects a subset of timesteps for gradient calculation. This approach maintains the ability to learn long-term dependencies while preventing memory exhaustion during the training of the compression modules.
Evaluation
The authors evaluated LCIRC using high-quality datasets including FineWeb-Edu and a newly generated FineWeb-LQA dataset, which contains query-answer pairs specifically designed for long-form context training. Benchmarking was conducted on InfiniteBench (100k+ tokens), LongBench, and L-Eval.
Key Results
- Efficiency: At a context length of 128k tokens, LCIRC requires only 122 TeraFLOPs, a 99% reduction compared to standard full-attention models (10,739 TeraFLOPs).
- Accuracy: On the InfiniteBench (En.MC) task, QD-LCIRC achieved a score of 38.86, vastly outperforming the base Llama-2-7B (6.99) and specialized models like AutoCompressor (18.34).
- Stability: Unlike many compression methods that degrade as context grows, LCIRC maintains stable perplexity even at 128k tokens.
Conclusion and Future Work
LCIRC demonstrates that query-aware recurrent compression is a viable path toward truly long-context LLMs. By prioritizing relevant information and bypassing quadratic complexity, it enables models to handle massive documents efficiently. Future research will explore generalizability to multilingual contexts and more diverse tasks beyond question answering.
Summary updated