LLoCO: Learning Long Contexts Offline

Sijun Tan, Xiuyu Li, Shishir Patil, Ziyang Wu, Tianjun Zhang +3 more
4/11/2024
cs.CLcs.AIcs.LG

Official code: jeffreysijuntan/lloco (118 stars, MIT, PyTorch, last commit 2024-06-15).

Abstract

Processing long contexts remains a challenge for large language models (LLMs) due to the quadratic computational and memory overhead of the self-attention mechanism and the substantial KV cache sizes during generation. We propose LLoCO, a novel approach to address this problem by learning contexts offline through context compression and in-domain parameter-efficient finetuning with LoRA. Our method enables an LLM to create a concise representation of the original context and efficiently retrieve relevant information to answer questions accurately. Our approach extends the effective context window of a 4k token LLaMA2-7B model to handle up to 128k tokens. We evaluate our approach on several long-context question-answering datasets, demonstrating that LLoCO significantly outperforms in-context learning while using $30\times$ fewer tokens during inference. LLoCO achieves up to $7.62\times$ speed-up during inference and $11.52\times$ higher throughput during finetuning, substantially reduces the cost of long document question answering. This makes it a promising solution for efficient long context processing. Our code is publicly available on https://github.com/jeffreysijuntan/lloco.

View on arXivView PDF

Code Implementations(1)

PyTorchMIT

The official repo for "LLoCo: Learning Long Contexts Offline"

1188Shell, PythonApr 12, 20242 years agoMIT
context-compressionfinetunellmlong-contextpytorch

Similar Papers

Cite this paper

@article{tan2024lloco,
  title  = {LLoCO: Learning Long Contexts Offline},
  author = {Sijun Tan and Xiuyu Li and Shishir Patil and Ziyang Wu and Tianjun Zhang and Kurt Keutzer and Joseph E. Gonzalez and Raluca Ada Popa},
  year   = {2024},
  eprint = {2404.07979},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2404.07979v2}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2404.07979.svg)](https://codeofpaper.com/paper/2404.07979)

Discussion