TL;DR
Diffusion Language Models (DLMs) are naturally great at text infilling due to their bidirectional nature, but they traditionally require the length of the blank space to be fixed before generation. PILL (Probing-based InfiLling with preset-Length-free decoding) eliminates this limitation by using a lightweight probe to directly predict the missing span's length and decoding multiple candidate lengths in parallel. This approach achieves state-of-the-art infilling quality while running nearly twice as fast as previous iterative search baselines.
What Problem Does This Paper Address?
Infilling—generating missing text or code given a prefix and a suffix—is a notoriously difficult task for standard auto-regressive (left-to-right) language models because they cannot easily condition on the trailing text. Diffusion Language Models (DLMs) use bidirectional attention, making them a perfect fit for infilling.
However, DLMs have a major catch: you must specify the exact number of masked tokens before decoding begins. If your guess is slightly too short or too long, the generation quality degrades drastically.
Recent attempts at "adaptive-length decoding" try to solve this by iteratively adjusting the length during generation or searching for the best length using multi-step denoising confidence. Unfortunately, these methods suffer from two major flaws:
- Sensitivity to initialization: They require a preset initial length to start the search and often get trapped in local minima near that initial guess.
- Inference inefficiency: Iterative searching introduces massive computational overhead, requiring dozens of extra forward passes through the model.
Methods
The authors introduce PILL, a training-free framework for the DLM backbone that performs variable-length infilling using only two extra forward passes total. It operates in three distinct stages:
- Stage I: Length Probing: Instead of guessing a length, PILL inserts a single mask token
[M]between the prefix and suffix and runs a single forward pass. A lightweight, 3-layer MLP probe reads the bidirectional hidden state of this token to directly predict the target length ($\hat{L}$). To account for minor errors, this estimate is expanded into a small window of candidate lengths (e.g., $\hat{L} \pm 2$). - Stage II: Multi-slot Parallel Decoding: PILL decodes all candidate lengths simultaneously in a single sequence layout. By using a custom slot-wise attention mask, the candidates share the prefix/suffix context (saving KV-cache computation) but remain isolated from each other. Crucially, PILL uses position-ID interpolation to map tokens evenly across the gap, preventing the model from under-generating.
- Stage III: Post-hoc Selection: In one final forward pass, PILL evaluates all generated candidates using a specialized causal attention mask. It scores each option based on its internal coherence and how naturally it transitions into the suffix, selecting the highest-scoring candidate as the final output.
Datasets
The length probe was trained on auxiliary self-supervised datasets including Py150, LeetCode, CodeContests, and the C4 text corpus.
For evaluation, the authors tested PILL across eight benchmarks spanning code and natural language:
- Code: HumanEval-Infilling (single-line and multi-line), MBPP (single-line and multi-line), and MultiPL-E (Java and C/C++ splits).
- Text: WikiText and arXiv abstracts.
Key Insights and Ideas
- Contextual Hidden States are Highly Informative: The core "aha" moment is that a single mask token's hidden state in a bidirectional model already aggregates enough information from the surrounding prefix and suffix to accurately predict the length of what's missing.
- Position IDs Dictate Generation Behavior: The authors discovered that leaving position-ID gaps (common in left- or right-padded baseline designs) causes DLMs to under-generate because the model treats the extra IDs as empty space that still needs filling. Linearly interpolating position IDs across the gap completely resolves this structural issue.
- Parallelism Beats Iteration: Generating multiple length candidates in parallel via attention masking is computationally almost "free" compared to sequentially modifying lengths step-by-step.
Key Results
PILL was evaluated across five different DLMs (including LLaDA and Dream models) and consistently outperformed existing methods:
- Better Quality: Compared to CAL (the strongest baseline), PILL improved the average pass rate on code benchmarks by +4.8 points and boosted text generation by +6.0 BLEU-2.
- Substantial Speedups: PILL runs 1.82× faster than CAL. It adds less than 10% wall-clock overhead compared to a vanilla fixed-length baseline, whereas prior adaptive methods ballooned inference times by 94% to 117%.
Limitations and Future Work
While PILL is highly effective for single-span and basic multi-span infilling, the authors note several areas for future exploration:
- Complex Editing Scenarios: Real-world code refactoring often involves nested spans or repository-level dependencies, which PILL does not yet address.
- Scaling Verification: The experiments were bounded to models up to 7B/8B parameters due to hardware constraints. Verifying how the length probe scales to much larger diffusion backbones remains an open task.
Summary updated