MindSpeed:基于昇腾设备的大模型加速库项目

昇腾大模型加速库

分支33Tags11
文件最后提交记录最后更新时间
fix: update PULL_REQUEST_TEMPLATE.md Co-authored-by: clc2025<chenlucong@huawei.com> # message auto-generated for no-merge-commit merge: !3498 merge master into master fix: update PULL_REQUEST_TEMPLATE.md Created-by: clc2025 Commit-by: clc2025 Merged-by: ascend-robot Description: ## What this PR does / why we need it? Update PULL_REQUEST_TEMPLATE.md ## Does this PR introduce any user-facing change? NA ## How was this patch tested? NA See merge request: Ascend/MindSpeed!34987 天前
initial 2 年前
Add configurable MindSpeed Docker build Co-authored-by: wangjinyi6<wangjinyi6@huawei.com> # message auto-generated for no-merge-commit merge: !3435 merge feat/mindspeed-docker-clean into master Add configurable MindSpeed Docker build Created-by: wangjinyi6 Commit-by: wangjinyi6 Merged-by: ascend-robot Description: What this PR does / why we need it? mindspeed core镜像 dockerfile和构建脚本 Does this PR introduce any user-facing change? 新增docker文件夹 How was this patch tested? 910b机器上验证通过 See merge request: Ascend/MindSpeed!34351 个月前
feat: add custom pp layout Co-authored-by: wuweiqiang24<wuweiqiang11@huawei.com> # message auto-generated for no-merge-commit merge: !3496 merge add_pp_layout into master feat: add custom pp layout Created-by: wuweiqiang24 Commit-by: wuweiqiang24 Merged-by: ascend-robot Description: 新增pipeline-model-parallel-layout功能,支持自定义PP每个stage的层排布 验证链接:https://wiki.huawei.com/domains/137239/wiki/268925/WIKI2026052611233549 issue: https://gitcode.com/Ascend/MindSpeed/issues/166 See merge request: Ascend/MindSpeed!34967 小时前
feat: add custom pp layout Co-authored-by: wuweiqiang24<wuweiqiang11@huawei.com> # message auto-generated for no-merge-commit merge: !3496 merge add_pp_layout into master feat: add custom pp layout Created-by: wuweiqiang24 Commit-by: wuweiqiang24 Merged-by: ascend-robot Description: 新增pipeline-model-parallel-layout功能,支持自定义PP每个stage的层排布 验证链接:https://wiki.huawei.com/domains/137239/wiki/268925/WIKI2026052611233549 issue: https://gitcode.com/Ascend/MindSpeed/issues/166 See merge request: Ascend/MindSpeed!34967 小时前
refactor(moe): decouple GMM context from autograd Function ctx with GmmContext Co-authored-by: Muu<koimuu@163.com> # message auto-generated for no-merge-commit merge: !3495 merge dev into master refactor(moe): decouple GMM context from autograd Function ctx with GmmContext Created-by: Muuyo Commit-by: Muu Merged-by: ascend-robot Description: 1. Tensorwise GMM x, grad 采用 pertensor 量化, weight 采用 pertoken(按n轴分组tensor量化)量化 2. fix mlp overlap 多参数采用同一个gmm ctx 3. GMM Function op_dw 添加ctx参数 [自验文档](https://wiki.huawei.com/domains/76578/wiki/233229/WIKI2026052611220020) See merge request: Ascend/MindSpeed!34957 天前
hamilton attention implementation in te Co-authored-by: Xiaoda Zhang<zhangxiaoda@huawei.com> # message auto-generated for no-merge-commit merge: !3430 merge add-HA-implement-on-new-master into master hamilton attention implementation in te Created-by: Xiaoda_zhang Commit-by: Xiaoda Zhang Merged-by: ascend-robot Description: What this PR does / why we need it? Please describe the background and detailed changes of the PR. If it is a bugfix, please attach the related issue. 本PR在MindSpeed现有的代码基础上实现了Hamilton attention(HA) (参考https://github.com/infinigence/HamiltonAttention),包括正反向实现。 HA的优势:相比于ring attention只利用到机内的单条链路,HA能够将机内的full mesh网络全部利用起来,有效地减缓了ring atten中可能存在的通信未被计算掩盖时的通信瓶颈。 本PR实现了SBH和TND两种格式的CP,并且通过UT已经验过了正确性。性能上,在WAN和Qwen3-vl模型上验证了性能提升情况: WAN2.2, seq_len=18K | | ring attn (send/recv)| HA (4条ring) (alltoall)| |--|--|--| | 单个通信算子时间 | 3.6ms | 1.2ms | | 整个core attention时间(正向) |33.5ms | 16ms | | 整个core attention时间(反向) |45.9ms | 28.9ms | |一次迭代E2E时间 | 8.3s | 6.0s | WAN2.2, seq_len=37K | | ring attn (send/recv)| HA (4条ring) (alltoall)| |--|--|--| | 单个通信算子时间 | 8.6ms | 3.8ms | | 整个core attention时间(正向) |65.6ms | 45.3ms | | 整个core attention时间(反向) |106.7ms | 90.8ms | |一次迭代E2E时间 | 15.5s | 12.9s | Qwen3-vl, TND格式,每张图片seq_len=1024,62张图片,总seq_len=62K,CP切分后seq_len=7936 | | ring attn (send/recv)| HA (4条ring) (alltoall)| |--|--|--| | 单个通信算子时间 | 2.1ms | 1ms | | 整个core attention时间(正向) | 104ms | 104ms | | 整个core attention时间(反向) |34ms | 14ms | Qwen3-vl, TND格式,每张图片seq_len=4096,62张图片,总seq_len=248K,CP切分后seq_len=31744 | | ring attn (send/recv)| HA (4条ring) (alltoall)| |--|--|--| | 单个通信算子时间 |8.9ms | 2.6ms | | 整个core attention时间(正向) | 112ms | 112ms | | 整个core attention时间(反向) |135ms | 86ms | Does this PR introduce any user-facing change? Please describe whether the PR will result in any user-facing usage changes. If there is related documentation, please specify its path. 使能HA,需要用户配置enable_ha参数,以及传入HA涉及到的in_mapping_list/out_mapping_list表明多条ring是如何收发数据的,以及在TND格式下重组各个seq所需的permute_index。 How was this patch tested? Please explain how to verify the correctness and effectiveness of this feature, as well as its usage constraints and limitations. 已通过UT测试了正确性。 See merge request: Ascend/MindSpeed!343024 天前
fix:fix atten_mask_shape error when using transformer_engine Co-authored-by: Keilo_W<wangkaiyu11@h-partners.com> # message auto-generated for no-merge-commit merge: !3293 merge master into master fix:fix atten_mask_shape error when using transformer_engine Created-by: Keilo_W Commit-by: Keilo_W Merged-by: ascend-robot Description: An atten_mask_shape error will occur if --attention-mask-type causal is used together with --transformer-impl transformer_engine. To avoid this, you must also enable the --use-flash-attn option. See merge request: Ascend/MindSpeed!32932 个月前
修改完善pre-commit开源代码检测工具 Co-authored-by: wujinyuan1<wujinyuan1@huawei.com> # message auto-generated for no-merge-commit merge: !3454 merge master into master 修改完善pre-commit开源代码检测工具 Created-by: wujinyuan1 Commit-by: wujinyuan1 Merged-by: ascend-robot Description: What this PR does / why we need it? Please describe the background and detailed changes of the PR. If it is a bugfix, please attach the related issue. Does this PR introduce any user-facing change? Please describe whether the PR will result in any user-facing usage changes. If there is related documentation, please specify its path. How was this patch tested? Please explain how to verify the correctness and effectiveness of this feature, as well as its usage constraints and limitations. See merge request: Ascend/MindSpeed!345425 天前
!352 [Fix] fix order of getting batch of ulysses Merge pull request !352 from 郭鹏/master 1 年前
add w8a16 quant Co-authored-by: wangjunhang<wangjunhang7@huawei.com> # message auto-generated for no-merge-commit merge: !3460 merge Dev_W8A16 into master add w8a16 quant Created-by: goodflower9 Commit-by: wangjunhang Merged-by: ascend-robot Description: What this PR does / why we need it? This PR adds W8A16 MXFP8 QAT support based on the existing QAT flow. Does this PR introduce any user-facing change? Yes. Users can enable W8A16 MXFP8 QAT with: ``` --qat-scheme w8a16-mxfp8 ``` Related doc: ``` docs/zh/features/qat_quant.md ``` How was this patch tested? Enable fake quantization by adding the parameter --qat-scheme w8a16-mxfp8 https://wiki.huawei.com/domains/76578/wiki/233229/WIKI2026051211063362 See merge request: Ascend/MindSpeed!34603 天前
docs: add directory structure doc, contribution guide and license docs Co-authored-by: fanlu5<fanlu5@huawei.com> # message auto-generated for no-merge-commit merge: !3485 merge master into master docs: add directory structure doc, contribution guide and license docs Created-by: fanlu5 Commit-by: fanlu5 Merged-by: ascend-robot Description: What this PR does / why we need it? https://gitcode.com/Ascend/MindSpeed/issues/146 docs: add directory structure doc, contribution guide and license docs 1. add project directory structure documentation 2. add CONTRIBUTING.md contribution guide 3. add CC-BY 4.0 license for docs directory 4. update README with new sections including directory structure, contribution guide and license info Does this PR introduce any user-facing change? NA How was this patch tested? NA See merge request: Ascend/MindSpeed!348514 天前
!1138 【安全】冗余代码删除,Licnse添加 Merge pull request !1138 from jiangzhihan1/master 1 年前
Add reviewers Co-authored-by: wuweiqiang24<wuweiqiang11@huawei.com> # message auto-generated for no-merge-commit merge: merge add_reviewer into master Add reviewers Created-by: wuweiqiang24 Commit-by: wuweiqiang24 Merged-by: ascend-robot Description: Add reviewers in Owners See merge request: Ascend/MindSpeed!28747 个月前
docs:modify document Co-authored-by: z60112595<zhaotao68@h-partners.com> # message auto-generated for no-merge-commit merge: !3490 merge master into master docs:modify document Created-by: kali00 Commit-by: z60112595 Merged-by: ascend-robot Description: What this PR does / why we need it? https://gitcode.com/Ascend/MindSpeed/issues/163 1、将26.0.0_core_r0.12.1的docs下的资料修改内容合入到master中 2、给“说明”标签增加换行 3、将特性列表和自定义算子列表中的超链接修改成相对链接 Does this PR introduce any user-facing change? Please describe whether the PR will result in any user-facing usage changes. If there is related documentation, please specify its path. How was this patch tested? Please explain how to verify the correctness and effectiveness of this feature, as well as its usage constraints and limitations. See merge request: Ascend/MindSpeed!34907 天前
!2602 添加免责声明 Merge pull request !2602 from glhyy/secrity 10 个月前
feat: Add MXFP8 support for FSDP Co-authored-by: EVA1<jingsiyu1@huawei.com> Co-authored-by: quancs001<quancs@qq.com> Co-authored-by: h00638954<huangzhiyuan8@huawei.com> # message auto-generated for no-merge-commit merge: !3387 merge fsdp_lp_ag into master feat: Add MXFP8 support for FSDP Created-by: quancs001 Commit-by: EVA1;quancs001;h00638954 Merged-by: ascend-robot Description: 在FSDP框架下新增MXFP8 Dense/MoE模型训练支持,实现了包括: 1. 基础的低精通信+FSDP框架 2. 实现了对MXFP8+低精通信的支持 3. MoE模型,支持了EP、EFSDP的适配 See merge request: Ascend/MindSpeed!33871 个月前
【INFO update!!!】url替换 Co-authored-by: EX_mitsu<yangjie409@h-partners.com> # message auto-generated for no-merge-commit merge: merge master into master 【INFO update!!!】url替换 Created-by: EX_mitsuX Commit-by: EX_mitsu Merged-by: ascend-robot Description: 清理替换gitee相关url,添加新商发版本相关信息。 See merge request: Ascend/MindSpeed!28977 个月前

Badge Documentation

简介


MindSpeed Core是针对华为昇腾设备的大模型加速库。

大模型训练是一种非常复杂的过程,涉及到许多技术和挑战,其中大模型训练需要大量的显存资源是一个难题,对计算卡提出了不小的挑战。 为了在单个计算卡显存资源不足时,可以通过多张计算卡进行计算,业界出现了类似 Megatron、DeepSpeed 等第三方大模型加速库,对模型、输入数据等进行切分并分配到不同的计算卡上,最后再通过集合通信对结果进行汇总。

昇腾提供 MindSpeed Core 加速库,使客户大模型业务能快速迁移至昇腾设备,并且支持昇腾专有算法,确保开箱可用。更多信息请参考MindSpeed Core简介

此外在 MindSpeed Core 加速库的基础之上也提供了大语言模型、多模态模型套件加速库:

代码仓目录结构

关键目录结构如下,详细目录介绍请参考目录结构文档

MindSpeed/
├── mindspeed/                    # 核心代码目录
│   ├── core/                     # 核心功能模块,包含并行策略、内存管理、优化器等核心能力
│   ├── features_manager/         # 特性管理模块,统一管理各种优化特性的注册与配置
│   ├── functional/               # 功能特性模块,包含NPU数据转储、确定性计算、性能分析等
│   ├── op_builder/               # 算子构建模块,提供算子编译和注册工具
│   ├── ops/                      # 算子模块,包含融合算子、自定义算子等高效实现
│   ├── args_utils.py             # 参数工具,提供参数解析和验证功能
│   ├── arguments.py              # 参数定义,包含分布式训练相关参数
│   ├── megatron_adapter.py       # Megatron-LM适配器,实现与Megatron框架的集成
│   ├── patch_utils.py            # 补丁工具,提供动态代码补丁功能
│   ├── train.py                  # 训练模块,提供训练流程控制
│   └── ...                       # 其他模块和功能
├── docs/                         # 文档目录,包含中英文特性文档、用户指南等
├── tests-extend/                 # 测试目录,包含扩展测试用例
└── tools/                        # 工具目录,提供辅助开发和性能分析工具

最新消息


  • [May 21, 2025]: 🚀 MindSpeed Core 支持Mcore 0.12.1版本。

注: 当前版本初步支持两种版本的Transformer实现。如需回溯老版本Transformer实现,需要用户配置参数--transformer-impl local

社区会议


版本说明


当前版本推荐配套表如下:

软件 版本
MindSpeed Core分支 master
Mcore版本 0.12.1
CANN版本 9.0.0
PyTorch 2.7.1
torch_npu版本 26.0.0
Python版本 Python3.10.x

更多具体说明请参考:版本配套表

安装


使用源码安装

MindSpeed Core拉取源码后使用pip命令行安装pip install -e MindSpeed,具体请参考 部署文档 安装 MindSpeed Core 指定分支及其依赖软件。

获取并切换Megatron-LM版本至 core_v0.12.1 版本,可参考:

git clone https://github.com/NVIDIA/Megatron-LM.git
cd Megatron-LM
git checkout core_v0.12.1

快速上手


概述

使用MindSpeed Core仅须增加一行代码,即可在昇腾训练设备上运行Megatron-LM,并进一步参考特性介绍 使能MindSpeed的各项加速特性。

操作方法

以 GPT 模型为例:在 Megatron-LM 目录下修改pretrain_gpt.py文件,在import torch下新增一行:import mindspeed.megatron_adaptor,即如下修改:

  import torch
  import mindspeed.megatron_adaptor # 新增代码行
  from functools import partial
  from contextlib import nullcontext
  import inspect

具体操作可以参考快速上手指导

MindSpeed LLM和MindSpeed MM的快速上手指导可参考:

加速特性分级说明


MindSpeed Core 加速特性分为三个层级,用户可根据实际需求选择通过设置启动脚本中的 --optimization-level {层级} 参数来自定义开启的优化层级。该参数支持以下配置:

层级 层级名称 介绍
0 基础功能兼容 提供Megatron-LM框架对NPU的基本功能适配。
1 亲和性增强🔥 在L0基础上使能部分融合算子与昇腾亲和计算改写。
2 加速特性使能🔥🔥 默认值。在L0、L1基础上开启更丰富的加速特性,加速特性通常通过具体参数使能,可参考"特性介绍"章节。

特性介绍


MindSpeed 特性由七大模块组成,分别为:Megatron特性支持、并行策略特性、内存优化特性、亲和计算特性、通信优化特性、关键场景特性以及多模态特性。其中【Released】表示是否商用发布,原型特性为非商用发布。

  • 特性的介绍中说明了对应特性的应用场景及使用说明。一般而言,在脚本中加入相关参数即可轻松使用对应特性。🛰️

  • MindSpeed 加速特性仅支持mcore,这也是Megatron在v0.6.0版本后主推分支,也是当前版本的默认分支。🛰️

  • 当前大模型训练主要使用bf16数据类型,以下特性若无特殊声明原则上兼容fp16, 如使用其它数据类型遇到问题可提交issue, 我们会快速响应。🛰️

  • 注意❗:在Megatron_core_r0.9.0后,alltoall dispatcher进行了调整,原版本alltoall dispatcher重命名为alltoall_seq。MindSpeed MoE特性对各分支的支持情况,见各特性说明。

各特性支持情况请查看MindSpeed Core 特性支持情况

自定义算子

昇腾训练自定义算子统一由torch_npu提供API,以下API预计2025年Q4起不维护,请优先使用torch_npu提供的自定义算子,如有新需求或问题可提issue反馈,我们会尽快回复。

部分自定义算子设置为公开接口,公开接口设置说明请参照 MindSpeed 安全声明中的公开接口声明,具体对外接口细节参照以下算子对应的手册链接。

自定义算子支持情况请查看MindSpeed Core 自定义算子支持情况

分支维护策略


🛠️ MindSpeed 版本分支的维护阶段如下:

状态 时间 说明
计划 🕐 1-3 个月 计划特性
开发 🕔 3 个月 开发特性
维护 🕚 6-12 个月 合入所有已解决的问题并发布版本,针对不同的MindSpeed 版本采取不同的维护策略,常规版本和长期支持版本维护周期分别为6个月和12个月
无维护 🕛 0-3 个月 合入所有已解决的问题,无专职维护人员,无版本发布
生命周期终止(EOL)🚫 N/A 分支不再接受任何修改

🛠️ MindSpeed 版本维护策略:

MindSpeed版本 维护策略 当前状态 发布时间 后续状态 EOL日期
26.0.0_core_r0.12.1 常规版本 维护 2026/03/30 预计2026/09/30起无维护
2.3.0_core_r0.12.1 常规版本 维护 2025/12/30 预计2026/06/30起无维护
2.2.0_core_r0.12.1 常规版本 停止维护 2025/09/30 2026/03/30起无维护
2.1.0_core_r0.12.1 常规版本 停止维护 2025/06/30 2025/12/30起无维护
2.1.0_core_r0.8.0 常规版本 停止维护 2025/06/30 2025/12/30起无维护
2.0.0_core_r0.8.0 常规版本 停止维护 2025/03/30 2025/9/30起无维护
1.0.0_core_r0.7.0 常规版本 停止维护 2024/12/30 2025/6/30起无维护
1.0.0_core_r0.6.0 常规版本 停止维护 2024/12/30 2025/6/30起无维护
1.0.RC3_core_r0.7.0 常规版本 停止维护 2024/09/30 2025/3/30起无维护
1.0.RC3_core_r0.6.0 常规版本 停止维护 2024/09/30 2025/3/30起无维护
1.0.RC2 常规版本 停止维护 2024/06/30 2024/12/30起无维护
1.0.RC1 常规版本 停止维护 2024/03/30 2024/9/30起无维护

常见问题


现象 介绍
Data helpers 数据预处理出错 ❗ data_helpers数据预处理出错
Torch extensions 编译卡住 ❗ Torch extensions卡住
megatron0.7.0版本长稳测试出现grad norm为nan ❗ grad_norm_nan
Gloo建链失败Gloo connectFullMesh failed with ... ❗ hccl-replace-gloo

技术文章


安全声明


⚠️ MindSpeed 安全声明

贡献指南


欢迎贡献 MindSpeed-Core!请查看贡献指南了解如何参与项目贡献。

免责声明


致MindSpeed使用者

  1. MindSpeed提供的所有内容仅供您用于非商业目的。
  2. 对于MindSpeed测试用例以及示例文件中所涉及的各模型和数据集,平台仅用于功能测试,华为不提供任何模型权重和数据集,如您使用这些数据进行训练,请您特别注意应遵守对应模型和数据集的License,如您因使用这些模型和数据集而产生侵权纠纷,华为不承担任何责任。
  3. 如您在使用MindSpeed过程中,发现任何问题(包括但不限于功能问题、合规问题),请在Gitee提交issue,我们将及时审视并解决。
  4. MindSpeed功能依赖的Megatron等第三方开源软件,均由第三方社区提供和维护,因第三方开源软件导致的问题的修复依赖相关社区的贡献和反馈。您应理解,MindSpeed仓库不保证对第三方开源软件本身的问题进行修复,也不保证会测试、纠正所有第三方开源软件的漏洞和错误。

致数据所有者

如果您不希望您的模型或数据集在MindSpeed中被提及,或希望更新MindSpeed中有关的描述,请在Gitee提交issue,我们将根据您的issue要求删除或更新您相关描述。衷心感谢您对MindSpeed的理解和贡献。

License声明

Ascend MindSpeed中涉及的模型,如模型目录下存在License的,以该License为准。如模型目录下不存在License的,以Apache 2.0许可证许可,对应许可证文本可查阅Ascend MindSpeed根目录。 MindSpeed产品的使用许可证,具体请参见LICENSE文件。 MindSpeed docs目录下的文档适用CC-BY 4.0许可证,具体请参见LICENSE文件。

致谢


🔎 MindSpeed-Core 由华为公司的下列部门联合贡献 :

华为公司:

  • 昇腾计算产品部
  • 计算算法部
  • 计算软件平台部
  • 计算技术开发部
  • 公共开发部:NAIE
  • 网络技术实验室

此外,MindSpeed-Core 感谢以下团队对项目的贡献:

  • 微信基础架构中心
  • 科大讯飞AI工程院内核技术部

感谢来自社区的每一个PR,欢迎贡献 MindSpeed-Core!