让大模型自己生成测试用例来发现代码漏洞,实现持续进化。
ACE: Self-Evolving LLM Coding Framework via Adversarial Unit Test Generation and Preference Optimization

- 用一个大模型交替生成代码和对抗性测试用例,主动挖掘运行时错误。
- 在多个评测集上比现有方法提升3%~7%的通过率,尤其对新场景效果更优。
- 无需真实答案或外部奖励模型,适合研究自进化编程系统的人参考。
大型语言模型在代码生成方面表现优异,但严重依赖大规模标注解法和基于验证的监督,限制了可扩展性并阻碍持续自我改进。现有求解器-验证器框架利用程序执行作为自动监督信号,但当求解器能力增强后,验证器生成的测试用例逐渐只确认语义正确性,难以暴露剩余缺陷。我们提出ACE,一种基于求解器-对抗者架构的自进化代码生成框架,通过以执行为中心的监督主动发现失败模式。单一LLM交替生成候选程序和优化的对抗性单元测试输入,旨在引发运行时错误、异常或非终止等执行级失败。监督信号仅来自执行结果:鲁棒程序用于有监督微调,对抗测试则通过基于执行偏好进行Kahneman-Tversky优化。整个训练流程无需真实代码或外部奖励模型。在CodeContests、MBPP和LiveCodeBench上的实验表明,ACE持续优于强基线,在pass@1上绝对提升3%~7%,在分布外基准上提升更大,同时保持竞争力或更高的推理效率。
原文摘要 · Abstract (English)
Large Language Models (LLMs) excel at code generation but remain heavily reliant on large-scale annotated solutions and verification-based supervision, which constrains scalability and hinders sustained self-improvement. Recent solver--verifier frameworks exploit program execution as an automatic supervision signal, but their effectiveness degrades as solvers become moderately strong: verifier-generated tests increasingly confirm semantic correctness rather than exposing the remaining failure modes. We propose \textbf{ACE}, a self-evolving code generation framework based on a solver--adversary architecture that prioritizes active failure discovery through execution-centric supervision. A single LLM alternates between generating candidate programs and producing adversarial unit test inputs optimized to induce execution-level failures, such as runtime errors, exceptions, or non-termination. Supervision is derived solely from execution outcomes: robust programs are selected for supervised fine-tuning, while adversarial tests are optimized via Kahneman--Tversky Optimization using execution-derived preferences. Notably, the entire training loop requires no ground-truth code or external reward models. Experiments on CodeContests, MBPP, and LiveCodeBench demonstrate that ACE consistently outperforms strong solver--verifier baselines, achieving 3--7\% absolute gains in pass@1, with larger improvements on out-of-distribution benchmarks, while maintaining competitive or improved inference efficiency.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。