[论文解读] Debug like a Human: A Large Language Model Debugger via Verifying Runtime Execution Step-by-step
LDB 是一种新颖的调试框架,使大型语言模型(LLMs)能够通过逐步分析运行时执行过程,迭代地改进代码,追踪基本块之间的中间变量和控制流。通过模拟人类调试实践——例如设置断点和检查变量状态——LDB 在 HumanEval、MBPP 和 TransCoder 基准测试中将代码生成准确率提升了高达 9.8%,达到当前最先进水平。
Large language models (LLMs) are leading significant progress in code generation. Beyond one-pass code generation, recent works further integrate unit tests and program verifiers into LLMs to iteratively refine the generated programs. However, these works consider the generated programs as an indivisible entity, which falls short for LLMs in debugging the programs, especially when the programs contain complex logic flows and data operations. In contrast, when human developers debug programs, they typically set breakpoints and selectively examine runtime execution information. The execution flow and the intermediate variables play a crucial role in the debugging process, yet they are underutilized in the existing literature on code generation. In this study, we introduce Large Language Model Debugger (LDB), a novel debugging framework that enables LLMs to refine their generated programs with the runtime execution information. Specifically, LDB segments the programs into basic blocks and tracks the values of intermediate variables after each block throughout the runtime execution. This allows LLMs to concentrate on simpler code units within the overall execution flow, verify their correctness against the task description block by block, and efficiently pinpoint any potential errors. Experiments demonstrate that LDB consistently enhances the baseline performance by up to 9.8% across the HumanEval, MBPP, and TransCoder benchmarks, archiving new state-of-the-art performance in code debugging for various LLM selections.
研究动机与目标
- 为了解决现有基于 LLM 的代码生成方法将程序视为不可分割整体、忽略细粒度执行细节的局限性。
- 弥合 LLM 调试与人类开发人员实践之间的差距,后者依赖于对中间状态和控制流的运行时检查。
- 通过利用执行轨迹和变量值,使 LLM 能够逐块验证正确性,从而提升代码生成的准确率。
- 开发一种与多种 LLM 主干架构兼容且在多种代码生成任务(包括文本到代码和代码翻译)中均有效的框架。
提出的方法
- LDB 使用控制流图分析将生成的程序分解为基本块,以实现细粒度的执行追踪。
- 使用失败的测试用例执行程序,并在每个基本块执行后记录中间变量的运行时值。
- 然后,框架查询 LLM 以评估每个代码块的行为相对于任务描述的正确性,并为每个代码块提供反馈。
- 基于 LLM 的判断结果和解释,模型重新生成经过修正的程序以纠正已识别的错误。
- 该过程是迭代的,使 LLM 能够利用运行时洞察逐步调试并改进代码。
- 该方法在多个基准测试和 LLM 架构(包括 GPT-3.5、StarCoder 和 CodeLlama)上进行了评估。
实验结果
研究问题
- RQ1LLM 是否能通过逐步分析运行时执行过程而非将程序视为整体单元,实现更高的代码生成准确率?
- RQ2与仅依赖执行后反馈相比,利用中间变量状态进行块级验证在多大程度上提升了调试性能?
- RQ3所提出的调试框架在多种 LLM 架构和代码生成任务中的有效性如何?
- RQ4当应用于更强大的 LLM(如 GPT-4 或 Reflexion)时,该框架是否仍能保持性能提升?
主要发现
- 与基线方法相比,LDB 在 HumanEval 基准测试中的代码生成准确率最高提升了 9.8%。
- 该框架在 HumanEval、MBPP 和 TransCoder 基准测试中,针对多种 LLM 主干架构均实现了最先进性能。
- 即使在 GPT-4 和 Reflexion 等强大模型上,LDB 也持续提升性能,证明了其通用性。
- 块级调试方法使 LLM 能够高精度地识别并修正逻辑错误,例如将‘检查偶数元素’误认为‘检查奇数元素’。
- LLM 对单个代码块的反馈能够准确识别错误逻辑,例如将‘奇数位置的奇数元素’误解为‘偶数位置的偶数元素’。
- 该方法通过独立隔离和验证每个基本块,有效处理复杂的控制流和数据操作。
阅读本论文
在 Nubint 阅读器中打开原文,边读边就任意段落提问。
在 Nubint 中阅读本论文本解读由 AI 根据论文原文生成,引用前请核对原文。