AlgoViz

Attention Is All You Need

medium 40 min

The 2017 paper that introduced the Transformer.

Numbers that decide

Work out a number when the answer changes what you build.

Work it out

Numbers worth having ready

QuestionAnswer
Base model shape6 + 6 layers, d_model 512, 8 heads of 64, d_ff 2048, 65M parameters
Big modeld_model 1024, 16 heads, d_ff 4096, 213M parameters
TrainingBase 12 h, big 3.5 days, 8 P100 GPUs
Results28.4 BLEU En-De, 41.8 En-Fr (Table 2)
KV bytes per token2 × layers × kv heads × head dim × bytes
Scores per head per layern²: 1,000 tokens give 1 million

KV cache for a batch

131,072 Btoken×8,192×16 requests≈17.2 GB131{,}072\ \tfrac{\text{B}}{\text{token}} \times 8{,}192 \times 16\ \text{requests} \approx 17.2\ \text{GB}
Our example: the 32-layer model with 8 KV heads of 128 in fp16, 16 requests of 8k tokens each. Add the weights on top.