用局部搜索框架逐步优化代码生成,效率与效果双提升。
Let's Revise Step-by-Step: A Unified Local Search Framework for Code Generation with LLMs
- 通过四步迭代流程:草稿、修改、评估、更新,实现代码逐步优化。
- 在多个任务上超越现有树搜索和改进型方法,显著提升生成质量。
- 适合需要高效精准代码生成的研究者与开发者使用。
大语言模型结合推理时扩展技术在代码生成中展现出潜力,但面临效率与可扩展性挑战。基于构建的树搜索方法存在树规模快速膨胀、令牌消耗高且缺乏随时可用性的问题;而基于改进的方法虽性能更优,却常受制于信息量不足的奖励信号和低效的搜索策略。本文提出 extbf{ReLoc},一个统一的局部搜索框架,用于实现分步代码修订。ReLoc 通过四个关键算法组件——初始代码草稿、邻域代码生成、候选评估与当前最优代码更新——探索一系列局部修订,每个组件均可通过特定决策规则实现不同局部搜索算法(如爬山法 HC、遗传算法 GA)。此外,我们设计了一种专用的修订奖励模型,基于修订距离评估代码质量,生成细粒度偏好以引导搜索向更有前景的候选方向发展。大量实验结果表明,该方法在多种代码生成任务中均取得卓越表现,显著优于基于构建的树搜索及当前最先进的改进型代码生成方法。
原文摘要 · Abstract (English)
Large Language Models (LLMs) with inference-time scaling techniques show promise for code generation, yet face notable efficiency and scalability challenges. Construction-based tree-search methods suffer from rapid growth in tree size, high token consumption, and lack of anytime property. In contrast, improvement-based methods offer better performance but often struggle with uninformative reward signals and inefficient search strategies. In this work, we propose \textbf{ReLoc}, a unified local search framework which effectively performs step-by-step code revision. Specifically, ReLoc explores a series of local revisions through four key algorithmic components: initial code drafting, neighborhood code generation, candidate evaluation, and incumbent code updating, each of which can be instantiated with specific decision rules to realize different local search algorithms such as Hill Climbing (HC) or Genetic Algorithm (GA). Furthermore, we develop a specialized revision reward model that evaluates code quality based on revision distance to produce fine-grained preferences that guide the local search toward more promising candidates. Finally, our extensive experimental results demonstrate that our approach achieves superior performance across diverse code generation tasks, significantly outperforming both construction-based tree search as well as the state-of-the-art improvement-based code generation methods.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。