One stack, one objective
An encoder-decoder model has two stacks and three attention types. A decoder-only model has one stack, one attention type, and one loss.
Every token is a prediction target, and the input and the label are the same sequence shifted by one position.
That is why the architecture won. The training signal is predictions per sequence rather than one, and it needs no labelled pairs at all.
The mask is the architecture
Adding negative infinity before the softmax sends those weights to exactly zero, so a position can attend to itself and everything before it and nothing after.
Without the mask, predicting the next token would be trivial: the answer is one of the inputs.
The mask is added rather than applied afterwards, because zeroing the weights after a softmax would leave them unnormalised.
One training step, in order
- Take a sequence of tokens as the input, and the same sequence shifted left as the target.
- Run every block with causal masking, in parallel across all positions.
- Project each position's final state to logits over the vocabulary.
- Compute cross-entropy at every position at once.
- Average across positions and tokens, and step.
The parallelism in step two is the reason this trains where a recurrent network cannot.
Masking makes all predictions independent given the weights, so one forward pass produces all of them.
Generation is the opposite shape
Training processes a whole sequence in one pass. Generation must produce one token, append it, and run again, so it is sequential by construction.
The KV cache is what makes this affordable: the keys and values of earlier tokens do not change, so each new step computes one new column rather than the whole matrix.
Prefill is compute-bound and decode is memory-bound, and that asymmetry is behind almost every serving optimisation.
Why encoders lost the argument
Masked language modelling trains on a fraction of the positions, which is a less efficient use of the same corpus and the same compute.
A bidirectional encoder also cannot generate. Predicting a masked token in place is a different task from continuing a sequence, and only one of them composes into open-ended output.
Translation, summarisation, classification and dialogue are all expressible as continuing a prompt, so one stack and one objective absorbed tasks that used to need separate architectures.
What was given up is real: a decoder's representation of a token cannot depend on what follows it.
For pure understanding tasks with a fixed input, an encoder still measures better per parameter.