Encoder-Decoder Architecture Comeback: Choosing Small Multimodal Models with Long Context Support

    An overview of why encoder-decoder architectures are regaining attention, how encoders and decoders divide their work, and how to adapt decoder-only weights into an encoder-decoder structure—plus practical guidance on choosing architectures for multimodal, long-context, and on-device scenarios.

    Why Encoder-Decoder Architectures Are Getting Attention Again

    Over the past few years, most large language models have adopted a decoder-only architecture. The model generates tokens autoregressively, with the input prompt and generated content sharing the same set of parameters and processed through causal attention. This design is structurally uniform and easy to scale, but it comes with three problems.

    First, when generating each token, the model can only read the input and prior text through causal attention—it cannot re-examine the entire input with bidirectional attention. For rewriting, summarization, and question-answering tasks, if the input is long, evidence is scattered, or the decoding strategy is aggressive, the risk of output inconsistent with the source text rises. Decoder-only models do not necessarily hallucinate, but since understanding the input and generating the output share the same pathway, it is harder to strengthen comprehension independently.

    Second, non-textual information such as images and audio must first be converted into token sequences and then concatenated with text, making the fusion process complex.

    Third, inference cost grows with context length. This problem is especially noticeable on devices with limited compute, such as mobile phones.

    The encoder-decoder architecture assigns “understanding the input” and “generating the output” to two separate modules. This idea originates from the classic Transformer design and has been extensively validated in tasks like machine translation. Revisiting it aims to pick a structure that better balances comprehension accuracy, multimodal fusion, and on-device efficiency. Decoder-only models still hold clear advantages in open-ended dialogue and general generation—the two approaches each have their own suitable use cases.

    What Do the Encoder and Decoder Each Do?

    The encoder typically uses bidirectional self-attention, where every position can see the entire input simultaneously, making it well suited for extracting semantics and building a complete input representation. The decoder uses causal masking—when generating token t, it can only see the t-1 previously generated tokens—while reading the encoder’s output through cross-attention.

    This division of labor yields two direct benefits. First, the input needs to be encoded only once, and the encoding can be cached. When the same material requires multiple generations—for example, producing several candidate summaries or handling multiple instructions—the encoding cost is paid only once. Second, input length and output length are independent. The encoder focuses on processing long inputs, while the decoder extracts only the information needed for generation.

    The table below compares the two approaches across key dimensions:

    Dimension Decoder-only Encoder-Decoder
    Input modeling Causal attention; input and output share one pathway Encoder uses bidirectional attention for a more complete input representation
    Cache reuse Relies on the KV cache, reading prior-token cache at each step Encoded input can be reused across multiple decoding passes
    Multimodal fusion Visual tokens are concatenated into the same sequence Visual tokens can fully interact with text during encoding
    On-device latency Per-step cost keeps rising as context grows Long inputs are encoded once; decoding stays relatively lightweight
    Training cost Many base model choices and a mature ecosystem Decoder weights can be transferred, but extra adaptation is required
    Best suited for Open-ended dialogue, general text generation Rewriting, summarization, QA, image-text understanding
    Less suitable for Tasks demanding extremely high input fidelity—needs evaluation to confirm Open-ended long conversations, or teams with limited base model options

    The following pseudocode illustrates the data flow. It is not directly runnable—in practice, you will need to adapt the interfaces, tensor shapes, and cache structures to your framework.

    1. # Pseudocode: encode once, decode multiple times
    2. encoder_states = encoder(input_tokens) # shape roughly [batch, src_len, hidden], computed only once
    3. cache = build_cross_attention_cache(encoder_states) # cache the K and V for cross-attention
    4. for task in tasks:
    5. output = decoder.generate(
    6. prompt=task.prompt,
    7. encoder_cache=cache, # reuse the encoding; watch the cache's memory footprint
    8. max_new_tokens=task.max_tokens,
    9. )
    10. results.append(output)

    How to Transfer Decoder Weights to an Encoder-Decoder Structure

    Training an encoder-decoder model from scratch requires substantial compute. A more economical route is adaptation: use a decoder-only model already trained on large-scale corpora as the seed, map the seed weights into an encoder-decoder structure, and continue training until the new structure converges.

    A typical mapping procedure looks like this:

    1. Each encoder layer inherits the self-attention and feed-forward weights from the corresponding layer of the seed model. Since the encoder uses bidirectional attention, the mask differs from the seed model and needs to be re-verified.
    2. The decoder inherits the self-attention and feed-forward weights from the corresponding layers, and new cross-attention layers are added, with those parameters initialized from scratch.
    3. The embedding and output layers reuse the seed weights, provided the vocabularies match.
    4. Continue training the newly added layers and structurally differing parts with a smaller learning rate to minimize damage to the model’s existing language capabilities.

    Keep the following boundaries in mind during transfer:

    • Parameters with matching names and shapes can be copied directly, but that only means the tensors fit—it does not mean they carry the same meaning.
    • Positional encoding needs separate handling. The seed model may use rotary or absolute positional encodings, and the encoder and decoder may also cover different position ranges.
    • The placement of layer normalization (pre-norm or post-norm) and the residual structure must match the seed model, otherwise the numerical distributions will shift.
    • Attention masks must be set separately: bidirectional for the encoder, causal for the decoder.