arXivDaily arXiv每日学术速递 周一至周五更新
arXiv周末暂无论文更新,休息一下吧,周末愉快~~
arXiv 2407.20042cs.SE
收藏

何时停止?通过防止多余 Token 生成实现 LLM 的高效代码生成

When to Stop? Towards Efficient Code Generation in LLMs with Excess Token Prevention

Lianghong Guo, Yanlin Wang, Ensheng Shi, Wanjun Zhong, Hongyu Zhang, Jiachi Chen, Ruikai Zhang, Yuchi Ma, Zibin Zheng

AI总结:

针对 Code LLMs 代码生成中持续产生多余 token 导致的效率问题,提出推理加速方法 CodeFast,通过训练轻量级模型 GenGuard 预测并适时终止多余推理,在不损害代码质量的前提下将推理速度提升 34% 至 452%。

摘要:

代码生成旨在自动生成满足给定自然语言需求的代码片段,在软件开发中发挥着重要作用。尽管 Code LLMs 在该领域表现出色,但其漫长的生成时间在实际使用中构成了显著限制。在本文中,我们首先针对不同 Code LLMs 在代码生成任务上进行深入的初步研究,并发现了一个显著的效率问题,即持续生成多余 token。这损害了开发者生产力并导致巨大的计算浪费。为了解决此问题,我们引入了 CodeFast,一种用于 Code LLMs 代码生成的推理加速方法。CodeFast 的核心思想是在检测到不必要的多余 token 时及时终止推理过程。首先,我们提出了一个自动数据构建框架来获取训练数据。然后,我们训练了一个适用于多种编程语言的统一轻量级模型 GenGuard,用于预测是否在当前步骤终止推理。最后,我们利用 GenGuard 增强 Code LLM,以加速其在代码生成任务中的推理。我们在四个广泛使用的代码生成数据集上,使用 CodeFast 对五个具有代表性的 Code LLMs 进行了大量实验。实验结果表明:(1) CodeFast 能够显著提升各种 Code LLMs 在代码生成中的推理速度,提升幅度从 34% 到 452% 不等,且不损害生成代码的质量。(2) CodeFast 在不同参数设置下保持稳定,并且能够泛化到未训练的数据集。我们的代码和数据可在 https://github.com/DeepSoftwareAnalytics/CodeFast 获取。

英文摘要:

Code generation aims to automatically generate code snippets that meet given natural language requirements and plays an important role in software development. Although Code LLMs have shown excellent performance in this domain, their long generation time poses a signification limitation in practice use. In this paper, we first conduct an in-depth preliminary study with different Code LLMs on code generation tasks and identify a significant efficiency issue, i.e., continual generation of excess tokens. It harms the developer productivity and leads to huge computational wastes. To address it, we introduce CodeFast, an inference acceleration approach for Code LLMs on code generation. The key idea of CodeFast is to terminate the inference process in time when unnecessary excess tokens are detected. First, we propose an automatic data construction framework to obtain training data. Then, we train a unified lightweight model GenGuard applicable to multiple programming languages to predict whether to terminate inference at the current step. Finally, we enhance Code LLM with GenGuard to accelerate its inference in code generation tasks. We conduct extensive experiments with CodeFast on five representative Code LLMs across four widely used code generation datasets. Experimental results show that (1) CodeFast can significantly improve the inference speed of various Code LLMs in code generation, ranging form 34% to 452%, without compromising the quality of generated code. (2) CodeFast is stable across different parameter settings and can generalize to untrained datasets. Our code and data are available at https://github.com/DeepSoftwareAnalytics/CodeFast

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑