Improving Variable-Length Generation in Diffusion Language Models via Length Regularization

Zicong Cheng, Ruixuan Jia, Jia Li, Guo-Wei Yang, Meng-Hao Guo, Shi-Min HuarXiv 2026

TL;DR

Diffusion Language Models (DLLMs) excel at bidirectional text generation but struggle when the target text length is unknown, often leading to cut-off or repetitive outputs. This paper introduces LR-DLLM, a training-free inference framework that corrects an intrinsic length-induced bias in DLLM confidence scores using a simple logarithmic regularizer, enabling dynamic and highly reliable variable-length generation.

What Problem Does This Paper Address?

Traditional autoregressive language models generate text token-by-token from left to right until they hit an end-of-sequence ([EOS]) token, naturally adapting to variable lengths. Diffusion Large Language Models (DLLMs), on the other hand, generate text by iteratively denoising a fixed-length canvas. While this bidirectional nature makes them incredibly powerful for context-dependent tasks like fill-in-the-middle (FIM) infilling, it introduces a major flaw: they implicitly assume the target span length is known in advance.

If a user guesses a canvas length that is too short, the DLLM under-generates and cuts off; if it's too long, the model produces redundant, repetitive text. Simply trying multiple lengths and picking the one with the highest average model confidence doesn't work either. The authors discover that DLLMs suffer from an intrinsic length-induced bias: a model's raw confidence naturally drifts downward following a logarithmic curve as the mask length increases, completely independent of how well the text actually fits semantically.

Methods

To resolve this, the authors propose LR-DLLM (Length-Regularized DLLM), a completely training-free, model-agnostic decoding framework that treats generation length as an explicit inference variable. It operates in two distinct stages:

  1. Stage I (Initialization by Probing): The framework probes the underlying DLLM using a small set of exponentially spaced candidate mask lengths ($L \in \{1, 2, 4, 8, \dots\}$). By observing the raw confidence scores, it fits a linear model to estimate an instance-specific length bias coefficient ($\hat{k}$). It then subtracts this predictable bias to compute a calibrated length-confidence signal: $$\text{CL}(L) = \text{AVG}_{\text{conf}}(L) - \hat{k} \log L$$ The length that maximizes this calibrated signal is chosen as the initial guess.

  2. Stage II (Inference-Time Refinement): As decoding progresses, the framework performs a greedy local search at each step, evaluating whether expanding or contracting the remaining mask length by $\pm 1$ token improves the calibrated confidence score. Once a locally stable length is found, it materializes and commits the leftmost token, reduces the remaining mask length by one, and repeats the process.

Datasets

The authors evaluated LR-DLLM across several challenging benchmarks to test both infilling and general-purpose reasoning:

  • HumanEval-Infilling: A benchmark for evaluating code infilling capabilities across random, single-line, and multi-line spans.
  • McEval: A multilingual code evaluation benchmark covering four programming languages (Python, C++, JavaScript, Rust) to assess cross-language generalization.
  • GSM8K & MATH500: Standard datasets used to evaluate multi-step mathematical reasoning capabilities.
  • HumanEval: The classic text-to-code generation benchmark.

Key Insights and Ideas

  • The Logarithmic Bias Discovery: The core "aha moment" of the paper is demonstrating that average token confidence decreases predictably as a function of $\log L$.
Figure 1. Average confidence as a function of mask length L (log-scaled x-axis). The observed trend is well characterized by a logarithmic dependence (∝log 𝐿), while a linear fit provides a noticeably poorer approximation.

Using a statistical-physics perspective, the authors explain that a longer unconstrained generation space naturally yields a exponentially larger number of feasible token combinations (microstates), which inherently dilutes the model's per-token certainty.

  • Plug-and-Play Flexibility: Unlike prior variable-length methods that require expensive model retraining or specialized control tokens, LR-DLLM works entirely at inference time. It can be wrapped around any off-the-shelf DLLM without altering its weights or original language modeling capabilities.
  • Bidirectional Local Search is Crucial: Stage II's mid-span local adjustments act as a vital error-correction mechanism. It fixes local inconsistencies that emerge mid-generation (like drifting variables or broken control flows in code) rather than just relying blindly on the initial length guess.

Key Results

  • Code Infilling Superiority: On HumanEval-Infilling, LR-DLLM achieved a 51.3% Pass@1 using the DreamCoder-7B backbone, outperforming the training-based variable-length baseline, DreamOn, by +13.4%.
  • Robust Multilingual Generalization: On the McEval benchmark, LR-DLLM achieved a 51.5% average Pass@1 (+14.3% over DreamOn). The gains were most pronounced in the difficult multi-line infilling setting, where it more than doubled the baseline accuracy for languages like JavaScript and Rust.
  • General Reasoning Gains: On MATH500, LR-DLLM achieved a 50.8% relative improvement over the training-free baseline DAEDAL on LLaDA-8B, jumping from 26.4 to 39.8 accuracy by preventing incomplete derivations.
  • Low Overhead: Despite performing local length sweeps, the average number of additional forward calls per generated token remained low and bounded (typically between 3.4 and 5.2 calls), ensuring practical efficiency.

Limitations and Future Work

  • Greedy Local Search Risks: Although the inference overhead is small on average, the greedy hill-climbing strategy in Stage II can occasionally hit unstable local optima or long tails in highly complex generation scenarios, leading to rare outlier cases with higher computational costs.
  • Unidirectional Token Commitment: During Stage II, the framework shrinks the problem size by strictly committing tokens from the left boundary. This design choice partially restricts the fully non-autoregressive, parallel generation potential inherent to diffusion models during the final token-materialization step. The authors suggest exploring non-linear or multi-token commitment strategies in future work.

Summary updated

BibTeX
@misc{cheng2026improving,
  author = {Zicong Cheng and Ruixuan Jia and Jia Li and Guo-Wei Yang and Meng-Hao Guo and Shi-Min Hu},
  title = {{Improving Variable-Length Generation in Diffusion Language Models via Length Regularization}},
  year = {2026},
  eprint = {2602.07546},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2602.07546},
}
Figure