Efficient Attention via Pre-Scoring: Prioritizing Informative Keys in Transformers
Zhexiang Li, Haoyu Wang, Yutong Bao, David Woodruff
TL;DR
This paper tackles the quadratic cost of transformer self-attention by introducing a clustering- or leverage-based pre-scoring step that prioritizes informative keys before applying HyperAttention. By selecting a small, representative set of keys (often $k=d{+}1$ centroids) and optionally using a leverage-score sketch, the method preserves heavy-attention signals while reducing computation, achieving up to 20× speedups over FlashAttention in long-context scenarios and substantial perplexity improvements on ChatGLM2/GLM3 and competitive accuracy in Vision Transformers. The authors provide theoretical guarantees under a planted-subspace model, showing that clustering-based pre-scoring can recover all heavy keys with high probability, and extend the approach to $\,\ell_p$-norms via Minkowski-$k$-means. Empirical results across language and vision tasks demonstrate robust improvements in efficiency-accuracy trade-offs, supported by reproducible experiments and open-source code.
Abstract
Recent advances in transformer architectures deeply enhanced long-context language modeling. Among them, HyperAttention achieves competitive efficiency by combining a single-level LSH-based clustering with uniform residual sampling. However, HyperAttention fails to find all significant keys, which in turn raises the overall perplexity. We propose a pre-scoring mechanism that prioritizes significant keys before applying HyperAttention. We introduce three scoring methods: $k$-means and kernel $k$-means clustering, $k$-median clustering, and leverage score-based ranking (inspired by LevAttention) to filter keys effectively. We further replace HyperAttention's original uniform residual sampling, relying exclusively on our pre-scoring mechanism. Experiments on ChatGLM2 (131k token context) reduce perplexity from 12 to 8.3, which outperforms standard HyperAttention. Moreover, when running on the Vision-Transformer (ViT), our method shows that it can guarantee similar accuracy compared with LevAttention, and will surpass LevAttention given specific parameters. Although this method introduces some computational overhead, its combination with HyperAttention achieves up to 20 times faster than FlashAttention, providing a balanced trade-off between speed and modeling accuracy. Our results highlight the effectiveness of integrating pre-scoring into hierarchical attention mechanisms, significantly improving transformer efficiency.
