让大模型编辑代码更快更准,通过直接复制原文段落减少重复生成。
Copy-as-Decode: Grammar-Constrained Parallel Prefill for LLM Editing

- 用规则语法重构编辑过程,支持并行复制输入段落和生成新内容。
- 在相同条件下比传统逐词生成快6.8到303倍,最高可覆盖98%原始内容。
- 机制确定性高,适合需要精准控制的代码编辑场景,如自动化修复。
大模型编辑文本和代码时,即使多数内容与输入一致,仍会逐词自回归重生成。本文提出 Copy-as-Decode,一种解码层机制,将编辑生成重构为基于双原语语法的结构化解码:`<copy lines="i-j"/>` 指代输入行范围,`<gen>...</gen>` 生成新内容。词元级有限状态机保证语法正确性;服务层原语通过单次并行预填充前向计算更新每个复制段的键值缓存,而非执行N步自回归——共享推测解码的并行前向核,但以输入词元为草稿,程序强制接受替代概率验证。报告无端到端训练的上限分析:(i) 核心加速:在 Qwen2.5-{1.5B, 7B} 上,通过并行预填充复制 N 个词元,速度比自回归快 6.8×–303×(N ∈ [8, 512],A100 80GB bf16)。(ii) 复制上限:在 ProbeEdit 与 HumanEvalPack-Fix(Py/JS)上,线级原语可覆盖 74%–98% 的真实词元;结合各语料的跨度分布直方图,得出闭式墙钟时间上限为 29.0× / 3.4× / 4.2×(平均 13.0×)。词元级扩展可达 91%–99% 覆盖率,下限提升至 4.5×–6.5×。(iii) 流水线无损:482 个用例中,理想程序经确定性解析器往返均成功,下游失败仅源于段落选择,非机制本身。扰动实验显示,一行错位噪声使平均匹配率从 100% 降至 15.48%。在 Qwen2.5-Coder-1.5B 上的微调试点将 HEvalFix-Py EM 从 0/33(未训练)提升至 12%–17%,表明具备可学习信号,非生产级选择器。批量服务集成与多文件覆盖作为后续方向。
原文摘要 · Abstract (English)
LLMs edit text and code by autoregressively regenerating the full output, even when most tokens appear verbatim in the input. We study Copy-as-Decode, a decoding-layer mechanism that recasts edit generation as structured decoding over a two-primitive grammar: <copy lines="i-j"/> references an input line range, <gen>...</gen> emits new content. A token-level FSM guarantees syntactic validity, and a serving-layer primitive updates the KV cache for each copy span via a single parallel-prefill forward rather than $N$ autoregressive steps -- sharing the parallel-forward kernel of speculative decoding but with input tokens as the draft and program-enforced acceptance replacing probabilistic verification. We report an upper-bound analysis that requires no end-to-end training. (i) Kernel speedup: on Qwen2.5-{1.5B, 7B}, copying $N$ tokens via parallel prefill is $6.8\times$--$303\times$ faster than autoregressive ($N \in [8, 512]$, A100 80GB bf16). (ii) Copy ceiling: on ProbeEdit and HumanEvalPack-Fix (Py/JS), $74$--$98\%$ of gold tokens are reachable under the line-level primitive; composed with the empirical kernel over each corpus's span histogram this yields a closed-form wall-clock bound of $29.0\times / 3.4\times / 4.2\times$ ($13.0\times$ pooled). A token-level extension reaches $91$--$99\%$ coverage with $4.5\times$--$6.5\times$ floors. (iii) Pipeline losslessness: oracle programs round-trip through the deterministic resolver on all $482$ cases, localizing any downstream failure to span selection rather than the mechanism. A perturbation study shows pooled EM drops from $100\%$ to $15.48\%$ under off-by-one noise. A fine-tuning pilot on Qwen2.5-Coder-1.5B lifts HEvalFix-Py EM from $0/33$ (untrained) to $12$--$17\%$, a learnability signal, not a production selector. Batched-serving integration and multi-file coverage are scoped as follow-up.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。