Abstract
While decoder-only large language models (LLMs) have shown impressive results, encoder-decoder models are still widely adopted in real-world applications for their inference efficiency and richer encoder representation. In this paper, we study a novel problem: adapting pretrained decoder-only LLMs to encoder-decoder, with the goal of leveraging the strengths of both approaches to achieve a more favorable quality-efficiency trade-off. We argue that adaptation not only enables inheriting the capability of decoder-only LLMs but also reduces the demand for computation compared to pretraining from scratch. Through extensive experiments based on Gemma 2 (2B and 9B), we demonstrate that under similar inference budget, encoder-decoder LLMs achieve comparable pretraining performance but substantially better finetuning performance than their decoder-only counterparts.
Introduction
The current landscape of Large Language Models (LLMs) is dominated by decoder-only architectures, such as GPT-4 and Llama. While powerful, these models utilize the same causal attention mechanism for both input understanding and output generation, which can be inefficient. In contrast, encoder-decoder architectures (like T5) employ bidirectional attention in the encoder, allowing for a more comprehensive understanding of the input. Furthermore, they support asymmetrical configurations—such as a "heavy" encoder paired with a "light" decoder—to optimize inference speed. However, training high-performing encoder-decoder models from scratch is computationally expensive. This research explores "recycling" existing high-quality decoder-only models into encoder-decoder architectures through a process of adaptation.
Methodology: Encoder-Decoder Adaptation
The proposed framework initializes an encoder-decoder model using weights from pretrained decoder-only checkpoints, specifically the Gemma 2 family.
The adaptation involves several key steps:
- Architecture Alignment: The model maintains core Gemma 2 features like Rotary Embeddings (RoPE) but is split into distinct encoder and decoder components.
- Weight Initialization: The encoder is initialized directly from the decoder-only model. The decoder reuses the Feed-Forward Network (FFN) and self-attention layers.
- Bridging the Cross-Attention Gap: Since decoder-only models lack cross-attention layers, these are either initialized from existing self-attention weights or trained from scratch during a "warmup" phase.
- Training Objectives: The authors evaluated two primary strategies: PrefixLM (predicting the latter half of a sequence given the first half, enhanced by knowledge distillation from the original model) and UL2 (a mixture of denoising tasks).
Experimental Results and Key Insights
The models were adapted using up to 2 trillion tokens and evaluated across a wide range of benchmarks, including MMLU, GSM8K, and SuperGLUE.
Quality-Efficiency Trade-Off
A significant finding is the superior performance of the encoder-decoder inductive bias. Even with equivalent compute, the bidirectional nature of the encoder provides a better foundation for processing inputs than causal attention.
As shown in the figure above, the 9B-2B hybrid model (a 9B encoder paired with a 2B decoder) represents a major breakthrough. It achieves the high-quality reasoning of a 9B model while maintaining the low generation latency of a 2B model. Specifically, the adapted Gemma 2B-2B outperformed the standard Gemma 2B by approximately 7% on instruction-tuning benchmarks.
Superior Representations and Rapid Convergence
On the SuperGLUE benchmark, the adapted models showed substantial gains over their decoder-only predecessors, indicating that the encoder-decoder structure generates much richer internal text representations. Furthermore, the adaptation process is highly efficient; models reached performance parity with their ancestors after only a few tens of billions of tokens, a fraction of the original pretraining cost.
Conclusion
Adapting pretrained decoder-only LLMs into encoder-decoder architectures offers a more favorable quality-efficiency trade-off than training from scratch or sticking to decoder-only designs. This approach allows for flexible model combinations, like the 9B-2B hybrid, which optimizes for both understanding and generation speed. Future work will explore scaling these techniques to larger model families and investigating their potential in multimodal tasks such as vision-language modeling.
Summary updated