arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2406.18294cs.CL
收藏

分层上下文剪枝:基于仓库级预训练代码大语言模型优化真实世界代码补全

Hierarchical Context Pruning: Optimizing Real-World Code Completion with Repository-Level Pretrained Code LLMs

Shenzhen Institute of Advanced Technology, Chinese Academy of Sciences(中国科学院深圳先进技术研究院);University of Chinese Academy of Sciences(中国科学院大学);The University of Sydney(悉尼大学);University of California, Irvine(加州大学欧文分校);Institute of Automation, Chinese Academy of Sciences(中国科学院自动化研究所)

Lei Zhang, Yunshui Li, Jiaming Li, Xiaobo Xia, Jiaxi Yang, Run Luo, Minzheng Wang, Longze Chen, Junhao Liu, Min Yang

AI总结:

针对仓库级代码补全中上下文超限问题,提出分层上下文剪枝(HCP)策略,在函数级建模并保持拓扑依赖,显著减少输入长度并提升补全准确率。

摘要:

近期开发的一些代码大语言模型(Code LLMs)在仓库级代码数据上进行了预训练(Repo-Code LLMs),使这些模型能够识别仓库结构并利用跨文件信息进行代码补全。然而,在真实开发场景中,简单拼接整个代码仓库通常会超出这些 Repo-Code LLMs 的上下文窗口限制,导致性能显著下降。在本研究中,我们在六个 Repo-Code LLMs 上进行了广泛的初步实验和分析。结果表明,保持文件的拓扑依赖关系并增加补全提示中的代码文件内容,可以提高补全准确率;剪枝所有依赖文件中函数的具体实现并不会显著降低补全准确率。基于这些发现,我们提出了一种名为分层上下文剪枝(HCP)的策略,以构建具有高信息量代码内容的补全提示。HCP 在函数级别对代码仓库进行建模,保持代码文件之间的拓扑依赖关系,同时移除大量不相关的代码内容,显著减少了仓库级代码补全的输入长度。我们在六个 Repo-Code LLMs 的实验中应用了 HCP 策略,结果表明我们提出的方法能够在大幅减少输入长度的同时显著提高补全准确率。我们的代码和数据可在 https://github.com/Hambaobao/HCP-Coder 获取。

英文摘要:

Some recently developed code large language models (Code LLMs) have been pre-trained on repository-level code data (Repo-Code LLMs), enabling these models to recognize repository structures and utilize cross-file information for code completion. However, in real-world development scenarios, simply concatenating the entire code repository often exceeds the context window limits of these Repo-Code LLMs, leading to significant performance degradation. In this study, we conducted extensive preliminary experiments and analyses on six Repo-Code LLMs. The results indicate that maintaining the topological dependencies of files and increasing the code file content in the completion prompts can improve completion accuracy; pruning the specific implementations of functions in all dependent files does not significantly reduce the accuracy of completions. Based on these findings, we proposed a strategy named Hierarchical Context Pruning (HCP) to construct completion prompts with high informational code content. The HCP models the code repository at the function level, maintaining the topological dependencies between code files while removing a large amount of irrelevant code content, significantly reduces the input length for repository-level code completion. We applied the HCP strategy in experiments with six Repo-Code LLMs, and the results demonstrate that our proposed method can significantly enhance completion accuracy while substantially reducing the length of input. Our code and data are available at https://github.com/Hambaobao/HCP-Coder.

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

↑