离散扩散模型是一种强大的新兴范式,用于代码生成。它们通过迭代地对部分损坏的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.
Evaluating, Understanding, and Improving Constrained Text Generation for Large Language Models
Wangxuan Institute of Computer Technology, Peking University(北京大学王选计算机研究所);Center for Data Science, Peking University(北京大学数据科学中心);The MOE Key Laboratory of Computational Linguistics, Peking University(北京大学教育部计算语言学重点实验室)
Diffusion Models for Non-autoregressive Text Generation: A Survey
Gaoling School of Artificial Intelligence, Renmin University of China(中国人民大学高瓴人工智能学院);School of Information, Renmin University of China(中国人民大学信息学院);Beijing Key Laboratory of Big Data Management and Analysis Methods(北京大数据管理与分析方法重点实验室)
Improved Paraphrase Generation via Controllable Latent Diffusion
National Key Laboratory for Novel Software Technology(计算机软件新技术国家重点实验室);Collaborative Innovation Center of Novel Software Technology and Industrialization(软件新技术与产业化协同创新中心);Nanjing University(南京大学)
Lookahead-then-Verify: Reliable Constrained Decoding for Diffusion LLMs under Context-Free Grammars
College of AI, Tsinghua University(清华大学人工智能学院);School of Computer Science, Peking University(北京大学计算机学院);School of Computer Science and Engineering, Beihang University(北航计算机科学与工程学院);School of Computer Science and Technology, Beijing Institute of Technology(北京理工大学计算机科学与技术学院);School of Computing, National University of Singapore(新加坡国立大学计算机学院)
NeuroLogic A*esque Decoding: Constrained Text Generation with Lookahead Heuristics
Allen Institute for Artificial Intelligence(艾伦人工智能研究所);Paul G. Allen School of Computer Science & Engineering, University of Washington(华盛顿大学保罗·G·艾伦计算机科学与工程学院)