当模型编辑过多:关于最小代码编辑的保真度

·

研究论文 · 2026/09/07

大型语言模型(LLM)越来越多地用于编辑现有代码,但仅正确性是不够的:有用的修复还应该是最小化、可审查且忠实于原始实现的。我们研究了过度编辑,即模型在修复错误之外重写代码的倾向。我们通过向参考解决方案注入受控的AST级损坏,从400个BigCodeBench问题构建了一个评估框架,为每个修复任务提供了已知的最小补丁。在前沿LLM中,过度编辑普遍存在,即使在像GPT-5.5这样的强模型中也是如此:高Pass@1可能与不必要的大编辑和增加的认知复杂性共存。保留指令显著减少了这种行为,将平均多余Levenshtein距离从0.195降至0.131,将增加的认知复杂性降低26.6%,并将Pass@1提高2.3个百分点。然而,这些收益并非仅仅来自更大的推理预算或更大的模型。接下来,我们询问是否可以在后训练期间直接学习最小编辑。我们观察到,监督微调会过拟合到已见的损坏模式,而强化学习在域外编辑保真度和性能保持之间提供了最佳权衡。这些结果将编辑保真度定位为代码修复质量的一个独立轴,并表明它可以被测量和学习。

该论文针对代码修复中一个被忽视但重要的方面——编辑保真度,提供了系统的评估方法和训练策略,对提升LLM代码编辑的实用性和可审查性具有重要价值。

Large language models (LLMs) are increasingly used to edit existing code, but correctness alone is not enough: useful repairs should also be minimal, reviewable, and faithful to the original implementation. We study over-editing, the tendency of a model to rewrite code beyond what is required to fix a bug. We construct an evaluation framework from 400 BigCodeBench problems by injecting controlled AST-level corruptions into reference solutions, giving each repair task a known minimal patch. Across frontier LLMs, over-editing is widespread even among strong models like GPT-5.5: high Pass@1 can coexist with unnecessarily large edits and added cognitive complexity. A preservation instruction substantially reduces this behavior, lowering average excess Levenshtein distance from 0.195 to 0.131, reducing added cognitive complexity by 26.6%, and increasing Pass@1 by 2.3 points. However, these gains do not simply follow from a larger reasoning budget or larger models. We next ask whether minimal editing can be learned directly during post-training. We observe that supervised fine-tuning overfits to seen corruption patterns, whereas reinforcement learning gives the best out-of-domain edit-fidelity and performance-retention trade-off. These results position edit fidelity as a distinct axis of code-repair quality and show that it can be measured and learned.

阅读原文

参与讨论