arXiv:2506.10948cs.LG2025-06NeurIPS被引 12

让AI写代码时实时试运行,边写边修正,提升准确率。

Execution Guided Line-by-Line Code Generation

  • 生成代码时动态插入执行反馈信号,逐行引导
  • 在多种任务中超越传统方法,复杂题表现更优
  • 支持多智能体并行探索,适合挑战性编程场景

我们提出一种新型神经代码生成方法,将实时执行信号引入语言模型生成过程。尽管大语言模型在代码生成方面表现出色,但通常在推理时不利用执行反馈——这正是程序员常用的关键信号。我们的方法,执行引导的无分类器引导(EG-CFG),在生成过程中动态整合执行信号,提供逐行反馈以引导生成可执行的代码。该方法采用多阶段流程:首先通过束搜索对每行生成候选代码;其次,通过在测试用例上执行这些候选代码提取执行信号;最后,将这些信号融入后续生成的提示中。通过在同一线内保持信号一致性,并在行边界刷新信号,方法在保持语法结构的同时提供连贯指导。此外,该方法天然支持任务级别的并行性,多个智能体可并行探索不同推理路径,共同生成多样化的候选解。在多种编码任务上的实验表明,相较于标准方法,EG-CFG显著提升代码生成性能,在从基础问题到具有挑战性的竞赛编程和数据科学任务中均达到当前最优水平。代码已公开于:https://github.com/boazlavon/eg_cfg

原文摘要 · Abstract (English)

We present a novel approach to neural code generation that incorporates real-time execution signals into the language model generation process. While large language models (LLMs) have demonstrated impressive code generation capabilities, they typically do not utilize execution feedback during inference, a critical signal that human programmers regularly leverage. Our method, Execution-Guided Classifier-Free Guidance (EG-CFG), dynamically incorporates execution signals as the model generates code, providing line-by-line feedback that guides the generation process toward executable solutions. EG-CFG employs a multi-stage process: first, we conduct beam search to sample candidate program completions for each line; second, we extract execution signals by executing these candidates against test cases; and finally, we incorporate these signals into the prompt during generation. By maintaining consistent signals across tokens within the same line and refreshing signals at line boundaries, our approach provides coherent guidance while preserving syntactic structure. Moreover, the method naturally supports native parallelism at the task level in which multiple agents operate in parallel, exploring diverse reasoning paths and collectively generating a broad set of candidate solutions. Our experiments across diverse coding tasks demonstrate that EG-CFG significantly improves code generation performance compared to standard approaches, achieving state-of-the-art results across various levels of complexity, from foundational problems to challenging competitive programming and data science tasks. Our code is available at: https://github.com/boazlavon/eg_cfg

代码生成执行反馈大模型智能编程

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。