保持代码感知LLM的时效性:全刷新、上下文增量与增量微调
Keeping Code-Aware LLMs Fresh: Full Refresh, In-Context Deltas, and Incremental Fine-Tuning
AI总结:
针对代码库持续演进导致代码感知LLM性能下降的问题,本文构建领域漂移框架,比较全刷新、上下文增量学习、增量微调三类策略,提出别名感知评估协议和遗忘探针,实验表明增量微调在混合场景最优,上下文学习在无训练时最快见效,全刷新为新代码准确率上限。
摘要:
现代代码库持续演进:文件被重命名或删除;公共API发生偏移;原本熟悉的模块内部行为出现变化。即使开发者的自然语言问题本身看起来没有变化,昨天训练的、能将开发者自然语言问题映射到仓库中相关文件路径精确集合的模型,明天也会出现性能下降。在本文中,我们在系统规模下,针对多个广泛使用的代码仓库,研究如何在不降低对早期代码的保留能力的前提下,保持此类模型的时效性。我们将时效性问题构建为基础快照与当前HEAD版本之间的领域漂移形式,并比较了三类更新策略:(A)全刷新,在新版本快照上重新训练整个模型;(B)上下文学习(ICL),在推理时注入最新增量(原始git diff或简洁的英文摘要);(C)增量微调(Inc-FT),在基于增量生成的训练集上进行微调,通过精心控制新、旧数据的混合比例来缓解灾难性遗忘。我们提出了一种别名感知的评估协议,该协议在文件重命名时给予模型相应的分数,同时从不奖励指向已删除路径的预测;还提出了一种实用的遗忘探针,用于量化模型输出过时路径的残留情况。在Flask、SQLAlchemy、Pandas和Poetry这四个代码仓库上的实验结果表明:采用旧数据感知混合策略的Inc-FT在新旧混合测试集上实现了最佳的整体平衡;当训练不可行时,使用英文增量摘要的ICL能最快提升模型对新代码的处理能力;而当追求最高的新代码准确率时,全刷新策略仍是性能上限。此外,我们还比较了基于Git-diff的Inc-FT与基于完整文件的Inc-FT,结果显示在重命名/删除操作频繁的更新窗口中,diff策略表现更优,而在行为变化频繁的更新窗口中,完整文件上下文策略更胜一筹。
英文摘要:
Modern codebases evolve continuously: files are renamed or deleted; public APIs drift; behavior shifts within otherwise familiar modules. A model trained yesterday to map a developer's natural-language question to the exact set of repository file paths that matter will degrade tomorrow, even if the questions themselves look unchanged. In this paper we study, at system scale and across several widely used repositories, how to keep such a model fresh without surrendering retention on earlier code. We frame freshness as a form of domain drift between a base snapshot and the current HEAD, and we compare three families of update strategies: (A) Full Refresh, retraining the entire model at the new snapshot; (B) In-Context Learning (ICL) that injects recent deltas (raw git diffs or concise English summaries) at inference; and (C) Incremental Fine-Tuning (Inc-FT) on delta-derived training sets, with carefully controlled NEW:OLD mixing to mitigate catastrophic forgetting. We contribute an alias-aware evaluation protocol that credits rename while never rewarding deleted paths, and a practical Forgetting Probe that quantifies residual emissions of obsolete paths. Across Flask, SQLAlchemy, Pandas, and Poetry, Inc-FT with old-aware mixes delivers the best overall balance on mixed sets, ICL with English delta summaries delivers the fastest new-code lift when training is not feasible, and Full Refresh remains the ceiling when maximum NEW accuracy matters. We also compare Git-diff Inc-FT to full-file Inc-FT, showing that diffs excel in rename/delete-heavy windows while full-file context wins in behavior-change-heavy windows.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。