Walk through a T5 decoder block in order, list the attention sub-layers and what each one's Q, K, V read from.
Same topic, related formats. Practice these next.
Same topic, related formats. Practice these next.
T5 decoder block order: causal self-attention first (Q, K, V from decoder), then cross-attention (Q from decoder, K, V from encoder), then position-wise FFN, each with residual and norm.
Think of a translator writing the next word of a translation. First the translator reviews what they have already written so far (causal self-attention: looking at their own previous work). Then the translator looks at the original sentence to see what still needs translating (cross-attention: consulting the encoder). Finally the translator polishes the wording for the next word individually (FFN: per-token refinement). The order matters because reviewing your own progress before consulting the source means you ask the source the right question.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
6 min: T5 decoder block structure, three sub-layers in causal-self -> cross -> FFN order, projection sources per sub-layer, mask conventions, why causal then cross is the natural ordering, encoder K, V caching, modern survival of encoder-decoder in code, speech, multimodal.
| Sub-layer | Q from | K, V from | Mask |
|---|---|---|---|
| Decoder self-attention | Decoder hidden state | Decoder hidden state | Causal lower-triangular |
| Cross-attention | Decoder hidden state (post self attn) | Encoder final-layer output | None on encoder axis; optional padding mask |
| Position-wise FFN | N/A (no attention) | N/A (per-token MLP) | N/A |
Real products, models, and research that use this idea.
What an interviewer would ask next. Try answering before peeking at the approach.
Red flags and common mistakes that signal junior thinking. Click to expand.
Putting cross-attention before self-attention. The decoder must process its own context first (causal self-attention) before forming a query against the encoder output (cross-attention).
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.