Attention Is All You Need: The Transformer
Publication Boundary
- Paper: Attention Is All You Need
- Authors: Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N. Gomez, Łukasz Kaiser, and Illia Polosukhin
- Venue and version: NIPS 2017 proceedings paper
- Evaluated workload: supervised encoder-decoder machine translation on WMT 2014 English–German and English–French
The proceedings value used here is 41.0 BLEU for the large English–French model; the later arXiv abstract reports 41.8. Decoder-only language models, KV-cache serving, FlashAttention, scaling laws, long-context methods, instruction tuning, and modern mixture-of-experts deployments are later work.
What the Paper Claimed
The paper replaced recurrent and convolutional sequence-to-sequence layers with attention and position-wise feed-forward layers. Its central empirical claim was about translation quality, training cost, and sequence parallelism, not that recurrence disappeared from every future sequence task or that attention alone solved language understanding.
The original Transformer is an encoder-decoder:
- the encoder reads the source sentence bidirectionally,
- the decoder uses masked self-attention over prior target positions,
- decoder cross-attention reads encoder outputs,
- generation remains autoregressive at inference time.
Thus “no recurrence in the network” does not mean “all output tokens can be generated simultaneously.” Teacher-forced training exposes all target positions in parallel; inference still predicts the next token from the generated prefix.
Model State and Architecture
Both encoder and decoder contain six layers in the paper's base and big configurations.
Encoder layer
Each encoder layer contains:
- multi-head self-attention,
- residual addition followed by layer normalization,
- a position-wise feed-forward network,
- another residual addition followed by layer normalization.
The original paper used post-norm:
Many later large models use pre-norm or other normalization arrangements; projecting those backward changes the algorithm.
Decoder layer
Each decoder layer adds a third sublayer: attention over encoder outputs. Its self-attention is causally masked so position
The decoder state during translation comprises the generated target prefix; the encoder memory is reused for each next-token step. The 2017 paper did not describe the modern serving term “KV cache,” although caching projected keys/values is a direct later implementation consequence.
Scaled Dot-Product Attention
For query, key, and value matrices:
Multi-head attention learns separate projections:
The base model used
Feed-Forward, Embeddings, and Position
Each position independently applies:
with
The paper shared the source embedding, target embedding, and pre-softmax weight matrix where vocabulary construction allowed, and multiplied embeddings by
Because attention without position information is permutation-equivariant, the model adds sinusoidal encodings:
The paper also tested learned positional embeddings and found nearly identical translation quality in its ablation. It chose sinusoids partly for the possibility of extrapolating beyond trained lengths; the evaluation did not establish robust modern long-context extrapolation.
Optimization Protocol
Training used Adam with
with 4,000 warmup steps. Regularization included residual dropout and label smoothing with
These details are not incidental. Comparing architectures while changing tokenizer, optimizer, checkpoint averaging, and decoding can attribute gains incorrectly.
Complexity and Dependency Paths
For sequence length
| Layer type | Complexity per layer | Sequential operations | Maximum path length |
|---|---|---|---|
| Self-attention | |||
| Recurrent | |||
| Convolution, kernel |
Self-attention is computationally cheaper than recurrence under this simplified comparison when
The table is not a complete hardware cost model. Projection and FFN terms, memory traffic, kernel launch overhead, padding, and actual accelerator utilization matter. At long
Illustrative memory calculation
If an implementation materialized one attention-score tensor for batch size 1,
That is per layer before gradients and other intermediates. This is illustrative, not a measurement from the paper. Modern tiled kernels can compute exact attention without writing the full score matrix to high-bandwidth memory, changing memory traffic but not the dense all-pairs arithmetic of standard attention.
Training and Data Methodology
Datasets
- WMT 2014 English–German: about 4.5 million sentence pairs, byte-pair encoding, shared source-target vocabulary of about 37,000 tokens.
- WMT 2014 English–French: about 36 million sentence pairs, word-piece vocabulary of about 32,000 tokens.
Batches contained roughly 25,000 source tokens and 25,000 target tokens. Length batching reduced padding.
Hardware and schedule
Training ran on one machine with eight NVIDIA P100 GPUs:
| Configuration | Parameters | Steps | Seconds/step | Reported training time |
|---|---|---|---|---|
| Base | 65 million | 100,000 | about 0.4 | about 12 hours |
| Big | 213 million | 300,000 | about 1.0 | about 3.5 days |
The paper estimated training FLOPs as training time multiplied by number of GPUs and their sustained single-precision capacity (9.5 TFLOP/s per P100). This is an estimate, not profiler-counted effective model FLOPs. The table reports about
Decoding
The reported translation results used beam search with beam size 4, length penalty
BLEU is sensitive to tokenization and evaluation setup. Preserve the paper's task and pipeline when comparing values.
Quantitative Results
| Model | WMT14 EN–DE BLEU | WMT14 EN–FR BLEU | Parameters |
|---|---|---|---|
| Transformer base | 27.3 | 38.1 | 65M |
| Transformer big | 28.4 | 41.0 | 213M |
The paper compared with prior recurrent and convolutional translation systems and reported better quality with substantially lower estimated training cost. It did not compare against later Transformers, decoder-only LMs, or current accelerators.
Ablations
Ablations used English–German newstest2013 and did not use checkpoint averaging. Among the reported observations:
- reducing attention to one head cost about 0.9 BLEU relative to the cited multi-head setting,
- very small per-head dimensions hurt quality,
- increasing model dimensions generally improved quality but increased cost,
- learned and sinusoidal positional encodings performed nearly identically in that experiment.
Ablations are local to the tested base recipe; they do not prove eight heads or sinusoidal positions are globally optimal.
Failure Modes as a Train/Serve System
The paper is a model paper rather than a production-serving design, but its computation creates concrete system failure modes:
| Failure | Manifestation | Mitigation boundary |
|---|---|---|
| Padding/shape skew | Wasted compute and memory | Token-based batching and length buckets |
| Attention activation exhaustion | OOM at long sequence/batch | Bound sequence, rematerialize, tile attention |
| Mask bug | Decoder sees future target tokens | Unit tests against causal dependency and leakage |
| Tokenizer/version mismatch | Different IDs and outputs | Pin tokenizer with weights |
| Numerical overflow/underflow | NaNs or unstable softmax | Stable softmax, scaling, precision tests |
| Autoregressive worker loss | Partial translation/output | Retry semantics belong to later serving layer |
| Beam-search configuration drift | BLEU/output changes without weight change | Version decoding policy |
The model's reproducible identity is more than weights:
What the Paper Did Not Establish
- It evaluated machine translation, not general language modeling, chat, retrieval, vision, or agents.
- It was an encoder-decoder, not the decoder-only architecture dominant in later LLMs.
- It did not evaluate KV-cache allocation, continuous batching, speculative decoding, or prefill/decode disaggregation.
- It did not present scaling laws or compute-optimal training claims.
- It did not solve quadratic long-context cost; restricted attention was proposed as future work.
- It did not demonstrate that every head learns a stable interpretable role.
- It used sequence lengths and hardware far smaller than modern long-context deployments.
- BLEU improvements do not establish safety, factuality, instruction following, or reasoning quality.
Later Evolution, Kept Separate
Decoder-only autoregressive models later reused masked self-attention for language modeling. Serving systems cache keys and values, page that memory, batch token iterations, and sometimes separate prefill from decode. FlashAttention later made exact attention IO-aware through tiling. Multi-query/grouped-query attention reduced KV heads; sparse and linear attention variants changed the cost structure.
These systems consequences are covered in LLM Inference Platforms, LLM Infrastructure, and GPU Inference Internals. They are descendants, not results of the 2017 evaluation.
Design-Review Questions
- Is the architecture encoder-only, encoder-decoder, or decoder-only, and which attention masks apply?
- Does a complexity claim include projections, FFN, memory traffic, padding, and backward activations?
- Is an
tensor materialized, recomputed, or tiled? - Are tokenizer, vocabulary sharing, positions, and decoding policy versioned with weights?
- Are quality numbers tied to dataset version, preprocessing, checkpoint averaging, and beam settings?
- Is training cost measured by profiler, theoretical operations, or device-time capacity estimate?
- Does a later serving conclusion actually follow from the 2017 paper, or from later systems work?
- What sequence lengths make
true for the claimed self-attention advantage? - Can a causal-mask test prove future tokens cannot influence earlier decoder states?
- Are learned/sinusoidal position conclusions being extrapolated far beyond trained length?
Lessons That Generalize
- Removing sequential dependencies can matter more to hardware utilization than minimizing asymptotic arithmetic alone.
- State representation and mask semantics are part of the algorithm, not implementation detail.
- Report model quality with the full data, optimization, checkpoint, and decoding protocol.
- Constant dependency-path length and parallel training coexist with autoregressive inference.
- A successful primitive creates new systems bottlenecks; quadratic attention and later KV state became an infrastructure workload.
- Separate the original evidence from later influence to avoid rewriting history through today's architecture.