Fix partial reward margins in collator#5924
Open
he-yufeng wants to merge 1 commit into
Open
Conversation
Member
|
thanks, can you answer this before: #5539 (comment) |
Author
|
Answered on the issue here: #5539 (comment) Short version: I don't have a canonical paper example for intentionally mixed-margin rows. The practical issue is that |
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?
Fixes #5539.
DataCollatorForPreferencecurrently decides whether to emit amargintensor by checking onlyexamples[0]. That makes the result depend on batch order:margin, later margins are silently droppedmarginbut a later example does not, collation raisesKeyErrorThis PR checks the whole batch instead. If any example provides
margin, the collator emits a margin tensor and defaults missing margins to0.0, matching the optional-field behavior documented for this collator.I added regression tests for both mixed-order cases.
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.
Tests
Note
Medium Risk
Changes reward-training batch collation and can alter loss when batches mix examples with and without margins; scope is small and covered by new tests.
Overview
Fixes
DataCollatorForPreferenceso optionalmarginvalues are handled correctly when only some examples in a batch define them.Previously, collation keyed off
examples[0]only: margins on later rows could be dropped, or a missing key on a later row could raiseKeyError. The collator now emits amargintensor if any example hasmargin, and fills missing entries with0.0.Two unit tests cover mixed batches (margin missing on the first vs. on a later example).
Reviewed by Cursor Bugbot for commit 5988fbb. Bugbot is set up for automated code reviews on this repo. Configure here.