Translating one source sentence into many target languages, what attention-side trick scales?
An encoder-decoder translation service receives N requests that all translate the same English source sentence into different target languages (French, Spanish, German, Japanese). Identify the attention-side optimization the runtime can apply, and explain why it is structurally available in encoder-decoder but only partially in decoder-only.
Run the encoder once and reuse the cached cross-attention K, V across all N decoder generations; decoder-only can do this partially via prefix caching.
Imagine a museum tour guide who has memorized a long script about one painting. If ten visitors all want to hear about that painting in ten different languages, the guide does not need to look at the painting ten times. They look once, form one mental description, and then translate that description into each language. The painting is the source sentence; the mental description is the encoder output; the translations are the decoder runs. Encoder-decoder transformers do exactly this. Decoder-only models work more like a guide who has to re-look at the painting every time they start a new translation, unless they have a clever notebook that remembers what they saw last time when the visitor description matches exactly.
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.
Name the cross-attention K, V cache; explain why it is reusable across the N target generations; quantify the saving; connect prefix caching as the decoder-only analog; cite vLLM and SGLang as production implementations.
| Aspect | Encoder-decoder K, V reuse | Decoder-only prefix caching |
|---|---|---|
| Granularity of sharing | Whole encoder output | Exact token-level prefix match |
| Robustness to per-request diff | High, decoder state is independent | Low, any divergence ends sharing |
| Cache structure | Per-layer cross-attn K, V | Per-layer self-attn K, V blocks |
| Typical use case | Translation, ASR beam search | Chat with shared system prompt |
| Saving for N parallel runs | Encoder cost / N (large) | Depends on prefix overlap |
Real products, models, and research that use this idea.
- Google's production NMT service for translation: encoder K, V cache shared across multi-target translation requests.
- Whisper (encoder-decoder ASR): the audio encoder runs once per utterance and the decoder beam search reads the same cached cross-attention K, V for every hypothesis.
- vLLM and SGLang in 2026 production: prefix caching for decoder-only models with system-prompt reuse; the closest analog to encoder K, V caching.
- Hugging Face's `EncoderDecoderModel.generate` with `past_key_values`: caches cross-attention K, V across beam-search and multi-output generation.
What an interviewer would ask next. Try answering before peeking at the approach.
QWhy is cross-attention K, V cacheable but cross-attention Q is not?
QWhat changes if the source is very long but each target is very short? Does the reuse still pay off?
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.
Claiming decoder-only can do exact encoder-output reuse via prefix caching. Prefix caching only works for exact token-level prefix matches; cross-attention reuse works regardless of how decoder runs diverge.
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.