差异与完整文件:面向 Flutter/Dart 代码模型的迭代编辑式与直接生成方法的实证比较
研究论文 · 2026/09/10
大型语言模型用于代码编辑时,至少有两种输出方式:直接生成(模型一次性输出整个修改后的文件)和基于迭代差异的生成(“步骤”,模型输出一系列局部搜索/替换编辑,一次应用一个,直到发出完成信号或步骤预算耗尽)。基于差异的方式很有吸引力,因为它模仿了开发者编辑代码的方式,并且每轮应该需要少得多的生成令牌。我们在共享的 Flutter/Dart 数据集上,以两种方式训练了两个代码模型——一个从零开始训练的 100M 参数模型(Rainbow-Pony-100M)和一个微调的 Qwen2.5-Coder-0.5B——并评估了所有四个所得模型,每个模型在约 1,790 个任务的保留集上。直接生成在我们测量的每个指标上都显著优于基于差异的生成——编译/静态分析通过率、每字节比特数、与参考的字符级相似度,以及盲法 LLM 评判对目标达成、正确性和代码质量的评分——并且这种差距在通过匹配 ID 比较控制任务难度后以及限制在双方都能编译的代码上时仍然存在。然后我们确定了基于差异的生成确实获胜的条件背后的一个单一、与架构无关的机制:它在短小、空间局部的编辑上具有竞争力,其类别级胜利恰好集中在两个任务类别——重构和错误处理/边缘情况修复——这些类别在我们的数据集中具有最低的平均编辑步骤数。我们将此称为任务局部性,并讨论了它对基于编辑的训练方式何时适合和不适合代码编辑模型的意义。
本文通过严格的实证比较,揭示了直接生成与基于差异的生成在代码编辑任务中的性能差异,并提出了“任务局部性”这一关键概念,为选择代码编辑模型的训练方式提供了重要指导。
Large language models used for code editing can be trained and deployed in at least two output regimes: direct generation, where the model emits the entire modified file in one shot, and iterative diff-based generation ("steps"), where the model emits a sequence of localized search/replace edits applied one at a time until it signals completion or a step budget is exhausted. The diff-based regime is attractive because it mirrors how developers edit code and should require far fewer generated tokens per turn. We train two code models - a 100M-parameter model trained from scratch (Rainbow-Pony-100M) and a fine-tuned Qwen2.5-Coder-0.5B - in both regimes on a shared Flutter/Dart dataset, and evaluate all four resulting models on a held-out set of approx 1,790 tasks per model. Direct generation substantially outperforms diff-based generation on every metric we measure - compilation/static-analysis pass rate, bits-per-byte, character-level similarity to the reference, and blinded LLM-judge ratings of goal fulfillment, correctness, and code quality - and the gap persists after controlling for task difficulty via a matched-ID comparison and when restricting to code that compiles on both sides. We then identify a single, architecture-independent mechanism behind the conditions where diff-based generation does win: it is competitive on short, spatially localized edits, and its category-level wins concentrate in exactly the two task categories - refactoring and error-handling/edge-case fixes - with the lowest mean edit-step count in our dataset. We term this task locality and discuss its implications for when an edit-based training regime is and is not the right choice for a code-editing model.