arXiv:2601.13384cs.SEcs.CL2026-01ACL被引 8

让代码补全能主动纠错,提升安全性和准确性。

From Completion to Editing: Unlocking Context-Aware Code Infilling via Search-and-Replace Instruction Tuning

  • 用搜索替换机制实现一次推理完成补全与修正。
  • 仅用2万样本微调,性能超越基线模型。
  • 适合需要高安全性的开发者和自动编程工具。

主流的填空式代码补全(FIM)方法受限于无法修正上下文错误,且依赖不安全的基线模型。虽然聊天类大模型更安全,但其代理工作流存在性能下降问题。为此,我们提出搜索-替换补全(SRI)框架,将代理验证与编辑机制内化为单次推理过程。通过显式搜索阶段结构化地实施修改,SRI将补全任务与聊天模型的指令遵循先验对齐,使补全从静态填充演变为动态上下文感知编辑。我们构建了高质量数据集 SRI-200K,微调了 SRI-Coder 系列模型。大量实验表明,仅需2万条样本,SRI-Coder即可使聊天模型在补全性能上超越其基线版本。关键的是,与FIM式微调不同,SRI保持了通用编码能力,并维持与标准FIM相当的推理延迟。我们已将SRI应用于整个Qwen3-Coder系列,鼓励开发者社区使用该框架实现高级自动补全与辅助开发。

原文摘要 · Abstract (English)

The dominant Fill-in-the-Middle (FIM) paradigm for code completion is constrained by its rigid inability to correct contextual errors and reliance on unaligned, insecure Base models. While Chat LLMs offer safety and Agentic workflows provide flexibility, they suffer from performance degradation and prohibitive latency, respectively. To resolve this dilemma, we propose Search-and-Replace Infilling (SRI), a framework that internalizes the agentic verification-and-editing mechanism into a unified, single-pass inference process. By structurally grounding edits via an explicit search phase, SRI harmonizes completion tasks with the instruction-following priors of Chat LLMs, extending the paradigm from static infilling to dynamic context-aware editing. We synthesize a high-quality dataset, SRI-200K, and fine-tune the SRI-Coder series. Extensive evaluations demonstrate that with minimal data (20k samples), SRI-Coder enables Chat models to surpass the completion performance of their Base counterparts. Crucially, unlike FIM-style tuning, SRI preserves general coding competencies and maintains inference latency comparable to standard FIM. We empower the entire Qwen3-Coder series with SRI, encouraging the developer community to leverage this framework for advanced auto-completion and assisted development.

代码补全指令微调智能编辑

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。