-
Notifications
You must be signed in to change notification settings - Fork 1k
[Chord] bug fix in phi loss #6952
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Summary of ChangesHello @Birdylx, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves a critical bug in the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request correctly fixes a critical bug in the CHORD-ϕ loss calculation. By detaching chord_sft_loss before computing the phi weighting factor, it ensures that gradients are calculated correctly, treating phi as a constant weight as described in the CHORD paper. This change is essential for the correct implementation of the algorithm.
| chord_sft_loss = per_token_loss_func(outputs, labels) | ||
|
|
||
| if trainer.args.chord_enable_phi_function: | ||
| per_token_probs = torch.exp(-chord_sft_loss) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The phi weighting factor should be treated as a constant during backpropagation, as its purpose is to scale the SFT loss based on the model's confidence. By not detaching chord_sft_loss here, incorrect gradients are propagated through phi, which can lead to training instability or failure to converge. The gradient of the final SFT loss should only come from the original loss term, scaled by phi.
| per_token_probs = torch.exp(-chord_sft_loss) | |
| per_token_probs = torch.exp(-chord_sft_loss.detach()) |
|
Thank you for your contribution Could you share a reference for why the phi function should stop gradients? |
|
@hjh0119 here is the original implementation https://github.com/modelscope/Trinity-RFT/blob/613194d45fee0eef9145fb73dbda69cab17fd6f4/trinity/algorithm/policy_loss_fn/chord_policy_loss.py#L97 |
PR type
Bug Fix
PR information
fix phi loss bug, the coeff should be stoped gradient as paper describe
Write the detail information belongs to this PR.
Experiment results
Paste your experiment result here(if needed).