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.


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

0
下载
关闭预览

相关内容

代码(Code)是专知网的一个重要知识资料文档板块,旨在整理收录论文源代码、复现代码,经典工程代码等,便于用户查阅下载使用。
《深度学习代码智能》综述、基准和工具集
专知会员服务
56+阅读 · 2024年1月2日
【干货书】优化:原理和算法,738页pdf
专知会员服务
106+阅读 · 2023年6月24日
《用于代码弱点识别的 LLVM 中间表示》CMU
专知会员服务
15+阅读 · 2022年12月12日
专知会员服务
110+阅读 · 2021年8月23日
一个牛逼的 Python 调试工具
机器学习算法与Python学习
15+阅读 · 2019年4月30日
深度学习开发必备开源框架
九章算法
12+阅读 · 2018年5月30日
尽早跑通深度学习的实践代码,是入门深度学习的最快途径
算法与数据结构
22+阅读 · 2017年12月13日
GAFT:一个使用 Python 实现的遗传算法框架
Python开发者
10+阅读 · 2017年8月1日
国家自然科学基金
43+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
2+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
3+阅读 · 2014年12月31日
VIP会员
最新内容
学习数据的几何:形状空间分析数学综述
专知会员服务
6+阅读 · 6月17日
定向能反无人机系统最新发展动态
专知会员服务
7+阅读 · 6月17日
从燃煤战舰到算法战争:水面指挥的永恒要求
专知会员服务
4+阅读 · 6月17日
相关VIP内容
相关基金
国家自然科学基金
43+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
2+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
3+阅读 · 2014年12月31日
Top
微信扫码咨询专知VIP会员