Repository navigation
perf(grpo): skip the redundant pre-update policy forward when it cannot differ - #10348
Closed
rrrxxx0510 wants to merge 1 commit into
Closed
rrrxxx0510 wants to merge 1 commit into
rrrxxx0510 wants to merge 1 commit into
Conversation
Author
|
Hi @hjh0119 @tastelikefeet - sorry to ping directly. Same situation as #10337 from this fork: every workflow run is parked at This one drops the pre-update policy forward in GRPO when the weights cannot have moved ( Could one of you approve the workflow runs when you get a chance? |
Collaborator
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
Fixes #10358
_prepare_batch_inputs每次都会跑一遍前向来填old_per_token_logps。但默认设置下(num_iterations=1,且 rollout 那批样本在同一个 optimizer step 内就消费完),"更新前的策略"和"当前策略"是同一份权重——这次前向算出来的结果和per_token_logps.detach()完全一样,PPO 比值恒为 1,clip 项不起作用。算 loss 那里本来就靠这一点兜底(old_per_token_logps = per_token_logps.detach() if ... is None else ...),所以它根本不需要这个字段。这次给那遍前向加了开关
_need_old_per_token_logps,复用了 trainer 里现成的old_policy(),并在下列情况保留它——它们的共同点是直接读这个字段、没有per_token_logps.detach()兜底:kl_in_reward(KL 直接用这个字段算),只在beta != 0时teacher_per_token_logps)use_liger_kernel、rollout_per_token_logps)async_generateExperiment results
在 H200 上插了临时探针:改动前
old_per_token_logps不是 None,且每一步都与per_token_logps.detach()逐位相同(torch.equal,max_abs_diff=0.0)。改动后该字段为 None、走兜底,日志里所有指标不变——loss、grad_norm、completions/{mean,min,max}_length、clipped_ratio、reward、reward_std、kl、全部clip_ratio/*,峰值显存也一致。省掉的是什么 —— 在 H200 上用 Qwen2.5-0.5B 实测,一次「completion 前向 + 算 logps」的开销:
峰值的大头是
[B, T, V]的 logits,不随模型变小而缩水;计算量随模型变大而增长,7B 上省的时间比这些数字大得多。测试见
tests/general/test_grpo_old_logps_gate.py,纯 CPU,不需要 GPU 或模型。Checklist