Code often suffers from performance bugs. These bugs necessitate the research and practice of code optimization. Traditional rule-based methods rely on manually designing and maintaining rules for specific performance bugs (e.g., redundant loops, repeated computations), making them labor-intensive and limited in applicability. In recent years, machine learning and deep learning-based methods have emerged as promising alternatives by learning optimization heuristics from annotated code corpora and performance measurements. However, these approaches usually depend on specific program representations and meticulously crafted training datasets, making them costly to develop and difficult to scale. With the booming of Large Language Models (LLMs), their remarkable capabilities in code generation have opened new avenues for automated code optimization. In this work, we proposed FasterPy, a low-cost and efficient framework that adapts LLMs to optimize the execution efficiency of Python code. FasterPy combines Retrieval-Augmented Generation (RAG), supported by a knowledge base constructed from existing performance-improving code pairs and corresponding performance measurements, with Low-Rank Adaptation (LoRA) to enhance code optimization performance. Our experimental results on the Performance Improving Code Edits (PIE) benchmark demonstrate that our method outperforms existing models on multiple metrics. The FasterPy tool and the experimental results are available at https://github.com/WuYue22/fasterpy.


翻译:代码中常常存在性能缺陷。这些缺陷催生了代码优化的研究与实践。传统的基于规则的方法依赖于针对特定性能缺陷(如冗余循环、重复计算)手动设计和维护规则,这使得其劳动密集且适用范围有限。近年来,基于机器学习和深度学习的方法通过学习标注代码语料库和性能测量中的优化启发式规则,已成为有前景的替代方案。然而,这些方法通常依赖于特定的程序表示和精心构建的训练数据集,导致开发成本高昂且难以扩展。随着大语言模型(LLMs)的兴起,其在代码生成方面的卓越能力为自动化代码优化开辟了新途径。在本工作中,我们提出了FasterPy,一个低成本、高效的框架,旨在使LLMs适应于优化Python代码的执行效率。FasterPy结合了检索增强生成(RAG)与低秩适应(LoRA),前者由现有性能提升代码对及相应性能测量构建的知识库支持,以提升代码优化性能。我们在性能改进代码编辑(PIE)基准测试上的实验结果表明,我们的方法在多项指标上优于现有模型。FasterPy工具及实验结果可在 https://github.com/WuYue22/fasterpy 获取。

0
下载
关闭预览

相关内容

代码(Code)是专知网的一个重要知识资料文档板块,旨在整理收录论文源代码、复现代码,经典工程代码等,便于用户查阅下载使用。
Python图像处理,366页pdf,Image Operators Image Processing in Python
LibRec 每周算法:LDA主题模型
LibRec智能推荐
29+阅读 · 2017年12月4日
国家自然科学基金
17+阅读 · 2017年12月31日
国家自然科学基金
3+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2014年12月31日
国家自然科学基金
10+阅读 · 2014年12月31日
VIP会员
相关基金
国家自然科学基金
17+阅读 · 2017年12月31日
国家自然科学基金
3+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2014年12月31日
国家自然科学基金
10+阅读 · 2014年12月31日
Top
微信扫码咨询专知VIP会员