Abstract The ability of Large Language Models (LLMs) to process and generate coherent text is markedly weakened when the number of input tokens exceeds their pretraining length. Given the expensive overhead of finetuning large-scale models with longer sequences, we propose Dual Chunk Attention (DCA), which enables Llama2 70B to support context windows of more than 100k tokens without continual training. By decomposing the attention computation for long sequences into chunk-based modules, DCA manages to effectively capture the relative positional information of tokens within the same chunk (Intra-Chunk) and across distinct chunks (Inter-Chunk), as well as integrates seamlessly with Flash Attention. In addition to its impressive extrapolation capability, DCA achieves performance on practical long-context tasks that is comparable to or even better than that of finetuned models. When compared with proprietary models, our training-free 70B model attains 94% of the performance of gpt-3.5-16k, indicating it is a viable open-source alternative.
Introduction
Most Large Language Models (LLMs) are pretrained on a fixed context length, typically around 4,096 tokens. When inputs exceed this window, the model's coherence often collapses. While finetuning on longer sequences is a possible solution, it is computationally expensive and constrained by the scarcity of high-quality long-text datasets. Existing training-free methods like Position Interpolation (PI) or NTK-Aware RoPE attempt to stretch positional embeddings but often suffer from increased perplexity (PPL) as the input length grows. The challenge lies in extending the context window without sacrificing positional resolution or local token relationships.
Methodology: Dual Chunk Attention (DCA)
The proposed Dual Chunk Attention (DCA) framework addresses these limitations by decomposing the attention mechanism into three specialized modules. This approach allows the model to reuse high-resolution position indices it already understands, rather than scaling them into a compressed space.
- Intra-Chunk Attention: The sequence is divided into chunks smaller than the pretraining window. This module handles attention within a single chunk, capturing local dependencies using original position indices.
- Inter-Chunk Attention: This module manages dependencies between distant chunks. To handle "unseen" relative positions, DCA assigns a constant, large position index (the maximum seen during training) to tokens in previous chunks, signaling distance without introducing untrained specificities.
- Successive-Chunk Attention: This refinement maintains "locality" across adjacent chunks. By adjusting position indices at chunk boundaries, it ensures a smooth transition and prevents the loss of immediate textual flow.
DCA is orthogonal to existing scaling methods and can be combined with PI or NTK-Aware RoPE. Furthermore, it integrates with Flash Attention 2 to maintain computational efficiency.
Experimental Evaluation
DCA was evaluated across several benchmarks, including PG19 for language modeling, the L-Eval suite for closed-ended tasks, and "needle in a haystack" passkey retrieval tests. A unique "unseen data" test was also conducted using the LaTeX source of the research paper itself to ensure the model was not relying on training data.
Key Results and Efficiency
DCA demonstrates massive extrapolation capabilities. Llama2-70B, originally trained for a 4k context, handled over 100k tokens with negligible perplexity increases. In passkey retrieval, DCA maintained 100% accuracy up to 32k tokens and reached 192k tokens when combined with other methods.
The training-free DCA-70B model achieved 94% of the performance of GPT-3.5-16k, outperforming many models that underwent expensive long-context finetuning. Larger models (70B) showed more significant benefits from DCA than smaller ones (7B), suggesting that higher-parameter models possess more robust internal representations for chunked attention.
Conclusion
Dual Chunk Attention provides a scalable, training-free solution for extending the context window of LLMs. While it excels at information retrieval, challenges remain in global document synthesis. Future work will focus on improving global reasoning while preserving the efficiency of the training-free approach.
Summary updated