用强化学习让大模型自动适应代码库API更新
ReCode: Updating Code API Knowledge with Reinforcement Learning
- 构建2000条数据集,训练模型通过强化学习迁移旧API到新版本
- 在CodeUpdateArena任务上显著提升性能,优于监督微调方法
- 适配性强,不损害模型通用编程能力,适合工程化部署
大型语言模型(LLMs)具备出色的代码生成能力,但在面对外部库API频繁更新时表现不佳,根源在于其训练数据中包含过时的API知识,即使能访问最新文档。为解决此问题,本文提出ReCode(基于规则的强化学习用于代码更新),模拟程序员对API变更的适应过程。我们构建了约2000条数据条目,用于训练模型基于更新信息进行版本迁移。引入改进的字符串相似度作为强化学习奖励函数。实验表明,ReCode显著提升了模型在动态API场景下的代码生成性能,尤其在未见的CodeUpdateArena任务上表现突出。关键的是,相比监督微调,ReCode对模型通用代码生成能力影响更小。我们在多种LLM和强化学习算法(GRPO、DAPO)上验证,均取得一致提升。值得注意的是,经训练后,Qwen2.5-Coder-7B的性能超过32B参数的指令微调模型及同架构推理模型。
原文摘要 · Abstract (English)
Large Language Models (LLMs) exhibit remarkable code generation capabilities but falter when adapting to frequent updates in external library APIs. This critical limitation, stemming from reliance on outdated API knowledge from their training data, even with access to current documentation, impedes reliable code generation in dynamic environments. To tackle this issue, we propose ReCode (rule-based Reinforcement learning for Code Update), a novel framework that mimics human programmer adaptation to API changes. Specifically, we construct a dataset of approximately 2,000 data entries to train the LLMs to perform version migration based on updated information. Then, we introduce a modified string similarity metric for code evaluation as the reward for reinforcement learning. Our experiments demonstrate that ReCode substantially boosts LLMs' code generation performance in dynamic API scenarios, especially on the unseen CodeUpdateArena task. Crucially, compared to supervised fine-tuning, ReCode has less impact on LLMs' general code generation abilities. We apply ReCode on various LLMs and reinforcement learning algorithms (GRPO and DAPO), all achieving consistent improvements. Notably, after training, Qwen2.5-Coder-7B outperforms that of the 32B parameter code instruction-tuned model and the reasoning model with the same architecture. Code is available at https://github.com/zjunlp/ReCode.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。