Streaming Attention Approximation via Discrepancy Theory
Insu Han, Michael Kapralov, Ekaterina Kochetkova, Kshiteej Sheth, Amir Zandieh
TL;DR
This work tackles the memory bottleneck of long-context generation in Transformer-based models by introducing BalanceKV, a streaming attention approximation method grounded in discrepancy theory. It constructs SoftmaxBalance to balance exponentiated key-query interactions, implemented in streaming via BalanceKV and a MergeAndReduce framework, yielding sublinear memory usage with provable accuracy for Attn$(q_j,K_j,V_j)$. A lower bound via INDEX shows inherent space-accuracy trade-offs. Empirically, BalanceKV improves end-to-end performance on long-context benchmarks such as LongBench and Needle-In-A-Haystack, while offering competitive efficiency relative to state-of-the-art cache-compression methods.
Abstract
Large language models (LLMs) have achieved impressive success, but their high memory requirements present challenges for long-context token generation. In this paper we study the streaming complexity of attention approximation, a key computational primitive underlying token generation. Our main contribution is BalanceKV, a streaming algorithm for $ε$-approximating attention computations based on geometric process for selecting a balanced collection of Key and Value tokens as per Banaszczyk's vector balancing theory. We complement our algorithm with space lower bounds for streaming attention computation. Besides strong theoretical guarantees, BalanceKV exhibits empirically validated performance improvements over existing methods, both for attention approximation and end-to-end performance on various long context benchmarks.
