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
1/18/2024
cs.SEcs.AI

No official code found. Best implementation: v587su/SEC (3 stars, last commit 2024-05-27).

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.

View on arXivView PDF

Code Implementations(1)

v587su/SECCommunity100%

Source code of the paper "When Neural Code Completion Models Size up the Situation: Attaining Cheaper and Faster Completion through Dynamic Model Inference"

31Shell, PythonJan 8, 20242 years ago

Similar Papers

Cite this paper

@article{sun2024when,
  title  = {When Neural Code Completion Models Size up the Situation: Attaining Cheaper and Faster Completion through Dynamic Model Inference},
  author = {Zhensu Sun and Xiaoning Du and Fu Song and Shangwen Wang and Li Li},
  year   = {2024},
  eprint = {2401.09964},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2401.09964v1}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2401.09964.svg)](https://codeofpaper.com/paper/2401.09964)

Discussion