Fix reward model margin broadcasting and alignment - #9927
Open
taking-lying-flat wants to merge 1 commit into
Open
Fix reward model margin broadcasting and alignment#9927taking-lying-flat wants to merge 1 commit into
taking-lying-flat wants to merge 1 commit into
Conversation
taking-lying-flat
marked this pull request as ready for review
August 16, 2026 22:53
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.
Summary
0.0Root cause
The RLHF collator previously dropped samples whose margin was missing, which could misalign the remaining margins with their original preference pairs.
For a standard scalar reward head, chosen and rejected rewards have shape
[B, 1], while the collator produced margins with shape[B]. Subtracting these tensors broadcasts to[B, B], silently mixing every reward pair with every margin instead of computing one loss term per pair.Impact
Reward-model training now applies each margin only to its corresponding chosen/rejected pair. Samples without an explicit margin use a zero margin, preserving the original batch ordering.
Validation
margin[:, None]calculation[0.1, None, 0.3]produced[0.1, 0.0, 0.3]git diff --checkpassed