Profile

Settings

Loading…

← Papers

Help

FAQ

Which features require signing in?

You can read the commentary, paper info, Model Structure and related papers of public papers without signing in. Sign in to manage your account or contact us about your inquiries.

Can I upload a PDF file?

Upload papers with an arXiv or DOI link; the commentary is public to everyone. Papers whose source and terms of use can't be verified, so the commentary can't be made public, can't be uploaded. Uploading PDF files and keeping papers private are for subscribers only, and a paper uploaded as a file is saved as private only. Searching for official info by title runs only when you press the button.

Are the figures and AI commentary accurate?

Figures come only from the original paper, and only those whose terms of use are verified are shown. The commentary is written by AI and may be wrong. Check important claims, numbers and figure context against the evidence in the original paper.

I want to report a copyright issue.

Terms of use and the source of the original paper are on the Paper info tab. If there's a problem, choose "Paper content, figures and copyright" under Contact us and send the paper link, the part in question, and evidence that you hold the rights. Receiving your report doesn't confirm any rights or remove anything right away. You can see the result of the review under My inquiries.

I forgot my password.

If you signed up with email, use Forgot password in the sign-in window to reset it with your verified email. If you signed up with Google, Naver or Kakao, change your password with that service.

What should I include in an inquiry?

Tell us which screen you were on and what you were doing when the problem happened, along with the paper link. Don't include personal information such as passwords, API keys, verification codes or phone numbers. Inquiries and replies are stored in Refivu and you can see them under My inquiries.

How do I delete my account?

In Settings, under My account, press Delete account. Review what will be deleted and complete identity verification to delete your account. For other requests, choose "Account" under Contact us.

Paper commentary

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

  • Problem Incremental Transformer decoding is slowed by the memory traffic of reloading large key and value tensors at every step.
  • Method Shares one set of keys and one set of values across all attention heads while keeping a separate query per head, and applies this to every attention layer of the translation model.
  • Results Decoder time per output token fell from 46 µs to 3.8 µs for greedy decoding on TPUv2, on WMT14 English-German with sequence length 128.

Why incremental decoding is bound by memory traffic

Transformer replaces recurrence with attention layers that move information within and between sequences, which lets training process all positions of a sequence together. Generation cannot be parallelized in the same way, because the output at one position becomes part of the input that the next position depends on. Each decoding step therefore has to reload the cached keys and values, so on modern accelerators the speed of incremental inference is set by memory bandwidth rather than by arithmetic.

For batched attention over whole sequences, the arithmetic cost is \(\Theta(bnd^2)\) and the memory traffic is \(O(bnd + bhn^2 + d^2)\), under the assumptions m = n, k = v = d/h and n ≤ d. The ratio of memory access to arithmetic is \(O(1/k + 1/(bn))\), which is low enough for accelerators whose compute capacity can be two orders of magnitude above their memory bandwidth.

The \(1/b\) term can be reduced with a larger batch, as far as memory allows. The \(n/d\) term is harder to remove, because it comes from reloading the cache at each step. Earlier work reduces the number of attended positions, either through local neighborhoods or by compressing memory positions, as in Liu et al. (2018), Zhang et al. (2018) and Povey et al.

(2018). This paper takes a different route: it shrinks the keys and values by dropping their heads dimension while keeping the heads dimension in the queries.

Sharing one key and value set across heads

In multi-head attention each of the h heads has its own query, key and value projections, \(P_q\), \(P_k\) and \(P_v\), and the outputs are passed through a projection \(P_o\) and summed. The keys and values are therefore stored per head, as tensors of shape [b, h, m, k] and [b, h, m, v] in the incremental setting. Each decoding step appends one new key and one new value per head to these caches.

Multi-query attention keeps h query heads, but \(P_k\) and \(P_v\) project to a single set of keys and values with shapes [d, k] and [d, v], so every head reads the same memory. In the code this comes down to dropping the heads index from the einsum equations that involve K, V, \(P_k\) and \(P_v\), while queries, logits and the output projection keep their heads dimension.

During incremental decoding the cache therefore holds tensors of shape [b, m, k] and [b, m, v] with no head axis, and each head attends over this one shared cache. The per-head outputs are still projected by \(P_o\) and summed, so the form of the layer output does not change.

With this change the incremental ratio becomes \(\Theta(1/d + n/(dh) + 1/b)\), which the analysis describes as reducing the \(n/d\) term by a factor of h. The memory access per call is \(\Theta(bnd + bn^2k + nd^2)\), where the cache term carries no factor for the number of heads. The authors expect a large batch size b to make this gain substantial, and the experiments are meant to show that the speed gains are real and that quality stays high.

Models and training setup

The translation baseline is an encoder-decoder Transformer with 6 layers, \(d_{model}\) 1024, \(d_{ff}\) 4096, h = 8 and \(d_k = d_v = 128\), trained on WMT 2014 English-German. Each training batch held 128 examples, each a 256-token input and a 256-token target, on a 32-core TPUv3 cluster, with about 2 hours per model.

The multi-query model replaces every attention layer, covering encoder self-attention, decoder self-attention and encoder-decoder attention. Its feed-forward hidden layers are widened from 4096 to 5440, which brings its total parameter count to that of the baseline.

The local variants limit decoder self-attention to the current position and the previous 31 positions, a window of 32, while the other attention layers stay unchanged. Their purpose is to show that local attention and multi-query attention are orthogonal.

The alternatives reduce the number of heads h, or the key and value dimensions \(d_k\) and \(d_v\), and their feed-forward layers are widened so that the parameter count matches the baseline.

Translation quality on WMT 2014 English-German

Dev scores come from greedy decoding and report ln(PPL) per subword token and BLEU, while test BLEU was computed with greedy decoding and with beam-4 search. The table of WMT14 EN-DE results collects these scores for each attention variant.

On dev, the multi-query model has ln(PPL) 1.439 against 1.424 for the multi-head baseline, and greedy BLEU 26.5 against 26.7. The multi-query model is therefore slightly behind on both dev metrics, with the gap smaller than for any alternative that reduces h, \(d_k\) or \(d_v\).

On the test set the multi-query model scores 27.5 with beam 1 and 28.5 with beam 4, against 27.7 and 28.4 for the baseline. With beam-4 decoding the multi-query model has the highest BLEU of the variants in this comparison.

In the local pair, the multi-query local model has dev ln(PPL) 1.437 against 1.427 for the multi-head local model. Test BLEU with beam 4 is 28.2 for multi-query local against 28.3 for multi-head local, so the local multi-query model again trails the local baseline by a small margin.

Reducing heads gives ln(PPL) of 1.518 with one head, 1.480 with two heads of \(d_k = 64\), 1.488 with four heads and 1.513 with eight heads of \(d_k = 16\). Dev BLEU for these alternatives is 25.8, 26.2, 26.1 and 25.8, all below the multi-query model's 26.5 on the same metric.

Billion-Word language modeling results

The language-model experiments use transformer-decoder models on the Billion-Word LM Benchmark, with 6 layers, \(d_{ff}\) 8192 and 192 million parameters per model. They ran for 136K steps, which the paper gives as 10 epochs, at a batch size of 64K tokens.

Scores are per-word perplexity on the dev set, not per-subword-token perplexity. The multi-query model is slightly worse than the baseline, and better than the alternatives that reduce h, \(d_k\) and \(d_v\).

Training and decoding cost on TPUv2

Speed was measured on one TPUv2 with 8 cores, and Table 2 reports the timings separately from the quality scores in Table 1. A training step of 32,768 input tokens and 32,768 target tokens took 433 ms for the baseline and 425 ms for the multi-query model. Per input-plus-target token, training costs 13.2 µs for the baseline and 13.0 µs for the multi-query model.

For incremental greedy inference on a batch of 1024 sequences, 128 per core, with source and target lengths of 128, the baseline encoder took 222 ms and each decoder step 47 ms. The multi-query encoder took 195 ms and each decoder step took 3.9 ms. Amortized per output token, the encoder costs 1.7 µs for the baseline and 1.5 µs for the multi-query model, while the decoder costs 46 µs and 3.8 µs respectively.

With beam-4 search, the amortized cost is 2.0 + 203 µs per token for the multi-head model and 1.6 + 32 µs for the multi-query model, where the second term is the decoder. With local attention, the decoder cost is 23 µs per token for the multi-head local model and 3.3 µs for the multi-query local model in greedy decoding.

Limits of the timing and the evidence

Fixed input shapes forced padding and masking in the decoder self-attention, so memory tensors were padded to the maximum length of 128, or to the window of 32 for local attention. Each decoding step therefore took the same time regardless of position, and the authors note that growing the tensors incrementally could save time near the start of a sequence.

The quality cost is described by the authors as minor, and the measured gaps are small but present: dev ln(PPL) 1.439 against 1.424 on WMT14, and slightly worse per-word perplexity on the Billion-Word benchmark.

The analysis is theoretical and assumes m = n, k = v = d/h and n ≤ d. Experiments cover two benchmarks, WMT 2014 English-German and the Billion-Word LM Benchmark, and speed was measured only on TPUv2.

Learning rates, dropout and label smoothing are not given in the text, which marks the configuration details as to be added before publication.

Paper info

Authors
Noam Shazeer
Venue
arXiv · Preprint
First published
2019-11-6
Added
2026-10-20
Updated
2019-11-6
Version
v1
arXiv
1911.02150
Category
cs.NE · cs.CL · cs.LG
Original paper terms
arXiv non-exclusive 1.0
What we show
Paper info and commentary

AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.

Quote from the paper

Noam Shazeer (2019). Fast Transformer Decoding: One Write-Head is All You Need. arXiv:1911.02150v1. https://arxiv.org/abs/1911.02150v1

BibTeX
@misc{shazeer2019fast,
  title = {{Fast Transformer Decoding: One Write-Head is All You Need}},
  author = {Noam Shazeer},
  year = {2019},
  eprint = {1911.02150},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1911.02150v1}
}

See related papersBrowse other papers

Paper preview
Account security

Connect Google account

If you connect a Google account, you can sign in with it too.

Refivu

Delete account

Refivu
Refivu

Sign up