Constrained Code Generation with Discrete Diffusion
Lize Shao, Michael Cardei, Zichen Xie, Ferdinando Fioretto, Wenxi Wang
NeurIPS page · Open on the map
Category: Diffusion & Image Generation › Discrete Diffusion Constrained Generation · Type: new method · Keywords: code generation, discrete diffusion, constraint satisfaction, program analysis, neurosymbolic inference
Areas: Code & Coding Agents › Code Generation and Optimization › Code Generation
Summary
CDC is a training-free neurosymbolic framework that integrates constraint satisfaction into discrete diffusion code generation to improve functional correctness, security, and syntax while requiring less corrective computation.
Explained to a 5-year-old
We want to make computer code that follows rules. A new way uses a step-by-step cleaning process that can check the code as it is being made. It looks at the code piece by piece and fixes it while making sure it works and is safe. This helps the code be correct and secure without needing extra training. It makes writing code easier and safer.
Explained to a 5-year-old, longer
When we ask a computer to write a program, we want it to be correct and safe. Old ways write code one piece at a time, but sometimes they make mistakes. A new idea treats code like a picture that can be cleaned step by step. At each cleaning step, the computer sees the whole picture and can check if the code follows the rules. It can fix parts that are wrong while keeping the rest similar to what it would have made. This checking happens without training a new model, just using the existing cleaning process. It helps the code be correct, secure, and syntactically right. The method also uses less extra work and changes only small parts. This makes generating code faster and more reliable. It works on many different coding tasks. It also helps when we need code that must not have bugs or security holes. Overall, it makes writing code easier for everyone.
For a technical reader
The paper proposes a way to guide a diffusion-based code generator so that the produced programs satisfy functional, security, and syntax constraints. It does this by adding constraint-aware operators to the denoising process that locate problematic regions and adjust them locally. These operators combine optimization and program analysis without requiring any additional training. As a result, the generated code is more reliable and needs fewer post-generation fixes. The approach also reduces computational overhead compared to baseline diffusion and autoregressive models.
Problem
Generating code that satisfies functional correctness, security, and syntax constraints is challenging, especially when using diffusion models that may produce invalid programs. Existing diffusion-based code generation methods lack a mechanism to enforce program-level constraints during the denoising process.
Method
The approach augments a discrete diffusion sampler with constraint-aware denoising operators that combine mathematical optimization and program analysis to identify constraint-relevant regions of the intermediate program state and locally adjust the denoising trajectory, steering generation toward feasible programs while staying close to the base diffusion model.
Results
The approach achieves higher functional correctness, security, and syntax compliance compared to discrete diffusion and autoregressive baselines while using less corrective computation and making more localized edits.
Contributions
A training-free neurosymbolic inference framework that integrates constraint satisfaction directly into the reverse denoising process of discrete diffusion, enabling constraint-aware generation without additional training.
Research questions this paper is counted under
This page was written by language models from the title and abstract of each paper, and the answers were checked by two other models. It can be wrong: check the paper itself. Suggest a correction