{"about":{"site":"https://codewithpapers.app","non_affiliation":"Code with Papers and Syntology are not affiliated with, endorsed by, or sponsored by Papers with Code, Meta, or the pwc-archive mirror.","licence":"CC BY-SA 4.0","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","attribution":"https://codewithpapers.app/attribution","modified":"archive material modified by Syntology; see the attribution page"},"url":"/paper/diffucoder-understanding-and-improving-masked","title":"DiffuCoder: Understanding and Improving Masked Diffusion Models for Code Generation","arxiv_id":"2506.20639","date":"2025-06-25","proceeding":null,"authors":["Shansan Gong","Ruixiang Zhang","Huangjie Zheng","Jiatao Gu","Navdeep Jaitly","Lingpeng Kong","Yizhe Zhang"],"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 causal 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.","url_abs":"https://arxiv.org/abs/2506.20639v1","url_pdf":"https://arxiv.org/pdf/2506.20639v1.pdf","source":{"archive":"pwc-archive (Hugging Face), CC BY-SA 4.0","snapshot":"2025-07-28","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","row_kind":"abstracts"},"code_links":[{"paper_slug":"diffucoder-understanding-and-improving-masked","repo_url":"https://github.com/apple/ml-diffucoder","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok","spdx":"NOASSERTION"}}],"tasks":[{"task_slug":"code-generation","task_name":"Code Generation"},{"task_slug":"denoising","task_name":"Denoising"},{"task_slug":"reinforcement-learning-1","task_name":"Reinforcement Learning (RL)"}],"methods":[],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2506.20639","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2506.20639"}},"developers":"https://syntology.ai/developers","read_at":"2026-09-24T18:15:14+00:00","read_at_is":"when the build read Syntology's graph, not when any sample ran","claim":"Per-sample execution status on synthesized fixtures; not a correctness claim about the paper. Samples come from repositories linked to the paper, official or community; repo_kind says which.","repos":[{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/apple/ml-diffucoder","reach":{"status":"ok","spdx":"NOASSERTION"}}],"summary":{"ran":2,"unverified":5},"by_repo_kind":{"official":{"samples":7,"ran":2,"repositories":1}},"repo_kind_vocabulary":{"official":"The archive marks this repository official for the paper","named_in_paper":"The archive records that the paper mentions this repository; it is not marked official","listed":"In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper","found_in_text":"Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted","community":"Not in the archive's code links for this paper; a community repository Syntology harvested"},"n_pointer_only_for_licence":7,"samples":[{"code_sha256_prefix":"ce353d566f3f2c9f","entry":"format_reward","repo":"apple/ml-diffucoder","repo_kind":"official","path":"src/open_r1/rewards.py","file_url":"https://github.com/apple/ml-diffucoder/blob/HEAD/src/open_r1/rewards.py","link_basis":"harvester_set","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"ce353d566f3f2c9f"}},{"code_sha256_prefix":"0a5673b11c91e69d","entry":"tag_count_reward","repo":"apple/ml-diffucoder","repo_kind":"official","path":"src/open_r1/rewards.py","file_url":"https://github.com/apple/ml-diffucoder/blob/HEAD/src/open_r1/rewards.py","link_basis":"harvester_set","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"0a5673b11c91e69d"}},{"code_sha256_prefix":"d345b73199f35a01","entry":"get_provider","repo":"apple/ml-diffucoder","repo_kind":"official","path":"src/open_r1/utils/code_providers.py","file_url":"https://github.com/apple/ml-diffucoder/blob/HEAD/src/open_r1/utils/code_providers.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NOASSERTION","inline_ok":false,"mcp_get_code":{"code_sha256":"d345b73199f35a01"}},{"code_sha256_prefix":"f32a6b72ed50b5fa","entry":"main","repo":"apple/ml-diffucoder","repo_kind":"official","path":"recipes/process_data.py","file_url":"https://github.com/apple/ml-diffucoder/blob/HEAD/recipes/process_data.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NOASSERTION","inline_ok":false,"mcp_get_code":{"code_sha256":"f32a6b72ed50b5fa"}},{"code_sha256_prefix":"e573a98030dedd8d","entry":"selective_log_softmax","repo":"apple/ml-diffucoder","repo_kind":"official","path":"src/open_r1/coupled_grpo.py","file_url":"https://github.com/apple/ml-diffucoder/blob/HEAD/src/open_r1/coupled_grpo.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NOASSERTION","inline_ok":false,"mcp_get_code":{"code_sha256":"e573a98030dedd8d"}},{"code_sha256_prefix":"0fa983fc585a3b51","entry":"split_tensor_dict","repo":"apple/ml-diffucoder","repo_kind":"official","path":"src/open_r1/coupled_grpo.py","file_url":"https://github.com/apple/ml-diffucoder/blob/HEAD/src/open_r1/coupled_grpo.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NOASSERTION","inline_ok":false,"mcp_get_code":{"code_sha256":"0fa983fc585a3b51"}},{"code_sha256_prefix":"2efaae630544ffa2","entry":"transform_question_format","repo":"apple/ml-diffucoder","repo_kind":"official","path":"recipes/process_data.py","file_url":"https://github.com/apple/ml-diffucoder/blob/HEAD/recipes/process_data.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NOASSERTION","inline_ok":false,"mcp_get_code":{"code_sha256":"2efaae630544ffa2"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}