Bifurcated Attention: Accelerating Massively Parallel Decoding with Shared Prefixes in LLMs
Ben Athiwaratkun, Sujan Kumar Gonugondla, Sanjay Krishna Gouda, Haifeng Qian, Hantian Ding, Qing Sun, Jun Wang, Jiacheng Guo, Liangfu Chen, Parminder Bhatia, Ramesh Nallapati, Sudipta Sengupta, Bing Xiang
TL;DR
This work tackles the latency bottleneck in massively parallel autoregressive decoding caused by memory IO in the KV-cache during incremental decoding. It introduces context-aware bifurcated attention, which splits attention into context- and decoding-related KV components to preserve FLOPs while dramatically reducing memory IO, enabling much larger batch sizes and longer contexts with minimal latency impact. The study analyzes generalized multi-group attention across the spectrum from multi-head to multi-query, showing how the number of attention groups $g$ trades expressiveness for efficiency and how model size can compensate for reduced expressiveness. Empirical results demonstrate substantial speedups (over 2× to 6×) in various configurations on 7B-scale models, compatibility with Torch-Compile, and practical benefits for applications requiring multiple parallel samples or re-ranking, such as code generation and reasoning tasks. Overall, bifurcated attention offers a practical, IO-aware pathway to real-time, high-throughput decoding in LLMs without sacrificing accuracy, making it valuable for latency-sensitive AI services.
Abstract
This study introduces bifurcated attention, a method designed to enhance language model inference in shared-context batch decoding scenarios. Our approach addresses the challenge of redundant memory IO costs, a critical factor contributing to latency in high batch sizes and extended context lengths. Bifurcated attention achieves this by strategically dividing the attention mechanism during incremental decoding into two separate GEMM operations: one focusing on the KV cache from prefill, and another on the decoding process itself. While maintaining the computational load (FLOPs) of standard attention mechanisms, bifurcated attention ensures precise computation with significantly reduced memory IO. Our empirical results show over 2.1$\times$ speedup when sampling 16 output sequences and more than 6.2$\times$ speedup when sampling 32 sequences at context lengths exceeding 8k tokens on a 7B model that uses multi-head attention. The efficiency gains from bifurcated attention translate into lower latency, making it particularly suitable for real-time applications. For instance, it enables massively parallel answer generation without substantially increasing latency, thus enhancing performance when integrated with post-processing techniques such as re-ranking.
