Core Context Aware Transformers for Long Context Language Modeling

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

TL;DR

Core Context Aware (CCA) Attention is a novel, plug-and-play replacement for standard self-attention that allows Large Language Models (LLMs) to process contexts up to 128K tokens with linear complexity. By dynamically compressing redundant global information into "core tokens" while preserving local details, CCA-Attention achieves significant inference speedups and nearly 50% memory savings with minimal fine-tuning of existing models.

What Problem Does This Paper Address?

The "Achilles' heel" of the Transformer architecture is the self-attention mechanism. Because every token must attend to every preceding token, the computational and memory costs grow quadratically ($O(L^2)$) with the context length $L$.

As we push LLMs toward 128K context windows and beyond, two primary issues emerge:

  1. Computational Overhead: The KV (Key-Value) cache becomes massive, bottlenecking hardware memory and slowing down inference.
  2. Information Redundancy: In a 100,000-word document, not every word is equally important for predicting the next one. Standard attention treats all tokens as equally "available," which often introduces noise and hampers the model's ability to focus on the "core" semantic connections.

Existing solutions like StreamingLLM (which only keeps the first and last few tokens) or Sparse Attention (which uses fixed patterns) often lose critical intermediate information. The authors sought a way to reduce redundancy without sacrificing the comprehensive understanding required for complex reasoning.

Methods

The authors introduce CCA-Attention, which consists of two complementary modules designed to replace the standard self-attention layer:

Architecture of Core Context Aware (CCA) Attention
  1. Globality-Aware Pooling Module: Instead of attending to every individual past token, the model segments the input into groups. For each group, it calculates a "significance" score and compresses the group into a single core token. This compression is dynamic: it uses a weighted pooling strategy where the weights are derived from the attention scores of the last token in the group (acting as a proxy for the group's importance). This drastically reduces the number of tokens the model must "remember" for long-range dependencies.

  2. Locality-Preserving Module: To ensure the model doesn't lose fine-grained, immediate context (like the beginning of the current sentence), this module maintains a standard sliding window of the most recent tokens.

  3. Differentiable Fusion: The insights from the compressed global core tokens and the raw local tokens are fused together. Because the architecture maintains the same input/output dimensions as standard attention, it can be dropped into pretrained models like LLaMA 2 or LLaMA 3 with minimal friction.

Key Insights and Ideas

  • Redundancy is Sparse: Visualization of attention maps confirmed that in deep layers, LLMs naturally focus on a very small subset of "core" tokens. CCA-Attention bakes this observation directly into the architecture.
  • The "Last Token" Heuristic: A key insight was realizing that the last token in a segment often carries the most "instructional" or "summary" weight for that group, making it an effective query to determine the importance of other tokens in that group.
  • Inference-Time Elasticity: The group size ($g$) and window size ($s$) can be adjusted during inference. This allows a single trained model to be "stretched" or "compressed" to meet different hardware constraints or user traffic demands without retraining.

Key Results

The researchers evaluated CCA-Attention across rigorous benchmarks including LongBench, LongBench-E, and MMLU, fine-tuning models on the SlimPajama dataset.

Performance and efficiency comparison on LongBench-E
  • Massive Speedups: When processing 128K contexts, CCA-Attention achieved up to a 7.9x speedup in pre-filling latency compared to vanilla self-attention in specific configurations, and consistently showed ~3x to 4x speedups across standard benchmark evaluations.
  • Memory Efficiency: It reduced KV cache memory usage by 44% to 49%. For example, a LLaMA2-7B model at 128K context saw memory usage drop from 64GB to just 4.5GB.
  • Superior Accuracy: On the LongBench-E average score, CCA-LLM outperformed other efficient attention methods like MInference and StreamingLLM. It even showed better performance than vanilla attention in extremely long sequences by successfully filtering out "distractor" redundant information.
  • Minimal Fine-tuning: The authors demonstrated that "Partial Finetuning" (only updating the attention projection weights) is nearly as effective as "Full Finetuning," making the method highly accessible for existing open-source models.

Limitations and Future Work

  • Fine-tuning Requirement: While "minimal," the method still requires some fine-tuning on long-context data to adapt to the compressed core tokens. It is not a purely "zero-shot" modification for a base model.
  • Heuristic Dependency: The pooling mechanism relies on the "last token" significance proxy. While effective, more sophisticated learned pooling methods could potentially capture even more nuance.
  • Scaling Limits: While tested up to 128K, the paper does not explore the "breaking point" where the compression ratio becomes too high for the model to maintain coherence (e.g., 1M+ tokens).

The authors suggest that future work could involve integrating CCA-Attention with other efficiency techniques like quantization or applying it to multi-modal long-context tasks.

Summary updated

BibTeX
@inproceedings{chen2025core,
  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 Transformers for Long Context Language Modeling}},
  booktitle = {International Conference on Machine Learning},
  year = {2025},
  url = {https://openreview.net/forum?id=MAHPZNduS4},
}
Figure