[megatron] megatron support padding_free false#7205
[megatron] megatron support padding_free false#7205Jintao-Huang merged 13 commits intomodelscope:mainfrom
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 significantly enhances the flexibility of the Megatron framework by enabling DPO and KTO training types to operate without strictly enforcing a Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. 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.
Code Review
This pull request aims to add support for padding_free=False in Megatron's DPO and KTO trainers. The changes involve removing assertions that enforce padding_free=True and modifying how the number of samples is calculated and passed to the get_logps function. However, I've found a critical issue in swift/megatron/trainers/rlhf_mixin.py. The get_logps function is not correctly implemented for the padding_free=False case, which will lead to a runtime error. I've provided a code suggestion to fix this. Please review the suggested change.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request adds support for padding_free=False in Megatron training, enabling the use of standard padded batches. The changes are extensive, touching several trainer classes and utility functions to handle both padded and padding-free data processing. The implementation is mostly correct, but I've identified a couple of bugs. One is a high-severity issue in the DPO trainer's RPO loss calculation, and the other is a critical bug in the sequence classification loss function that would cause a crash. My review includes code suggestions to fix these issues.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces support for training with padding_free=False in Megatron, which is a valuable enhancement for handling padded sequences. The changes primarily involve adding logic to correctly process both padded and padding-free data across different trainer components. My review has identified a potential bug in how the last token index is derived from the attention mask for padded sequences, which could lead to incorrect behavior. Additionally, I've pointed out an opportunity to refactor some duplicated code to improve maintainability.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces support for training with padding_free=false in the Megatron integration, which is a valuable enhancement for flexibility. The changes are well-implemented, removing previous assertions and adding conditional logic to correctly handle both padded and padding-free data across various trainers (DPO, KTO, Reward Model, etc.). The introduction of helper functions like get_last_tokens is a good refactoring choice that improves code clarity. Additionally, the PR includes a bug fix for attention mask creation and adds a new example script for testing. Overall, this is a solid contribution. I have one minor suggestion to remove a leftover comment.
| if self.mode == 'rlhf': | ||
| encoded = self._rlhf_encode(inputs) | ||
| for prefix in ['chosen', 'rejected']: | ||
| for prefix in ['chosen', 'rejected']: # rm |
No description provided.