arXiv:2410.10209cs.CLcs.SE2024-10ICML被引 20

用高效代码微调大模型,让生成的代码又对又快。

EffiCoder: Enhancing Code Generation in Large Language Models through Efficiency-Aware Fine-tuning

  • 用多模型生成候选代码,选执行时间与内存最低的作为最优解。
  • 微调后模型正确率提升至57.7%,正确任务平均耗时下降48.4%。
  • 适合关注代码性能的开发者和自动化编程研究者。

随着大语言模型在代码生成中扮演越来越重要的角色,提升代码的正确性与效率变得至关重要。现有方法主要关注正确性,常忽略效率问题。为此,我们提出EffiCoder,通过在高质量数据集上微调大模型,同时提升代码的正确性与效率。该数据集包含经过验证的正确且高效的代码样本。方法上,利用多个大模型为不同编程语言的任务生成多样化候选代码,并通过本地执行评估其执行时间和内存占用。最终选择执行时间最短、内存消耗最低的代码作为输出。实验结果表明,使用Effi-Instruct进行微调后,Qwen2.5-Coder-7B-Instruct的pass@1得分从44.8%提升至57.7%,正确任务的平均执行时间降低48.4%。EffiCoder为提升人工智能驱动的代码生成提供了可扩展且高效的方法,适用于软件开发与计算问题求解。源码已公开于https://github.com/huangd1999/EffiCoder。

原文摘要 · Abstract (English)

As large language models (LLMs) play an increasingly important role in code generation, enhancing both correctness and efficiency has become crucial. Current methods primarily focus on correctness, often overlooking efficiency. To address this gap, we introduce EffiCoder to improve both aspects by fine-tuning LLMs on a high-quality dataset comprising correct and efficient code samples. Our methodology involves leveraging multiple LLMs to generate diverse candidate code solutions for various tasks across different programming languages. We then evaluate these solutions by measuring their execution time and memory usage through local execution. The code solution with the lowest execution time and memory consumption is selected as the final output for each task. Experimental results demonstrate significant improvements when fine-tuning with Effi-Instruct. For instance, Qwen2.5-Coder-7B-Instruct's pass@1 score increases from 44.8\% to 57.7\%, while the average execution time for correct tasks decreases by 48.4\%. EffiCoder offers a scalable and effective solution for advancing AI-driven code generation, benefiting software development and computational problem-solving. The source code of Effi-Code was released at https://github.com/huangd1999/EffiCoder.

代码生成效率优化大模型微调

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。