Why Encoder-Decoder Architectures Still Matter for LLMs

    This article explains why encoder-decoder architectures remain relevant alongside decoder-only models. It compares bidirectional and causal attention, shows how asymmetric compute allocation benefits understanding-heavy tasks, outlines a path for adapting existing decoder weights, and covers long-context and multimodal use cases. A selection guide and tuning checklist help readers choose the right architecture for their workload.

    Introduction: Architecture Choice Is About Division of Labor, Not Old vs. New

    In recent years, the default choice for mainstream large language models has shifted almost entirely to the decoder-only architecture: autoregressive reading-and-writing, a single training objective, simple inference implementation, and a mature ecosystem. Even so, some engineering teams continue to iterate on and strengthen the encoder-decoder architecture, while folding in long-context and multimodal input capabilities. This may look like going against the trend, but it is a rational return to architecture selection based on task shape.

    One point needs clarifying: the encoder-decoder architecture is not outdated. Its essence is separation of responsibilities: the encoder focuses on reading the input thoroughly, and the decoder focuses on writing the output well. Understanding this is the prerequisite for making an architecture decision.

    1. The Essential Difference Between Two Attention Paradigms

    The value of the encoder-decoder architecture comes from how attention visibility is designed.

    • Bidirectional attention (encoder side): every input token can see context on both the left and the right at once, so input representations converge globally during encoding. There is no structural flaw of “reading the end and forgetting the beginning.”
    • Causal attention (decoder side): generation can only see what has already been produced, which prevents future information leakage and lets the generation strategy be designed and swapped independently.
    • Decoder-only architecture: reading and generation share the same causal mask, so the model must complete both understanding and production in a single forward pass.

    The following sketch code expresses this visibility difference:

    1. # Encoder: bidirectional visibility, input representations converge in one pass
    2. enc_mask = build_bidirectional_mask(seq_len_in)
    3. # Decoder: causal visibility, supports incremental generation and KV reuse
    4. dec_mask = build_causal_mask(seq_len_out)
    5. # Decoder-only: reading and writing share a causal mask, understanding is constrained by generation order
    6. unified_mask = build_causal_mask(seq_len_in + seq_len_out)

    Key takeaway: when a task requires “first understand a long input precisely, then generate under control,” the input representation quality from bidirectional encoding often beats a unified causal mask. In long-context generation, decoder-only models are prone to attention dilution: as generated content grows longer, the relative weight of early, critical input fragments gets spread thin.

    2. Asymmetric Compute Allocation: Spend the Budget on Understanding

    The encoder-decoder architecture allows the two sides to differ in size, for example a “large encoder + small decoder” configuration. This is very practical in engineering:

    • Retrieval-augmented generation (RAG): many retrieved fragments, each short; understanding-heavy and generation-light, so a large encoder pays off clearly;
    • Document summarization and structured extraction: long input, short output, so compute naturally tilts toward the encoder side;
    • Question answering and instruction following with context: a limited answer space, so the decoder does not need to be large.

    The pseudocode below shows this on-demand ratio:

    1. config = {
    2. "encoder": {"layers": 24, "hidden": 2048}, # understanding-heavy
    3. "decoder": {"layers": 8, "hidden": 1024}, # generation-light
    4. "share_vocab": True, # shared vocabulary on both sides reduces parameters and GPU memory
    5. }

    By contrast, in a decoder-only architecture the input and output share the same parameters and compute, making this kind of structural tilt hard to achieve.

    3. Low-Cost Architecture Migration: From Retraining to Weight Adaptation

    A common misconception is that an encoder-decoder model must be pretrained from scratch. In practice, the industry already has a mature adaptation path: take a fully trained decoder-only model and convert it into an encoder-decoder architecture through weight splitting, sharing, and retraining.

    This migration approach brings three kinds of benefits:

    1. Controllable training cost: no need to rerun full pretraining, only continued training during the adaptation stage;
    2. Reuse of existing engineering assets: vocabulary design, rotary position embeddings, attention and normalization implementations, and training stability experience can be reused directly;
    3. Flexible shape: the encoder and decoder can be scaled up or down independently per scenario.

    The adaptation flow can be summarized as:

    1. Trained decoder weights
    2. |- Copy/split into two sets of parameters for encoder and decoder
    3. |- Switch the encoder to bidirectional attention, keep the decoder causal
    4. |- Add cross-attention across the two sides, share vocabulary and embedding layers
    5. └─ Small-scale continued training + task alignment -> encoder-decoder model

    4. Capability Fusion: A Natural Fit for Long Context and Multimodal Input

    The encoder-decoder architecture is especially friendly to long inputs and multimodal inputs. The encoder can map text, image patches, audio frames, and more into a unified intermediate semantic representation, and the decoder faces only a single, already-fused semantic state, without repeatedly looking back at the original multi-source input during generation. Compared with mixing multimodal tokens and output tokens in the same causal sequence, this layered design is clearer for context management and GPU memory usage.

    General cloud capabilities that can be paired in engineering include object storage for raw corpora and model artifacts, message queues for decoupling data pipelines, container platforms for elastic inference, and logging services with monitoring and alerting to track latency and failure rates.

    5. Selection Guidance and Tuning Checklist

    Prefer encoder-decoder: input is far longer than output; strictly controlled generation is required; multi-source heterogeneous inputs must be fused; mature decoder weights already exist and a low-cost rebuild is desired.

    Prefer decoder-only: mainly open-ended generation and dialogue; pursuing simplicity in inference implementation and ecosystem; input and output lengths are similar.

    Tuning points:

    • Set the size of both sides based on the input/output length ratio, and avoid wasting resources on an oversized decoder;
    • Share the vocabulary and embedding layers to reduce parameter and GPU memory pressure;
    • Warm up cross-attention layers with small batches, then open up full fine-tuning;
    • Use input truncation and chunked encoding to control peak GPU memory for long documents;
    • Build per-task evaluation sets, and monitor understanding metrics and generation metrics separately.

    Conclusion

    The endpoint of the architecture debate is not one structure winning, but whether the structure matches the task’s read/write ratio. The encoder-decoder architecture trades separation of responsibilities for input understanding quality and certainty in compute allocation; the decoder-only architecture trades uniformity for implementation simplicity and ecosystem advantages. As long-document understanding, retrieval augmentation, and multimodal input continue to grow, the former remains a piece that should not be ignored. If an organization wants to deploy this kind of solution on Baidu AI Cloud, it can combine general container platforms, object storage, and monitoring and alerting capabilities to complete end-to-end engineering.