arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2407.03157cs.CLcs.AIcs.LGcs.SE
收藏

当你编辑代码时,让代码 LLM 自行编辑

Let the Code LLM Edit Itself When You Edit the Code

National Key Laboratory of General Artificial Intelligence(通用人工智能国家重点实验室);School of Intelligence Science and Technology, Peking University(北京大学智能科学与技术学院);ByteDance Inc.(字节跳动公司)

Zhenyu He, Jun Zhang, Shengjie Luo, Jingjing Xu, Zhi Zhang, Di He

AI总结:

针对代码编辑后LLM重新预测计算成本高的问题,提出PIE方法,通过修正Key cache中的旋转矩阵确保位置正确,在降低85%以上计算开销的同时保持模型性能。

摘要:

在这项工作中,我们研究了代码生成中的一个典型场景:开发者实时编辑现有代码,并要求代码助手(例如大型语言模型)即时重新预测下一个 token 或下一行。朴素的方法是,LLM 需要重新编码整个 KV cache 以提供准确的预测。然而,此过程计算成本高昂,尤其是在序列长度较长时。简单地对编辑后的子序列进行编码并将其整合到原始 KV cache 中会遇到时间混淆问题,导致性能显著下降。我们通过引入 Positional Integrity Encoding (PIE)(位置完整性编码)来解决这种效率与准确性的权衡。基于 rotary positional encoding(旋转位置编码),PIE 首先移除 Key cache 中引发时间混淆的 rotary matrices(旋转矩阵),然后重新应用正确的旋转矩阵。此过程确保了 token 之间的位置关系正确,且仅需一轮矩阵乘法。我们利用参数规模为 1.3B、6.7B 和 33B 的 DeepSeek-Coder 模型,在 RepoBench-C-8k 数据集上通过大量实验验证了 PIE 的有效性。我们的评估包含三项真实世界的编码任务:代码插入、代码删除和多点代码编辑。结果表明,与标准的全量重计算方法相比,PIE 在所有模型规模和任务上均将计算开销降低了 85% 以上,同时很好地近似了模型性能。

英文摘要:

In this work, we investigate a typical scenario in code generation where a developer edits existing code in real time and requests a code assistant, e.g., a large language model, to re-predict the next token or next line on the fly. Naively, the LLM needs to re-encode the entire KV cache to provide an accurate prediction. However, this process is computationally expensive, especially when the sequence length is long. Simply encoding the edited subsequence and integrating it to the original KV cache meets the temporal confusion problem, leading to significantly worse performance. We address this efficiency and accuracy trade-off by introducing \underline{\textbf{Positional \textbf{I}ntegrity \textbf{E}ncoding} (PIE). Building upon the rotary positional encoding, PIE first removes the rotary matrices in the Key cache that introduce temporal confusion and then reapplies the correct rotary matrices. This process ensures that positional relationships between tokens are correct and requires only a single round of matrix multiplication. We validate the effectiveness of PIE through extensive experiments on the RepoBench-C-8k dataset, utilizing DeepSeek-Coder models with 1.3B, 6.7B, and 33B parameters. Our evaluation includes three real-world coding tasks: code insertion, code deletion, and multi-place code editing. Results demonstrate that PIE reduces computational overhead by over 85% compared to the standard full recomputation approach across all model sizes and tasks while well approximating the model performance.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑