paperbot · PL 论文追踪

全部论文 待读 收藏

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

何时停止?面向 LLM 高效代码生成的冗余 token 抑制
ISSTA Proceedings of the 33rd ACM SIGSOFT International Symposium on Software Testing and Analysis2024匹配度 2/10 · 论文关注代码 LLM 推理加速与冗余 token 抑制,属于 LLM 效率优化;虽与代码生成/Agentic 程序有间接关联,但未涉及用户核心的静态分析、形式化验证、浮点或贝叶斯程序分析,且研究目标本身是改进 LLM,与画像中“不感兴趣”的方向相符。引用 17 inbox
Lianghong Guo, Yanlin Wang, Ensheng Shi, Wanjun Zhong, Hongyu Zhang, Jiachi Chen, Ruikai Zhang, Yuchi Ma, Zibin Zheng
crossref: 2026-09-12

AI 速览

一句话:提出 CodeFast:用轻量模型 GenGuard 及时终止推理,抑制 Code LLM 生成冗余 token,加速 34%–452% 且不损代码质量。

代码生成旨在根据自然语言需求自动生成代码片段,但 Code LLM 推理时间过长,严重影响实际使用。作者先对多个 Code LLM 在代码生成任务上进行深入初步研究,发现持续生成冗余 token 这一显著效率问题,既损害开发者生产力又造成大量计算浪费。为此提出 CodeFast,其核心是在检测到不必要的冗余 token 时及时终止推理:首先设计自动数据构造框架获得训练数据,然后训练一个可适用于多种编程语言的统一轻量模型 GenGuard,用于预测当前步是否应终止推理,最后用 GenGuard 增强 Code LLM 以加速代码生成推理。在 5 个代表性 Code LLM 与 4 个广泛使用的代码生成数据集上的大量实验表明:CodeFast 可将不同 Code LLM 的推理速度提升 34% 至 452%,且不损害生成代码质量;同时在不同参数设置下表现稳定,并能泛化到未训练过的数据集。

问题
Code LLM 在代码生成任务中推理耗时长,存在持续生成冗余 token 的效率问题,严重影响实际使用并造成大量计算浪费。
方法
提出 CodeFast:通过自动数据构造框架获取训练数据,训练跨多编程语言的统一轻量模型 GenGuard 预测当前步是否应终止推理,并用其增强 Code LLM 以加速代码生成。
评估
在 5 个代表性 Code LLM 和 4 个常用代码生成数据集上实验,推理速度提升 34%–452% 且不损代码质量;并在不同参数设置下验证稳定性与对未训练数据集的泛化能力。
原文摘要(Abstract)

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 task 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 task. 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.

链接与引用

DOI 原文 ·

BibTeX
@inproceedings{paperbot8519,
  title = {When to Stop? Towards Efficient Code Generation in LLMs with Excess Token Prevention},
  author = {Lianghong Guo and Yanlin Wang and Ensheng Shi and Wanjun Zhong and Hongyu Zhang and Jiachi Chen and Ruikai Zhang and Yuchi Ma and Zibin Zheng},
  booktitle = {ISSTA},
  year = {2024},
  doi = {10.1145/3650212.3680343}
}