NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Diffusion is a code repair operator and generator

Mukul Singh, Gust Verbruggen, Vu Le, Sumit GulwaniarXiv 2025

Abstract

Code diffusion models generate code by iteratively removing noise from the latent representation of a code snippet. During later steps of the diffusion process, when the code snippet has almost converged, differences between discrete representations of these snippets look like last-mile repairs applied to broken or incomplete code. We evaluate the extent to which this resemblance can be exploited to leverage pre-trained code diffusion models for the problem of last-mile repair by considering two applications with significant potential. First, we can leverage the diffusion model for last-mile repair by adding noise to a broken code snippet and resuming the diffusion process. Second, we can leverage the diffusion model to generate arbitrary amount of training data for last-mile repair tasks (that are computationally more efficient) by sampling an intermediate program (input) and the final program (output) from the diffusion process. We perform experiments on 3 domains (Python, Excel and PowerShell) to evaluate applications, as well as analyze properties.

Introduction

In the world of software development, "last-mile repair" refers to fixing the small syntax errors or minor bugs that prevent a nearly finished code snippet from compiling or running. While Large Language Models (LLMs) like GPT-4 are proficient at this, they often require massive compute and can struggle with "long-tail" errors that are underrepresented in their training data.

Furthermore, training specialized repair models is difficult because high-quality datasets of "broken code vs. fixed code" are scarce. Existing methods usually rely on synthetic errors—like randomly deleting a bracket—which do not always resemble the mistakes real humans make. This research investigates whether the iterative nature of diffusion models can provide a more natural way to both fix code and generate training data.

Methodology

The authors leverage CodeFusion, a latent diffusion model. Unlike auto-regressive models that generate code token-by-token from left to right, diffusion models start with a "blur" of noise and iteratively refine it into a clean code snippet. The paper proposes two novel applications for this architecture:

1. Diffusion as a Repair Operator

Instead of starting from pure noise, the researchers take a broken code snippet, convert it into a latent representation, add a controlled amount of Gaussian noise at a specific timestep $t$, and then let the diffusion model "denoise" it back to a functional state. This treats the broken code as a late-stage noisy version of the target code.

An example of a 'broken' Excel formula representing a late-stage diffusion state.

2. Diffusion as a Data Generator

By sampling intermediate steps of a standard code generation process, the authors can create pairs of (broken, fixed) code. Because the diffusion process refines code globally rather than just swapping single tokens, the resulting errors are more complex and diverse than those produced by rule-based systems.

The corresponding 'clean' Excel formula ($x_0$) after the diffusion process completes.

Experimental Results

The researchers evaluated their approach across three distinct domains: Excel formulas, PowerShell commands, and Python snippets.

Key findings include:

  • Direct Repair Performance: Despite having only 60 million parameters, the pre-trained CodeFusion model outperformed the much larger Codex on Python (+8%) and PowerShell (+11%) repair tasks.
  • Synthetic Data Superiority: Models fine-tuned on diffusion-generated data consistently beat those trained on data from GPT-4o or rule-based systems. A CodeT5+ model trained on diffusion data achieved a 91.1% execution match on Python repair.
  • Optimal Noise Timing: The "optimal" time to inject noise depends on the language. Simple Excel formulas benefit from noise injected late in the process, while complex Python logic requires earlier injection to allow the model more "time" to restructure the code.

Limitations and Future Work

While promising, the model currently operates "blindly," without access to compiler error messages or unit test results. It repairs code based purely on the syntactic "look and feel." Additionally, the experiments were limited to short snippets (up to 128 tokens). Future work could involve "controlled decoding," where the model is guided by external feedback to stay closer to the user's original intent.

Conclusion

By treating the denoising process as a repair operator or a synthetic data generator, researchers have demonstrated that diffusion models are remarkably effective at "last-mile" code repair, often outperforming much larger models through more natural error modeling and global refinement.

Summary updated

BibTeX
@misc{singh2025diffusion,
  author = {Mukul Singh and Gust Verbruggen and Vu Le and Sumit Gulwani},
  title = {{Diffusion is a code repair operator and generator}},
  year = {2025},
  eprint = {2508.11110},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2508.11110},
}
Figure