xLM: A Python Package for Non-Autoregressive Language Models

Dhruvesh Patel, Durga Prasad Maram, Sai Sreenivas Chintha, Benjamin Rozonoyer, Andrew McCallum

TL;DR

XLM is a new Python framework designed to bring order to the "wild west" of non-autoregressive language models (NARLMs). By providing a unified, modular architecture built on PyTorch Lightning and Hydra, it allows researchers to implement, compare, and share diverse models—like diffusion and insertion models—without rewriting boilerplate code from scratch.

What Problem Does This Paper Address?

In the world of AI, Autoregressive Language Models (ARLMs)—the ones that predict text one token at a time from left to right—are the gold standard. Because they are so dominant, we have excellent, standardized libraries like Hugging Face transformers to build them.

However, there is a growing interest in Non-Autoregressive Language Models (NARLMs). These models might generate text by filling in blanks (diffusion), inserting tokens at arbitrary positions, or editing existing text. They offer the potential for much faster inference and better quality on specific tasks like planning. The problem? Every new NARLM paper usually comes with its own "bespoke" codebase. Data loading, loss functions, and prediction logic are often hard-coded and incompatible with other models. This makes it incredibly difficult for researchers to perform fair "apples-to-apples" comparisons or reuse components across different methods.

Methods

The authors introduce xlm-core, a library built on three pillars: PyTorch (for deep learning), PyTorch Lightning (for training workflows), and Hydra (for complex configuration management).

The framework is built on several clever design principles:

  • Maximal Independence: Each model implementation lives in its own isolated folder. This prevents "spaghetti code" where changing one model accidentally breaks another.
  • Composition over Inheritance: Instead of building massive, complex class hierarchies, XLM uses a "Harness" that plugs in specific Model, LossFunction, and Predictor components. You can swap a loss function in a config file without touching a single line of Python.
  • Copy over Branching: In a move that might surprise traditional software engineers, the authors advocate for copying code templates when starting a new model. This "scaffolding" approach ensures that research code remains self-contained and easy to share without requiring deep refactoring of the core library.
  • Arbitrary Code Injection: Using Hydra, the library can instantiate entire Python classes directly from YAML configuration files, allowing for extreme flexibility at runtime.

Datasets

The paper demonstrates the library's utility using two main types of benchmarks:

  1. Star Graphs (StarEasy, StarMedium, StarHard): These are synthetic "path-finding" tasks where a model must generate a valid path between nodes in a graph. These are excellent for testing a model's ability to plan and maintain global structure.
  2. LM1B (One Billion Word Benchmark): A standard large-scale corpus of news domain text used to evaluate general unconditional language modeling.
  3. OpenWebText: Mentioned as a benchmark for evaluating small language model performance.

Key Insights and Ideas

  • Standardizing the Non-Standard: The biggest "aha moment" is that even though NARLMs look very different (e.g., a diffusion model vs. an insertion model), they share a common lifecycle. By abstracting the "Harness" (the execution logic) away from the "Model" (the neural net), XLM makes these diverse approaches comparable.
  • The Scaffolding Workflow: The library includes a command (xlm-scaffold) that automatically generates the directory structure and placeholder files for a new model. This lowers the barrier to entry for researchers who want to experiment with a new idea quickly.
  • Configuration as Code: By leaning heavily on Hydra, the authors move the complexity of model setup out of the Python scripts and into readable YAML files. This makes experiments more reproducible and easier to manage.

Key Results

The authors used XLM to reproduce results for several state-of-the-art models, including Masked Diffusion (MDLM), Masked Language Models (MLM), and Insertion Language Models (ILM).

  • Fidelity: The XLM implementations matched the results reported in the original research papers within a 2% margin, proving the framework is robust.
  • Performance on Planning: In the Star Graph tasks, the Insertion Language Model (ILM) significantly outperformed standard autoregressive models on "Hard" graphs (97.5% sequence accuracy vs. 25.2% for ARLM), highlighting why NARLMs are worth studying.
  • Unified Benchmarking: The paper provides a clear table (Table 2) comparing negative log-likelihood and entropy across different NARLM architectures on the same dataset—a feat that was previously a major engineering headache.

Limitations and Future Work

While XLM is a powerful tool for research, the authors note a few areas for growth:

  • Model Scope: The library is currently geared toward "small" non-autoregressive models. Scaling these techniques to multi-billion parameter models remains a challenge for the broader field.
  • Expanding Modalities: Currently focused on text, the authors plan to add support for non-text sequences, such as molecule generation.
  • Newer Architectures: They plan to integrate even newer methods like "Edit Flows" and optimize performance using FlexAttention (introduced in PyTorch 2.5), which allows for faster attention mechanisms with arbitrary masks—a feature particularly useful for the irregular generation patterns of NARLMs.

Summary updated

Abstract

In recent years, there has been a resurgence of interest in non-autoregressive text generation in the context of general language modeling. Unlike the well-established autoregressive language modeling paradigm, which has a plethora of standard training and inference libraries, implementations of non-autoregressive language modeling have largely been bespoke making it difficult to perform systematic comparisons of different methods. Moreover, each non-autoregressive language model typically requires it own data collation, loss, and prediction logic, making it challenging to reuse common components. In this work, we present the XLM python package, which is designed to make implementing small non-autoregressive language models faster with a secondary goal of providing a suite of small pre-trained models (through a companion xlm-models package) that can be used by the research community. The code is available at https://github.com/dhruvdcoder/xlm-core.
BibTeX
@inproceedings{patel2026xlm,
  author = {Dhruvesh Patel and Durga Prasad Maram and Sai Sreenivas Chintha and Benjamin Rozonoyer and Andrew McCallum},
  title = {{xLM: A Python Package for Non-Autoregressive Language Models}},
  booktitle = {EACL (System Demonstrations)},
  year = {2026},
  doi = {10.18653/v1/2026.eacl-demo.31},
}
Figure