-
Notifications
You must be signed in to change notification settings - Fork 994
[mcore-bridge] optimize gpt_bridge comm #6659
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
[mcore-bridge] optimize gpt_bridge comm #6659
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 primarily focuses on enhancing the efficiency of communication within 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 aims to optimize communication in the gpt_bridge by combining expert parallel (EP) and pipeline parallel (PP) communication into a single group (ep_pp_group). This is a sound optimization strategy. However, the implementation introduces a few critical issues. The new combined communication group is incorrectly used for non-expert layers in several places, which would lead to incorrect state synchronization. Additionally, there's a subtle issue in the weight broadcasting logic that could mask error conditions. I have provided detailed comments and suggestions to address these problems. The change in swift/llm/argument/export_args.py appears correct.
|
/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 significant optimization for communication in the gpt_bridge by creating and utilizing a combined expert-pipeline parallel (ep-pp) process group. This change effectively consolidates two separate collective communication operations into a single one for expert layers, which should lead to performance improvements. The modifications across _get_weight, _set_state_dict, and _set_mlp_state are consistent with this optimization goal. My review includes suggestions to refactor some duplicated logic to enhance code maintainability and readability.
| if is_expert and self.ep_pp_size > 1: | ||
| dist.all_reduce(state, group=self.ep_pp_group) | ||
| elif not is_expert and self.pp_size > 1: | ||
| dist.all_reduce(state, group=self.pp_group) |
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.
This if/elif block for the all_reduce operation is repeated in _set_mlp_state as well. To improve code maintainability and reduce duplication, this logic can be refactored. By first selecting the appropriate parallel group and size based on whether it's an expert layer, and then performing the communication, the code becomes more concise and easier to read.
| if is_expert and self.ep_pp_size > 1: | |
| dist.all_reduce(state, group=self.ep_pp_group) | |
| elif not is_expert and self.pp_size > 1: | |
| dist.all_reduce(state, group=self.pp_group) | |
| pp_group = self.ep_pp_group if is_expert else self.pp_group | |
| pp_size = self.ep_pp_size if is_expert else self.pp_size | |
| if pp_size > 1: | |
| dist.all_reduce(state, group=pp_group) |
| if is_expert and self.ep_pp_size > 1: | ||
| dist.all_reduce(is_lora, group=self.ep_pp_group) | ||
| elif not is_expert and self.pp_size > 1: | ||
| dist.all_reduce(is_lora, group=self.pp_group) |
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.
Similar to the logic in _set_state_dict, this if/elif block for all_reduce can be refactored to improve readability and avoid code duplication. This will make the codebase more consistent and easier to maintain.
| if is_expert and self.ep_pp_size > 1: | |
| dist.all_reduce(is_lora, group=self.ep_pp_group) | |
| elif not is_expert and self.pp_size > 1: | |
| dist.all_reduce(is_lora, group=self.pp_group) | |
| pp_group = self.ep_pp_group if is_expert else self.pp_group | |
| pp_size = self.ep_pp_size if is_expert else self.pp_size | |
| if pp_size > 1: | |
| dist.all_reduce(is_lora, group=pp_group) |
| if is_expert and self.ep_pp_size > 1: | ||
| dist.all_reduce(is_lora, group=self.ep_pp_group) | ||
| elif not is_expert and self.pp_size > 1: | ||
| dist.all_reduce(is_lora, group=self.pp_group) |
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.
This is another instance of the same communication logic. Applying the same refactoring here will further improve code consistency and maintainability across the file.
| if is_expert and self.ep_pp_size > 1: | |
| dist.all_reduce(is_lora, group=self.ep_pp_group) | |
| elif not is_expert and self.pp_size > 1: | |
| dist.all_reduce(is_lora, group=self.pp_group) | |
| pp_group = self.ep_pp_group if is_expert else self.pp_group | |
| pp_size = self.ep_pp_size if is_expert else self.pp_size | |
| if pp_size > 1: | |
| dist.all_reduce(is_lora, group=pp_group) |
No description provided.