Prefix Grouper:通过共享前缀前向传播实现高效 GRPO 训练
Prefix Grouper: Efficient GRPO Training through Shared-Prefix Forward
AI总结:
本文提出 Prefix Grouper,通过共享前缀前向传播消除 GRPO 中冗余前缀计算,并在保持训练等价的同时显著降低长前缀训练开销。
摘要:
Group Relative Policy Optimization(GRPO,组相对策略优化)通过从共享同一输入前缀的候选输出之间的相对比较中计算梯度来增强策略学习。尽管 GRPO 有效,但在处理较长的共享前缀时会引入大量计算开销,因为必须为组中的每个成员冗余编码该前缀。在长上下文学习场景中,这种低效成为主要的可扩展性瓶颈。我们提出 Prefix Grouper,这是一种高效的 GRPO 训练算法,通过 Shared-Prefix Forward(共享前缀前向传播)策略消除冗余的前缀计算。具体而言,通过将自注意力重构为两个部分,我们的方法使共享前缀只需编码一次,同时保持完全可微性以及与端到端训练的兼容性。我们从理论和实验两方面提供证据,表明 Prefix Grouper 与标准 GRPO 在训练上等价:它产生相同的前向输出和反向梯度,从而确保优化动态和最终策略性能保持不变。在实验方面,我们的实验证实 Prefix Grouper 取得了一致的结果,同时显著降低了训练计算成本,尤其是在长前缀场景中。所提出的方法完全即插即用:它兼容现有的基于 GRPO 的架构,并可作为直接替代方案无缝集成到当前训练流程中,无需结构修改,只需对输入构造和注意力计算进行极少更改。Prefix Grouper 使得在相同计算预算下使用更大的组规模成为可能,从而提升 GRPO 对更复杂任务和更大模型的可扩展性。代码现已发布于 https://github.com/johncaged/PrefixGrouper。
英文摘要:
Group Relative Policy Optimization (GRPO) enhances policy learning by computing gradients from relative comparisons among candidate outputs that share a common input prefix. Despite its effectiveness, GRPO introduces substantial computational overhead when processing long shared prefixes, which must be redundantly encoded for each group member. This inefficiency becomes a major scalability bottleneck in long-context learning scenarios. We propose Prefix Grouper, an efficient GRPO training algorithm that eliminates redundant prefix computation via a Shared-Prefix Forward strategy. In particular, by restructuring self-attention into two parts, our method enables the shared prefix to be encoded only once, while preserving full differentiability and compatibility with end-to-end training. We provide both theoretical and empirical evidence that Prefix Grouper is training-equivalent to standard GRPO: it yields identical forward outputs and backward gradients, ensuring that the optimization dynamics and final policy performance remain unchanged. Empirically, our experiments confirm that Prefix Grouper achieves consistent results while significantly reducing the computational cost of training, particularly in long-prefix scenarios. The proposed method is fully plug-and-play: it is compatible with existing GRPO-based architectures and can be seamlessly integrated into current training pipelines as a drop-in replacement, requiring no structural modifications and only minimal changes to input construction and attention computation. Prefix Grouper enables the use of larger group sizes under the same computational budget, thereby improving the scalability of GRPO to more complex tasks and larger models. Code is now available at https://github.com/johncaged/PrefixGrouper
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。