arXiv:2605.23491cs.LGcs.AI2026-05被引 3

无需真实测试用例,通过代码与测试用例协同进化提升生成质量

CoSPlay: Cooperative Self-Play at Test-Time with Self-Generated Code and Unit Test

论文配图:CoSPlay: Cooperative Self-Play at Test-Time with Self-Generated Code and Unit Test
图 1 · 摘自论文原文
  • 代码与测试用例双向迭代优化,利用通过率信号动态修正
  • 在四个基准上将正确率从22.1%提升至33.2%,测试用例准确率达78.3%
  • 适用于多种模型,无需训练,适合资源受限的高效推理场景

最近的可验证奖励强化学习(RLVR)和测试时扩展(TTS)通过可执行验证推进了大模型代码生成。然而,真实测试用例(GT UTs)仍是瓶颈:SOTA RLVR方法需其进行昂贵训练,而现有TTS方法缺乏它们则竞争力下降。这推动了无真实测试用例的TTS研究,现有方法直接使用自动生成的测试用例来优化和筛选代码候选。但此类测试用例常含噪声或与错误代码虚假关联,且测试质量无法在无可靠代码的情况下验证。核心挑战在于共同提升两者质量。为此,我们提出CoSPlay,一种无真实测试用例、无需训练的框架,通过合作自演进联合优化代码与测试用例。首先探索多样解法并识别潜在失败模式以生成判别性测试思路;然后利用代码-测试执行矩阵中的双向通过率信号,迭代剔除或修复弱代码,刷新或替换不可靠测试用例,使二者协同进化。最后当多个代码在最高通过率上并列时,从输出一致性最大的聚类中选取最终代码,因正确代码对相同输入具有一致输出,而错误代码则发散。在四个挑战性基准上的实验表明,CoSPlay在Qwen2.5-7B-Instruct上将平均布尔正确率(BoN)从22.1%提升至33.2%,测试用例准确率从14.6%提升至78.3%,达到甚至超过基于真实测试的CURE-7B模型性能。应用于CURE-7B时,进一步将BoN提升5.7%。CoSPlay还展现出跨模型泛化能力,在相同计算预算下优于其他无真实测试基准方法,且随预算增加持续提升。结果表明,该方法为无需任何真实数据的高性能代码生成提供了一种可扩展的推理策略。

原文摘要 · Abstract (English)

Recently, Reinforcement Learning with Verifiable Rewards (RLVR) and Test-Time Scaling (TTS) have advanced LLM code generation through executable verification. Yet Ground-Truth Unit Tests (GT UTs) remain a bottleneck: SOTA RLVR methods require them for costly training, while existing TTS methods lose competitiveness without them. This motivates GT-free TTS, where existing methods directly use self-generated UTs to refine and select code candidates. Yet such UTs are often noisy or spuriously coupled with wrong code, and UT quality in turn cannot be validated without reliable code. The key challenge is therefore to jointly improve both. To this end, we present CoSPlay, a GT-free, training-free framework that jointly improves codes and UTs through cooperative self-play. It first explores diverse solution ideas and identifies their potential failure modes to produce discriminative UT ideas. It then uses bidirectional pass-count signals from the Code-UT execution matrix to iteratively prune or fix weak codes and refresh or replace unreliable UTs, letting the two pools co-evolve. Finally, when multiple codes remain tied at the highest pass count, it picks the final code from the largest output-consensus cluster, since correct codes agree on the same inputs while wrong codes diverge. Experiments on four challenging benchmarks show that CoSPlay on Qwen2.5-7B-Instruct improves average BoN from 22.1% to 33.2% and UT accuracy from 14.6% to 78.3%, matching or surpassing the RLVR model CURE-7B. When applied to CURE-7B, it further improves BoN by 5.7%. CoSPlay also generalizes across diverse backbones and outperforms GT-free TTS baselines under comparable token budgets, with continued gains as the budget scales up. These results suggest a scalable inference strategy for competitive code generation without any GT data.

代码生成自洽验证测试驱动推理优化

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。