用轻量微调和提示工程提升大模型代码审查评论生成效果
Prompting and Fine-tuning Large Language Models for Automated Code Review Comment Generation
- 采用量化低秩微调(QLoRA)在消费级硬件上优化开源大模型
- 用函数调用图增强提示,使GPT-3.5的BLEU-4提升约90%
- 闭源模型结合摘要与调用图提示,生成评论更贴近开发者实际需求
由于代码审查评论输出本身具有多样性和非唯一性,准确生成仍具挑战。预训练于编程与自然语言数据的大模型在代码任务中表现良好,但大规模预训练存在环境影响及项目泛化问题。本文首先在消费级硬件上,以参数高效、量化低秩(QLoRA)方式微调开源大模型,提升评论生成性能;其次,通过在输入代码补丁中加入函数调用图和代码摘要等语义元信息,增强提示,探索其在代码审查中的效果。两种策略均有效:在CodeReviewer数据集上,使用函数调用图增强的少样本提示使GPT-3.5的BLEU-4得分相较预训练基线提升约90%;少样本提示的Gemini-1.0 Pro、QLoRA微调的Code Llama与Llama 3.1模型也取得25%至83%的性能提升。额外的人工评估验证了实验结果,反映真实开发者对生成评论的感知质量。
原文摘要 · Abstract (English)
Generating accurate code review comments remains a significant challenge due to the inherently diverse and non-unique nature of the task output. Large language models pretrained on both programming and natural language data tend to perform well in code-oriented tasks. However, large-scale pretraining is not always feasible due to its environmental impact and project-specific generalizability issues. In this work, first we fine-tune open-source Large language models (LLM) in parameter-efficient, quantized low-rank (QLoRA) fashion on consumer-grade hardware to improve review comment generation. Recent studies demonstrate the efficacy of augmenting semantic metadata information into prompts to boost performance in other code-related tasks. To explore this in code review activities, we also prompt proprietary, closed-source LLMs augmenting the input code patch with function call graphs and code summaries. Both of our strategies improve the review comment generation performance, with function call graph augmented few-shot prompting on the GPT-3.5 model surpassing the pretrained baseline by around 90% BLEU-4 score on the CodeReviewer dataset. Moreover, few-shot prompted Gemini-1.0 Pro, QLoRA fine-tuned Code Llama and Llama 3.1 models achieve competitive results (ranging from 25% to 83% performance improvement) on this task. An additional human evaluation study further validates our experimental findings, reflecting real-world developers' perceptions of LLM-generated code review comments based on relevant qualitative metrics.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。