一句话:提出 NTR 两阶段框架,用微调 LLM 做模板选择与补丁生成,显著提升自动程序修复效果。
论文关注自动程序修复(APR)中 LLM 与传统模板方法结合不充分的问题:模板被不加区分地使用、覆盖不足,小规模 LLM 的零样本修复效果欠佳。作者提出 NTR(Neural Template Repair),一个包含模板选择与补丁生成两阶段的微调框架。模板选择被建模为多分类问题,微调百万级参数的 LLM 以挑选候选模板;补丁生成阶段则以选中的模板(如“修改条件表达式”)作为可能方向,指导十亿级 LLM 微调以精确生成补丁。框架还引入表示“无合适模板”的特殊模板,并按概率对模板排序,从而缓解模板不匹配问题,并在 GPU 显存受限下高效搜索补丁空间。在 Defects4J V1.2 与 HumanEval-Java 上,NTR 配合 StarCoder 分别修复 128 与 129 个缺陷,超过最佳基线 14 与 59 个;配合更大的 CodeLlama 则达 139 与 136 个,超过基线 25 与 66 个,且相比基础模型自身能力额外修复 22 与 23 个缺陷。
Recent advancements in automated program repair (APR) have been significantly driven by the application of Large Language Models (LLMs). In particular, the integration of LLMs with traditional template-based repair methods has demonstrated effective outcomes. Despite this, the synergy between the strengths of traditional methods and LLMs remains underexploited. This oversight originates from the indiscriminate use of templates and their insufficient coverage. Also, using small-scale LLMs within the zero-shot learning context proves to be suboptimal. To alleviate the limitations, we propose NTR (Neural Template Repair), a two-stage repair framework including template selection and patch generation, both of which are under the fine-tuning paradigm. In the template selection phase, we formulate it as a multiclass classification problem and fine-tune million-level LLMs for better selecting possible templates. During the patch generation phase, we leverage the chosen templates as probable directions (e.g., ‘Mutate Conditional Expression’) to guide the fine-tuning process of LLMs at the billion-level scale for precise patch creation. Moreover, we incorporate a unique template to signify the absence of a suitable template and employ a probability-based prioritization of templates, thereby optimizing patch generation. This framework not only effectively addresses template mismatch issues, but also enables the billion-level LLMs to explore the patch space more efficiently, despite the GPU memory constraints. We evaluate NTR with different foundational models on Defects4J V1.2 and HumanEval-Java, the framework consistently demonstrates significant effectiveness. When utilizing StarCoder as the foundational model for patch generation, NTR fixes 128 and 129 bugs in Defects4J and HumanEval, outperforming the best baseline APR tool by 14 and 59 bugs. With the larger CodeLlama model, the fixed bugs rise to 139 and 136, respectively, exceeding the baseline by 25 and 66 bugs. Notably, the performance stems not only from the foundational models but also benefits greatly from our NTR framework. Specifically, NTR's implementation with StarCoder and CodeLlama leads to 22 and 23 additional fixes, which is beyond what the models achieve on their own. This emphasizes the success of our new perspective on utilizing templates to unlock the bug-fixing potential of LLMs.
DOI 原文 ·
@inproceedings{paperbot8756,
title = {Template-Guided Program Repair in the Era of Large Language Models},
author = {Kai Huang and Jian Zhang and Xiangxin Meng and Yang Liu},
booktitle = {ICSE},
year = {2025},
doi = {10.1109/icse55347.2025.00030}
}