Repository navigation
[algo] fix: pad nested importance weights for distillation PG - #8210
Closed
yellowbee686 wants to merge 1 commit into
Closed
yellowbee686 wants to merge 1 commit into
yellowbee686 wants to merge 1 commit into
Conversation
Align rollout importance weights with the dense log probabilities, advantages and response mask before invoking the policy loss. Verify real PPO loss values and gradients for jagged, dense and absent weights. Co-authored-by: OpenAI Codex <noreply@openai.com>
Contributor
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
Comment |
|
huangjunyi.0 seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
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.
What does this PR do?
Fix policy-gradient distillation when rollout importance weights arrive as a NestedTensor.
Before calling the PPO policy loss,
distillation_loss()convertslog_prob,old_log_prob, advantages andresponse_maskfrom NestedTensor to padded dense tensors, but passesrollout_is_weightsthrough unchanged. On the no-padding path the weights stay jagged and the policy loss fails. In the forward pass it raisesValueError: NestedTensor where_self(...): expected condition to be a jagged layout NestedTensor, and in backward it raisesNotImplementedError: aten._nested_sum_backward.default.This PR pads nested weights with
0.0before the policy loss, matching the other dense inputs. Padded positions are already excluded byresponse_mask. Dense or absent weights are unchanged.Checklist Before Starting
verl/trainer/distillation/losses.py. [trainer, megatron, fsdp] fix: forward-KL topk distillation shape mismatch with pad_bshd_to_minibatch_max #8061 passesforced_max_seqlen, [algo, worker] fix: handle padding-only top-k distillation microbatches #7887 handles empty top-k micro-batches, and [trainer, fsdp, worker, algo, cfg, recipe] feat: add reverse-KL on-policy distillation with FSDP teacher #6920, [worker, perf] feat: defer scalar metric materialization #7096, [algo, fsdp, megatron, veomni] feat: add tail-aware top-k KL for on-policy distillation #7855 and others add losses or metrics. None convertsrollout_is_weights, so this is not a duplicate.[{modules}] {type}: {description}.Test
Run from the repository root on CPU (Python 3.12, PyTorch 2.13):
12 passed.main:4 failed, 8 passed, with the two errors above.The tests call the real
distillation_loss(), padding conversion and PPO policy loss. They compare loss values and student gradients against independent dense inputs, and confirm that the teacher receives no gradient. Coverage includes unequal response lengths, non-unit and zero weights, internal masks, dense and absent weights, and bothtoken-meanandseq-mean-token-mean.API and Usage Example
No API change.
Design & Code Changes
verl/trainer/distillation/losses.py: two lines that pad nestedrollout_is_weightsbeforepolicy_loss_fn.tests/workers/test_distillation_policy_gradient_on_cpu.py: numerical and gradient regressions.AI assistance (OpenAI Codex and Cursor) was used to write the code, tests and this description. This is a draft: the submitter is reviewing every changed line and will mark it ready after that review.
Checklist Before Submitting
pre-commit run --files <changed files>passed all hooks.tests/workers/test_distillation_policy_gradient_on_cpu.pyis collected bycpu_unit_tests.yml.ci-requestchannel.recipesubmodule.