Core Context Aware Attention for Long Context Language Modeling

Yaofo Chen, Zeng You, Shuhai Zhang, Haokun Li, Yirui Li, Yaowei Wang, Mingkui Tan · OpenReview

Abstract

Transformer-based Large Language Models (LLMs) have exhibited remarkable success in various natural language processing tasks primarily attributed to self-attention mechanism, which requires a token to consider all preceding tokens as its context to compute the attention score. However, when the context length L becomes very large (e.g., 32K), more redundant context information will be included w.r.t. any tokens, making the self-attention suffer from two main limitations: 1) The computational and memory complexity scales quadratically w.r.t. L; 2) The presence of redundant context information may hamper the model to capture dependencies among crucial tokens, which may degrade the representation performance. In this paper, we propose a plug-and-play Core Context Aware (CCA) Attention for efficient long-range context modeling, which consists of two components: 1) Globality-pooling attention that divides input tokens into groups and then dynamically merges tokens within each group into one core token based on their significance; 2) Locality-preserved attention that incorporates neighboring tokens into the attention calculation. The two complementary attentions will then be fused to the final attention, maintaining comprehensive modeling ability as the full self-attention. In this way, the core context information w.r.t. a given token will be automatically focused and strengthened, while the context information in redundant groups will be diminished during the learning process. As a result, the computational and memory complexity will be significantly reduced. More importantly, the CCA-Attention can improve the long-context modeling ability by diminishing the redundant context information. Extensive experimental results demonstrate that our CCA-Attention significantly outperforms state-of-the-art models in terms of computational efficiency and long-context modeling ability.

Introduction

The standard Transformer architecture faces a significant challenge: the self-attention mechanism's computational cost grows quadratically ($O(L^2)$) with the sequence length $L$. Processing long documents (e.g., 128K tokens) leads to prohibitive time and memory consumption, much of which is spent on redundant information. Existing solutions often rely on fixed sparsity patterns—which may miss critical "lost in the middle" information—or require expensive retraining from scratch.

CCA-Attention (Core Context Aware Attention) addresses these limitations by distinguishing between core context (essential semantic links) and redundant context (repetitive or less critical info). It is a "plug-and-play" module that allows LLMs to handle massive contexts with linear complexity while focusing on crucial tokens.

Methodology

CCA-Attention replaces standard self-attention with two complementary modules that work in tandem to capture both global and local dependencies.

Overview of the CCA-Attention architecture, showing the Globality-aware pooling and Locality-preserving modules.

Globality-aware Pooling Module

This module segments input tokens into groups of size $g$. Instead of attending to every token, it employs a "group-wise weighted pooling" strategy. The last token in each group acts as a query to evaluate the importance of other tokens within that group, compressing them into a single "core token." This significantly reduces the global attention overhead.

Locality-preserving Module

To maintain fine-grained details, this module uses a sliding window of size $s$ to capture high-resolution information from the immediate neighborhood of each token.

Differentiable Fusion and Training

The outputs of both modules are concatenated and fused. Because the dimensions match standard attention, CCA-Attention can be integrated into existing models like LLaMA or Qwen. The authors recommend Partial Finetuning—only updating the attention projection weights—as an efficient adaptation strategy.

Experimental Results

The researchers evaluated CCA-Attention across several benchmarks, including LongBench, LongBench-E, RULER, and MMLU, using models like LLaMA-2-7B.

Comparison of CCA-LLM against state-of-the-art long-context models on LongBench-E and efficiency metrics.

Efficiency Gains

As shown in the performance table, CCA-Attention achieves substantial improvements in both speed and memory usage. On an NVIDIA A800 GPU with a 128K context, it reached a 7.9x speedup in the pre-filling stage compared to vanilla LLaMA-2. Furthermore, it reduced the Key-Value (KV) cache memory footprint by up to 46%, addressing a primary bottleneck for long-context serving.

Modeling Performance

On the LongBench-E benchmark, CCA-LLM outperformed other efficient attention methods such as MInference and StreamingLLM, particularly in complex tasks like multi-document QA and summarization. Importantly, the model retained its general reasoning capabilities on benchmarks like MMLU, demonstrating that the efficiency gains do not come at the cost of "forgetting" pre-trained knowledge.

Key Insights and Discussion

  • Sparsity Visualization: Attention maps confirm that models naturally focus on a small subset of tokens. CCA-Attention formalizes this observation into the architecture.
  • Weighted Pooling: Using the last token as a "query" for pooling preserves semantic nuances better than simple mean or max pooling.
  • Inference Elasticity: Group size ($g$) and window size ($s$) can be adjusted at inference time, allowing for dynamic trade-offs between accuracy and throughput.

Limitations and Future Work

While effective, CCA-Attention still requires minimal fine-tuning on long-context data to adapt to the pooled core tokens. Additionally, in extremely information-dense environments, the compression ratio might eventually limit performance. Future work will explore scaling these benefits to 70B+ parameter models.

Summary updated

BibTeX
@misc{chen2024core,
  author = {Yaofo Chen and Zeng You and Shuhai Zhang and Haokun Li and Yirui Li and Yaowei Wang and Mingkui Tan},
  title = {{Core Context Aware Attention for Long Context Language Modeling}},
  year = {2024},
  eprint = {2412.12465},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2412.12465},
}
Figure