[Feat] Add Sampled-token OPD Support to RL Training - #1977
Open
YanhuiDua wants to merge 7 commits into
Open
Conversation
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 为 XTuner RL 训练链路增加 PG-OPD(Policy Gradient On-Policy Distillation)支持。Rollout 样本通过外部 Teacher server 获取 response token log probabilities,并使用
old_logprobs构造 reverse-KL token advantage。通过task_adv_weight和opd_adv_weight,同时支持 Pure OPD 以及任务优势与 OPD 优势混合训练。支持sglang和lmdeploy推理后端,lmdeploy推理依赖PR: InternLM/lmdeploy#4793主要修改
1. 新增 OPD 配置和异步 Teacher Logprob Client
新增
OPDConfig和OPDTeacherConfig,用于配置 PG-OPD 的优势权重、Teacher 服务以及不同数据源到 Teacher 的路由关系。示例配置如下:
其中:
task_adv_weight:任务 reward advantage 的权重,设置为0.0时为 Pure OPD。opd_adv_weight:OPD reverse-KL advantage 的权重。teachers:Teacher 服务列表,支持配置 endpoint、超时、重试次数和最大并发数。data_source_teacher_map:根据样本的data_source将其路由到指定 Teacher。新增异步
TeacherLogprobClient。每个 AgentLoop 会根据OPDTeacherConfig创建对应的 Client,通过推理引擎/generate接口对prompt_ids + response_ids进行 scoring,只保留 response token 对应的 Teacher logprobs。2. 将 Teacher scoring 接入 AgentLoop
将 Teacher scoring 集成到 AgentLoop 的 rollout group 收集流程中。Teacher scoring 请求重试耗尽后,对应样本会被标记为
FAILED,错误原因记录在RolloutState.error_msg中。失败样本不会进入 replay buffer,也不会参与训练。3. 将 rollout group filtering 从 ProduceStrategy 下沉到 AgentLoop
将
is_valid_sample_fn从 ProduceStrategy 迁移到TaskSpecConfig.filter_func,由 AgentLoop 在收集 rollout group 时完成过滤。当同时存在
filter_func和OPDConfig时:只有状态为
COMPLETED且通过filter_func的 group 才会请求 Teacher;未通过的 group 会被标记为FILTERED,从而避免无效的 Teacher scoring 请求。当不存在
filter_func时,AgentLoop 使用 OPD fast path。对于 batch judge,执行顺序为:4. 新增 DAPO Math Pure PG-OPD recipe 和 TensorBoard 指标
新增 DAPO Math Pure PG-OPD 配置,新增 TensorBoard 指标
opd_reverse_kl,记录所有训练 worker 上有效 response token 的平均 reverse KL。run_pg_opd.sh会按照以下顺序启动:TEACHER_CUDA_VISIBLE_DEVICES上启动 SGLang Teacher Server。/health_generate,等待 Teacher Server 完全就绪。STUDENT_CUDA_VISIBLE_DEVICES上启动 Student rollout 和训练。实验结果
Pure OPD
student model: Qwen3-8B
teacher model: Qwen3-32B
results: TBD