Prove that a transformer encoder layer without positional encodings is permutation-equivariant: permuting the input tokens permutes the outputs in the same way. How do you show that a decoder with a causal mask and no positional encodings is not, and that it can still recover position information?
Sequence models and transformers, Attention
Level L5 Expert. Length Long. Nature Th+Mat Both.
What's being asked
Whether you can prove equivariance with permutation matrices and explain how the causal mask breaks it.
Key idea
For a permutation matrix , , so . A causal mask is not preserved by , so equivariance fails.
Steps
- Let hold the token vectors, , , , and . A permuted input is .
- Then , , and .
- Softmax acts on each row independently and permuting columns just reorders entries within a row, so .
- Output: , using . So .
- The feed-forward network, layer norm and residual connection act on each token separately, so they are equivariant too. Hence the whole layer is, and the model cannot tell word order without positional encodings.
- Causal mask: , but with the original mask is not the same as , since in general. The proof breaks.
- Position leak: suppose the first token is a special BOS whose value vector has a coordinate equal to , and all other tokens have there. If the scores are all equal, position attends uniformly to tokens, so that coordinate of the output is . The model can read off the position from it.
Common mistakes
- Saying softmax is permutation-invariant; it is equivariant in this setting, since the outputs are permuted along with the inputs.
- Concluding that causal models need no positional information at all; they usually still benefit, especially for generalising to longer lengths.
- Writing instead of : the permutation must act on both the rows and the columns of the score matrix.
How long your answer should be
One page; 8 minutes.
Last checked on 4 December 2026.
Read this
Previous in Sequence models and transformers: FlashAttention computes softmax attention one block of keys at a time, without storing the full score matrix. Derive the online softmax recurrence that keeps a running maximum and a running sum , and test it on the scores split into the blocks and with values ?
Next in Sequence models and transformers: In speculative decoding, a small draft model with next-token distribution proposes a token , and the large target model with distribution accepts it with probability . If it is rejected, a token is drawn from the residual . Show that the output token is distributed exactly as . For and , find the acceptance probability and the expected number of tokens per target pass when tokens are drafted?