Long Context Compression with Activation Beacon

Peitian Zhang, Zheng Liu, Shitao Xiao, Ninglu Shao, Qiwei Ye, Zhicheng Dou

TL;DR

Activation Beacon is a plug-in module that enables LLMs to process massive contexts (up to 128K tokens) by compressing their Key-Value (KV) cache activations into a small set of "beacon tokens." This approach achieves an 8x reduction in memory costs and a 2x inference speedup while maintaining performance comparable to full-attention models, even on contexts six times longer than its training data.

What Problem Does This Paper Address?

Modern Large Language Models (LLMs) are increasingly capable of handling long contexts, but they hit a wall of efficiency. The standard Transformer architecture suffers from two major bottlenecks:

  1. Quadratic Complexity: The computational cost of self-attention grows quadratically with sequence length.
  2. KV Cache Bloat: To generate text quickly, LLMs store the "Keys" and "Values" of every previous token in GPU memory. For a 128K context, this cache can consume tens of gigabytes, far exceeding the capacity of standard consumer hardware.

Existing solutions often fall short. "Soft prompt" methods (which summarize context into a few special tokens) create information bottlenecks, while "token dropping" methods often require knowing the user's question upfront, making them inefficient for multi-turn chats. The authors seek a method that is effective (high quality), efficient (low cost), and flexible (adjustable compression ratios).

Methods

The core innovation is the Activation Beacon, a plug-in module that redefines how an LLM "remembers" the past.

  • Beacon Tokens: The authors introduce a special token <b>. Instead of keeping the activations for every raw token, the model distills the information of a text segment into the activations of these beacon tokens.
  • Progressive Interleaved Compression: The context is divided into chunks. Within each chunk, beacon tokens are interleaved at regular intervals (determined by the desired compression ratio $\alpha$). For example, at a 4x compression ratio, one beacon token is placed after every four raw tokens.
  • Modified Self-Attention: As shown in the figure below, the LLM processes one chunk at a time. Raw tokens can attend to everything in the current chunk and the compressed beacon activations from previous chunks. Once a chunk is processed, the raw activations are discarded, and only the beacon activations are stored.
Figure 1: Overview of Activation Beacon. The context is partitioned into chunks. Each chunk is further split into fine-grained units and interleaved with beacon tokens according to a compression ratio (2 in the figure). The LLM encodes one chunk at a time, compressing the context into beacon tokens’ activations, which are accumulated and reused for encoding following chunks.
  • Training Strategy: The backbone LLM remains frozen. Only the beacon's new projection matrices and token embeddings are trained using a "compression-based auto-regression" loss. Crucially, the model is trained with randomized compression ratios (from 2x to 32x), allowing a single trained plug-in to be used at different efficiency levels during inference.
Figure 2: Activation Beacon performs compression during self attention while reusing all other modules of the LLM. Forward ➀: encode and compress the first chunk. Forward ➁: encode and compress the second chunk conditioned on activations of preceding beacon tokens.

Datasets

The authors used a two-phase training approach:

  1. Pre-training: 1 billion tokens sampled from the RedPajama corpus.
  2. Fine-tuning: A mix of LongAlpaca (QA/summarization), BookSum (narrative summarization), and a Synthesized QA dataset generated by GPT-3.5-turbo to simulate long-context multi-turn conversations.

Evaluation was performed on LongBench (comprising 21 tasks like document understanding and code completion) and the Needle-in-a-Haystack test to measure fine-grained information retrieval.

Key Insights and Ideas

  • Activations are better than Embeddings: Previous methods tried to compress context into "soft prompt" input embeddings. Activation Beacon compresses the internal activations (KV cache) at every layer, which provides a much higher capacity for representing complex information.
  • Interleaving is Crucial: The authors found that interleaving beacons within the text is significantly better than just appending them at the end of a chunk. This gives each beacon a "differentiated attention scope," allowing for more fine-grained distillation of the text.
  • Generalization Beyond Training: Remarkably, even though the model was only trained on sequences up to 20K tokens, it generalizes effectively to 128K tokens. This suggests the progressive compression mechanism successfully captures the recursive nature of long-range dependencies.

Key Results

  • Efficiency Gains: Activation Beacon achieves a 2x speedup in inference and an 8x reduction in KV cache memory usage at 128K context lengths.
  • Performance Parity: On the LongBench benchmark, Activation Beacon (with compression) matched or slightly exceeded the performance of the uncompressed Llama-2-7B and Qwen-2-7B baselines.
  • Needle-in-a-Haystack: The model maintained near-perfect retrieval accuracy up to 128K tokens, significantly outperforming other compression methods like ICAE or AutoCompressor, which struggle as context grows.
FLOPs comparison showing that Activation Beacon significantly reduces computational overhead as context length increases.

Limitations and Future Work

While highly effective, the authors note a few areas for improvement:

  • Training Length: The 20K training limit was a hardware constraint; training on even longer sequences might further boost performance.
  • Fixed Chunking: The current method uses equal-sized chunks. Future work could explore dynamic chunking based on semantic boundaries (e.g., sentences or paragraphs).
  • Scaling: While tested on 7B and 72B models, the impact of scaling to even larger architectures remains an open question.

Overall, Activation Beacon represents a significant step toward making "infinite" context windows practical for real-world applications without requiring a supercomputer.

Summary updated

Abstract

Long context compression is a critical research problem due to its significance in reducing the high computational and memory costs associated with LLMs. In this paper, we propose Activation Beacon, a plug-in module for transformer-based LLMs that targets effective, efficient, and flexible compression of long contexts. To achieve this, our method introduces the following technical designs. 1) We directly compress the activations (i.e. keys and values at every layer), rather than leveraging soft prompts to relay information (which constitute a major bottleneck to encapsulate the complex information within long contexts). 2) We tailor the compression workflow, where each fine-grained input unit is progressively compressed, enabling high-quality compression and efficient computation during both training and inference. 3) We train the model through compression-based auto-regression, making full use of plain texts and instructional data to optimize the model's compression performance. 4) During training, we randomly sample a compression ratio at each step, teaching the model to support a wide range of compression configurations. Extensive evaluations are conducted on various long-context tasks whose lengths (e.g., 128K) may far exceed the maximum training length (20K), such as document understanding, few-shot learning, and Needle-in-a-Haystack. Whilst existing methods struggle to handle these challenging tasks, Activation Beacon maintains a comparable performance to the uncompressed baseline across various scenarios, achieving a 2x acceleration in inference time and an 8x reduction of memory costs for KV cache. Our data, model, and code have been released at \url{https://github.com/FlagOpen/FlagEmbedding/}.
BibTeX
@inproceedings{zhang2025long,
  author = {Peitian Zhang and Zheng Liu and Shitao Xiao and Ninglu Shao and Qiwei Ye and Zhicheng Dou},
  title = {{Long Context Compression with Activation Beacon}},
  booktitle = {International Conference on Learning Representations},
  year = {2025},
  url = {https://openreview.net/forum?id=1eQT9OzfNQ},
}
Figure