arXivDaily arXiv每日学术速递 周一至周五更新
感恩节,周五至周末无更新,大家顺遂。周一再来吧
arXiv 2605.16829cs.CLcs.PL
收藏

带有离散扩散的约束代码生成

Constrained Code Generation with Diffusion Language Models

University of Virginia(弗吉尼亚大学)

Lize Shao, Michael Cardei, Zichen Xie, Ferdinando Fioretto, Wenxi Wang

AI总结:

本文提出了一种无需训练的神经符号推理框架CDC,通过将约束满足直接整合到反向去噪过程中,提升代码生成中功能正确性、安全性和语法的约束满足能力。

摘要:

离散扩散模型是一种强大的新兴范式,用于代码生成。它们通过迭代地对部分损坏的token序列进行细化来构建程序,并能够并行地细化token。重要的是,这种范式在每次去噪步骤中暴露了全局程序状态,这为强制执行程序级功能和安全约束提供了自然的干预点,从而在最终代码提交前指导生成。基于这一观察,本文引入了Constrained Diffusion for Code (CDC),一种无需训练的神经符号推理框架,它将约束满足直接整合到反向去噪过程中。CDC在基础离散扩散采样器上增加了具有约束意识的去噪运算符,这些运算符结合数学优化与程序分析,以识别中间程序状态中与约束相关的区域,并在本地调整去噪轨迹,使生成过程朝向可行的程序发展,同时保持接近基础模型。在代码生成基准测试中,CDC在功能正确性、安全性和语法方面一致提高了约束满足能力,优于离散扩散和自回归基线,使用更少的纠正计算和更局部的编辑。

英文摘要:

Diffusion language models (DLMs) are a powerful, emerging paradigm for code generation. They construct programs through iterative refinement of partially corrupted token sequences and enable parallel token refinement. Importantly, this paradigm exposes a global program state at each denoising step, which provides a natural intervention point for enforcing program-level functionality and security constraints, guiding the generation before the final code is committed. Building on this observation, the paper introduces Constrained Diffusion for Code (CDC), an inference-time neurosymbolic framework that integrates constraint satisfaction directly into the reverse denoising process without retraining the base diffusion model. CDC augments the base diffusion sampler with constraint-aware denoising operators that combine mathematical optimization with program analysis to identify constraint-relevant regions of the intermediate program state and locally adjust the denoising trajectory, steering generation toward feasible programs while remaining close to the base model. Across code generation benchmarks, CDC consistently improves constraint satisfaction in functional correctness, security, and even syntax, outperforming diffusion and autoregressive baselines with less corrective computation and more localized edits.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑