DiffuCoder: Understanding and Improving Masked Diffusion Models for Code Generation

Shansan Gong, Rui-Xiang Zhang, Huangjie Zheng, Jia-Tao Gu, N. Jaitly, Ling-Peng Kong, Yi-Zhe Zhang

arXiv:2506.20639 · 2026-11-15 공개 · arXiv · PDF

reinforcement-learning diffusion-models code-generation llm-training autoregressive masked-diffusion evalplus coupled-grpo

Abstract

Diffusion large language models (dLLMs) are compelling alternatives to autoregressive (AR) models because their denoising models operate over the entire sequence. The global planning and iterative refinement features of dLLMs are particularly useful for code generation. However, current training and inference mechanisms for dLLMs in coding are still under-explored. To demystify the decoding behavior of dLLMs and unlock their potential for coding, we systematically investigate their denoising processes and reinforcement learning (RL) methods. We train a 7B dLLM, \textbf{DiffuCoder}, on 130B tokens of code. Using this model as a testbed, we analyze its decoding behavior, revealing how it differs from that of AR models: (1) dLLMs can decide how causal their generation should be without relying on semi-AR decoding, and (2) increasing the sampling temperature diversifies not only token choices but also their generation order. This diversity creates a rich search space for RL rollouts. For RL training, to reduce the variance of token log-likelihood estimates and maintain training efficiency, we propose \textbf{coupled-GRPO}, a novel sampling scheme that constructs complementary mask noise for completions used in training. In our experiments, coupled-GRPO significantly improves DiffuCoder's performance on code generation benchmarks (+4.4\% on EvalPlus) and reduces reliance on AR bias during decoding. Our work provides deeper insight into the machinery of dLLM generation and offers an effective, diffusion-native RL training framework. https://github.com/apple/ml-diffucoder.

한국어 요약

한 줄 요약

DiffuCoder는 코드 생성을 위한 7B 규모의 디퓨전 언어 모델로, coupled-GRPO라는 새로운 RL 알고리즘을 통해 EvalPlus 벤치마크에서 +4.4% 성능 향상을 달성했다.

핵심 기여도

핵심 아이디어

기존 AR 모델과 달리, 디퓨전 언어 모델(dLLM)은 전체 시퀀스를 병렬적으로 반복적으로 정제하는 방식으로, 코드 생성에 유리한 글로벌 플래닝과 반복적 정제 기능을 제공한다. 그러나 dLLM의 decoding 메커니즘과 RL 학습 방법은 여전히 불확실하다. 본 연구는 dLLM의 decoding behavior를 분석하고, 이를 기반으로 diffusion-native RL 알고리즘을 설계하는 데 초점을 맞춘다.

핵심 통찰은 sampling temperature가 단순히 토큰 선택의 다양성뿐 아니라, 생성 순서에도 영향을 미친다는 점이다. 이는 RL rollout 시 샘플 다양성을 높여 최적의 생성을 유도할 수 있음을 시사한다. 이를 바탕으로 coupled-GRPO 알고리즘은 complementary mask noise를 사용해 token likelihood 추정의 분산을 줄이고, semi-AR decoding 없이도 학습 효율성을 유지한다.

기술적 접근법

주요 결과

의의 및 한계

DiffuCoder는 open-source dLLM으로, 코드 생성에서 AR 모델과 경쟁할 수 있는 성능을 보인다. coupled-GRPO는 dLLM의 비자율적 특성을 활용한 RL 학습 프레임워크로, 분산 감소와 학습 효율성 향상을 동시에 달성했다. 이는 디퓨전 모델의 학습 방법론을 확장하는 데 기여한다.

그러나 본 연구는 특정 코드 생성 벤치마크에만 초점을 맞춘 점이 한계이다. 또한, coupled-GRPO는 다른 태스크나 언어에 대한 일반화 가능성은 명시되지 않았으며, 더 큰 규모의 모델에서의 성능은 검증되지 않았다.

실용적 활용

DiffuCoder와 coupled-GRPO는 코드 생성, 자동 프로그래밍, 소프트웨어 개발 도구 등에 적용 가능하다. 특히, 병렬 생성과 반복적 정제가 필요한 복잡한 코드 생성 작업에서 효과적일 것으로 기대된다. 또한, open-source로 제공되므로, 연구자와 엔지니어가 dLLM 기반의 RL 학습 방법론을 탐구하는 데 활용할 수 있다.