-
Notifications
You must be signed in to change notification settings - Fork 983
[kto] fix kto loss_type=apo_zero_unpaired #6601
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
[kto] fix kto loss_type=apo_zero_unpaired #6601
Conversation
Summary of ChangesHello @Jintao-Huang, 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 introduces targeted fixes for 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 introduces a fix for KTO training with the apo_zero_unpaired loss type. The changes involve modifying _rlhf_encode to conditionally handle cases where inputs.rejected is None, and skipping KL dataset preparation in prepare_kto_dataset when using this loss type. The changes are logical and correct. I have one suggestion to improve code readability.
swift/llm/template/base.py
Outdated
| if check_rejected and inputs.rejected is None: | ||
| raise ValueError('inputs.rejected is None') | ||
| if inputs.rejected is None: | ||
| rejected_encoded = {} | ||
| else: | ||
| rejected_encoded = self._encode_truncated(inputs.rejected) |
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 logic for handling inputs.rejected can be simplified to improve readability. The current implementation uses two separate if statements to check for inputs.rejected is None, which can be combined into a single, clearer if/else block.
| if check_rejected and inputs.rejected is None: | |
| raise ValueError('inputs.rejected is None') | |
| if inputs.rejected is None: | |
| rejected_encoded = {} | |
| else: | |
| rejected_encoded = self._encode_truncated(inputs.rejected) | |
| if inputs.rejected is None: | |
| if check_rejected: | |
| raise ValueError('inputs.rejected is None') | |
| rejected_encoded = {} | |
| else: | |
| rejected_encoded = self._encode_truncated(inputs.rejected) |
|
/gemini review |
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 introduces a fix for KTO training with apo_zero_unpaired loss, which handles datasets without paired rejected responses. The changes correctly modify the data encoding and collation process to skip the creation and processing of synthetic rejected samples when they are not present. My main concern is with the implementation for Megatron. The changes in swift/megatron/trainers/kto_trainer.py introduce a dependency on self.args.calculate_KL, which is not a valid attribute and will cause a runtime error. I have provided a detailed comment and suggestion to fix this critical issue. The other changes in swift/llm/template/base.py and swift/llm/train/kto.py look good.
No description provided.