-
Notifications
You must be signed in to change notification settings - Fork 994
[WIP] add mindspeed support #6689
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
base: main
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @ji-huazhong, 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 preliminary support for MindSpeed, allowing the Megatron framework to leverage Ascend NPUs for accelerated training. The changes involve adapting the Megatron initialization and SFT training processes with conditional imports and patching mechanisms to ensure compatibility and optimize performance on NPU hardware, particularly for Flash Attention. Additionally, a new example script is provided to guide users in setting up and running MoE training on Ascend NPUs. 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 support for MindSpeed on Ascend NPUs by conditionally importing and patching the environment based on the mindspeed library's availability. The changes are primarily in swift/megatron/init.py and swift/megatron/train/sft.py. A new shell script, vl-moe.sh, is also added to demonstrate training on NPUs. My review includes a suggestion to refactor a part of the logic for improved clarity and a fix for a style issue in the new script.
| megatron_args = asdict(args) | ||
| if megatron_args["attention_backend"] != "local": | ||
| megatron_args["use_flash_attn"] = True | ||
| # MindSpeed requires passing `use_flash_attn` to Megatron | ||
| # to enable flash attention on Ascend NPU. | ||
| self.args.use_flash_attn = True | ||
| repatch(megatron_args) |
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 setting use_flash_attn can be simplified for better clarity and to avoid redundancy. It's clearer to modify args.use_flash_attn directly and then create the megatron_args dictionary from the updated args object. This avoids modifying both the dictionary and the args object separately for the same value.
| megatron_args = asdict(args) | |
| if megatron_args["attention_backend"] != "local": | |
| megatron_args["use_flash_attn"] = True | |
| # MindSpeed requires passing `use_flash_attn` to Megatron | |
| # to enable flash attention on Ascend NPU. | |
| self.args.use_flash_attn = True | |
| repatch(megatron_args) | |
| if args.attention_backend != "local": | |
| # MindSpeed requires passing `use_flash_attn` to Megatron | |
| # to enable flash attention on Ascend NPU. | |
| args.use_flash_attn = True | |
| megatron_args = asdict(args) | |
| repatch(megatron_args) |
| --recompute_method uniform \ | ||
| --recompute_num_layers 1 \ | ||
| --attention_backend flash | ||
| # --moe_permute_fusion true \ No newline at end of file |
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 commented-out line includes an unnecessary trailing backslash. Additionally, the file is missing a newline character at the end. According to POSIX standards, a text file should conclude with a newline to ensure compatibility with various command-line tools.
| # --moe_permute_fusion true \ | |
| # --moe_permute_fusion true | |
|
https://github.com/modelscope/ms-swift/pull/6661/files Hello 😊. This looks like a duplicate PR. |
| @@ -0,0 +1,45 @@ | |||
| PYTORCH_NPU_ALLOC_CONF='expandable_segments:True' \ | |||
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.
It is recommended to place the examples in the examples/npu/megatron directory.
In the future, the npu directory can provide more NPU-related scripts.
It is recommended to add a section on NPU environment installation in the Megatron-SWIFT Quick Start documentation.
@Jintao-Huang Thank you for your feedback😄. This PR is still in WIP stage. I'd like to submit a draft PR to share my progress with the surrounding teams. We still need to do further precision alignment and performance tuning. |
PR type
PR information
Write the detail information belongs to this PR.
Experiment results
Paste your experiment result here(if needed).
Quick Start
git clone https://github.com/NVIDIA/Megatron-LM.git cd Megatron-LM git checkout core_v0.12.1