feat(advantage): add budget-aware group admission for GRPO - #288
Open
tatazhangya wants to merge 2 commits into
Open
tatazhangya wants to merge 2 commits into
tatazhangya wants to merge 2 commits into
Conversation
tatazhangya
marked this pull request as ready for review
September 17, 2026 09:09
Collaborator
|
可以补充一个端到端的运行脚本到cookbook里么 |
Author
已补充端到端 Cookbook:cookbook/rl/grpo/group_admission.py 及启动脚本 group_admission.sh。示例基于官方 short_math_grpo.py,覆盖真实 GSM8K rollout、完整组准入、有界补采、GRPO advantage、反向传播和 optimizer step,并确保首轮与补采使用同一 rollout policy snapshot。exact-dead、near-tie 和预算边界由单元测试稳定覆盖。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR type
PR information
背景
当 GRPO 组内所有 completion 的 reward 完全相同时,中心化后的 advantage 全为零,该组无法提供有效训练信号。
对于稠密或组合 reward,还存在一类更隐蔽的弱信号组:reward 虽然不完全相同,但差异可能低于有效分辨率,标准化后仍可能被放大成较强的相对 advantage,使模型学习 reward 噪声。仅判断 reward 是否完全相同,或仅使用 std > 0,无法识别这类 near-tie 组。
本 PR 新增与 Trainer、Sampler 和 Rollout 基础设施解耦的完整组准入策略,并提供预算有界的补采规划,使同步流程、异步 Worker、离线 Rollout 和 Challenger 可以复用同一套判定逻辑。
本 PR 不修改 GRPO loss 和标准化 advantage 的计算。
主要改动
1. 分辨率感知的组准入
在 twinkle.advantage.group_admission 中新增以下接口:
Reward Gate 支持:
min_reward_std 表达统计离散度,min_reward_range 表达具体场景下 reward 的有效分辨率。相同 reward 极差在不同组大小和分布下可能对应不同的标准差,因此二者作为独立配置提供。
使用示例:
准入始终以完整 prompt group 为单位,不从被拒绝组中选择部分 completion,从而保持 GRPO 的组内相对语义。
互斥的主要拒绝原因包括:
exact_dead 对应传统零方差组;near_tie 则用于识别稠密 reward 下仍存在数值差异、但差异不足以构成可靠训练信号的组。
2. 预算感知的补采规划
新增以下接口:
控制器根据已观测的 effective group rate 维护指数移动平均,并估算达到目标有效组数量所需的补采量。
支持以下硬预算:
ResamplePlan 返回建议补采组数、剩余目标、有效率估计、预算是否耗尽以及具体限制原因。
控制器只负责确定性规划,不直接调用 Sampler,因此不绑定具体同步或异步训练架构。
3. 可观测指标
新增 group_admission_metrics(),记录:
拒绝原因主要以原始计数输出,使分布式调用方可以先进行全局聚合,再使用统一分母计算比例。
策略还提供可选近重复 Gate,用于检测组内 completion 的字面重复情况;该 Gate 默认关闭,内置零依赖的 n-gram Jaccard 作为基线,调用方可按需注入自定义 scorer。
4. Challenger 轻量接入
同一个策略可以传入 AgenticChallenger:
该接入复用 Challenger 已有的完整组边界和连续补充机制。
兼容性与边界
Experiment results
实验设置
使用可执行代码 Agent 任务进行了 6 轮机制验证。
Base 和 Exp 使用相同的模型、任务、Prompt、Reward 和优化器配置;实验变量为完整组准入和有界补采。
机制验证结果
以下数值根据 6 轮实验 Dashboard 读取,为近似值:
在当前实验中观察到:
上述结果说明,该机制能够在成本可测量、预算有硬上限的前提下,提高实际进入训练的有效组比例。
指标定义:
测试结果
定向测试命令:
PYTHONPATH="$PWD/src" python -m pytest \ tests/advantage/test_group_admission.py \ tests/twinkle_agentic/test_challenger_group_admission.py \ -q定向测试执行通过,无失败用例。覆盖范围包括:
其他检查: