[Paper Review] Fast Transformer Decoding: One Write-Head is All You Need
This paper proposes multi-query attention, a variant of multi-head attention that shares keys and values across all attention heads, drastically reducing memory bandwidth during incremental decoding. The method achieves up to 12x faster inference with only minor quality degradation, making it ideal for latency-sensitive applications.
Multi-head attention layers, as used in the Transformer neural sequence model, are a powerful alternative to RNNs for moving information across and between sequences. While training these layers is generally fast and simple, due to parallelizability across the length of the sequence, incremental inference (where such paralleization is impossible) is often slow, due to the memory-bandwidth cost of repeatedly loading the large "keys" and "values" tensors. We propose a variant called multi-query attention, where the keys and values are shared across all of the different attention "heads", greatly reducing the size of these tensors and hence the memory bandwidth requirements of incremental decoding. We verify experimentally that the resulting models can indeed be much faster to decode, and incur only minor quality degradation from the baseline.
Motivation & Objective
- To address the high memory bandwidth cost of incremental decoding in Transformers, which limits inference speed on modern hardware.
- To reduce the size of key and value tensors in multi-head attention without significantly degrading model performance.
- To enable faster inference in latency-critical applications by minimizing repeated memory access during autoregressive generation.
- To evaluate whether sharing keys and values across heads maintains competitive quality compared to standard multi-head attention.
Proposed method
- Proposes multi-query attention, where all attention heads share the same key and value projections, reducing the number of parameters and memory bandwidth.
- Modifies the standard multi-head attention mechanism by replacing separate key and value projections per head with a single shared projection across all heads.
- Uses the same query projection per head but shares the key and value projections across all heads, reducing the size of K and V tensors from O(hd) to O(d).
- Employs standard self-attention computation with shared K and V matrices, maintaining the same attention mechanism but with reduced memory footprint.
- Applies the method to both standard and local attention variants, evaluating performance across different settings.
- Employs batched inference and incremental decoding on TPUv2 hardware to measure training and inference costs.
Experimental results
Research questions
- RQ1Can sharing keys and values across all attention heads reduce memory bandwidth during incremental decoding without significant performance loss?
- RQ2How does the proposed multi-query attention compare in quality to standard multi-head attention and other reduced-attention variants?
- RQ3To what extent does multi-query attention improve inference speed in autoregressive generation?
- RQ4Does the method maintain competitive performance on machine translation and language modeling benchmarks?
- RQ5Can the speedup be achieved without increasing training time or model size?
Key findings
- The multi-query model reduced decoder inference time from 47μs to 3.8μs per token on TPUv2, a 12.4x speedup in the incremental decoding phase.
- The amortized inference cost per token dropped from 46μs (baseline) to 3.8μs (multi-query), with encoder cost also reduced from 1.7μs to 1.5μs.
- On the WMT14 EN-DE translation task, the multi-query model achieved a BLEU score of 28.5 with beam search (4), slightly outperforming the baseline (28.4).
- In the billion-word language modeling benchmark, the multi-query model had a perplexity of 30.2, only slightly worse than the baseline (29.9).
- The model maintained similar training time (13.0μs/token vs. 13.2μs/token) despite the architectural change, indicating no training overhead.
- The method outperformed all alternatives that reduced h, dk, or dv in both quality and speed, demonstrating its effectiveness as a memory-bandwidth-optimized solution.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.