Shall We Pretrain Autoregressive Language Models with Retrieval? A Comprehensive Study

Boxin Wang, Wei Ping, Peng Xu, Lawrence McAfee, Zihan Liu, Mohammad Shoeybi, Yi Dong, Oleksii Kuchaiev, Bo Li, Chaowei Xiao, Anima Anandkumar, Bryan Catanzaro

Introduction

Large Language Models (LLMs) like GPT-4 have revolutionized natural language processing by internalizing vast amounts of world knowledge within their parameters. However, this "black box" approach faces three critical challenges: efficiency, factuality, and staleness. To store more facts, models must grow exponentially in size, leading to high deployment costs. Furthermore, without a grounding mechanism, these models often hallucinate or provide outdated information.

While Retrieval-Augmented Generation (RAG) is commonly applied at the inference stage to mitigate these issues, it is often treated as an auxiliary component. This study investigates a more fundamental shift: integrating retrieval directly into the pretraining phase. By scaling the Retrieval-Enhanced TRansfOrmer (RETRO) architecture to 9.5 billion parameters, researchers demonstrate that baking retrieval into the model's foundation significantly improves factual accuracy, text quality, and parameter efficiency.

Methodology: Scaling RETRO and RETRO++

The core of this study revolves around the RETRO architecture, originally proposed by DeepMind and here refined by NVIDIA researchers. Unlike standard transformers, RETRO utilizes a chunk-wise retrieval mechanism.

Architecture and Retrieval Mechanism

Instead of retrieving information based on an entire prompt, RETRO decomposes text into 64-token chunks. It uses the preceding chunk to query a massive 330-billion-token database for the $k$-nearest neighbors. The architecture employs a frozen BERT model for chunk embedding and a trainable bidirectional encoder to process retrieved neighbors. The primary GPT-style decoder then incorporates this external context via chunk-wise cross-attention.

To address the "cold start" problem—retrieving for the very first chunk of a sequence—the authors implemented a "Left Padding" strategy. This ensures the model can leverage retrieval even when the initial context is minimal.

The RETRO++ Enhancement

The researchers introduced RETRO++, a hybrid approach designed for knowledge-intensive tasks like Question Answering. In RETRO++, the most relevant retrieved document is fed directly into the decoder (similar to standard RAG), while the RETRO encoder continues to process the broader set of evidence. This dual-pathway approach maximizes the utility of retrieved information.

Experimental Setup

The models were pretrained on a 330-billion-token corpus synthesized from 15 high-quality sources, including Wikipedia and CommonCrawl. The retrieval database consisted of 5.3 billion chunks derived from this same pretraining data. Evaluation spanned several benchmarks:

  • Language Modeling: Perplexity across various scales.
  • Open-Domain QA: Natural Questions (NQ) and TriviaQA.
  • Safety and Factuality: TruthfulQA, FACTUALITYPROMPTS, and REALTOXICTYPROMPTS.
  • Reasoning: Hellaswag and BoolQ.

Key Insights

1. Pretraining is Essential

A critical finding is that simply prepending retrieved text to a standard GPT model at inference time (without specific pretraining) can sometimes degrade performance. Models must be trained to distinguish between helpful evidence and retrieval noise. RETRO models learn this distinction during the pretraining phase, making them more robust.

2. Reduced Degeneration and Toxicity

RETRO models exhibit significantly less "degeneration" (repetitive loops) than standard GPTs. By anchoring generation in human-authored text from the database, the model maintains higher coherence. Furthermore, by utilizing a "clean" retrieval source like Wikipedia, RETRO can act as a safety filter, reducing the toxicity of generated outputs compared to standard models.

3. Scaling and Efficiency

Externalizing memory allows for superior parameter efficiency. A 9.5B RETRO model can match or outperform significantly larger standard GPT models. At the 9.5B scale, RETRO achieved a perplexity of 6.72, compared to 7.86 for a standard GPT of the same size.

Performance Results

  • Open-Domain QA: RETRO++ set new benchmarks, achieving an Exact Match (EM) score of 54.1 on Natural Questions. This significantly outperformed the original RETRO (45.5) and even surpassed RAG-tuned GPT models (50.9).
  • Factuality: On TruthfulQA, RETRO demonstrated higher resilience to common human falsehoods compared to standard GPT architectures.
  • Knowledge-Intensive Tasks: While RETRO showed parity with GPT on linguistic reasoning tasks, it demonstrated clear advantages in tasks requiring dense factual knowledge, such as Hellaswag and BoolQ.

Limitations and Future Directions

Despite its advantages, RETRO introduces new complexities. The model’s accuracy is strictly tied to the quality of its retrieval database; biased or incorrect source data will be reflected in the output. Additionally, the retrieval process increases the computational burden, adding approximately 25% more GPU hours to the pretraining phase.

Future work will likely explore scaling RETRO to the 50B–100B+ parameter range to determine if the retrieval advantage continues to widen at the frontier of model size.

Conclusion

This study provides compelling evidence that retrieval should not be an afterthought in LLM development. By integrating retrieval into pretraining, RETRO++ creates a more efficient, factual, and less toxic foundation model. As the industry seeks to move beyond simply increasing parameter counts, retrieval-enhanced pretraining offers a viable path toward more knowledgeable and reliable AI systems.

Summary updated

BibTeX
@inproceedings{wang2023shall,
  author = {Boxin Wang and Wei Ping and Peng Xu and Lawrence McAfee and Zihan Liu and Mohammad Shoeybi and Yi Dong and Oleksii Kuchaiev and Bo Li and Chaowei Xiao and Anima Anandkumar and Bryan Catanzaro},
  title = {{Shall We Pretrain Autoregressive Language Models with Retrieval? A Comprehensive Study}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2023},
  doi = {10.18653/v1/2023.emnlp-main.482},
}
Figure