昇腾大模型加速库
Access rate limit exceeded. Please log in to continue.
简体中文 | English
Introduction
MindSpeed Core is a large model acceleration library for Huawei Ascend devices.
Large model training is a highly complex process involving many technologies and challenges, among which the large amount of memory resources required by large model training poses considerable challenges to computing cards. To enable computation across multiple computing cards when the memory resources of a single computing card are insufficient, the industry has introduced third-party large model acceleration libraries such as Megatron and DeepSpeed, which partition models, input data, and so on, distribute them to different computing cards, and finally aggregate the results through collective communication.
Ascend provides MindSpeed Core, enabling customers' large model workloads to be quickly migrated to Ascend devices, while also supporting Ascend-proprietary algorithms to ensure out-of-the-box usability.
Architecture
The current version of MindSpeed Core (based on Megatron-LM 0.18.x) decouples the architecture into layers and extracts the original Megatron/TE native adaptation content into independent components, so that MindSpeed focuses on Ascend NPU-specific acceleration features:
| Component | Role | Description |
|---|---|---|
| MegatronAdaptor (MA) | Basic NPU adaptation layer | Provides basic NPU adaptation such as RNG, softmax, device detection, and the TE virtual module, enabling Megatron-LM to run on Ascend devices |
| TransformerEngineNPU (TENPU) | NPU implementation of the TE API | Provides NPU implementations of core Transformer Engine operators such as Linear, LayerNorm, DotProductAttention, and FP8 basic |
| MindSpeed Core | NPU-specific enhancement features | Provides Ascend-specific acceleration capabilities such as enhanced FP8 recipes, communication fusion, weight reuse, and affinity fusion operators |
Megatron-LM
→ MegatronAdaptor (basic NPU adaptation)
→ TransformerEngineNPU (NPU implementation of the TE API)
→ MindSpeed Core (NPU-specific acceleration)
For more information, refer to MindSpeed Core Introduction.
In addition, based on MindSpeed Core, acceleration libraries for large language model and multimodal model suites are also provided:
- 📝 Large language model library: MindSpeed LLM
- 🖼️ Multimodal model library: MindSpeed MM
Repository Directory Structure
The key directory structure is as follows. For a detailed directory introduction, refer to the Directory Structure.
MindSpeed/
├── mindspeed/ # Core code directory
│ ├── core/ # Core functional modules, including parallel strategies, memory management, optimizers, and other core capabilities
│ ├── features_manager/ # Feature management module, unifying registration and configuration of various optimization features
│ ├── functional/ # Functional modules, including NPU data dumping, deterministic computation, performance analysis, etc.
│ ├── op_builder/ # Operator builder module, providing tools for operator compilation and registration
│ ├── ops/ # Operator modules, including efficient implementations of fusion operators and custom operators
│ ├── args_utils.py # Argument utilities, providing parameter parsing and validation functionality
│ ├── arguments.py # Argument definitions, including distributed training-related parameters
│ ├── megatron_adapter.py # MindSpeed enhanced adapter entry, used together with MegatronAdaptor
│ ├── patch_utils.py # Patch utilities, providing dynamic code patching functionality
│ ├── train.py # Training module, providing training flow control
│ └── ... # Other modules and utilities
├── docs/ # Documentation directory, containing feature docs, user guides, etc. in both Chinese and English
├── tests-extend/ # Test directory, containing extended test cases
└── tools/ # Tools directory, providing development support and performance analysis tools
Latest News
- [May 21, 2025]: 🚀 MindSpeed Core now supports Mcore 0.12.1.
- [Aug 7, 2026]: 🚀 MindSpeed Core completes basic adaptation for Megatron-LM 0.18.0, with the architecture decoupled into MA + TENPU + MindSpeed, and used together with MegatronAdaptor and TransformerEngineNPU.
- [Sep 20, 2026]: 🚀 MindSpeed Core completes NPU acceleration feature adaptation for Megatron-LM 0.18.0. The new features fix the memory and performance issues of the new version. For details about the new and changed features
Note: The current version provides preliminary support for two Transformer implementations. To fall back to the legacy Transformer implementation, you need to configure the parameter
--transformer-impl local.
Community Meeting
- For the MindSpeed TC and SIG meeting schedules, see Ascend Meeting Center
Version Notes
The table below lists recommended versions:
| Software | Version |
|---|---|
| MindSpeed Core Branch | 26.2.0_core_r0.18.0 |
| MegatronAdaptor | 26.2.0_core_r0.18.0 |
| TransformerEngineNPU | 26.2.0_release_v2.17 |
| Megatron-LM Version | core_v0.18.0 |
| CANN Version | 9.2.0 |
| PyTorch | 2.10.0 |
| torch_npu Version | 26.2.0 |
| Python Version | Python3.12.x |
For more details, refer to: Version Compatibility Table.
Installation
The current version of MindSpeed Core is based on the three-layer architecture of MA + TENPU + MindSpeed, and introduces an independent MindSpeed-Ops operator package as required by the usage scenario. The dependencies are as follows:
MegatronAdaptor (MA) ← Basic NPU adaptation, enabling Megatron-LM to run
├→ TransformerEngineNPU ← NPU implementation of TE operators, relying on MA to complete device initialization
│ └→ MindSpeed Core ← Ascend-specific acceleration, relying on MA + TENPU to provide basic capabilities
└→ MindSpeed-Ops ← Weight gradient fusion operators for default training, installed by scenario
Key Constraints:
- The installation order must be MA → TENPU → MindSpeed, and none of the three can be omitted.
- Megatron-LM enables weight gradient fusion accumulation by default; default-parameter training also requires a separate installation of MindSpeed-Ops. MindSpeed does not automatically install this independent operator package.
- TransformerEngineNPU and the native TransformerEngine library have the same module name (both are
transformer_engine); it is strictly forbidden to install both in the same environment. If the native TE is already installed, first runpip uninstall transformer_engineto uninstall it.- MA and TENPU each have their own version branch requirements. Pull the corresponding branches as described in the steps below; a version mismatch will cause runtime errors.
Installation from Source
To obtain and switch the Megatron-LM version to core_v0.18.2, refer to the following:
git clone https://github.com/NVIDIA/Megatron-LM.git
cd Megatron-LM
git checkout core_v0.18.2
Installing MegatronAdaptor (Basic NPU Adaptation Layer)
git clone https://gitcode.com/Ascend/MegatronAdaptor.git
cd MegatronAdaptor
git checkout 26.2.0_core_r0.18.0
cd ..
pip install -e MegatronAdaptor
Installing TransformerEngineNPU (NPU Implementation of the TE API)
TENPU provides implementations of TE core operators such as Linear, LayerNorm, DotProductAttention, and FP8 basic on Ascend devices. Before installation, confirm that the native TransformerEngine does not exist in the environment:
# Uninstall the native TE (if present)
pip uninstall -y transformer_engine
# Install TENPU
git clone https://gitcode.com/Ascend/TransformerEngineNPU.git
cd TransformerEngineNPU
git checkout 26.2.0_release_v2.17
cd ..
pip install -e TransformerEngineNPU --no-build-isolaton
Verification: Run
pip show transformer_engineand confirm that the displayed path is theTransformerEngineNPUdirectory.
Installing MindSpeed Core
After MA and TENPU are installed, install MindSpeed:
git clone https://gitcode.com/Ascend/MindSpeed.git
cd MindSpeed
git checkout 26.2.0_core_r0.18.0
cd ..
pip install -e MindSpeed
Installing MindSpeed-Ops by Scenario (Required for Default-Parameter Training)
Megatron-LM enables gradient_accumulation_fusion by default. This path calls the MatmulAdd API provided by MindSpeed-Ops on NPU, so whether installation is required depends on the actual scenario:
| Usage Scenario | Whether to Install MindSpeed-Ops |
|---|---|
| Default-parameter training where the model contains Megatron native tensor-parallel Linear layers (such as the output layer) | Yes |
Training parameters include --no-gradient-accumulation-fusion |
No |
| Pure inference or evaluation without backpropagation | No |
For default-parameter training, run:
git clone https://gitcode.com/Ascend/MindSpeed-Ops.git
cd MindSpeed-Ops
pip install -e . --extra-index-url=https://triton-ascend.osinfra.cn/pypi/simple --no-build-isolation --no-deps
python -c "from mindspeed_ops.api.atb.npu_matmul_add import npu_matmul_add_fp32, npu_matmul_add_fp16; print('MindSpeed-Ops MatmulAdd API loaded successfully')"
cd ..
The FP32 main-gradient path of Atlas A2/A3 training products uses ATB JIT fused operators, which requires CANN-NNAL to be installed,
nnal/atb/set_env.shto be loaded, and a C++/Ninja compilation toolchain to be available. For details, see MindSpeed-Ops Software Installation.
Environment Verification
After installation, you can verify in Python whether each component is correctly installed:
# Verify MA
import megatron_adaptor # If no error is reported, MA is loaded correctly
# Verify TENPU
import transformer_engine # If no error is reported, TENPU is working correctly (not the native TE)
# Verify MindSpeed
import mindspeed.megatron_adaptor # If no error is reported, MindSpeed is loaded correctly
# Default-parameter training also requires verification of the MindSpeed-Ops MatmulAdd API
from mindspeed_ops.api.atb.npu_matmul_add import npu_matmul_add_fp32, npu_matmul_add_fp16
For details, refer to the Installation Guide to learn about hardware/OS compatibility, CANN/PyTorch/torch_npu installation, and other detailed prerequisite steps.
Quick Start
Overview
To use MindSpeed Core, you only need to add one line of code to run Megatron-LM on Ascend training devices with the layered MA + TENPU + MindSpeed architecture, and then refer to Feature Introduction to enable the various acceleration features of MindSpeed.
Usage
Take the GPT model as an example: in the Megatron-LM directory, modify the pretrain_gpt.py file and add a new line under import torch: import megatron_adaptor, as shown in the following modification:
import torch
import megatron_adaptor # Add the new code line.
from functools import partial
from contextlib import nullcontext
import inspect
For specific operations, refer to Quick Start.
For the quick start guides of MindSpeed LLM and MindSpeed MM, refer to:
- LLM training
- Multimodal model training
Acceleration Feature Layers
The MindSpeed Core acceleration feature is divided into three layers. You can select an optimization layer by setting the --optimization-level {Layer} parameter in the startup script according to your actual needs. This parameter supports the following configurations:
| Layer No. | Layer Name | Description |
|---|---|---|
| 0 | Basic function compatibility | Provides basic functional adaptation of the Megatron-LM framework for NPU. |
| 1 | Affinity enhancement 🔥 | On top of L0, enables some fused operators and Ascend-affinity computation rewrites. |
| 2 | Acceleration enabling 🔥🔥 | This the default value. On top of L0 and L1, enables a richer set of acceleration features. These acceleration features are usually enabled through specific parameters. For details, refer to the "Feature Introduction" chapter. |
Feature Introduction
MindSpeed features consist of seven major modules: Megatron, parallel strategy, memory optimization, affinity computation, communication optimization, key scenario, and multimodal features. Among them, [released] indicates whether the feature is commercially released; [prototype] features are not commercially released.
-
The application scenarios and usage instructions of the corresponding feature are provided. Generally, adding the relevant parameters to the script allows you to easily use the feature. 🛰️
-
MindSpeed acceleration features support only Mcore, which is the branch promoted by Megatron after v0.6.0 and is also the default branch of the current version. 🛰️
-
Current large model training mainly uses the bf16 data type. Unless otherwise stated, the following features are in principle compatible with fp16. If you encounter problems when using other data types, you can submit an issue, and we will respond in a timely manner. 🛰️
-
Note❗: After
Megatron_core_r0.18.0,alltoall dispatcherhas been adjusted, andalltoall_seqis no longer supported. For the support status of MindSpeed MoE features across branches, see the description of each feature.
For details, see MindSpeed Core Feature Support.
Custom Operators
Custom operators for Ascend training are uniformly provided through TorchNPU APIs. The following APIs are expected to be no longer maintained starting from Q4, 2025. Please prioritize using the custom operators provided by TorchNPU. If you have new requirements or encounter problems, you can submit an issue for feedback, and we will respond as soon as possible.
Some custom operators are set as public APIs. For instructions on public API settings, please refer to the Public API Statement in the MindSpeed Security Statement. For specific external API details, refer to the manual links corresponding to the operators.
For custom operator support, please refer to Custom Operators Supported by MindSpeed Core.
Branch Maintenance Policy
🛠️ Maintenance period of MindSpeed branches:
| Status | Time | Description |
|---|---|---|
| Planned 🕐 | 1-3 months | Planned features |
| Development 🕔 | 3 months | Feature development |
| Maintenance 🕚 | 6-12 months | Merge all resolved issues and release versions. Different maintenance policies are adopted for different MindSpeed versions. The maintenance cycles for Regular Releases and Long-Term Support releases are 6 months and 12 months, respectively. |
| No Maintenance 🕛 | 0-3 months | Merge all resolved issues, with no dedicated maintenance personnel and no version releases. |
| End of Life (EOL) 🚫 | N/A | The branch no longer accepts any modifications. |
🛠️ MindSpeed version maintenance policy:
| MindSpeed Version | Maintenance Policy | Current Status | Release Date | Subsequent Status | EOL Date |
|---|---|---|---|---|---|
| 26.1.0_core_r0.12.1 | Regular Release | Maintenance | 2026/06/30 | Estimated No Maintenance Since 2026/12/30 | |
| 26.0.0_core_r0.12.1 | Regular Release | Maintenance | 2026/03/30 | Estimated No Maintenance Since 2026/09/30 | |
| 2.3.0_core_r0.12.1 | Regular Release | End of Maintenance | 2025/12/30 | Estimated No Maintenance Since 2026/06/30 | |
| 2.2.0_core_r0.12.1 | Regular Release | End of Maintenance | 2025/09/30 | No Maintenance Since 2026/03/30 | |
| 2.1.0_core_r0.12.1 | Regular Release | End of Maintenance | 2025/06/30 | No Maintenance Since 2025/12/30 | |
| 2.1.0_core_r0.8.0 | Regular Release | End of Maintenance | 2025/06/30 | No Maintenance Since 2025/12/30 | |
| 2.0.0_core_r0.8.0 | Regular Release | End of Maintenance | 2025/03/30 | No Maintenance Since 2025/09/30 | |
| 1.0.0_core_r0.7.0 | Regular Release | End of Maintenance | 2024/12/30 | No Maintenance Since 2025/06/30 | |
| 1.0.0_core_r0.6.0 | Regular Release | End of Maintenance | 2024/12/30 | No Maintenance Since 2025/06/30 | |
| 1.0.RC3_core_r0.7.0 | Regular Release | End of Maintenance | 2024/09/30 | No Maintenance Since 2025/03/30 | |
| 1.0.RC3_core_r0.6.0 | Regular Release | End of Maintenance | 2024/09/30 | No Maintenance Since 2025/03/30 | |
| 1.0.RC2 | Regular Release | End of Maintenance | 2024/06/30 | No Maintenance Since 2024/12/30 | |
| 1.0.RC1 | Regular Release | End of Maintenance | 2024/03/30 | No Maintenance Since 2024/09/30 |
FAQs
For FAQs, see MindSpeed FAQs.
Reference
- MindSpeed Accelerates Million-Level Ultra-Long Sequence Large Model Training 🚀🚀
- MindSpeed Accelerates Trillion-Parameter MoE Large Model Training 🚀🚀
- Struggling with Large Model Training Memory Optimization? MindSpeed Has Solutions 🚀🚀
Security Statement
⚠️ MindSpeed Security Statement
Contribution Guide
Welcome to contribute to MindSpeed Core! Please refer to the Contribution Guide to learn how to participate in project contributions.
Disclaimer
Welcome to contribute to MindSpeed Core! Please refer to the Contribution Guide to learn how to participate in project contributions.
Disclaimer
To MindSpeed Users
- All content provided by MindSpeed is intended solely for your non-commercial use.
- Regarding the models and datasets involved in MindSpeed test cases and sample files, the platform uses them only for functional testing. Huawei does not provide any model weights or datasets. If you use such data for training, please pay special attention to complying with the licenses of the corresponding models and datasets. Huawei assumes no responsibility for any infringement disputes arising from your use of these models and datasets.
- If you encounter any issues (including but not limited to functional issues and compliance issues) while using MindSpeed, please submit an issue on Gitee, and we will review and resolve it in a timely manner.
- The third-party open-source software that MindSpeed features depend on, such as Megatron, is provided and maintained by their respective third-party communities. Fixes for issues caused by third-party open-source software depend on the contributions and feedback of the relevant communities. You should understand that the MindSpeed repository does not guarantee fixes for issues in the third-party open-source software itself, nor does it guarantee testing or correcting all vulnerabilities and errors in third-party open-source software.
To Data Owners
In addition, we appreciate the following teams for their contributions to the project:
License Statement
For models involved in Ascend MindSpeed, if a license exists in the model directory, that license prevails. If no lLicense exists in the model directory, the model is licensed under the Apache 2.0 license, and the corresponding license content can be found in the root directory of Ascend MindSpeed. For the license governing the use of MindSpeed, see LICENSE file. Documents in the MindSpeed docs directory are licensed under the CC-BY 4.0 license. For details, see the LICENSE file.
Acknowledgments
🔎 MindSpeed-Core is jointly contributed by Huawei Technologies Co., Ltd. and developers.
In addition, we appreciate the following teams for their contributions to the project:
- WeChat Infrastructure Center
- Kernel Technology Department, iFLYTEK AI Engineering Institute
Thanks to every PR from the community. Contributions to MindSpeed Core are welcome!