Introduction
As Large Language Models (LLMs) scale to handle million-token contexts, the "prefilling" phase—processing the initial prompt—has emerged as a significant computational bottleneck. Standard attention mechanisms possess a quadratic complexity ($O(N^2)$) relative to sequence length, making long-context processing prohibitively expensive. While sparse attention methods attempt to mitigate this by calculating only essential scores, they often rely on static patterns or lossy "pooling" techniques that can degrade model accuracy.
This paper introduces SharePrefill, a novel sparse attention mechanism that accelerates prefilling without sacrificing performance. By leveraging the observation that attention heads often share similar sparse patterns across different layers and inputs, SharePrefill implements a "compute once, share many" strategy to bypass the quadratic complexity of standard attention.
Methods: Pattern Sharing and Clustering
SharePrefill operates on the principle of redundancy within the transformer architecture. The method consists of three primary components:
- Offline Clustering: Using an autoencoder to compress attention maps from representative tasks, the authors apply hierarchical clustering to group attention heads across different layers into clusters with similar behavioral patterns.
- Online Pattern Sharing: During inference, a single "pivotal head" is selected for each cluster to perform full, dense attention. The resulting precise sparse pattern is then shared with all other heads in that cluster, bypassing redundant calculations.
- Dynamic Verification: To maintain robustness, the system calculates the Jensen-Shannon (JS) distance for a subset of queries. If the shared pattern is a poor fit for a specific head, the system reverts to a conservative "vertical-slash" pattern.
Key Insights: Redundancy as a Feature
The core innovation of SharePrefill lies in identifying Inter-head Similarity (multiple heads looking at the same tokens) and Cross-input Consistency (heads behaving similarly regardless of the specific prompt). As shown in Figure 6, attention patterns for specific heads remain remarkably stable even when the input content changes from code debugging to English dialogue.
This consistency allows the offline clustering to remain valid across diverse downstream tasks. Furthermore, the authors argue that "pooling" methods used in other sparse attention frameworks are inherently lossy because they ignore fine-grained token-level alignment, leading to "blurry" estimations that hurt accuracy.
Key Results
The researchers evaluated SharePrefill against state-of-the-art methods using the InfiniteBench suite and the PG-19 dataset.
As illustrated in Figure 2, SharePrefill consistently occupies the top-left quadrant of the performance-efficiency trade-off:
- Accuracy: On Llama-3-8B-Instruct-262k, SharePrefill achieved an average InfiniteBench score of 39.05, matching the accuracy of the much slower MInference (39.14) and significantly outperforming FlexPrefill (36.44).
- Efficiency: SharePrefill reduced 128K context latency to 16.92 seconds, providing a notable speedup over both MInference (19.14s) and FlexPrefill (20.86s).
- Perplexity: In language modeling tasks (PG-19), SharePrefill's perplexity closely tracked the gold-standard FlashAttention-2, whereas competing sparse methods showed performance degradation at longer context lengths.
Conclusion and Future Work
SharePrefill demonstrates that head redundancy is a powerful lever for optimizing long-context LLMs. By sharing high-quality patterns instead of estimating low-quality ones, the method achieves a superior balance of speed and precision.
Future research will focus on the theoretical underpinnings of why these redundant patterns emerge and exploring the scalability of a "global pattern dictionary" in multi-GPU environments. Additionally, the authors suggest that the principles of head similarity could eventually be extended to accelerate the decoding (generation) phase of LLM inference.
Summary updated