Abstract
Large Language Models (LLMs) are typically constrained by limited context windows, hindering their application in processing extensive documents or codebases. We present SharedLLM, a "self-injection" framework that extends the context window by partitioning a single model into a hierarchical compressor-decoder pair. By utilizing a specialized "context tree" for multi-grained information retrieval, SharedLLM achieves superior long-context performance with significant speedups and reduced memory overhead compared to existing baselines. Our approach eliminates the need for complex alignment stages by sharing weights between the compressor and decoder, ensuring they operate within the same representation space.
Introduction
The utility of Large Language Models (LLMs) is often bottlenecked by their context window, typically ranging from 2,048 to 4,096 tokens for models like Llama-2. Extending this window is critical for tasks involving entire books or massive codebases but presents significant challenges. Existing solutions generally fall into three categories: expensive continual pre-training, streaming/sliding window methods that risk losing distant information, and context compression techniques that often require complex alignment between a separate compressor and the main LLM.
SharedLLM addresses these challenges by providing a high-fidelity long-context memory solution without massive compute requirements or architectural complexity. It introduces a hierarchical architecture that leverages the inherent capabilities of pre-trained models through a self-injection mechanism.
Methodology
SharedLLM consists of two primary sub-modules: a lower model (the compressor) and an upper model (the decoder).
Self-Injection and Weight Sharing
A key innovation of SharedLLM is that both the upper and lower models are initialized from the same off-the-shelf LLM checkpoint. This "self-injection" ensures that both modules share the same hidden space, removing the need for an additional alignment stage. The "sender" (compressor) and "receiver" (decoder) naturally speak the same mathematical language.
The Context Tree
To manage long-form text, the input is partitioned into chunks and organized into a binary "context tree." * Higher nodes provide a "bird's-eye view" through coarse-grained, highly compressed information. * Lower nodes capture fine-grained details with less compression.
Query-Aware Retrieval
During inference, the model employs a depth-first search algorithm to navigate the context tree based on the specific query. This allows the model to "zoom in" on relevant segments for fine-grained details while maintaining a coarse representation of less relevant background information, optimizing the "attention budget."
Experimental Setup
The researchers evaluated SharedLLM across several rigorous benchmarks. The model was trained on a 20B token subset of RedPajama, covering ArXiv, C4, and GitHub. Performance was tested using:
- Language Modeling Perplexity: Evaluated on PG19 (books), ProofPile (mathematics), and CodeParrot (code) for sequences up to 128K tokens.
- Long-Context Understanding: Tasks from InfiniBench (
Math.FindandEn.MC) and LongBench (14 English tasks including QA and summarization).
Key Results
SharedLLM demonstrates significant improvements in both efficiency and performance.
Efficiency and Memory
The architecture achieves a 2× speedup over streaming architectures and a 3× speedup over traditional encoder-decoder models. Notably, SharedLLM can process contexts exceeding 200K tokens on a single 80GB A800 GPU, whereas many vanilla models encounter Out-of-Memory (OOM) errors at much lower thresholds.
Performance and Extrapolation
On the Math.Find task, a "needle-in-a-haystack" test, SharedLLM scored 13.58, outperforming InfLLM (11.14) and StreamingLLM (6.00). Despite being trained on 8K token sequences, the model maintains stable perplexity on sequences up to 128K tokens.
Conclusion and Future Work
SharedLLM offers a robust framework for scaling LLM context windows through multi-grained self-injection. By bypassing the representation gap via weight sharing and employing a dynamic context tree, it balances detail and efficiency. Future work will focus on hardware-level optimizations, integrating advanced retrieval methods like BM25 or Graph-RAG, and scaling the approach to models with 70B+ parameters.
Summary updated