Skip to main content
QUICK REVIEW

[论文解读] Repoformer: Selective Retrieval for Repository-Level Code Completion

Di Wu, Wasi Uddin Ahmad|arXiv (Cornell University)|Mar 15, 2024
Web Data Mining and AnalysisComputer Science被引用 3
一句话总结

本文提出Repoformer,一种用于仓库级代码补全的可选检索框架,利用自监督代码语言模型动态判断是否需要检索,从而在提升准确率的同时提高推理效率。通过避免不必要的检索,其推理速度最高可提升70%而性能不下降,在多个基准测试中优于固定检索基线方法。

ABSTRACT

Recent advances in retrieval-augmented generation (RAG) have initiated a new era in repository-level code completion. However, the invariable use of retrieval in existing methods exposes issues in both efficiency and robustness, with a large proportion of the retrieved contexts proving unhelpful or harmful to code language models (code LMs). In this paper, we propose a selective RAG framework to avoid retrieval when unnecessary. To power this framework, we design a self-supervised learning approach to enable a code LM to accurately self-evaluate whether retrieval can improve its output quality and robustly leverage the potentially noisy retrieved contexts. Using this LM as both the selective RAG policy and the generation model, our framework achieves state-of-the-art repository-level code completion performance on diverse benchmarks including RepoEval, CrossCodeEval, and CrossCodeLongEval, a new long-form code completion benchmark. Meanwhile, our analyses show that selectively retrieving brings as much as 70% inference speedup in the online serving setting without harming the performance. We further demonstrate that our framework is able to accommodate different generation models, retrievers, and programming languages. These advancements position our framework as an important step towards more accurate and efficient repository-level code completion.

研究动机与目标

  • 解决在仓库级代码补全中,检索增强生成(RAG)始终执行检索所导致的效率低下和鲁棒性差的问题。
  • 减少因检索无关或噪声的跨文件上下文而造成的计算浪费,这些上下文会降低模型性能。
  • 开发一种可自我评估的代码语言模型,能够自主判断检索是否能提升补全质量。
  • 实现对不同代码语言模型、检索器、编程语言和补全粒度的泛化能力。
  • 构建一种即插即用的可选检索策略,以在真实编程环境中同时提升准确率和降低延迟。

提出的方法

  • 设计一种自监督RAG模拟流程,通过将代码片段与检索到的跨文件上下文配对,生成训练数据。
  • 采用多任务目标训练代码语言模型(Repoformer),联合优化代码生成与可选检索决策。
  • 引入一个检索触发标记(<cc>),由模型预测以根据上下文相关性决定是否调用检索。
  • 使用自评估损失($\mathcal{L}_{eval}$)教会模型评估检索是否能提升输出质量。
  • 在文件内补全与检索增强生成的组合数据上微调模型,且检索决策基于模型内部置信度。
  • 通过使用同一模型同时作为可选检索策略和代码生成器,简化流水线,消除独立策略网络。
Figure 1 : (a) An overview of the proposed selective RAG framework. Given the current file context, a policy first assesses whether retrieval is required and triggers the retriever selectively. Then, the code LM makes a hypothesis with the optional retrieved context. With Repoformer , the two stages
Figure 1 : (a) An overview of the proposed selective RAG framework. Given the current file context, a policy first assesses whether retrieval is required and triggers the retriever selectively. Then, the code LM makes a hypothesis with the optional retrieved context. With Repoformer , the two stages

实验结果

研究问题

  • RQ1能否训练代码语言模型来自我评估检索是否能提升其代码补全输出质量?
  • RQ2与始终检索相比,可选检索是否能在不降低性能的前提下减少推理延迟?
  • RQ3当触发检索时,模型对噪声或无关检索上下文的鲁棒性如何?
  • RQ4相同的可选检索策略能否在不同代码语言模型、编程语言和检索方法间实现泛化?
  • RQ5是否可能训练模型在已知答案或跨文件上下文不必要时主动避免检索?

主要发现

  • Repoformer通过避免不必要的检索,实现了70%的推理速度提升,且性能无下降。
  • 在RepoEval和CrossCodeEval上,Repoformer在代码块和函数补全任务中均优于固定检索基线。
  • 消融研究显示,A2(使用$\mathcal{L}_{eval}$)的可选决策优于A1,后者因损失不平衡而默认执行检索。
  • A3(训练时移除$CC$)的RAG性能更差,证明使用检索上下文进行训练对模型鲁棒性至关重要。
  • A4(将$CC$置于填充跨度内部)在函数补全任务中表现不佳,表明其破坏了预训练的完形填空语义。
  • Repoformer在多种编程语言和补全粒度下均保持强劲性能,展现出良好的泛化能力。
Figure 2 : A comparison between fill-in-the-middle and self-selective RAG. We mark the end of the current file with a new token <eof> , which triggers the LM’s self-evaluation. $\rightarrow$ denotes the invocation of the LM. LM-generated parts are colored in red. fim_p , fim_s , and fim_m refer to t
Figure 2 : A comparison between fill-in-the-middle and self-selective RAG. We mark the end of the current file with a new token <eof> , which triggers the LM’s self-evaluation. $\rightarrow$ denotes the invocation of the LM. LM-generated parts are colored in red. fim_p , fim_s , and fim_m refer to t

阅读本论文

在 Nubint 阅读器中打开原文,边读边就任意段落提问。

在 Nubint 中阅读本论文

本解读由 AI 根据论文原文生成,引用前请核对原文。