Aligning the Objective of LLM-based Program Repair

📄 arXiv: 2404.08877v5 📥 PDF

作者: Junjielong Xu, Ying Fu, Shin Hwei Tan, Pinjia He

分类: cs.SE, cs.CL, cs.LG

发布日期: 2024-04-13 (更新: 2025-02-21)

备注: Accepted by ICSE'25


💡 一句话要点

提出D4C框架以解决LLM程序修复中的目标对齐问题

🎯 匹配领域: 支柱九:具身大模型 (Embodied Foundation Models)

关键词: 大型语言模型 程序修复 自动化修复 目标对齐 D4C框架 故障定位 机器学习

📋 核心要点

  1. 现有的LLM程序修复方法在目标对齐和故障定位方面存在不足,限制了其修复能力。
  2. 论文提出通过对齐LLM的输出与训练目标,允许其直接修复整个程序,而非先定位故障。
  3. D4C框架在Defects4J上修复了180个错误,超越了现有方法10%,并减少了90%的采样次数。

📝 摘要(中文)

大型语言模型(LLMs)在自动化程序修复(APR)方面取得了良好效果。然而,解码器仅模型(如GPT-4)的下一个令牌预测训练目标与当前填充式方法的掩蔽跨度预测目标不一致,限制了LLMs充分利用预训练知识进行程序修复。此外,现有方法依赖于语句级故障定位方法提供待修复的错误代码段,限制了LLMs探索潜在补丁的能力。本文提出了一种新的方法,通过对齐输出与训练目标,允许LLMs在不先识别故障语句的情况下修复整个程序,从而显著提升其APR能力。基于这一思路,我们设计了D4C框架,在Defects4J上成功修复180个错误,超越了现有最先进的APR方法,并减少了90%的补丁采样次数。

🔬 方法详解

问题定义:本文旨在解决现有LLM程序修复方法中目标对齐不一致的问题,导致LLMs无法充分利用其预训练知识进行有效的程序修复。现有方法依赖于语句级故障定位,限制了LLMs的修复能力。

核心思路:论文的核心思路是通过对齐LLM的输出与其训练目标,允许模型在不先识别故障语句的情况下直接修复整个程序。这种方法能够更好地利用LLMs的潜力,提升其修复效果。

技术框架:D4C框架的整体架构包括输入程序代码、生成修复建议和输出修复后的代码。该框架通过优化提示设计,使得LLMs能够直接进行调试和修复。

关键创新:最重要的技术创新在于将传统的故障定位-修复流程替换为直接调试的方式,这一思路显著提高了LLMs在程序修复中的有效性。

关键设计:D4C框架在参数设置上进行了优化,采用了适合程序修复的损失函数和网络结构,以确保模型能够高效地生成修复补丁。

🖼️ 关键图片

fig_0
fig_1
fig_2

📊 实验亮点

实验结果显示,D4C框架在Defects4J数据集上成功修复了180个错误,超越了现有最先进的APR方法10%。此外,该方法在补丁采样次数上减少了90%,展示了其高效性和有效性。

🎯 应用场景

该研究的潜在应用领域包括软件开发、代码审查和自动化测试等。通过提高程序修复的效率和准确性,D4C框架能够为开发者节省大量时间和资源,提升软件质量。未来,该方法可能在更广泛的编程语言和开发环境中得到应用,推动自动化程序修复技术的发展。

📄 摘要(原文)

Large language models (LLMs) have achieved decent results on automated program repair (APR). However, the next token prediction training objective of decoder-only LLMs (e.g., GPT-4) is misaligned with the masked span prediction objective of current infilling-style methods, which impedes LLMs from fully leveraging pre-trained knowledge for program repair. In addition, while some LLMs can locate and repair bugs in certain functions using the related artifacts (e.g., test cases), existing methods still depend on statement-level fault localization methods to provide a list of buggy hunks for repair. This restriction hinders LLMs from exploring potential patches beyond the given locations. In this paper, we investigate a new approach to adapt LLMs to program repair. Our core insight is that LLM's APR capability can be greatly improved by simply aligning the output to their training objective and allowing them to refine the whole program without first identifying faulty statements. Based on this insight, we designed D4C, a straightforward prompting framework for APR. D4C can repair 180 bugs correctly in Defects4J, with each patch being sampled only 10 times. This surpasses the SOTA APR methods with perfect fault localization by 10% and reduces the patch sampling number by 90%. Our findings reveal that (1) objective alignment is crucial for fully exploiting LLM's pre-trained capability, and (2) replacing the traditional localize-buggy-hunks-then-repair workflow with direct debugging is more effective for LLM-based APR methods. Thus, we believe this paper introduces a new mindset for harnessing LLMs in APR.