arXiv:2501.14723cs.LG2025-01被引 50

通过迭代测试与编辑,用多轮推理提升代码生成效果。

CodeMonkeys: Scaling Test-Time Compute for Software Engineering

  • 让模型边写代码边运行测试,反复优化修改方案。
  • 在SWE-bench数据集上解决57.4%的问题,耗资约2300美元。
  • 适合需要高精度代码修复的研究者和工程团队。

扩展测试时计算能力是提升大语言模型能力的有前景方向。然而,测试时计算可多种方式扩展,且有效融合不同方法仍是研究热点。本文在真实GitHub问题(SWE-bench数据集)背景下提出CodeMonkeys系统,允许模型通过联合生成与运行测试脚本,迭代修改代码库。针对每个问题,采样多条多轮修正轨迹,形成候选修改集合。该方法同时支持“串行”扩展(增加每条轨迹的迭代次数)与“并行”扩展(增加每题的轨迹数量)。通过并行扩展,可分摊前期成本,实现上下文检索:仅需让语言模型读取所有文件即可定位相关代码。最终通过模型生成的测试进行投票,并额外使用一轮多轮轨迹完成候选方案选择。整体在约2300美元预算下,成功解决SWE-bench Verified中57.4%的问题。该选择机制亦可用于整合多个来源的候选方案,对现有顶尖结果集成后达到66.2%准确率,超越其中任一单个模型表现。代码与数据已开源:https://scalingintelligence.stanford.edu/pubs/codemonkeys。

原文摘要 · Abstract (English)

Scaling test-time compute is a promising axis for improving LLM capabilities. However, test-time compute can be scaled in a variety of ways, and effectively combining different approaches remains an active area of research. Here, we explore this problem in the context of solving real-world GitHub issues from the SWE-bench dataset. Our system, named CodeMonkeys, allows models to iteratively edit a codebase by jointly generating and running a testing script alongside their draft edit. We sample many of these multi-turn trajectories for every issue to generate a collection of candidate edits. This approach lets us scale "serial" test-time compute by increasing the number of iterations per trajectory and "parallel" test-time compute by increasing the number of trajectories per problem. With parallel scaling, we can amortize up-front costs across multiple downstream samples, allowing us to identify relevant codebase context using the simple method of letting an LLM read every file. In order to select between candidate edits, we combine voting using model-generated tests with a final multi-turn trajectory dedicated to selection. Overall, CodeMonkeys resolves 57.4% of issues from SWE-bench Verified using a budget of approximately 2300 USD. Our selection method can also be used to combine candidates from different sources. Selecting over an ensemble of edits from existing top SWE-bench Verified submissions obtains a score of 66.2% and outperforms the best member of the ensemble on its own. We fully release our code and data at https://scalingintelligence.stanford.edu/pubs/codemonkeys.

代码生成测试时计算LLM自动化修复

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