A decoder layer supports sequence generation by adding a second multi-head attention stage to the self-attention path. It usually works with an encoder: the encoder output supplies keys and values, while the previous attention result supplies queries. Residual connections organize both attention stages, and positional encodings provide sequence information instead of explicit recurrent time connections. section 12.5.2
For autoregressive use, account for these design points:
- Use a triangular mask to prevent attention from seeing future inputs. section 12.5.2
- Pair the decoder with an encoder for sequence-to-sequence tasks such as machine translation. section 12.5.2

