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

DiffuCoder: Understanding and Improving Masked Diffusion Models for Code Generation

Shansan Gong, Ruixiang Zhang, Huangjie Zheng, Jiatao Gu, Navdeep Jaitly, Lingpeng Kong, Yizhe Zhang

In the world of Large Language Models (LLMs), the "left-to-right" autoregressive (AR) paradigm is king. But as any developer knows, writing code isn't a linear process; it involves global planning, jumping between functions, and iterative refinement. Masked Diffusion Models (MDMs) offer a compelling alternative by operating on the entire sequence at once.

A new paper, "DiffuCoder: Understanding and Improving Masked Diffusion Models for Code Generation," dives deep into the mechanics of these models. The researchers introduce DiffuCoder, a 7B-parameter diffusion LLM, and a novel reinforcement learning (RL) framework designed specifically for the "non-causal" nature of diffusion.

TL;DR

DiffuCoder is a 7B diffusion-based model that challenges the dominance of autoregressive models in code generation by refining entire sequences in parallel. The authors introduce coupled-GRPO, a novel RL sampling scheme that uses complementary masks to stabilize training, resulting in a 4.4% boost on the EvalPlus benchmark and significantly better performance during accelerated (fewer-step) decoding.

What Problem Does This Paper Address?

While diffusion models are theoretically better suited for tasks requiring global structure (like coding), they remain under-explored compared to their AR cousins. Specifically:

  1. Decoding Mystery: We don't fully understand how diffusion models actually "decide" which tokens to generate first.
  2. RL Inefficiency: Standard Reinforcement Learning from Human Feedback (RLHF) methods, like PPO or GRPO, are designed for AR models. Applying them to diffusion often results in high variance or forces the model back into a "semi-AR" block-decoding style, which defeats the purpose of using diffusion in the first place.
Non-linear code generation order in DiffuCoder

Methods

The authors trained DiffuCoder using a multi-stage pipeline: adaptation pre-training (130B tokens), mid-training, and instruction tuning. To improve the model further, they focused on two innovations:

  • AR-ness Metrics: They developed "Local" and "Global" autoregressive-ness metrics to quantify how much a model sticks to a left-to-right pattern versus jumping around the sequence.
  • Coupled-GRPO: This is the paper's core algorithmic contribution. Group Relative Policy Optimization (GRPO) usually requires estimating token log-likelihoods, which is computationally expensive and noisy in diffusion.
  • The "Coupled" Trick: Instead of random masking, they use pairs of complementary masks. If Mask A hides the first half of a code block, Mask B hides the second half.
  • The Benefit: This ensures every single token is evaluated at least once in a "realistic" partial-masking context during a training batch. Mathematically, this uses "antithetic variates" to drastically reduce the variance of the policy gradient.
DiffuCoder training pipeline and Coupled-GRPO sampling scheme

Datasets

  • Pre-training: 130B tokens from RefineCode and Stackv2, supplemented with text and math from Fineweb and DCLM.
  • Reinforcement Learning: 21K "hard" samples filtered from Acecoder-87K, featuring verifiable test cases.
  • Evaluation: A suite of standard benchmarks including HumanEval (+), MBPP (+), EvalPlus, and BigCodeBench (both Completion and Instruction subsets).

Key Insights and Ideas

  • The "Entropy Sink": The researchers discovered that even diffusion models have a natural bias toward predicting the "next" token (left-to-right) because language inherently has causal structure. They call this the "entropy sink"—the model is simply more confident about tokens immediately following a prefix.
  • Temperature Controls Order, Not Just Choice: In AR models, increasing sampling temperature just makes token choices more diverse. In DiffuCoder, higher temperature also diversifies the order in which tokens are generated, creating a much richer search space for RL to explore.
  • Code is Less Linear than Math: The analysis shows that while math generation remains highly autoregressive, code generation is more "global." DiffuCoder naturally learns to jump back and forth to refine code, much like a human programmer.
  • Parallelism via RL: By training with coupled-GRPO, the model actually becomes less dependent on AR bias. This makes it more robust when you reduce the number of decoding steps (e.g., cutting steps in half for a 2x speedup).

Key Results

  • Benchmark Superiority: DiffuCoder-Instruct with coupled-GRPO achieved a 67.9% on EvalPlus, outperforming its base version and showing a +4.4% improvement over standard instruction tuning.
  • Efficiency Gains: When decoding steps were halved (to speed up generation), the coupled-GRPO model experienced a significantly smaller performance drop compared to standard models.
  • Model Agnostic: The authors proved their method isn't just for DiffuCoder; applying coupled-GRPO to the Dream-7B model also yielded consistent performance gains on MBPP.

Limitations and Future Work

  • Compute Intensity: Even with the efficiency of coupled-GRPO, training and inferencing diffusion models remains more compute-heavy than AR models of the same parameter count.
  • Reasoning Chains: The current work focuses on direct code generation. The authors note that encouraging "long-chain reasoning" (like Chain-of-Thought) within a diffusion framework is a promising but currently unaddressed frontier.
  • Scaling: While 7B is a standard "workhorse" size, testing these diffusion-native RL methods on 70B+ models remains a task for future research.

Summary updated

BibTeX
@inproceedings{gong2026diffucoder,
  author = {Shansan Gong and Ruixiang ZHANG and Huangjie Zheng and Jiatao Gu and Navdeep Jaitly and Lingpeng Kong and Yizhe Zhang},
  title = {{DiffuCoder: Understanding and Improving Masked Diffusion Models for Code Generation}},
  booktitle = {International Conference on Learning Representations},
  year = {2026},
  url = {https://openreview.net/forum?id=58NA3unZj5},
}
Figure