When to Stop? Towards Efficient Code Generation in LLMs with Excess Token Prevention
Not on the map. Why?
Abstract (arXiv)
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
Key facts. Cited by 21 papers in the map (data through 7 Oct 2026). First posted on arXiv 29 Jul 2024.
Builds on
No reference list yet.
Built on by
Citing papers per year: 2024: 3; 2025: 11; 2026: 7.
21 papers.
Sort:
By area:
- 2024LLM Hallucinations in Practical Code Generation: Phenomena, Mechanism, and Mitigationcited by 92
- 2024Agents in Software Engineering: Survey, Landscape, and Visioncited by 60
- 2025What to Retrieve for Effective Retrieval-Augmented Code Generation? An Empirical Study and Beyondcited by 22
- 2025An Empirical Study of Agent Developer Practices in AI Agent Frameworkscited by 14
- 2025Towards an Understanding of Context Utilization in Code Intelligencecited by 10
- 2025Marking Code Without Breaking It: Code Watermarking for Detecting LLM-Generated Codecited by 7
- 2026AlignCoder: Aligning Retrieval with Target Intent for Repository-Level Code Completioncited by 7
- 2025EfficientUICoder: A Bidirectional Token Compression Framework for Efficient MLLM-Based UI Code Generationcited by 4
- 2024Evaluating Quantized Large Language Models for Code Generation on Low-Resource Language Benchmarkscited by 3
- 2025Integrating Expert Knowledge into Logical Programs via LLMscited by 3
- 2025Breaking the Loop: Detecting and Mitigating Denial-of-Service Vulnerabilities in Large Language Modelscited by 3
- 2025Green Prompting: Characterizing Prompt-driven Energy Costs of LLM Inferencecited by 3
9 more
- 2026ShortCoder: Knowledge-Augmented Syntax Optimization for Token-Efficient Code Generationcited by 3
- 2026DRAINCODE: Stealthy Energy Consumption Attacks on Retrieval-Augmented Code Generation via Context Poisoningcited by 3
- 2025Optimizing Token Consumption in LLMs: A Nano Surge Approach for Code Reasoning Efficiencycited by 2
- 2026PhoenixRepair: Rethinking Repair Strategy Exploration in Software Agentscited by 2
- 2026SolAgent: A Specialized Multi-Agent Framework for Solidity Code Generationcited by 1
- 2025Benchmarking Web API Integration Code Generationcited by 0
- 2025RRT*former: Environment-Aware Sampling-Based Motion Planning using Transformercited by 0
- 2026HiKV: Hierarchical Importance-Aware KV Cache with Hardware Acceleration for LLM Decodingcited by 0
- 2026Adaptive Critical Token-Aware Retrieval for Repository-Level Code Generationcited by 0
- 2026Adaptive Critical Token-Aware Retrieval for Repository-Level Code Generation1 Sep 2026
- 2026HiKV: Hierarchical Importance-Aware KV Cache with Hardware Acceleration for LLM Decoding24 Jul 2026
- 2026PhoenixRepair: Rethinking Repair Strategy Exploration in Software Agents21 Jul 2026
- 2026SolAgent: A Specialized Multi-Agent Framework for Solidity Code Generation30 Jan 2026
- 2026DRAINCODE: Stealthy Energy Consumption Attacks on Retrieval-Augmented Code Generation via Context Poisoning28 Jan 2026
- 2026AlignCoder: Aligning Retrieval with Target Intent for Repository-Level Code Completion27 Jan 2026
- 2026ShortCoder: Knowledge-Augmented Syntax Optimization for Token-Efficient Code Generation14 Jan 2026
- 2025An Empirical Study of Agent Developer Practices in AI Agent Frameworks1 Dec 2025
- 2025RRT*former: Environment-Aware Sampling-Based Motion Planning using Transformer19 Nov 2025
- 2025Benchmarking Web API Integration Code Generation24 Sep 2025
- 2025EfficientUICoder: A Bidirectional Token Compression Framework for Efficient MLLM-Based UI Code Generation15 Sep 2025
- 2025Optimizing Token Consumption in LLMs: A Nano Surge Approach for Code Reasoning Efficiency22 Apr 2025
9 more
- 2025Towards an Understanding of Context Utilization in Code Intelligence11 Apr 2025
- 2025What to Retrieve for Effective Retrieval-Augmented Code Generation? An Empirical Study and Beyond26 Mar 2025
- 2025Green Prompting: Characterizing Prompt-driven Energy Costs of LLM Inference9 Mar 2025
- 2025Breaking the Loop: Detecting and Mitigating Denial-of-Service Vulnerabilities in Large Language Models1 Mar 2025
- 2025Marking Code Without Breaking It: Code Watermarking for Detecting LLM-Generated Code26 Feb 2025
- 2025Integrating Expert Knowledge into Logical Programs via LLMs17 Feb 2025
- 2024Evaluating Quantized Large Language Models for Code Generation on Low-Resource Language Benchmarks18 Oct 2024
- 2024LLM Hallucinations in Practical Code Generation: Phenomena, Mechanism, and Mitigation30 Sep 2024
- 2024Agents in Software Engineering: Survey, Landscape, and Vision13 Sep 2024
- 2025EfficientUICoder: A Bidirectional Token Compression Framework for Efficient MLLM-Based UI Code Generationcited by 4
- 2026ShortCoder: Knowledge-Augmented Syntax Optimization for Token-Efficient Code Generationcited by 3
- 2026HiKV: Hierarchical Importance-Aware KV Cache with Hardware Acceleration for LLM Decodingcited by 0
- 2026HiKV: Hierarchical Importance-Aware KV Cache with Hardware Acceleration for LLM Decoding24 Jul 2026
- 2026ShortCoder: Knowledge-Augmented Syntax Optimization for Token-Efficient Code Generation14 Jan 2026
- 2025EfficientUICoder: A Bidirectional Token Compression Framework for Efficient MLLM-Based UI Code Generation15 Sep 2025
- 2024LLM Hallucinations in Practical Code Generation: Phenomena, Mechanism, and Mitigationcited by 92
- 2025Towards an Understanding of Context Utilization in Code Intelligencecited by 10
- 2026AlignCoder: Aligning Retrieval with Target Intent for Repository-Level Code Completioncited by 7
- 2024Evaluating Quantized Large Language Models for Code Generation on Low-Resource Language Benchmarkscited by 3
- 2025Breaking the Loop: Detecting and Mitigating Denial-of-Service Vulnerabilities in Large Language Modelscited by 3
- 2025Green Prompting: Characterizing Prompt-driven Energy Costs of LLM Inferencecited by 3
- 2025Benchmarking Web API Integration Code Generationcited by 0
- 2025RRT*former: Environment-Aware Sampling-Based Motion Planning using Transformercited by 0
- 2026Adaptive Critical Token-Aware Retrieval for Repository-Level Code Generationcited by 0
- 2026Adaptive Critical Token-Aware Retrieval for Repository-Level Code Generation1 Sep 2026
- 2026AlignCoder: Aligning Retrieval with Target Intent for Repository-Level Code Completion27 Jan 2026
- 2025RRT*former: Environment-Aware Sampling-Based Motion Planning using Transformer19 Nov 2025
- 2025Benchmarking Web API Integration Code Generation24 Sep 2025
- 2025Towards an Understanding of Context Utilization in Code Intelligence11 Apr 2025
- 2025Green Prompting: Characterizing Prompt-driven Energy Costs of LLM Inference9 Mar 2025
- 2025Breaking the Loop: Detecting and Mitigating Denial-of-Service Vulnerabilities in Large Language Models1 Mar 2025
- 2024Evaluating Quantized Large Language Models for Code Generation on Low-Resource Language Benchmarks18 Oct 2024
- 2024LLM Hallucinations in Practical Code Generation: Phenomena, Mechanism, and Mitigation30 Sep 2024