MRCoder:一种用于仓库级代码生成的高效上下文选择方法

MRCoder: An Efficient Context Selecting Approach for Repository-Level Code Generation

精选理由

MRCoder用Map-Reduce思路解决仓库级代码生成的上下文选择难题,比现有RAG方法节省30-50% token,推理快52%,在CoderEval和DevEval上准确率更高。

AI 摘要

MRCoder采用Map-Reduce范式,在Map阶段通过轻量草稿模型和结构感知草稿引导选择(SADGS)筛选信息上下文,在Reduce阶段聚合上下文并利用并行验证加速解码。在CoderEval和DevEval基准上,使用Qwen2.5-Coder和DeepSeek-Coder作为骨干模型时,MRCoder提升了代码生成准确率,同时减少了30%到50%的token消耗,推理时间降低最多52%。该方法相比现有RAG及上下文选择方法更高效地平衡了质量和计算开销。

原文 · arXiv: DeepSeek

MRCoder: An Efficient Context Selecting Approach for Repository-Level Code Generation

Large language models (LLMs) have demonstrated strong capabilities in code generation. However, repository-level code generation remains challenging, as it requires effectively identifying and utilizing repository-specific context. While retrieval-augmented generation (RAG) incorporates relevant code snippets, it often introduces redundant context that interferes with the LLM's ability to utilize relevant information, leading to degraded generation quality and increased computational cost. Moreover, existing context selection and compression methods struggle to balance efficiency and quality, either introducing additional computational overhead or failing to effectively select valid context. In this paper, we propose MRCoder, an efficient context selection framework that improves both the effectiveness and efficiency of repository-level code generation. MRCoder adopts a Map-Reduce paradigm: in the Map Phase, a lightweight draft model generates drafts over partitioned contexts, and Structure-Aware Draft-Guided Selection (SADGS) selects informative contexts based on drafts through API consistency and logical similarity; in the Reduce Phase, the refined contexts are aggregated for final generation, with a parallel verification strategy further accelerating decoding. We evaluate MRCoder on two widely used repository-level code generation benchmarks, CoderEval and DevEval, using Qwen2.5-Coder and DeepSeek-Coder as backbone LLMs. Experimental results show that MRCoder improves code generation accuracy over strong baselines while reducing token consumption by 30 to 50% and inference time by up to 52%. These results demonstrate that our proposed structured and draft-guided context selection strategy is crucial for improving both the quality and efficiency of repository-level code generation