Diffusion On Syntax Trees For Program Synthesis
Shreyas Kapur, Erik Jenner, Stuart Russell
TL;DR
This work tackles the lack of runtime feedback in autoregressive code generation by introducing diffusion operating on syntax trees. It defines a forward process of small, grammar-constrained mutations and trains a conditional denoiser to invert these edits, complemented by a tree-edit-path training target to produce meaningful refinements. A value network guides search, enabling beam search to efficiently navigate the program space, and the system is demonstrated on inverse-graphics tasks across CFG-based languages like CSG2D and TinySVG. Empirically, the approach outperforms autoregressive and REPL-based baselines in both repair accuracy and efficiency, while maintaining syntactic validity throughout generation. The work highlights a promising direction for neural program synthesis that integrates feedback from program outputs with structured search, albeit within a narrow DSL scope and with future potential to scale to broader programming domains.
Abstract
Large language models generate code one token at a time. Their autoregressive generation process lacks the feedback of observing the program's output. Training LLMs to suggest edits directly can be challenging due to the scarcity of rich edit data. To address these problems, we propose neural diffusion models that operate on syntax trees of any context-free grammar. Similar to image diffusion models, our method also inverts ``noise'' applied to syntax trees. Rather than generating code sequentially, we iteratively edit it while preserving syntactic validity, which makes it easy to combine this neural model with search. We apply our approach to inverse graphics tasks, where our model learns to convert images into programs that produce those images. Combined with search, our model is able to write graphics programs, see the execution result, and debug them to meet the required specifications. We additionally show how our system can write graphics programs for hand-drawn sketches.
