Abstract: Historically, LLMs have been trained using either autoregressive (AR) or masked language modeling (MLM) objectives, with AR models gaining dominance in recent years. However, AR models are inherently incapable of masked infilling, which is the ability to predict masked tokens between past and future context. In contrast, MLM models suffer from intrinsic computational inefficiencies during both training and inference that hinder their scalability. This work introduces MARIA (Masked and Autoregressive Infilling Architecture), a novel approach that leverages the strengths of both paradigms to achieve state-of-the-art masked infilling performance. MARIA combines a pre-trained MLM and AR model by training a linear decoder that takes their concatenated hidden states as input. This minimal modification enables the AR model to perform infilling while retaining its inherent advantages in terms of faster inference with KV caching. Our results demonstrate that MARIA significantly outperforms existing methods, namely discrete diffusion models, on masked infilling tasks.
Introduction
The landscape of Large Language Models (LLMs) has long been divided by two primary training objectives: Autoregressive (AR) modeling and Masked Language Modeling (MLM). AR models, such as the GPT series, excel at generative tasks by predicting the next token based on preceding context. Their architecture allows for efficient inference through Key-Value (KV) caching. Conversely, MLM models like BERT are designed for bidirectional understanding, making them naturally adept at "filling in the blanks" or text infilling. However, MLMs lack the generative efficiency of AR models and do not scale as effectively for long-form generation.
As applications like interactive code completion and document editing demand high-quality infilling, the limitations of standard AR models—which are "blind" to future context—become apparent. While techniques like Fill-in-the-Middle (FIM) or discrete diffusion have been proposed, they often introduce significant computational overhead or are limited to simple infilling scenarios. This paper presents MARIA (Masked and Autoregressive Infilling Architecture), a hybrid approach that grants AR models bidirectional vision without sacrificing their generative speed.
The MARIA Architecture
MARIA achieves the "best of both worlds" by integrating a frozen, pre-trained MLM with a frozen, pre-trained AR model. The core innovation lies in the fusion of their internal representations.
The process involves three main components:
- Frozen Base Models: MARIA utilizes existing high-performance models, such as ModernBERT (MLM) and OLMo (AR). By keeping these models frozen, the approach avoids the massive computational cost of retraining.
- Hidden State Concatenation: For a given sequence with masked tokens, the MLM processes the entire sequence (including future context), while the AR model processes the sequence up to the current token. Their respective hidden states are then concatenated.
- Linear Decoder: A lightweight linear layer is trained to map these combined hidden states to the vocabulary space, predicting the masked tokens.
This architecture allows the MLM to act as a "look-ahead" mechanism, providing the AR model with the necessary context to perform accurate infilling. Crucially, because the AR component remains linear in its generation, MARIA can leverage standard KV caching, ensuring that inference remains fast.
Training and Initialization
To optimize the training of the linear decoder, the researchers introduced a "Product of Experts" initialization strategy. By initializing the linear layer such that its initial outputs approximate the average of the two base models' predictions, the training process converges significantly faster than with random initialization. This strategy allows the model to start from a high baseline of linguistic competence, focusing training on the nuances of fusion rather than basic language understanding.
Experimental Results
MARIA was evaluated across multiple benchmarks, including WikiText, LM1B, and ArXiv papers, focusing on perplexity and generation quality.
Infilling Quality and Human Preference
To assess the fluency and coherence of the generated text, the authors employed an "LLM Judge" (GPT-4o-mini) to calculate ELO scores. This metric compares MARIA's outputs against ground truth text and other baselines like SMDM (discrete diffusion) and DiffuLlama.
As shown in the evaluation, MARIA 7B and 1B achieved the highest ELO scores, indicating that their infilling is perceived as more coherent and stylistically consistent than specialized diffusion models. In some instances, the MARIA 7B model even surpassed the ground truth text in perceived quality.
Efficiency and Throughput
A key advantage of MARIA is its inference speed. In throughput tests (tokens per second), MARIA 1B outperformed all other tested models, including standalone MLMs and diffusion models. The overhead of the single MLM pass is minimal compared to the efficiency gains provided by the AR model's KV caching during the generation of the infilling block.
Conclusion
MARIA demonstrates that state-of-the-art infilling performance does not require a complete architectural overhaul. By cleverly fusing existing AR and MLM models, MARIA provides a scalable, efficient, and high-quality solution for bidirectional text generation. Future work may explore optimizing the MLM pass further or applying this fusion technique to domain-specific models for code or biological sequences.
Summary updated