Lune

ICSE2024Top-tier venue

When Neural Code Completion Models Size up the Situation: Attaining Cheaper and Faster Completion through Dynamic Model Inference

Zhensu Sun, Xiaoning Du, Fu Song, Shangwen Wang, Li Li

Abstract

Leveraging recent advancements in large language models, modern neural code completion models have demonstrated the capability to generate highly accurate code suggestions. However, their massive size poses challenges in terms of computational costs and environmental impact, hindering their widespread adoption in practical scenarios. Dynamic inference emerges as a promising solution, as it allocates minimal computation during inference while maintaining the model's performance. In this research, we explore dynamic inference within the context of code completion. Initially, we conducted an empirical investigation on GPT-2, focusing on the inference capabilities of intermediate layers for code completion. We found that 54.4% of tokens can be accurately generated using just the first layer, signifying significant computational savings potential. Moreover, despite using all layers, the model still fails to predict 14.5% of tokens correctly, and the subsequent completions continued from them are rarely considered helpful, with only a 4.2% Acceptance Rate. These findings motivate our exploration of dynamic inference in code completion and inspire us to enhance it with a decision-making mechanism that stops the generation of incorrect code. We thus propose a novel dynamic inference method specifically tailored for code completion models. This method aims not only to produce correct predictions with largely reduced computation but also to prevent incorrect predictions proactively. Our extensive evaluation shows that it can averagely skip 1.7 layers out of 16 layers in the models, leading to an 11.2% speedup with only a marginal 1.1% reduction in ROUGE-L.

Ask Lune

Know this paper in minutes, not an afternoon.

Lune can read every page of it and the top-tier papers that cite it, and gives you its claims, its evidence and its limits, each one cited to the paper it comes from. No skimming, no AI slop.

6 top-tier papers have cited it since. Know what they found before your reviewers do.

Questions to start from

Lune can draw on

the full paper · the top-tier papers that cite it · related work

Get the answer

Free to start. No credit card required.

Lineage

  • Differentiation-Based Extraction of Proprietary Data from Fine-Tuned LLMs cites CodeBERT: A Pre-Trained Model for Programming and Natural Languages
  • Differentiation-Based Extraction of Proprietary Data from Fine-Tuned LLMs cites API-Guided Dataset Synthesis to Finetune Large Code Models
  • DynaBERT: Dynamic BERT with Adaptive Width and Depth cites BERT Loses Patience: Fast and Robust Inference with Early Exit
  • Confident Adaptive Language Modeling cites BERT Loses Patience: Fast and Robust Inference with Early Exit
  • Confident Adaptive Language Modeling cites DynaBERT: Dynamic BERT with Adaptive Width and Depth
Builds onCited byLeft to right by year; the more cited, the higher.

Cited by top-tier papers6

  1. When to Stop? Towards Efficient Code Generation in LLMs with Excess Token PreventionLianghong Guo, Yanlin Wang, Ensheng Shi, Wanjun Zhong et al.ISSTA 2024 · 16 citations
  2. "My productivity is boosted, but ..." Demystifying Users' Perception on AI Coding AssistantsYunbo Lyu, Zhou Yang, Jieke Shi, Jianming Chang et al.ASE 2025 · 8 citations
  3. API-Guided Dataset Synthesis to Finetune Large Code ModelsZongjie Li, Daoyuan Wu, Shuai Wang, Zhendong SuOOPSLA 2025 · 6 citations
  4. Differentiation-Based Extraction of Proprietary Data from Fine-Tuned LLMsZongjie Li, Daoyuan Wu, Shuai Wang, Zhendong SuCCS 2025 · 1 citation
  5. Can LLM Aid in Solving Constraints with Inductive Definitions?Weizhi Feng, Shidong Shen, Jiaxiang Liu, Taolue Chen et al.FM 2026

Builds on9

  1. CodeBERT: A Pre-Trained Model for Programming and Natural LanguagesZhangyin Feng, Daya Guo, Duyu Tang, Nan Duan et al.EMNLP Findings 2020 · 2,828 citations
  2. Are Emergent Abilities of Large Language Models a Mirage?Rylan Schaeffer, Brando Miranda, Sanmi KoyejoNeurIPS 2023 · 796 citations
  3. BERT Loses Patience: Fast and Robust Inference with Early ExitWangchunshu Zhou, Canwen Xu, Tao Ge, Julian J. McAuley et al.NeurIPS 2020 · 473 citations
  4. DynaBERT: Dynamic BERT with Adaptive Width and DepthLu Hou, Zhiqi Huang, Lifeng Shang, Xin Jiang et al.NeurIPS 2020 · 401 citations
  5. Confident Adaptive Language ModelingTal Schuster, Adam Fisch, Jai Gupta, Mostafa Dehghani et al.NeurIPS 2022 · 394 citations

Related papers

  1. Balancing Latency and Accuracy of Code Completion via Local-Cloud Model CascadingHanzhen Lu, Lishui Fan, Jiachi Chen, Qiuyuan Chen et al.FSE 2026 · 1 citation
  2. CodeFill: Multi-token Code Completion by Jointly learning from Structure and Naming SequencesMaliheh Izadi, Roberta Gismondi, Georgios GousiosICSE 2022 · 79 citations
  3. D-LLM: A Token Adaptive Computing Resource Allocation Strategy for Large Language ModelsYikun Jiang, Huanyu Wang, Lei Xie, Hanbin Zhao et al.NeurIPS 2024 · 39 citations
  4. TypePro: Boosting LLM-Based Type Inference via Inter-Procedural SlicingTeyu Lin, Minghao Fan, Huaxun Huang, Zhirong Shen et al.FSE 2026
  5. Position-Aware Depth Decay Decoding (D³): Boosting Large Language Model Inference EfficiencySiqi Fan, Xuezhi Fang, Xingrun Xing, Peng Han et al.ACL Findings 2025 · 4 citations
Dusk over the sea between two cliffs drawn in fine vertical lines