arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2405.18649cs.CLcs.AIcs.SE
收藏

LeDex:训练大语言模型(LLMs)以更好地自我调试和解释代码

LeDex: Training LLMs to Better Self-Debug and Explain Code

Purdue University(普渡大学);AWS AI Labs(亚马逊云科技人工智能实验室);University of Virginia(弗吉尼亚大学)

Nan Jiang, Xiaopeng Li, Shiqi Wang, Qiang Zhou, Soneya Binta Hossain, Baishakhi Ray, Varun Kumar, Xiaofei Ma, Anoop Deoras

AI总结:

针对现有自我调试方法在小型开源LLMs上效果差的问题,提出LeDex训练框架,通过自动化收集解释与优化数据集、结合SFT和RL训练,大幅提升LLMs自我调试能力及代码解释质量。

摘要:

在代码生成领域,自我调试至关重要,它能让LLMs基于执行反馈优化生成的代码。这一点尤为关键,因为复杂任务中一次生成正确解决方案极具挑战。现有自我调试研究多聚焦提示方法,为LLMs提供少量示例,但在小型开源LLMs上效果不佳。本研究提出LeDex训练框架,显著提升LLMs的自我调试能力。直观上,我们观察到对错误代码的解释链加代码优化,有助于LLMs更好地分析错误代码并优化。因此,我们提出自动化管道,通过从LLM自身或更大的教师模型生成大量解释和优化轨迹,再经执行验证筛选,收集高质量的代码解释与优化数据集。我们对成功和失败轨迹进行监督微调(SFT),并结合考虑代码解释与优化质量的新型奖励设计进一步强化学习(RL)。SFT在四个基准上使pass@1提升高达15.92%,pass@10提升9.30%;RL训练额外使pass@1提升高达3.54%,pass@10提升2.55%。训练后的LLMs展现出迭代优化能力,可持续优化代码。最后,人类评估显示,经我们框架训练的LLMs能生成更有用的代码解释,帮助开发者更好地理解源代码中的错误。

英文摘要:

In the domain of code generation, self-debugging is crucial. It allows LLMs to refine their generated code based on execution feedback. This is particularly important because generating correct solutions in one attempt proves challenging for complex tasks. Prior works on self-debugging mostly focus on prompting methods by providing LLMs with few-shot examples, which work poorly on small open-sourced LLMs. In this work, we propose LeDex, a training framework that significantly improves the self-debugging capability of LLMs. Intuitively, we observe that a chain of explanations on the wrong code followed by code refinement helps LLMs better analyze the wrong code and do refinement. We thus propose an automated pipeline to collect a high-quality dataset for code explanation and refinement by generating a number of explanations and refinement trajectories from the LLM itself or a larger teacher model and filtering via execution verification. We perform supervised fine-tuning (SFT) and further reinforcement learning (RL) on both success and failure trajectories with a novel reward design considering code explanation and refinement quality. SFT improves the pass@1 by up to 15.92% and pass@10 by 9.30% over four benchmarks. RL training brings additional up to 3.54% improvement on pass@1 and 2.55% improvement on pass@10. The trained LLMs show iterative refinement ability and can keep refining code continuously. Lastly, our human evaluation shows that the LLMs trained with our framework generate more useful code explanations and help developers better understand bugs in source code.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑