用上下文强化学习让大模型高效生成多轮代码,兼顾效果与成本。
Bridging Online and Offline RL: Contextual Bandit Learning for Multi-Turn Code Generation
- 将多轮代码生成转为单步补全任务,结合离线轨迹与在线学习。
- 在LiveCodeBench上使Qwen3 8B和R1-Distill 8B的通过率提升6.2%和9.0%。
- 可缓解模型上下文奖励欺骗问题,适合需要迭代决策的生成任务。
近期研究关注使用强化学习训练大语言模型完成真实任务,如多轮代码生成。尽管在线强化学习表现更优,但其高训练成本与不稳定性限制了广泛应用。本文观察到多轮代码生成可建模为可恢复的单步马尔可夫决策过程,提出一种结合离线轨迹的上下文强化学习方法Cobalt。Cobalt首先利用参考模型收集代码生成轨迹,并将其拆分为部分轨迹作为上下文提示;随后在在线贝叶斯学习中,模型通过单步生成完成每个提示。Cobalt优于基于GRPO和VeRPO的两个多轮在线强化学习基线,在LiveCodeBench上使R1-Distill 8B和Qwen3 8B的Pass@1分数分别提升最高9.0和6.2个百分点。此外,我们分析了大模型在上下文中对奖励的操纵行为,并通过扰动轨迹增强训练以缓解该问题。结果表明,Cobalt是多轮代码生成等迭代决策任务的有力方案。代码与数据已公开于https://github.com/OSU-NLP-Group/cobalt。
原文摘要 · Abstract (English)
Recently, there have been significant research interests in training large language models (LLMs) with reinforcement learning (RL) on real-world tasks, such as multi-turn code generation. While online RL tends to perform better than offline RL, its higher training cost and instability hinders wide adoption. In this paper, we build on the observation that multi-turn code generation can be formulated as a one-step recoverable Markov decision process and propose contextual bandit learning with offline trajectories (Cobalt), a new method that combines the benefits of online and offline RL. Cobalt first collects code generation trajectories using a reference LLM and divides them into partial trajectories as contextual prompts. Then, during online bandit learning, the LLM is trained to complete each partial trajectory prompt through single-step code generation. Cobalt outperforms two multi-turn online RL baselines based on GRPO and VeRPO, and substantially improves R1-Distill 8B and Qwen3 8B by up to 9.0 and 6.2 absolute Pass@1 scores on LiveCodeBench. Also, we analyze LLMs' in-context reward hacking behaviors and augment Cobalt training with perturbed trajectories to mitigate this issue. Overall, our results demonstrate Cobalt as a promising solution for iterative decision-making tasks like multi-turn code generation. Our code and data are available at https://github.com/OSU-NLP-Group/cobalt.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。