TL;DR
Core Context Aware (CCA) Attention is a plug-and-play attention mechanism that compresses long sequences into dynamically pooled "core tokens" while preserving local windowed attention. By maintaining full reachability between all token pairs at near-linear complexity, CCA-Attention speeds up inference by up to 5.7× and slashes memory consumption while outperforming existing sparse attention approaches on long-context benchmarks.
What Problem Does This Paper Address?
Standard full self-attention scales quadratically, $\mathcal{O}(L^2)$, with sequence length $L$, causing severe compute and GPU memory bottlenecks as contexts reach 32K tokens and beyond. While many previous works introduce fixed or sparse attention patterns (e.g., sliding windows, strided sampling, or streaming sinks), they sacrifice reachability—the ability of any given token to access and exchange information with any prior token across the document. Discarding intermediate tokens degrades performance on long-context tasks (such as needle-in-a-haystack retrieval and multi-document QA). Furthermore, full attention often suffers from "attention dilution" due to redundant, irrelevant context tokens.
Methods
The authors propose Core Context Aware (CCA) Attention, a drop-in replacement for standard self-attention in pretrained decoder models that consists of three synergistic components:
- Globality-Pooling Attention: Divides preceding tokens into groups of size $k$. For each group, an attention-pooling operation calculates a single representative core token $c_i \in \mathbb{R}^{1 \times d}$ weighted by token importance (queried by the group’s final token). The model then attends over this compressed sequence of core tokens, dropping global attention complexity from $\mathcal{O}(L^2)$ to $\mathcal{O}(Lm)$, where $m = \lfloor L/k \rfloor$.
- Locality-Preserved Attention: Because autoregressive masking prevents tokens from attending to the core token of their own immediate group, a sliding-window attention mechanism is applied over the preceding $s$ tokens ($s \ge k$) with complexity $\mathcal{O}(Ls)$ to capture fine-grained local dependencies.
- Adaptive Attention Fusion: Merges the global and local representations via a learnable channel-wise gating parameter $\alpha \in \mathbb{R}^d$: $$\text{Att}^{\text{fuse}} = \text{Att}^{\text{global}} \odot \alpha + \text{Att}^{\text{local}} \odot (1 - \alpha)$$ This guarantees that every token remains causally reachable from any prior token.
CCA-Attention reuses the pretrained projection weights ($W^Q, W^K, W^V$) and is implemented as an optimized, low-level fused GPU operator in Triton. During generation, its KV-cache storage complexity drops to $\mathcal{O}(L/k + s)$.
Datasets
- Pretraining / Continuous Fine-tuning: SlimPajama (627B token cleaned/deduplicated reproduction of RedPajama) used for 1,000 steps of continuous fine-tuning on context lengths of 4K, 8K, 16K, and 32K.
- Evaluation:
- Multi-Document QA (Lost in the Middle): Evaluated via Exact Match (EM) score. The authors scaled this benchmark from its native 4K ceiling to 8K, 16K, and 32K variants by packing 48, 96, and 190 documents, respectively.
- MMLU: 57-subject multitask general knowledge benchmark evaluated in a 5-shot setting.
- LongBench & LongBench-E: Comprehensive bilingual, multi-task long-context evaluation suite.
- PG-19: Evaluated perplexity (PPL) on long book chapters.
Key Insights and Ideas
- Compression Beats Truncation: Most tokens in long contexts receive minimal attention, but discarding them entirely breaks cross-context reasoning. Grouping tokens and synthesizing them into dynamic core tokens compresses noise while preserving essential semantic signals.
- Full Reachability via Hybrid Fusion: Combining global pooled tokens with local windowed tokens ensures that every past token still mathematically contributes to the final representation ($a_{ij} > 0$), bridging the gap between sparse efficiency and dense accuracy.
- Negligible Adaptation Overhead: Instead of requiring full pretraining from scratch (like linear attention alternatives), CCA-Attention can be plugged into pretrained base models (like LLaMA-2) with modest continuous fine-tuning (requiring as few as ~1B tokens).
Key Results
- Inference Speed & Memory: On an NVIDIA A800, CCA-Attention delivers a 3.5× speedup and 46% memory reduction at 32K tokens (2.6s and 19.1 GB vs. 9.2s and 35.5 GB for FlashAttention-2 full attention). At 64K, it achieves a 5.7× speedup (5.7s vs. 32.4s) and drops memory from 60.0 GB to 33.9 GB.
- Long-Document QA (EM Score): On LLaMA-2-7B evaluated at a 32K context length, CCA-Attention maintains an EM score of 27.77, substantially outperforming LongLoRA (13.85) and LM-Infinite (8.93). At 128K context, it scores 31.50 vs. 17.5 for vanilla self-attention.
- Generalization (MMLU): CCA-Attention prevents the severe performance degradation seen in other long-context adaptation methods (e.g., achieving 39.65 on LLaMA-2-7B at 16K, compared to LongLoRA's drop to 17.73).
- LongBench-E: Achieves the highest average score (22.12) compared to MInference (22.08), LM-Infinite (21.20), and StreamingLLM (14.94).
Limitations and Future Work
- Short-Context Trade-Off: On shorter contexts (4K and 8K), CCA-Attention's EM scores trail behind dense full self-attention (e.g., 29.93 vs. 41.59 on 8K LLaMA-2-7B), as the benefits of token compression diminish when contextual redundancy is low.
- Fine-Tuning Dependency: Unlike purely training-free inference methods (such as StreamingLLM or MInference), CCA-Attention requires a short continuous fine-tuning stage to learn the pooling and fusion parameters.
- Hyperparameter Sensitivity: Group size $k$ and local window $s$ present a direct trade-off between semantic granularity and computational throughput that requires domain-specific calibration.
Summary updated