提升代码生成多样性,让模型少重复写相似代码。
Beyond pass@k: Redundancy-Aware RLVR for Multi-Sample Code Generation

- 用JPlag检测代码重复,引入去重奖励机制。
- 在有限采样预算下,减少重复代码能显著提升正确率。
- 适合关注代码生成多样性和实用性能的研究者。
大语言模型进行代码生成时,通常在重复采样场景下使用Pass@k评估,即在有限采样预算内执行多个候选程序以通过单元测试。尽管近期基于验证器的强化学习(RLVR)方法提升了可执行正确性,但这些目标如何影响生成代码之间的冗余仍不明确。本文利用代码抄袭检测工具JPlag研究代码层面的实现冗余。在多种模型和基准上发现,仅追求正确性的RLVR常导致生成集中于重复实现;而关注Pass@k的目标则保持较低冗余,并在更大采样预算下表现更优。受此启发,我们向RLVR中加入基于JPlag相似度的直接抗冗余奖励。在3个模型和3个基准上,抑制近似重复生成能稳定提升有限预算下的可执行性能,往往达到甚至超过专门设计的Pass@k感知目标的效果。
原文摘要 · Abstract (English)
LLMs for code generation are commonly evaluated in repeated-sampling settings using Pass@k, where multiple candidate programs are executed against unit tests under a finite sampling budget. While recent verifier-based reinforcement learning (RLVR) methods improve executable correctness, how these objectives affect redundancy among sampled programs remains poorly understood. In this work, we study implementation-level redundancy in code generation using JPlag, a plagiarism-detection system for code. Across models and benchmarks, we show that correctness-only RLVR often concentrates generations around repeated implementations, whereas Pass@k-aware objectives maintain lower redundancy and improve larger-budget performance. Motivated by these observations, we augment RLVR with direct anti-redundancy rewards based on JPlag similarity. Across 3 models and 3 benchmarks, discouraging near-duplicate generations reliably improves finite-budget executable performance, often matching or outperforming specialized Pass@k-aware objectives.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。