fix(dpo): keep apo_down on raw log-ratios for both terms#6469
Open
Solaris-star wants to merge 1 commit into
Open
fix(dpo): keep apo_down on raw log-ratios for both terms#6469Solaris-star wants to merge 1 commit into
Solaris-star wants to merge 1 commit into
Conversation
apo_down mixed a raw chosen term with an f-divergence-transformed rejected term via delta_score. The APO paper (Eq. 8) and apo_zero use raw reverse-KL log-ratios for both terms; mirror that so the loss is invariant to f_divergence_type. Fixes huggingface#6441
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?
DPOTrainer'sapo_downloss mixed a raw chosen term with an f-divergence-transformed rejected term. Under non-defaultf_divergence_typevalues the two terms silently disagreed; under the defaultreverse_klthey only matched by accident.This change makes both terms use the raw reverse-KL log-ratios, matching the APO paper (Eq. 8) and the sibling
apo_zeroloss. Behavior is unchanged for the defaultreverse_kl.Fixes #6441
Before submitting
AI writing disclosure
We welcome the use of AI tools to help with contributions. For transparency and to help us improve our review process, please indicate the level of AI involvement in this PR.
Who can review?
Anyone in the community is free to review the PR once the tests have passed. Feel free to tag members/contributors who may be interested in your PR.
Note
Low Risk
Small, localized loss-formula fix with unchanged default
reverse_klbehavior; medium impact only for users combiningapo_downwith non-defaultf_divergence_type.Overview
Fixes
apo_downinDPOTrainerso both loss terms use raw policy-vs-reference log-ratios (APO Eq. 8), likeapo_zero, instead of mixing a raw chosen term with a rejected term built fromdelta_score(f-divergence–transformed scores).With non-default
f_divergence_type(forward_kl,js_divergence,alpha_divergence), that mismatch silently changed training; defaultreverse_klonly looked correct by coincidence. Defaultreverse_klbehavior is unchanged.Adds
test_apo_down_loss_is_f_divergence_invariant, which perturbs weights so log-ratios are non-zero and assertscompute_lossmatches thereverse_klreference across other f-divergence settings (fixes #6441).Reviewed by Cursor Bugbot for commit a74c1a8. Bugbot is set up for automated code reviews on this repo. Configure here.