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

Directional Diffusion-Style Code Editing Pre-training

Qingyuan Liang, Zeyu Sun, Qihao Zhu, Junhao Hu, Yifan Zhao, Yizhou Chen, Mingxuan Zhu, Guoqing Wang, Lu Zhang · DOI

Introduction

Software development is fundamentally an iterative process. Rather than writing complex systems from scratch in a single pass, developers continuously refine, fix, and update existing code snippets. This "code evolution" is characterized by intentional, fine-grained modifications that reflect developer intent. However, traditional code pre-training models often struggle to capture this evolutionary trajectory.

This paper introduces DivoT5, a novel pre-training framework that treats code editing as a "directional diffusion" process. By simulating the incremental nature of human coding, DivoT5 achieves state-of-the-art performance on code refinement and bug fixing, often outperforming models with significantly larger parameter counts.

The Problem: Static vs. Evolutionary Modeling

Existing models like CodeT5 or PLBART typically approach code editing through two primary lenses:

  1. Masked Language Modeling (MLM): Predicting missing tokens based on surrounding context.
  2. Denoising Auto-Encoding (DAE): Restoring a version of code that has been corrupted by random noise.

The authors argue that these methods fail to capture the "evolutionary direction" of code. Humans do not inject random noise into programs; they make specific, directional changes to move from a functional (or buggy) state to a desired state. Standard models often overlook the relationship between these versions, struggling with the token-level modifications that are essential for precise code editing.

Methodology: Directional Diffusion at the Data Level

The core innovation of DivoT5 is Directional Diffusion. Unlike traditional diffusion models in computer vision that add Gaussian noise to continuous embeddings, DivoT5 operates on discrete code tokens. It simulates the path from an initial state ("Old Code," $X_T$) to a final state ("New Code," $X_0$).

Pre-training Tasks

The framework employs four specialized tasks to ground the model in the evolutionary process:

  • Keep Span Mask: This task masks tokens that remain unchanged between versions, forcing the model to identify and preserve the stable parts of the codebase.
  • Random Mask with Evolutionary Direction: A sequence-to-sequence task that is grounded in the specific direction of the final edit.
  • DAE with Evolutionary Direction: This task introduces realistic "noise"—such as insertions, deletions, and replacements—to the old code, simulating the low-quality or buggy starting points developers often encounter.
  • Evolutionary Direction Reinforcement (EDR): Considered the "secret sauce" of the framework, EDR trains the model to transform any intermediate version ($X_t$) into the final version ($X_0$). This teaches the model the entire trajectory of a multi-step edit rather than just the start and end points.

Crucially, while the training is inspired by diffusion, the inference remains a single-pass auto-regressive process. This ensures that DivoT5 is as computationally efficient as a standard Transformer model, avoiding the high inference costs typically associated with multi-step denoising.

Experimental Setup

Datasets

The authors utilized CodeChangeNet and CommitPack-Java, totaling approximately 5.2 million instances. By extracting intermediate evolution steps using diff tools, they expanded the training set to nearly 9 million samples.

Evaluation Scenarios

The model was evaluated across three distinct scenarios:

  1. NL-guided editing: Tasks like CodeReview and BugFixing.
  2. Code-only editing: Code Refinement and code-only versions of CodeReview.
  3. Generalization (Non-editing): Code Translation (e.g., Java to C#).

Key Results and Insights

DivoT5-base (220M parameters) demonstrated remarkable efficiency and performance:

  • Superiority over Baselines: On the CodeReview task, DivoT5 achieved a 29% relative gain in Exact Match (EM) score over CodeT5-base (increasing from 34.46% to 44.41%).
  • Outperforming Large Language Models (LLMs): Despite its smaller size, DivoT5-base outperformed DeepSeekCoder-6.7B, Llama-3-8B, and ChatGPT (GPT-3.5) in few-shot settings for specific code-editing tasks.
  • Parameter Efficiency: The 60M parameter version (DivoT5-small) outperformed the 220M parameter CodeT5-base on several benchmarks, suggesting that the quality of the pre-training task is more critical than raw parameter count for specialized editing tasks.

The Importance of Trajectory

The research highlights that modeling the path of an edit is more effective than simply showing the model the "before" and "after" states. By focusing on token-level granularity rather than line-level diffs, DivoT5 captures the subtle modifications that define real-world development.

Limitations and Future Work

While DivoT5 excels at fine-grained edits, the authors note several areas for future exploration:

  • Scaling: Future work will investigate whether the benefits of directional diffusion hold as the model scales beyond 220M parameters.
  • Input-Output Gaps: The advantage of this approach is less pronounced in tasks where there is a massive gap between input and output, such as generating complex logic from a brief natural language prompt.
  • Structural Refactoring: The model is currently optimized for localized changes; high-level architectural refactoring remains a challenge for future iterations.

Summary updated

BibTeX
@article{liang2025directional,
  author = {Qingyuan Liang and Zeyu Sun and Qihao Zhu and Junhao Hu and Yifan Zhao and Yizhou Chen and Mingxuan Zhu and Guoqing Wang and Lu Zhang},
  title = {{Directional Diffusion-Style Code Editing Pre-training}},
  journal = {IEEE Transactions on Software Engineering},
  year = {2025},
  url = {https://openreview.net/forum?id=RxzC6uMJG9},
}
Figure