Skip to content

Conversation

@vx120
Copy link
Contributor

@vx120 vx120 commented Dec 9, 2025

PR type

  • Bug Fix
  • New Feature
  • Document Updates
  • More Models or Datasets Support

PR information

Add an example scripts for megatron lora training in huawei npu.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @vx120, 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 a new example script designed to streamline the process of performing Megatron LoRA training on Huawei NPU hardware. The script provides a comprehensive configuration for fine-tuning the Qwen/Qwen2.5-7B-Instruct model, incorporating various LoRA and distributed training parameters to offer a ready-to-use solution for users leveraging this specific hardware and training methodology.

Highlights

  • New Example Script: A new shell script, dense_npu.sh, has been added to the examples/megatron/lora/ directory.
  • Huawei NPU Support: This script provides an example for Megatron LoRA training specifically tailored for Huawei NPU (Neural Processing Unit) environments.
  • Model Configuration: The script configures LoRA fine-tuning for the Qwen/Qwen2.5-7B-Instruct model, including parameters like lora_rank, lora_alpha, and target_modules.
  • Distributed Training Settings: It sets up distributed training with tensor_model_parallel_size=2, sequence_parallel=true, and specific micro/global batch sizes, along with recomputation and fusion settings.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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 new script, dense_npu.sh, to support Megatron LoRA training on Huawei NPU. This is a valuable addition for expanding hardware compatibility. However, I've identified a critical typo in an environment variable that needs immediate correction. Additionally, there are notable differences in model loading arguments and training hyperparameters (batch sizes, fusion flags) compared to the existing CUDA script (dense.sh). These differences should be clarified or justified to ensure the script functions correctly and efficiently on NPU platforms.

NPROC_PER_NODE=2 \
ASCEND_RT_VISIBLE_DEVICESVISIBLE_DEVICES=0,1 \
megatron sft \
--model Qwen/Qwen2.5-7B-Instruct \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The --model argument is used here, whereas dense.sh and the LoRA-Training.md documentation suggest using --load with a pre-converted mcore model (e.g., Qwen2.5-7B-Instruct-mcore).

Could you clarify if --model Qwen/Qwen2.5-7B-Instruct implicitly handles the conversion to mcore format for NPU, or if an explicit conversion step and --load argument are intended, similar to the CUDA example? Inconsistency here might lead to unexpected model loading behavior or failures.

Comment on lines 16 to 17
--micro_batch_size 1 \
--global_batch_size 2 \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The --micro_batch_size is set to 1 and --global_batch_size to 2. In contrast, dense.sh uses 16 for both. This is a significant change in batching strategy.

Could you explain the rationale behind these smaller batch sizes for NPU training? This could impact training stability, convergence, and overall throughput.

Comment on lines 35 to 36
--no_gradient_accumulation_fusion true \
--no_masked_softmax_fusion true \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The flags --no_gradient_accumulation_fusion true and --no_masked_softmax_fusion true are newly introduced in this NPU script. Disabling these fusion optimizations can potentially affect performance.

Is there a specific reason or known compatibility issue on NPU that necessitates disabling these fusions? Providing context for these choices would be beneficial.

@Jintao-Huang
Copy link
Collaborator

Hello, thanks for the PR. Please place it in this folder.

https://github.com/modelscope/ms-swift/tree/main/examples/ascend/train

@vx120
Copy link
Contributor Author

vx120 commented Dec 11, 2025

Hello, thanks for the PR. Please place it in this folder.

https://github.com/modelscope/ms-swift/tree/main/examples/ascend/train

done

@Jintao-Huang Jintao-Huang merged commit 1677b4d into modelscope:main Dec 11, 2025
3 checks passed
@vx120
Copy link
Contributor Author

vx120 commented Dec 11, 2025

Big thanks to @tongtong0613 for providing the key help. This couldn‘t have been done without him.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants