Decoder
The half of a model that writes output one token at a time, each new token based only on what came before it.
Draft - this entry has not been reviewed yet.
Formal
A stack of neural network layers in which each token may look only at earlier tokens, so the stack can guess the next token, add it to the text and repeat; decoder-only designs drop the encoder entirely.
In plain English
Like a storyteller by a campfire who can hear everything said so far but never peeks ahead, adding one word, then the next.
In practice
A product owner at a webshop sees that product texts twice as long take about twice as long to appear and cost twice as much, because the decoder must produce every token in turn.
Why it matters
Almost every large language model is decoder-only, which is why replies arrive gradually and why the length of an answer, not just the question, drives its cost.
Technical deep dive
In the original transformer (Vaswani et al., 2017) each decoder block had three sublayers: masked multi-head self-attention over the tokens generated so far, cross-attention whose queries come from the decoder and whose keys and values come from the encoder output, and a position-wise feed-forward network, each wrapped in a residual connection and layer normalisation. A decoder-only model, introduced at scale by GPT (Radford et al., 2018, a 12-layer stack of about 117 million parameters), simply drops the cross-attention sublayer; the prompt and the continuation live in one sequence and are processed by the same causal stack.
The causal mask is what makes the stack autoregressive: attention scores for positions j > i are set to −∞ before the softmax, so the representation at position i depends only on tokens 1…i. That allows efficient training with teacher forcing, where all positions of a training sequence are predicted in parallel and the loss is the summed cross-entropy of each next token. At inference the model produces a probability distribution over the vocabulary for the next position, a decoding rule selects a token (greedy argmax, beam search, or sampling with temperature, top-k or top-p/nucleus sampling), the token is appended and the step repeats until an end-of-sequence token or a length limit.
Inference therefore has two phases with different bottlenecks. Prefill processes the whole prompt in one parallel pass and is compute-bound; it largely determines time to first token. Decode generates one token per forward pass and is bound by memory bandwidth, because all weights and the growing KV cache must be read for every token; total latency is roughly time to first token plus output length times time per output token. This is why providers usually price output tokens higher than input tokens. Speculative decoding (Leviathan et al.; Chen et al., 2023) lets a small draft model propose several tokens that the large model verifies in one pass, with an acceptance rule that preserves the large model's output distribution.
Decoder-only designs dominate large language models because a single objective, next-token prediction on raw text, scales well and one architecture covers both understanding and generation. Encoder-decoder models such as T5 and BART remain common where input and output are clearly separate, such as translation, speech recognition (Whisper) and some summarisation. Note that "decoder" is also used for a different thing in autoencoders and in latent diffusion, where it maps a latent code back to pixels; that decoder is not autoregressive.
What to learn first
Everything this builds on, foundations first.
Relationships
- Part of
- Transformer
- Requires
- TokenAttention mechanism
- Don't confuse with
- Encoder
Sources & further reading
Reference works
- Vaswani et al. (2017), Attention Is All You Need
- Radford et al. (2018), Improving Language Understanding by Generative Pre-Training
Textbooks
- Jurafsky & Martin, Speech and Language Processing (3rd ed. draft)
Where this data comes from
This entry was drafted by an AI from the sources above and has not yet been checked by a person. Treat it as a starting point, and check anything important against the sources.
See the review queueSuggest a correction on GitHubThis term as JSON
Check yourself
Loading…