[论文解读] REPOFUSE: Repository-Level Code Completion with Fused Dual Context
RepoFuse 提出了一种新颖的仓库级代码补全框架,通过使用排名截断生成(RTG)技术融合类比与推理上下文,实现高精度代码补全并降低推理延迟。相较于先前方法,其精确匹配准确率提升 59.75%,推理速度提升 26.8%,同时仅使用 75.4% 的上下文长度。
The success of language models in code assistance has spurred the proposal of repository-level code completion as a means to enhance prediction accuracy, utilizing the context from the entire codebase. However, this amplified context can inadvertently increase inference latency, potentially undermining the developer experience and deterring tool adoption - a challenge we termed the Context-Latency Conundrum. This paper introduces REPOFUSE, a pioneering solution designed to enhance repository-level code completion without the latency trade-off. REPOFUSE uniquely fuses two types of context: the analogy context, rooted in code analogies, and the rationale context, which encompasses in-depth semantic relationships. We propose a novel rank truncated generation (RTG) technique that efficiently condenses these contexts into prompts with restricted size. This enables REPOFUSE to deliver precise code completions while maintaining inference efficiency. Through testing with the CrossCodeEval suite, REPOFUSE has demonstrated a significant leap over existing models, achieving a 40.90% to 59.75% increase in exact match (EM) accuracy for code completions and a 26.8% enhancement in inference speed. Beyond experimental validation, REPOFUSE has been integrated into the workflow of a large enterprise, where it actively supports various coding tasks.
研究动机与目标
- 为解决仓库级代码补全中的上下文-延迟困境,即更丰富的上下文会增加推理延迟。
- 通过利用两种互补的跨文件上下文类型——类比上下文与推理上下文,提升代码补全准确率。
- 通过一种新颖的提示构建技术,将相关上下文压缩为简洁提示,实现高效、低延迟的代码补全。
- 在真实世界基准和生产规模的企业工作流中验证该方法的有效性。
提出的方法
- RepoFuse 从代码相似性分析中提取类比上下文,并从类与 API 之间的语义关系中提取推理上下文。
- 采用排名截断生成(RTG)技术,筛选并浓缩最相关的上下文,形成紧凑提示,最大限度减少 token 使用量。
- 将少样本提示与融合后的上下文结合,引导语言模型实现高精度代码补全。
- RTG 根据与当前代码补全任务的相关性,动态对上下文片段进行排序并截断,确保在有限上下文窗口内保持高精度。
- 该框架设计为与现有代码大语言模型兼容,无需重新训练或微调。
- 通过 CrossCodeEval 基准测试进行评估,并在大型企业环境中部署,以验证其在真实场景中的性能。
实验结果
研究问题
- RQ1融合类比与推理上下文是否能在不增加推理延迟的前提下提升代码补全准确率?
- RQ2排名截断生成(RTG)在压缩仓库级上下文的同时,对保持预测性能的有效性如何?
- RQ3与现有检索增强型代码补全方法相比,RepoFuse 在减少上下文长度和推理时间方面能达到何种程度?
- RQ4所提出的方法是否能在真实世界的企业开发环境中保持高准确率?
主要发现
- 在 CrossCodeEval 基准测试中,RepoFuse 相较于最先进模型,精确匹配(EM)准确率提升 40.90% 至 59.75%。
- 与传统基于上下文的方法相比,推理速度提升 26.8%,显著提升实时可用性。
- 该模型仅使用其他方法所需上下文长度的 75.4%,显著减小提示规模。
- RepoFuse 已成功集成至大型企业的软件开发流水线中,证明其具备生产环境部署能力。
- 该方法在避免微调大语言模型计算成本的同时,保持了高准确率。
- 该方法展现出强大的泛化能力,在多种代码补全场景中均实现准确率与效率的可测量提升。
阅读本论文
在 Nubint 阅读器中打开原文,边读边就任意段落提问。
在 Nubint 中阅读本论文本解读由 AI 根据论文原文生成,引用前请核对原文。