arXiv(opens in a new tab)cs.NENov 2019Cited by 64 papers on PaperVantageClassic Paper

Manuscript Offprint

arXiv:1911.02150

Fast Transformer Decoding: One Write-Head is All You Need

Noam Shazeer

Abstract

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.

1 Introduction

The Transformer neural sequence model [Vaswani et al., 2017] has emerged as a popular alternative to recurrent sequence models. Transformer relies on attention layers to communicate information between and across sequences. One major challenge with Transformer is the speed of incremental inference. As we will discuss, the speed of incremental Transformer inference on modern computing hardware is limited by the memory bandwidth necessary to reload the large "keys" and "values" tensors which encode the state of the attention layers. In the following sections, we will review the multi-head-attention layers used by Transformer, provide a performance analysis, and propose an architectural variation (multi-query attention) which greatly improves inference speed with only minor quality degradation.

References (6)

  • Neural machine translation by jointly learning to align and translate, 2014
  • One Billion Word Benchmark for Measuring Progress in Statistical Language Modeling
  • Generating wikipedia by summarizing long sequences
  • A time-restricted self-attention layer for ASR. In Proceddings of the IEEE International Conference on Acoustics, Speech and Signal Processing (ICASSP)
  • Attention is all you need
  • Accelerating neural transformer via an average attention network, 2018

Cited by (64)