Abstract
Large Language Models (LLMs) face significant computational challenges when processing long contexts due to the quadratic scaling of the attention mechanism. This paper introduces the Pretraining Context Compressor (PCC), a decoupled framework designed to shrink extensive text into dense embedding "memory slots." By employing a dual-task pretraining strategy involving text reconstruction and completion, PCC enables up to 16x context compression with minimal performance degradation. This approach significantly reduces inference latency and GPU memory requirements, offering a scalable solution for long-context applications like Retrieval-Augmented Generation (RAG).
Introduction
The "quadratic wall" of the Transformer's attention mechanism remains a primary bottleneck for LLMs in tasks requiring massive context, such as long-form AI companions or complex Retrieval-Augmented Generation (RAG) systems. Processing these long sequences is both slow and memory-intensive, often exceeding the capabilities of consumer-grade hardware. Existing solutions typically involve explicit compression (deleting tokens) or implicit compression (vector embeddings). However, implicit methods are often tightly coupled to specific models and computationally heavy. PCC addresses these gaps by providing a universal, lightweight, and decoupled compressor that can be integrated with various downstream LLMs without architectural modifications.
Methodology
The PCC framework consists of two main components: a Memory Encoder (e.g., GPT2-Large or Llama-3-8B) and a Memory Converter (a two-layer MLP). The core innovation is a two-stage pretraining strategy:
- Text Reconstruction (Auto-encoding): The compressor learns to generate embeddings from which the original text can be reconstructed, ensuring high information density.
- Text Completion (Auto-regression): The model predicts subsequent tokens based on the compressed memory, ensuring the embeddings are compatible with the generative nature of LLMs.
The framework is decoupled; once the compressor is trained, it connects to a frozen downstream LLM via the Converter. This allows a smaller, efficient model to serve as a front-end for much larger models like Llama-3, Mistral, or Phi-3.
Experimental Setup
PCC was pretrained on 5 billion tokens from the FineWeb dataset. Evaluation spanned several domains to test robustness:
- RAG Tasks: SQuAD, HotPotQA, AdversarialQA, and Natural Questions (NQ).
- In-Context Learning (ICL): GSM8K (math), SST-2 (sentiment), and WSC (logic).
- Role-Playing: Harry Potter Dialogue (HPD) dataset.
Results and Discussion
PCC demonstrates superior performance over competitive baselines like AutoCompressor and LLMLingua-2. A key finding is the "16x sweet spot": while 4x compression is nearly lossless, 16x offers the optimal balance of speed and accuracy. Beyond 64x, performance begins to decline as information density exceeds the model's capacity to retain critical nuances.
In RAG tasks, the PCC (Large) variant at 4x compression achieved an average F1 score of 63.62, compared to 66.29 for the full-context reference. Efficiency gains are substantial: for an 8,192-token sequence, 16x compression reduced prefilling time from ~3091ms to just 187ms. Furthermore, PCC maintains a stable, low memory footprint, effectively bypassing the Out-of-Memory (OOM) errors common in standard LLMs handling long batches.
Conclusion
PCC provides a robust and efficient method for context compression, significantly accelerating LLM inference while maintaining high accuracy. The synergy between reconstruction and completion tasks ensures that compressed embeddings are both information-rich and "LLM-friendly." Future work includes exploring dynamic compression rates based on text complexity and scaling the compressor to even larger parameter counts to further enhance memory density.
Summary updated