FFTSparse: Relative-Position Correlation Guided Sparse Attention for Long-Context Language Models

Zemin Chao, Cen Jianhe, Qianhui Xu, Guangzhi Ge, Zhixin Qi, Hongzhi WangNeurIPS 2026

TL;DR

Reading a 128,000-token prompt forces a Large Language Model (LLM) to compare nearly every word against every other word—a quadratic bottleneck that brings long-context inference to a crawl. FFTSparse speeds up this attention mechanism by up to 8.37× without any model retraining by borrowing a classic trick from signal processing: the Fast Fourier Transform (FFT). By treating attention patterns like resonant frequencies, it rapidly spots the most important long-range connections in $O(N \log N)$ time while smartly adapting to heads that refuse to follow a neat pattern.

What Problem Does This Paper Address?

Modern LLMs can swallow entire books or codebases in a single prompt, but there is a catch: the prefilling stage (processing the input prompt before generating the first response token) gets exponentially slower as sequences grow. Standard self-attention scales quadratically—$O(L^2)$ with sequence length $L$.

To dodge this compute wall, researchers use sparse attention, calculating only the most important token-to-token interactions. Existing methods fall into two camps:

  • Static methods use fixed rules (like only looking at nearby words and the very first few tokens). They are fast, but blind to input-specific, long-range clues.
  • Dynamic methods adapt on the fly by scoring token pairs to see what matters. However, figuring out which pairs to keep often requires expensive pairwise scoring that eats up the very time you were trying to save.

The authors ask: How can we dynamically find critical long-range dependencies without paying a heavy computational tax to search for them?

Methods

First, FFTSparse compresses token sequences into manageable chunks of 128 tokens via mean pooling, operating on $N$ blocks using standard Block Sparse Attention (BSA) kernels. It also applies a standard Prior Mask to every attention head, preserving known essentials: initial "attention sink" tokens, a local sliding window, and key blocks relevant to the final query.

What’s new is how FFTSparse handles everything else:

  1. Dynamic Head Routing: Not all attention heads behave the same way. By checking the variance of scores along a small random sample of diagonals, FFTSparse classifies each head on the fly as either diagonal-dominant (structured stripes) or diffuse (scattered, unstructured).
  2. FFT Lag Extraction (for Diagonal Heads): Instead of scoring all $O(N^2)$ block pairs, the authors reframe finding dominant diagonal stripes—pairs separated by a specific relative distance or "lag"—as a cross-correlation problem. Using the Fast Fourier Transform (FFT), they project the compressed queries and keys into the frequency domain, multiply them, and transform them back, extracting the most resonant relative distances in $O(DN \log N)$ time (where $D$ is head dimension). They apply a logarithmic penalty to stabilize estimates at huge distances where fewer token pairs exist, and pair this with a "column mask" for globally important semantic hotspots.
  3. Top-$k$ Affinity Mask (for Diffuse Heads): Heads without neat diagonal stripes bypass the FFT and fall back to a traditional row-wise Top-$k$ block-scoring selection.

Datasets

Because FFTSparse is training-free, datasets are used strictly for evaluation (no new benchmarks are introduced):

  • LongBench: 15 datasets spanning six categories (including multi-hop QA like 2WikiMQA, summarization like QMSum, and code completion like LCC) to test accuracy on Llama-3.1-8B-Instruct and Qwen2.5-7B-Instruct. Component ablations also include HotpotQA, PassageRetrieval, and RepoBench-P.
  • InfiniteBench & Synthetic NIAH (Needle-in-a-Haystack): Real-world long-context inputs and synthetic retrieval tests used to benchmark wall-clock attention speed from 8K up to 128K tokens.

Key Insights and Ideas

  • RoPE Creates Harvestable Stripes: Rotary Position Embeddings (RoPE)—standard in modern LLMs—naturally modulate query-key interactions periodically based on relative distance. Consequently, high-scoring attention values cluster tightly along diagonal stripes. Selecting just the top 20% of stripes captures over 90% of the top 2% highest-scoring interactions!
Attention matrices exhibit prominent diagonal stripes induced by RoPE, allowing a small fraction of diagonals to capture the vast majority of high-scoring interactions.
  • Respect Head Diversity: Attention topology shifts dramatically across layers (e.g., in Llama-3.1, Layer 23 has 30 stripe heads and 2 diffuse heads, while Layer 14 has 13 stripe and 19 diffuse). Forcing FFT onto diffuse heads hurts efficiency by inflating mask density, while forcing Top-$k$ onto stripe heads wastes compute. Adaptive routing gets the best of both worlds.
  • When Priors Backfire: Curiously, removing the fixed structural prior mask hurt QA tasks but improved code tasks (boosting RepoBench-P from 43.97 to 50.51), suggesting that rigid local/boundary priors might clash with how code dependencies are structured.

Key Results

  • Massive Long-Context Speedups: Measured directly across all 32 attention layers of Llama-3.1-8B on an RTX 5090, FFTSparse achieves up to an 8.37× speedup on real 128K-token inputs (at threshold $\theta = 0.90$) and 7.03× at a more conservative setting ($\theta = 0.85$). At 128K tokens, the FFT lag path is 2.44× faster than the diffuse Top-$k$ path.
  • Competitive Accuracy: On LongBench ($\theta = 0.85$, ~10–15% retained blocks), Llama-3.1-8B scores 36.86 vs. 37.02 for full dense attention—a tiny 0.16-point drop. Qwen2.5-7B shows a slightly wider gap, scoring 41.25 vs. 42.52 for dense attention.
  • Leaner Masks: Adaptive routing achieves higher average accuracy (39.52) while keeping only 10.35% of attention blocks, outperforming forcing all heads to use stripes (12.41% blocks) or all diffuse (19.24% blocks).

Limitations and Future Work

  • Not Truly Sub-Quadratic End-to-End: While FFT lag discovery runs in $O(DN \log N)$ time, writing out the explicit block-level binary masks and running the fallback Top-$k$ affinity scoring for diffuse heads still retain $O(N^2)$ block-level operations.
  • Short-Context Overhead: At 8K tokens, FFTSparse is actually slower than standard FlashAttention (31.56 ms vs. 14.14 ms) because pattern-selection overhead outweighs sparse compute savings; the speedups kick in at 16K+ tokens.
  • Scope of Timings & Accuracy Trade-offs: Reported speedups measure the attention module in isolation, not end-to-end model prefilling (which includes feed-forward networks and projections). Furthermore, aggressive sparsification ($\theta = 0.90$) trades noticeable task accuracy for speed, and workloads heavy on diffuse heads will naturally see smaller FFT efficiency gains. (Future work directions are not explicitly discussed in the paper.)

Summary updated

Abstract

The quadratic cost of attention limits the efficiency of long-context language model prefilling. We observe that attention logits in the evaluated models often exhibit diagonal stripes: query--key pairs separated by particular relative distances have consistently high correlation. We introduce FFTSparse, a training-free hybrid block-sparse attention framework that exploits this structure. FFTSparse formulates dominant-lag extraction as cross-correlation and computes it using the Fast Fourier Transform in $O(DN\log N)$ time per head, where $N$ is the number of blocks and $D$ is the head dimension. A sampled head classifier routes diagonal-dominant heads to lag-based masks and diffuse heads to block-affinity masks, with structural priors preserving local and boundary interactions. The complete mask-construction pipeline also includes quadratic block-level mask writes and affinity scoring. Evaluations on Llama-3.1-8B-Instruct and Qwen2.5-7B-Instruct demonstrate a competitive accuracy--efficiency trade-off on LongBench. Direct measurements across all 32 layers of Llama-3.1-8B-Instruct yield up to an $8.37\times$ attention-module speedup at 128K tokens with a correlation threshold of $0.90$. These results support frequency-domain lag extraction as an efficient way to select structured long-range interactions.
BibTeX
@inproceedings{chao2026fftsparse,
  author = {Zemin Chao and Cen Jianhe and Qianhui Xu and Guangzhi Ge and Zhixin Qi and Hongzhi Wang},
  title = {{FFTSparse: Relative-Position Correlation Guided Sparse Attention for Long-Context Language Models}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=pbAu7eSrEE},
}
Figure