Translating one source sentence into many target languages, what attention-side trick scales?
Same topic, related formats. Practice these next.
Same topic, related formats. Practice these next.
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.
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.
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.
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.