Decoder-only LLMs ship without a cross-attention sub-layer, so where does the context go?
Modern decoder-only LLMs like GPT, Llama, and Mistral have no separate encoder and no cross-attention sub-layer. Yet they routinely 'condition on' system prompts, retrieved documents, and chat history. Explain how that conditioning actually happens architecturally, and what the encoder-decoder design buys back at the cost of complexity.
Decoder-only LLMs stuff all context into one causal sequence and let self-attention reach back over the prefix; encoder-decoder pays complexity for reusable encoder K, V across many generations.
Imagine two ways to brief a chef. The encoder-decoder way: a head chef reads the menu and the recipe once, writes a tidy summary card, and hands it to every line cook for the night. The decoder-only way: every single time a line cook starts a new plate, they re-read the menu and recipe themselves, with no summary card. The first way is efficient when many cooks share the same brief. The second way is simpler to set up, and works fine when every plate is for a different customer with different instructions. Modern chatbots use the second way because every conversation is unique anyway.
Detailed answer & concept explanation~6 min readEverything 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. 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.
Walk the sub-layer count difference, explain in-context conditioning via causal self-attention over the prefix, name the encoder-decoder reuse win, connect prefix caching as the decoder-only analog, and close with the workload split that explains why decoder-only dominates chat.
| Property | Decoder-only | Encoder-decoder |
|---|---|---|
| Sub-layers per decoder block | 2 (self-attn + FFN) | 3 (self-attn + cross-attn + FFN) |
| Where context lives | Prefix of the causal sequence | Encoder output, read via cross-attn |
| KV caches needed | One (decoder self-attn) | Two (self-attn + cross-attn K, V) |
| Source reuse across requests | Prefix caching (exact-match) | Native, encoder runs once |
| Typical use | General chat, completion | Translation, summarization, ASR |
Real products, models, and research that use this idea.
- Llama 4 Maverick: decoder-only, every system prompt + RAG context shares one causal sequence with the generation.
- GPT-5.5 chat: decoder-only with vLLM-style prefix caching to amortize repeated system-prompt prefixes across requests.
- T5 (Google, 2019): canonical encoder-decoder; still cited as the reference design when explaining cross-attention.
- Whisper (OpenAI speech): encoder-decoder because the audio encoder output is fixed and reusable across decoder beam search hypotheses.
- SGLang radix-tree prefix cache: production system that brings encoder decoder style K, V reuse to decoder-only serving.
What an interviewer would ask next. Try answering before peeking at the approach.
QWhy is prefix caching cheaper than re-running cross-attention in encoder-decoder, even though both reuse precomputed K, V?
QIf you wanted to add 'cross attention like' reusable conditioning to a decoder-only model post-training, how would you do it?
Don't say thisRed flags and common mistakes that signal junior thinking. Click to expand.
Red flags and common mistakes that signal junior thinking. Click to expand.
Saying decoder-only models 'have no context conditioning' because they lack cross-attention. Conditioning happens through the causal self-attention reading the prefix tokens.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.
Same topic, related formats. Practice these next.