Abstract
Large Language Models struggle with memory demands from the growing Key-Value (KV) cache as context lengths increase. Existing compression methods homogenize head dimensions or rely on attention-guided token pruning, often sacrificing accuracy or introducing computational overhead. We propose FourierAttention, a training-free framework that exploits the heterogeneous roles of transformer head dimensions: lower dimensions prioritize local context, while upper ones capture long-range dependencies. By projecting the long-context-insensitive dimensions onto orthogonal Fourier bases, FourierAttention approximates their temporal evolution with fixed-length spectral coefficients. Evaluations on LLaMA models show that FourierAttention achieves the best long-context accuracy on LongBench and Needle-In-A-Haystack (NIAH). Besides, a custom Triton kernel, FlashFourierAttention, is designed to optimize memory via streamlined read-write operations, enabling efficient deployment without performance compromise.
Introduction
As Large Language Models (LLMs) tackle increasingly long documents, they encounter a massive memory bottleneck: the Key-Value (KV) cache. This cache stores previous token representations to avoid redundant computations during autoregressive decoding, but its size grows linearly with sequence length. Existing solutions generally fall into two camps: token eviction (dropping "unimportant" tokens) and quantization/projection (reducing precision or dimensionality).
However, these methods typically treat head dimensions as homogeneous, assuming every dimension in a hidden vector serves the same purpose. FourierAttention introduces a "middle way" that is both memory-efficient and computationally lean by recognizing that different dimensions serve distinct roles in attention mechanisms.
Head Dimension Specialization
A core discovery of this research is the Head Dimension Specialization or "bifurcation" in Transformer head dimensions. By visualizing attention patterns, the researchers found that the first ~70 dimensions of a LLaMA head focus almost exclusively on local, recent tokens. In contrast, the upper ~58 dimensions focus on "sink tokens" (initial tokens) and long-range dependencies.
This insight suggests that dimensions are not equally sensitive to compression. Adding noise to the "local" dimensions barely affects long-range retrieval, but adding noise to the "global" dimensions causes the model to fail catastrophically. FourierAttention exploits this by applying different compression strategies to these distinct dimension groups.
The FourierAttention Framework
To exploit this specialization, the authors introduce a framework centered on HiPPO-FourierT. Inspired by High-order Polynomial Projection Operators, they use a translated Fourier Transform to approximate the temporal evolution of the KV cache. Instead of storing every token, they store a fixed number of spectral coefficients ($k \ll L$).
The framework employs several key innovations:
- Fourier vs. Polynomial Bases: Fourier transforms are shift-invariant and allow for better token-wise parallelism, making them a more natural fit for the Transformer architecture than Legendre polynomials.
- Fine-Grained Compression Schema: The authors use an "asymmetric inverted pyramid" strategy, compressing the Value (V) cache more aggressively than the Key (K) cache and compressing lower layers more than upper layers, where features are more oscillatory.
- FlashFourierAttention: A custom Triton kernel integrates decompression directly into the attention calculation, minimizing the overhead of reading and writing to memory.
Key Results and Evaluation
The framework was evaluated using LLaMA 3.1-8B and LLaMA 3.2-3B on comprehensive long-context benchmarks:
- Compression Rate: The framework successfully compresses approximately 76% of the KV cache to a fixed length.
- Accuracy: On LongBench, FourierAttention outperformed StreamingLLM, Palu, and KIVI, showing performance very close to the original uncompressed model.
- Retrieval Fidelity: In the Needle-In-A-Haystack test at 32k context, FourierAttention maintained nearly perfect retrieval scores, whereas other compression methods began to show significant recall errors.
- Reconstruction: FourierT achieved significantly lower Mean Squared Error (MSE) in reconstructing the original KV cache compared to polynomial-based methods.
Conclusion and Future Work
FourierAttention demonstrates that understanding the internal specialization of LLM head dimensions allows for significantly more efficient memory management without sacrificing long-context performance. While the framework achieves state-of-the-art results, future work will focus on further optimizing the FlashFourierAttention kernel for wall-clock speedups and exploring dynamic windowing for adaptive coefficient selection.
Summary updated