LLoCO: Learning Long Contexts Offline

Sijun Tan, Xiuyu Li, Shishir G. Patil, Ziyang Wu, Tianjun Zhang, Kurt Keutzer, Joseph Gonzalez, Raluca A. PopaEMNLP 2024

Abstract

Processing long documents with Large Language Models (LLMs) remains computationally expensive due to the quadratic scaling of self-attention mechanisms. We introduce LLoCO (Learning Long Contexts Offline), a framework that enables LLMs with limited context windows to effectively process up to 128k tokens. By combining a 30x context compression strategy with parameter-efficient finetuning via LoRA, LLoCO achieves significant improvements in inference speed (up to 7.62x) and performance on long-context benchmarks. Our approach outperforms standard retrieval and window-extension methods, particularly on complex reasoning tasks like NarrativeQA.

Introduction

The "quadratic bottleneck" of self-attention imposes severe limitations on the context length LLMs can handle efficiently. As input length increases, memory requirements for the KV cache grow quadratically, leading to slow inference and high operational costs. While Retrieval-Augmented Generation (RAG) and context window expansion offer partial solutions, they often struggle with global document understanding or prohibitive computational overhead. LLoCO addresses these challenges by allowing models to "study" documents offline through dense compression and targeted finetuning, effectively creating a "semi-closed book" environment.

Methodology

LLoCO implements a three-stage pipeline designed for efficiency and accuracy:

  1. Context Compression: Long documents are partitioned into 1536-token chunks. A specialized context encoder (AutoCompressor) reduces these chunks into 50 "summary embeddings" each, achieving a 30x compression ratio. This turns massive datasets into a short sequence of dense mathematical vectors.
  2. In-Domain Finetuning: To enable the LLM to interpret these compressed embeddings, we apply Low-Rank Adaptation (LoRA). This stage teaches the model the specific "language" of the compressed summaries for a particular domain.
  3. Inference and Serving: During inference, the system retrieves relevant compressed documents, loads the corresponding LoRA adapter, and prepends the summary embeddings to the user's query.
LLoCO architecture overview: A context encoder compresses long documents into summary embeddings, which are then processed by an LLM decoder augmented with LoRA adapters.

Experimental Results

We evaluated LLoCO across diverse benchmarks, including QuALITY, NarrativeQA, and QMSum. LLoCO successfully extended the 4k-token LLaMA2-7B model to handle 128k tokens, significantly outperforming base models with larger native windows.

Performance comparison of LLoCO against various baselines across multiple long-context benchmarks.

On the NarrativeQA (NQA) dataset, LLoCO achieved a score of 28.34, nearly doubling the 16.76 score of the 32k-window LLaMA2 baseline. Furthermore, the 30x compression ratio translated to a 7.62x inference speedup and 11.52x higher throughput during the finetuning phase compared to processing full, uncompressed text. These results demonstrate that LLoCO provides a superior balance between computational efficiency and model performance.

Key Insights and Discussion

A primary finding of this work is that compression alone is insufficient; the LLM must be trained to understand the compressed representation. Without the LoRA finetuning step, models struggle to extract nuance from summary tokens. This approach allows the model to leverage pre-studied knowledge while maintaining a small KV cache during inference, which is the "killer app" for efficiency on consumer-grade hardware.

Despite its strengths, LLoCO has limitations. The context encoder is currently coupled to specific LLM architectures, and the system typically handles one LoRA adapter at a time, complicating tasks that require cross-domain synthesis. Future research will focus on model-agnostic encoders and multi-adapter composition.

Conclusion

LLoCO demonstrates that offline document "studying" via compression and LoRA is a viable path toward efficient long-context processing. By reducing the token count by 30x, LLoCO offers a scalable solution for high-throughput, low-cost document analysis without sacrificing the depth of understanding required for complex reasoning tasks.

Summary updated

BibTeX
@inproceedings{tan2024lloco,
  author = {Sijun Tan and Xiuyu Li and Shishir G. Patil and Ziyang Wu and Tianjun Zhang and Kurt Keutzer and Joseph Gonzalez and Raluca A. Popa},
  title = {{LLoCO: Learning Long Contexts Offline}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2024},
  doi = {10.18653/v1/2024.emnlp-main.975},
}
Figure