用大模型先设计高效算法,再优化代码,兼顾效率与正确性。
LLM4EFFI: Leveraging Large Language Models to Enhance Code Efficiency and Correctness
- 分逻辑域和代码域两阶段优化:先选好算法,再调代码。
- 在多个基准上同时提升效率与正确性,达当前最优水平。
- 适合关注代码性能的开发者和自动化编程研究者。
大型语言模型(特别是代码类模型)在代码生成方面表现优异,但现有研究多聚焦于生成代码的正确性,而对效率关注不足。现有方法仅对初始代码进行局部优化,受限于原始逻辑,改进有限。人类开发者编写高质量代码时,通常先在逻辑层面设计多种方案,评估不同算法及其复杂度,再实现并优化。本文提出 ool:一种新型框架,使大模型能生成兼具效率与正确性的代码。该框架将效率优化分为两个阶段:在逻辑域探索算法,在代码域优化实现;通过合成测试用例迭代验证确保正确性。此先效率后正确的范式为高效代码生成提供了新路径。实验表明, ool 在多个代码效率基准上持续提升性能,使用不同大模型作为基座均达到最新最佳水平。
原文摘要 · Abstract (English)
Large Language Models (LLMs), particularly Code LLMs, have demonstrated impressive performance in code generation. Current research primarily focuses on the correctness of generated code, while efficiency remains less explored. Recent works have focused on modifying the initial version of the code to improve its efficiency. However, such refinements are limited by the algorithmic design and overall logic of the initial code, resulting in only incremental improvements. In contrast, when human developers write high-quality code, they typically begin by designing several potential solutions at the logical level, evaluating various algorithms and their complexities, and then proceeding to implement and optimize the solution. In this study, we introduce \tool: \uline{L}arge \uline{L}anguage \uline{M}odel for Code \uline{Effi}ciency, a novel framework that enables LLMs to generate code that balances both efficiency and correctness. Specifically, \tool divides the efficiency optimization process into two domains: algorithmic exploration in the logic domain and implementation optimization in the code domain. The correctness of the code is then guaranteed through a synthetic test case refinement process. This approach, which prioritizes efficiency before ensuring correctness, offers a new paradigm for efficient code generation. Experiments demonstrate that \tool consistently improves both efficiency and correctness, achieving new state-of-the-art performance in code efficiency benchmarks across various LLM backbones.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。