MindSpeed-LLM 模型支持列表全解析:稠密、稀疏与状态空间模型的昇腾训练指南
MindSpeed-LLM 模型支持列表全解析:稠密、稀疏与状态空间模型的昇腾训练指南
本文以 MindSpeed-LLM 官方模型支持列表(docs/zh/pytorch/models/supported_models.md)为骨架,系统梳理 PyTorch 框架在昇腾 NPU 上可训练的全部模型矩阵:按架构特点划分为稠密模型(Dense)、**稀疏模型(Sparse/MoE)与状态空间模型(SSM)**三大类,并逐项说明权重来源、训练脚本位置、支持序列长度、训练后端(Legacy/Mcore/FSDP2)、推荐集群规模与认证状态。读完本文,你将掌握如何依据模型规模与硬件条件选择合适的训练后端,快速定位对应训练/微调脚本,并理解脚本中集群规模、并行策略与关键环境变量的配置含义,可直接上手在昇腾集群上启动预训练任务。
表格字段说明
PyTorch 框架模型支持列表共包含 9 个字段,含义如下:
| 字段 | 说明 |
|---|---|
| 模型 | 模型名称 |
| 下载链接 | 模型权重下载地址,可访问 Hugging Face 等模型仓库获取 |
| 脚本位置 | 模型在本项目中的训练脚本路径,可用于快速定位和使用模型,具体可参考脚本环境变量说明 |
| 序列长度 | 支持的最大文本序列长度 |
| 训练后端 | 支持 Legacy、Mcore、FSDP2 三种实现方式。 • Legacy:历史实现方式 • Mcore:当前推荐的 Megatron 主流实现方式 • FSDP2:PyTorch 官方推荐的分布式训练实现方式 |
| 集群规模 | 模型训练时推荐使用的集群规模配置,格式为“节点数 × 卡数” |
| 支持版本 | 最终支持的维护版本,空白表示从上线起到当前 master 分支均在维护 |
| 贡献方 | 模型贡献来源 |
| 认证 | 【Pass】 已通过官方测试;【Test】 内部测试中,如有问题可反馈至项目 Issues |
硬件要求与使用前提
MindSpeed LLM 支持 Ascend 950PR & 950DT 系列产品、Atlas A3 训练系列产品和 Atlas A2 训练系列产品,可通过硬件信息查询)后,可通过 npu-smi info 查看单 NPU 的片上内存容量。
如果无法顺利访问 Hugging Face 社区下载权重资源,推荐前往 ModelScope 下载权重,需关注待下载文件的正确性和安全性。
脚本组织与集群规模约定
项目在根目录 examples/ 下按训练后端组织模型示例脚本,例如:
- examples/mcore:Mcore 后端示例(当前推荐的 Megatron 主流实现)
- examples/fsdp2:FSDP2 后端示例(PyTorch 官方推荐分布式训练实现)
- examples/rlhf:强化学习(GRPO 等)示例
脚本命名遵循统一规范:
- 预训练脚本:
pretrain_模型名_参数_文本序列长度_训练方案_训练产品.sh - 微调脚本:
tune_模型名_参数_文本序列长度_训练方案_训练产品.sh
例如 examples/mcore/qwen3 目录下同时提供 pretrain_qwen3_8b_4K_ptd.sh(预训练)、tune_qwen3_8b_4K_full_ptd.sh(全参微调)、tune_qwen3_8b_4K_lora_ptd.sh(LoRA 微调)等脚本。
项目中存在两类用途不同的脚本:
- 模型训练示例脚本(examples):旨在加载权重正常训练展示为主,便于复现与验证;
- 模型训练高性能脚本(tests/poc):旨在固定路由下高性能展示为主(如
tests/poc/qwen3_235b_8p_perf中按 A5 产品配置的 BF16/FP8 性能脚本),用户可根据使用场景按需选择。
在训练脚本中,集群规模通过以下两个变量表达:
NNODES=32 # 机器数量
NPUS_PER_NODE=16 # 每台机器上的NPU数量
以上配置即表示需要 32 台机器、每台机器 16 个 NPU。
稠密模型(Dense Model)
稠密模型是传统的深度学习模型结构,其神经元之间的连接是密集的,每一层的大多数或所有神经元都与下一层的所有神经元相连。这种模型很简单,训练相对直接,但参数量较大,计算成本较高。支持列表如下(“下载”列为对应开源权重规模,脚本位置以仓库相对路径给出;标注为“历史版本”的目录存在于对应版本的 examples/ 下):
| 模型 | 下载 | 脚本位置 | 序列长度 | 训练后端 | 集群规模 | 支持版本 | 贡献方 | 认证 |
|---|---|---|---|---|---|---|---|---|
| Aquila | 7B | aquila(2.0.0 版本 legacy) | 2k | Legacy | 1x8 | 2.0.0 | 【Ascend】 | 【Pass】 |
| Aquila2 | 7B | aquila2(2.0.0 版本 legacy) | 2k | Legacy | 1x8 | 2.0.0 | 【Ascend】 | 【Pass】 |
| Aquila2 | 34B | aquila2(2.0.0 版本 legacy) | 4k | Legacy | 2x8 | 2.0.0 | 【Ascend】 | 【Pass】 |
| Baichuan | 7B | baichuan(2.0.0 版本 legacy) | 4k | Legacy | 1x8 | 2.0.0 | 【Ascend】 | 【Pass】 |
| Baichuan | 13B | baichuan(2.0.0 版本 legacy) | 4k | Legacy | 1x8 | 2.0.0 | 【Ascend】 | 【Pass】 |
| Baichuan2 | 7B | baichuan2(2.0.0 版本 legacy) | 4k | Legacy | 1x8 | 2.0.0 | 【Ascend】 | 【Pass】 |
| Baichuan2 | 13B | baichuan2(2.3.0 版本 mcore) | 4k | Mcore | 1x8 | 2.3.0 | 【Ascend】 | 【Pass】 |
| Bloom | 7B1 | bloom(2.0.0 版本 legacy) | 2k | Legacy | 1x8 | 2.0.0 | 【Ascend】 | 【Pass】 |
| Bloom | 176B | bloom(2.0.0 版本 legacy) | 2k | Legacy | 2x8 | 2.0.0 | 【Ascend】 | 【Pass】 |
| ChatGLM3 | 6B | chatglm3(2.3.0 版本 mcore) | 8k | Mcore | 1x8 | 2.3.0 | 【Ascend】 | 【Pass】 |
| ChatGLM3 | 6B | chatglm3(2.3.0 版本 mcore) | 32k | Mcore | 1x8 | 2.3.0 | 【Ascend】 | 【Pass】 |
| ChatGLM3 | 6B | chatglm3(2.3.0 版本 mcore) | 64k | Mcore | 2x8 | 2.3.0 | 【Ascend】 | 【Pass】 |
| GLM4 | 9B | glm4(2.3.0 版本 mcore) | 8k | Mcore | 1x8 | 2.3.0 | 【Ascend】 | 【Pass】 |
| GLM4 | 9B | glm4(2.3.0 版本 mcore) | 32k | Mcore | 2x8 | 2.3.0 | 【Ascend】 | 【Pass】 |
| CodeLlama | 34B | codellama(2.2.0 版本 mcore) | 4k | Mcore | 2x8 | 2.2.0 | 【Ascend】 | 【Pass】 |
| InternLM | 7B | intern(2.0.0 版本 legacy) | 2k | Legacy | 1x8 | 2.0.0 | 【Ascend】 | 【Pass】 |
| InternLM | 65B | intern(2.0.0 版本 legacy) | 2k | Legacy | 4x8 | 2.0.0 | 【Ascend】 | 【Pass】 |
| InternLM2 | 20B | internlm2(2.2.0 版本 mcore) | 4k | Mcore | 1x8 | 2.2.0 | 【Ascend】 | 【Pass】 |
| InternLM2 | 20B | internlm2(2.2.0 版本 mcore) | 32k | Mcore | 1x8 | 2.2.0 | 【Ascend】 | 【Pass】 |
| InternLM2.5 | 1.8B | internlm25(2.3.0 版本 mcore) | 32k | Mcore | 1x8 | 2.3.0 | 【Ascend】 | 【Pass】 |
| InternLM2.5 | 7B | internlm25(2.3.0 版本 mcore) | 32k | Mcore | 1x8 | 2.3.0 | 【Ascend】 | 【Pass】 |
| InternLM2.5 | 20B | internlm25(2.3.0 版本 mcore) | 32k | Mcore | 2x8 | 2.3.0 | 【Ascend】 | 【Test】 |
| InternLM3 | 8B | internlm3(26.0.0 版本 mcore) | 8k | Mcore | 1x8 | 26.0.0 | 【Ascend】 | 【Pass】 |
| LLaMA | 7B | llama(2.0.0 版本 legacy) | 2k | Legacy | 1x8 | 2.0.0 | 【Ascend】 | 【Pass】 |
| LLaMA | 13B | llama(2.0.0 版本 legacy) | 2k | Legacy | 1x8 | 2.0.0 | 【Ascend】 | 【Pass】 |
| LLaMA | 33B | llama(2.0.0 版本 legacy) | 2k | Legacy | 4x8 | 2.0.0 | 【Ascend】 | 【Pass】 |
| LLaMA | 65B | llama(2.0.0 版本 legacy) | 2k | Legacy | 4x8 | 2.0.0 | 【Ascend】 | 【Pass】 |
| LLaMA2 | 7B | llama2(26.0.0 版本 mcore) | 4k | Mcore | 1x8 | 26.0.0 | 【Ascend】 | 【Pass】 |
| LLaMA2 | 13B | llama2(26.1.0 版本 mcore) | 4k | Mcore | 1x8 | 26.1.0 | 【Ascend】 | 【Pass】 |
| LLaMA2 | 34B | llama2(2.3.0 版本 mcore) | 4k | Mcore | 2x8 | 2.3.0 | 【Ascend】 | 【Pass】 |
| LLaMA2 | 70B | llama2(26.0.0 版本 mcore) | 4k | Mcore | 4x8 | 26.0.0 | 【Ascend】 | 【Pass】 |
| LLaMA2 | 70B | llama2(26.0.0 版本 mcore) | 128k | Mcore | 8x8 | 26.0.0 | 【Ascend】 | 【Pass】 |
| LLaMA3 | 8B | llama3(2.3.0 版本 mcore) | 8k | Mcore | 1x8 | 2.3.0 | 【Ascend】 | 【Pass】 |
| LLaMA3 | 70B | llama3(2.3.0 版本 mcore) | 8k | Mcore | 4x8 | 2.3.0 | 【Ascend】 | 【Pass】 |
| LLaMA3.1 | 8B | llama31(2.3.0 版本 mcore) | 8k | Mcore | 1x8 | 2.3.0 | 【Ascend】 | 【Pass】 |
| LLaMA3.1 | 8B | llama31(2.3.0 版本 mcore) | 128k | Mcore | 4x8 | 2.3.0 | 【Ascend】 | 【Pass】 |
| LLaMA3.1 | 50B | llama31(2.3.0 版本 mcore) | 128k | Mcore | 8x8 | 2.3.0 | 【Ascend】 | 【Pass】 |
| LLaMA3.1 | 70B | llama31(2.3.0 版本 mcore) | 8k | Mcore | 4x8 | 2.3.0 | 【Ascend】 | 【Pass】 |
| LLaMA3.1 | 70B | llama31(2.3.0 版本 mcore) | 128k | Mcore | 24x8 | 2.3.0 | 【Ascend】 | 【Pass】 |
| LLaMA3.1 | 200B | llama31(2.3.0 版本 mcore) | 8k | Mcore | 8x8 | 2.3.0 | 【Ascend】 | 【Pass】 |
| LLaMA3.1 | 405B | llama31(26.0.0 版本 mcore) | 8k | Mcore | 8x8 | 26.0.0 | 【Ascend】 | 【Pass】 |
| LLaMA3.1 | 405B | llama31(2.3.0 版本 mcore) | 128k | Mcore | 36x8 | 2.3.0 | 【Ascend】 | 【Pass】 |
| LLaMA3.2 | 1B | llama32(2.3.0 版本 mcore) | 8k | Mcore | 1x8 | 2.3.0 | 【Ascend】 | 【Pass】 |
| LLaMA3.2 | 3B | llama32(2.3.0 版本 mcore) | 8k | Mcore | 1x8 | 2.3.0 | 【Ascend】 | 【Pass】 |
| LLaMA3.3 | 70B-Instruct | llama33(2.3.0 版本 mcore) | 8k | Mcore | 4x8 | 2.3.0 | 【Ascend】 | 【Pass】 |
| Qwen | 7B | qwen(2.0.0 版本 legacy) | 8k | Legacy | 1x8 | 2.0.0 | 【Ascend】 | 【Pass】 |
| Qwen | 14B | qwen(2.0.0 版本 legacy) | 2k | Legacy | 1x8 | 2.0.0 | 【Ascend】 | 【Pass】 |
| Qwen | 72B | qwen(2.0.0 版本 legacy) | 8k | Legacy | 16x8 | 2.0.0 | 【Ascend】 | 【Pass】 |
| Qwen1.5 | 0.5B | qwen15(2.2.0 版本 mcore) | 8k | Mcore | 1x8 | 2.2.0 | 【Ascend】 | 【Pass】 |
| Qwen1.5 | 1.8B | qwen15(2.2.0 版本 mcore) | 8k | Mcore | 1x8 | 2.2.0 | 【Ascend】 | 【Pass】 |
| Qwen1.5 | 4B | qwen15(2.2.0 版本 mcore) | 8k | Mcore | 1x8 | 2.2.0 | 【Ascend】 | 【Pass】 |
| Qwen1.5 | 7B | qwen15(2.2.0 版本 mcore) | 8k | Mcore | 1x8 | 2.2.0 | 【Ascend】 | 【Pass】 |
| Qwen1.5 | 14B | qwen15(2.2.0 版本 mcore) | 8k | Mcore | 1x8 | 2.2.0 | 【Ascend】 | 【Pass】 |
| Qwen1.5 | 32B | qwen15(2.2.0 版本 mcore) | 8k | Mcore | 4x8 | 2.2.0 | 【Ascend】 | 【Pass】 |
| Qwen1.5 | 72B | qwen15(2.2.0 版本 mcore) | 8k | Mcore | 8x8 | 2.2.0 | 【Ascend】 | 【Pass】 |
| Qwen1.5 | 110B | qwen15(2.2.0 版本 mcore) | 8k | Mcore | 8x8 | 2.2.0 | 【Ascend】 | 【Pass】 |
| CodeQwen1.5 | 7B | qwen15(2.2.0 版本 mcore) | 8k | Mcore | 1x8 | 2.2.0 | 【Ascend】 | 【Pass】 |
| Qwen2 | 0.5B | qwen2(2.2.0 版本 mcore) | 4k | Mcore | 1x8 | 2.2.0 | 【Ascend】 | 【Pass】 |
| Qwen2 | 0.5B | qwen2(2.2.0 版本 mcore) | 32k | Mcore | 1x8 | 2.2.0 | 【Ascend】 | 【Pass】 |
| Qwen2 | 1.5B | qwen2(2.2.0 版本 mcore) | 4k | Mcore | 1x8 | 2.2.0 | 【Ascend】 | 【Pass】 |
| Qwen2 | 1.5B | qwen2(2.2.0 版本 mcore) | 32k | Mcore | 1x8 | 2.2.0 | 【Ascend】 | 【Pass】 |
| Qwen2 | 7B | qwen2(2.2.0 版本 mcore) | 4k | Mcore | 1x8 | 2.2.0 | 【Ascend】 | 【Pass】 |
| Qwen2 | 7B | qwen2(2.2.0 版本 mcore) | 32k | Mcore | 1x8 | 2.2.0 | 【Ascend】 | 【Pass】 |
| Qwen2 | 72B | qwen2(2.2.0 版本 mcore) | 4k | Mcore | 4x8 | 2.2.0 | 【Ascend】 | 【Pass】 |
| Qwen2 | 72B | qwen2(2.2.0 版本 mcore) | 32k | Mcore | 16x8 | 2.2.0 | 【Ascend】 | 【Pass】 |
| Qwen2.5 | 0.5B | qwen25(2.3.0 版本 mcore) | 32k | Mcore | 1x8 | 2.3.0 | 【Ascend】 | 【Pass】 |
| Qwen2.5 | 1.5B | qwen25(2.3.0 版本 mcore) | 32k | Mcore | 1x8 | 2.3.0 | 【Ascend】 | 【Pass】 |
| Qwen2.5 | 3B | qwen25(2.3.0 版本 mcore) | 32k | Mcore | 1x8 | 2.3.0 | 【Ascend】 | 【Pass】 |
| Qwen2.5 | 7B | qwen25(2.3.0 版本 mcore) | 32k | Mcore | 1x8 | 2.3.0 | 【Ascend】 | 【Pass】 |
| Qwen2.5 | 14B | qwen25(2.3.0 版本 mcore) | 32k | Mcore | 2x8 | 2.3.0 | 【Ascend】 | 【Pass】 |
| Qwen2.5 | 32B | qwen25(2.3.0 版本 mcore) | 32k | Mcore | 4x8 | 2.3.0 | 【Ascend】 | 【Pass】 |
| Qwen2.5 | 72B | qwen25(26.1.0 版本 mcore) | 32k | Mcore | 16x8 | 26.1.0 | 【Ascend】 | 【Pass】 |
| Qwen3 | 0.6B | qwen3 | 4k | Mcore | 1x8 | 26.1.0 | 【Ascend】 | 【Pass】 |
| Qwen3 | 1.7B | qwen3 | 4k | Mcore | 1x8 | 26.1.0 | 【Ascend】 | 【Pass】 |
| Qwen3 | 4B | qwen3 | 4k | Mcore | 1x8 | 26.1.0 | 【Ascend】 | 【Pass】 |
| Qwen3 | 8B | qwen3 | 4k | Mcore | 1x8 | master | 【Ascend】 | 【Pass】 |
| Qwen3 | 14B | qwen3 | 4k | Mcore | 1x8 | 26.1.0 | 【Ascend】 | 【Pass】 |
| Qwen3 | 32B | qwen3 | 4k | Mcore | 2x8 | 26.1.0 | 【Ascend】 | 【Pass】 |
| Qwen3 | 32B | qwen3 | 4k | FSDP2 | 1x16 | 26.1.0 | 【Ascend】 | 【Test】 |
| QwQ | 32B | qwq(2.2.0 版本 mcore) | 4k | Mcore | 1x8 | 2.2.0 | 【Ascend】 | 【Test】 |
| Qwen2.5-Math | 1.5B | qwen25_math(2.2.0 版本 mcore) | 4k | Mcore | 1x8 | 2.2.0 | 【Ascend】 | 【Pass】 |
| Qwen2.5-Math | 7B | qwen25_math(2.2.0 版本 mcore) | 4k | Mcore | 1x8 | 2.2.0 | 【Ascend】 | 【Pass】 |
| Qwen2.5-Math | 72B | qwen25_math(2.2.0 版本 mcore) | 4k | Mcore | 4x8 | 2.2.0 | 【Ascend】 | 【Test】 |
| CodeQwen2.5 | 7B | qwen25_coder(2.2.0 版本 mcore) | 8k | Mcore | 1x8 | 2.2.0 | 【China Mobile Cloud】 | 【Test】 |
| Yi | 9B | yi(2.0.0 版本 legacy) | 4k | Legacy | 1x4 | 2.0.0 | 【OpenMind】 | 【Test】 |
| Yi | 34B | yi(2.2.0 版本 mcore) | 4k | Mcore | 2x8 | 2.2.0 | 【Ascend】 | 【Pass】 |
| Yi1.5 | 6B | yi15(2.2.0 版本 mcore) | 4k | Mcore | 1x8 | 2.2.0 | 【Ascend】 | 【Pass】 |
| Yi1.5 | 9B | yi15(2.2.0 版本 mcore) | 4k | Mcore | 1x8 | 2.2.0 | 【Ascend】 | 【Pass】 |
| Yi1.5 | 34B | yi15(2.2.0 版本 mcore) | 4k | Mcore | 2x8 | 2.2.0 | 【Ascend】 | 【Test】 |
| Mistral | 7B | mistral(2.2.0 版本 mcore) | 32k | Mcore | 1x8 | 2.2.0 | 【Ascend】 | 【Pass】 |
| Gemma | 2B | gemma(2.2.0 版本 mcore) | 8k | Mcore | 1x8 | 2.2.0 | 【Ascend】 | 【Pass】 |
| Gemma | 7B | gemma(2.2.0 版本 mcore) | 8k | Mcore | 1x8 | 2.2.0 | 【Ascend】 | 【Pass】 |
| Gemma2 | 9B | gemma2(26.1.0 版本 mcore) | 8k | Mcore | 1x8 | 26.1.0 | 【Ascend】 | 【Pass】 |
| Gemma2 | 27B | gemma2(26.1.0 版本 mcore) | 8k | Mcore | 2x8 | 26.1.0 | 【Ascend】 | 【Pass】 |
| MiniCPM | 2B | minicpm(2.2.0 版本 mcore) | 4k | Mcore | 1x8 | 2.2.0 | 【Ascend】 | 【Pass】 |
| MiniCPM3 | 4B | minicpm3(2.2.0 版本 mcore) | 32k | Mcore | 1x8 | 2.2.0 | 【Ascend】 | 【Test】 |
| Phi3.5 | mini-instruct | phi35(26.1.0 版本 mcore) | 4k | Mcore | 1x8 | 26.1.0 | 【Ascend】 | 【Test】 |
| DeepSeek-Math | 7B | deepseek_math(2.2.0 版本 mcore) | 4k | Mcore | 1x8 | 2.2.0 | 【Ascend】 | 【Test】 |
| DeepSeek-R1-Distill-Qwen | 1.5B | deepseek_r1_distill_qwen(2.2.0 版本 mcore) | 4k | Mcore | 1x8 | 2.2.0 | 【Ascend】 | 【Pass】 |
| DeepSeek-R1-Distill-Qwen | 7B | deepseek_r1_distill_qwen(2.2.0 版本 mcore) | 4k | Mcore | 1x8 | 2.2.0 | 【Ascend】 | 【Pass】 |
| DeepSeek-R1-Distill-Qwen | 14B | deepseek_r1_distill_qwen(2.2.0 版本 mcore) | 4k | Mcore | 1x8 | 2.2.0 | 【Ascend】 | 【Pass】 |
| DeepSeek-R1-Distill-Qwen | 32B | deepseek_r1_distill_qwen(2.2.0 版本 mcore) | 8k | Mcore | 2x8 | 2.2.0 | 【Ascend】 | 【Pass】 |
| DeepSeek-R1-Distill-LLaMA | 8B | deepseek_r1_distill_llama(2.2.0 版本 mcore) | 8k | Mcore | 1x8 | 2.2.0 | 【Ascend】 | 【Pass】 |
| DeepSeek-R1-Distill-LLaMA | 70B | deepseek_r1_distill_llama(2.2.0 版本 mcore) | 8k | Mcore | 4x8 | 2.2.0 | 【Ascend】 | 【Pass】 |
| Seed-OSS | 36B | seed_oss | 2k | Mcore | 1x8 | master | 【Ascend】 | 【Pass】 |
| Magistral | 24B | magistral(26.1.0 版本 mcore) | 4k | Mcore | 1x8 | 26.1.0 | 【Ascend】 | 【Test】 |
| PLM | 1.8B | plm(26.1.0 版本 mcore) | 2k | Mcore | 1x8 | 26.1.0 | 【Ascend】 | 【Test】 |
稠密模型脚本实战示例:Qwen3-8B Mcore 预训练
以 examples/mcore/qwen3/pretrain_qwen3_8b_4K_ptd.sh 为例,脚本包含如下几个核心参数组,读者可直接修改路径与规模后复用:
- 集群规模与通信:
NPUS_PER_NODE=8、NNODES=1、WORLD_SIZE自动计算;MASTER_ADDR/MASTER_PORT配置分布式主节点。 - 并行策略:
TP=1(张量并行)、PP=2(流水线并行)、CP=1(上下文并行),MBS=1(微批大小)、GBS=64(全局批大小)、SEQ_LENGTH=4096。 - 模型结构:
--use-mcore-models开启 Mcore 实现,--spec mindspeed_llm.tasks.models.spec.qwen3_spec layer_spec指定模型规格,--qk-layernorm、--group-query-attention --num-query-groups 8、--rotary-base 1000000、--untie-embeddings-and-output-weights等对应 Qwen3 架构特性(其模型规格定义见 mindspeed_llm/tasks/models/spec)。 - 训练优化:
--use-flash-attn、--use-fused-swiglu、--use-fused-rmsnorm、--use-fused-rotary-pos-emb、--use-distributed-optimizer、--reuse-fp32-param、--overlap-grad-reduce、--overlap-param-gather、--use-ascend-coc等,充分利用昇腾融合算子与计算通信重叠能力。 - 数据与输出:
--handler-name GeneralPretrainHandler、--data-path、--split 100,0,0、--tokenizer-type PretrainedFromHF --tokenizer-name-or-path、--save/--load断点目录,以及--enable-hf2mg-convert --model-type-hf qwen3实现 Hugging Face 权重向 Megatron 格式的自动转换(对应转换脚本见 examples/mcore/qwen3/ckpt_convert_qwen3_hf2mcore.sh)。
启动方式为标准的 torchrun 多卡启动:
torchrun $DISTRIBUTED_ARGS pretrain_gpt.py \
$GPT_ARGS $DATA_ARGS $MOE_ARGS $OUTPUT_ARGS $OPTIMIZE_ARGS $TRAIN_ARGS $MODEL_PARALLEL_ARGS \
--load ${CKPT_LOAD_DIR} --save ${CKPT_SAVE_DIR} \
--distributed-backend nccl --transformer-impl local \
--enable-hf2mg-convert --model-type-hf qwen3
稀疏模型(Sparse Model / MoE)
稀疏模型采用了稀疏连接的神经元结构,只有少数神经元之间存在连接。典型的稀疏模型如混合专家模型(Mixture of Experts, MoE),包含多个专家网络,每次训练只激活部分专家。这种设计可以显著减少参数量和计算复杂度,提高训练效率,特别适合处理大规模数据集和复杂任务。但稀疏模型训练也存在缺点,易出现专家负载不均衡导致训练不稳定。支持列表如下:
| 模型 | 下载 | 脚本位置 | 序列长度 | 训练后端 | 集群规模 | 支持版本 | 贡献方 | 认证 |
|---|---|---|---|---|---|---|---|---|
| Qwen3 | 30B-A3B | qwen3_moe | 4k | Mcore | 2x8 | master | 【Ascend】 | 【Pass】 |
| Qwen3 | 30B-A3B | qwen3_moe | 4k | FSDP2 | 1x16 | master | 【Ascend】 | 【Test】 |
| Qwen3 | 235B-A22B | qwen3_moe | 4k | Mcore | 16x16 | master | 【Ascend】 | 【Pass】 |
| Qwen3 | 235B-A22B | qwen3_moe | 4k | FSDP2 | 16x16 | master | 【Ascend】 | 【Test】 |
| Qwen3-Next | 80B-A3B | qwen3_next(26.1.0 版本 mcore) | 16k | Mcore | 4x16 | 26.1.0 | 【Ascend】 | 【Pass】 |
| Qwen3-Next | 80B-A3B | qwen3_next(26.1.0 版本 fsdp2) | 16k | FSDP2 | 4x16 | 26.1.0 | 【Ascend】 | 【Test】 |
| Qwen3-Coder-Next | 80B-A3B | qwen3_coder_next(26.1.0 版本 mcore) | 16k | Mcore | 4x16 | 26.1.0 | 【Ascend】 | 【Test】 |
| Qwen2 | 57B-A14B | qwen2_moe(2.2.0 版本 mcore) | 4k | Mcore | 8x8 | 2.2.0 | 【Ascend】 | 【Pass】 |
| Grok-1 | 40B | grok-1(2.0.0 版本 mcore) | 8k | Mcore | 4x8 | 2.0.0 | 【Ascend】 | 【Pass】 |
| Mixtral | 8x7B | mixtral(2.2.0 版本 mcore) | 32k | Mcore | 8x8 | 2.2.0 | 【Ascend】 | 【Pass】 |
| Mixtral | 8x22B | mixtral(2.2.0 版本 mcore) | 32k | Mcore | 8x8 | 2.2.0 | 【Ascend】 | 【Pass】 |
| Mixtral | 8x22B | mixtral(2.2.0 版本 mcore) | 64k | Mcore | 8x8 | 2.2.0 | 【Ascend】 | 【Test】 |
| DeepSeek-V2 | 236B | deepseek2(2.2.0 版本 mcore) | 8k | Mcore | 20x8 | 2.2.0 | 【Ascend】 | 【Pass】 |
| DeepSeek-V2-coder | 236B | deepseek2_coder(2.2.0 版本 mcore) | 8k | Mcore | 20x8 | 2.2.0 | 【Ascend】 | 【Test】 |
| DeepSeek-V2-Lite | 16B | deepseek2_lite(26.1.0 版本 mcore) | 8k | Mcore | 1x8 | 26.1.0 | 【Ascend】 | 【Pass】 |
| DeepSeek-V2.5 | 236B | deepseek25(2.2.0 版本 mcore) | 8k | Mcore | 20x8 | 2.2.0 | 【Ascend】 | 【Test】 |
| DeepSeek-V3 | 671B | deepseek3 | 4k | Mcore | 64x8 | master | 【Ascend】 | 【Pass】 |
| DeepSeek-V3.2 | 671B | deepseek32 | 4k | Mcore | 32x16 | master | 【Ascend】 | 【Test】 |
| DeepSeek-V4-Flash | 284B | deepseek4_flash | 4k | Mcore | 8x16 | master | 【Ascend】 | 【Test】 |
| MiniCPM | 8x2B | minicpm(2.2.0 版本 mcore) | 4k | Mcore | 1x8 | 2.2.0 | 【Ascend】 | 【Test】 |
| Ling-mini-2.0 | 16B | ling_v2(26.1.0 版本 mcore) | 4k | Mcore | 1x8 | 26.1.0 | 【Ascend】 | 【Test】 |
| Ring | 1T | ling_v2(26.1.0 版本 mcore) | 32k | Mcore | 32x8 | 26.1.0 | 【Ascend】 | 【Test】 |
| Phi3.5 | MoE-instruct | phi35(26.1.0 版本 mcore) | 4k | Mcore | 2x8 | 26.1.0 | 【Ascend】 | 【Test】 |
| Hunyuan | 389B | hunyuanLarge(2.3.0 版本 mcore) | 8k | Mcore | 8x8 | 2.3.0 | 【Ascend】 | 【Pass】 |
| GPT4 | MoE-175B | gpt4(2.3.0 版本 mcore) | 128k | Mcore | 8x8 | 2.3.0 | 【Ascend】 | 【Pass】 |
| GLM4.5-Air | MoE-106B | glm45-air(26.1.0 版本 mcore) | 4k | Mcore | 8x8 | 26.1.0 | 【Ascend】 | 【Test】 |
| GLM5 | MoE-744B | glm5 | 4k | Mcore | 32x16 | master | 【Ascend】 | 【Pass】 |
| GLM5.2 | MoE-744B | glm52 | 4k | Mcore | 32x16 | master | 【Ascend】 | 【Test】 |
| Step3.5-Flash | MoE-196B | step35(26.1.0 版本 fsdp2) | 4k | FSDP2 | 12x16 | 26.1.0 | 【Ascend】 | 【Test】 |
| LongCat | MoE-560B | longcat | 4k | Mcore | 8x16 | master | 【Ascend】 | 【Test】 |
| GPT-OSS | MoE-20B | gpt_oss(26.1.0 版本 fsdp2) | 4k | FSDP2 | 1x16 | 26.1.0 | 【Ascend】 | 【Test】 |
| MiniMax-M2.7 | MoE-229B | minimax_m27(26.1.0 版本 fsdp2) | 4k | FSDP2 | 8x16 | 26.1.0 | 【Ascend】 | 【Test】 |
大规模 MoE 训练要点:DeepSeek-V3 为例
从支持列表可见,超过 300B 的 MoE 模型(如 DeepSeek-V3 671B、GLM5 744B)推荐集群规模普遍在数十节点以上,其训练脚本的并行配置极具参考价值。以 examples/mcore/deepseek3/pretrain_deepseek3_671b_4k_ptd.sh 为例:
- 多维并行:
TP=4、PP=8、EP=32(专家并行)、CP=1,全局批大小GBS=3840,序列长度 4k; - MLA(Multi-head Latent Attention):通过
--multi-latent-attention --qk-pos-emb-head-dim 64 --qk-head-dim 128 --q-lora-rank 1536 --kv-lora-rank 512 --v-head-dim 128等参数配置 DeepSeek 系列的 MLA 低秩注意力(对应实现见 mindspeed_llm/features_manager/transformer/multi_latent_attention); - MoE 优化:
--moe-grouped-gemm(分组 GEMM)、--moe-permutation-async-comm(排列异步通信)、--moe-token-dispatcher-type alltoall等,缓解专家负载不均衡并降低 All-to-All 通信开销; - HCCL 调优:
HCCL_ALGO="alltoall=level0:NA;level1:pipeline"、HCCL_BUFFSIZE=400等环境变量针对超节点互联进行通信算法定制。
GPT 模型词表配置
GPT 模型的词表文件与常规模型不同,需按以下步骤配置:
mkdir vocab_file
cd vocab_file
wget https://s3.amazonaws.com/models.huggingface.co/bert/gpt2-vocab.json
wget https://s3.amazonaws.com/models.huggingface.co/bert/gpt2-merges.txt
cd ..
# 处理成训练数据
python ./preprocess_data.py \
--input ./dataset/ \
--output-prefix ./dataset/gpt_text_sentence \
--tokenizer-type GPT2BPETokenizer \
--vocab-file ./vocab_file/gpt2-vocab.json \
--merge-file ./vocab_file/gpt2-merges.txt \
--append-eod \
--workers 4 \
--log-interval 1000
# 请根据真实存放路径配置预训练脚本以下参数
VOCAB_FILE="./vocab_file/gpt2-vocab.json" # 词表
MERGE_FILE="./vocab_file/gpt2-merges.txt" # BPE 合并表
DATA_PATH="./dataset/gpt_text_sentence" # 数据路径
其中 --append-eod 表示在文档末尾追加 <eod> token、--output-prefix 指定二进制输出路径(无后缀),相关参数定义见根目录 preprocess_data.py。
FSDP2 后端稀疏模型实战:Qwen3-MoE 为例
FSDP2 后端采用“YAML 配置 + CLI 覆盖”的启动方式。以 examples/fsdp2/qwen3_moe/pretrain_qwen3_30b_4k_fsdp2_A3.sh 为例,脚本通过 train_fsdp2.py 加载 YAML 配置,并用命令行参数覆盖模型路径、数据集、并行度与优化开关:
source examples/fsdp2/env_config.sh
NPUS_PER_NODE=16
torchrun $DISTRIBUTED_ARGS train_fsdp2.py \
examples/fsdp2/qwen3_moe/pretrain_qwen3_30b_4k_fsdp2_A3.yaml \
--model.model_name_or_path ./model_weights/Qwen3-30B-A3B/ \
--parallel.fsdp_size 16 \
--parallel.ep_size 1 \
--optimization.moe_grouped_gemm True \
--optimization.use_flash_attn True \
| tee logs/pretrain_qwen3_moe_30b_a3b_4K_fsdp2_${TIMESTAMP}.log
对应 YAML(如 examples/fsdp2/qwen3/pretrain_qwen3_8b_4k_fsdp2_A3.yaml)中的关键配置项包括:
| 配置段 | 关键项 | 说明 |
|---|---|---|
model |
train_from_scratch |
是否从零训练;false 表示加载预训练权重 |
data |
template / cutoff_len / data_manager_type |
数据模板(如 qwen3)、截断长度、数据管理器类型(mg 表示 Megatron 数据) |
parallel |
fsdp_modules / recompute |
FSDP 分片模块范围(model.layers.{*}、embed_tokens、lm_head)与重计算开关 |
training |
stage: pt / optimizer: adamw / lr / lr_scheduler_type: cosine |
训练阶段(预训练)、优化器、学习率与余弦调度 |
optimization |
use_flash_attn / use_fused_rmsnorm / moe_grouped_gemm |
融合算子与 MoE 分组 GEMM 开关 |
FSDP2 后端的完整入门流程(权重下载、数据准备、预训练与微调)可参考 FSDP2 快速入门。
状态空间模型(State Space Model, SSM)
状态空间模型是一类基于状态空间表示的序列模型,能够高效地建模长序列数据。与传统的 Transformer 模型相比,SSM 在处理长序列时具有更好的计算效率和内存效率。支持列表如下:
| 模型 | 下载 | 脚本位置 | 序列长度 | 训练后端 | 集群规模 | 支持版本 | 贡献方 | 认证 |
|---|---|---|---|---|---|---|---|---|
| Mamba2 | 2.7B | mamba2(26.0.0 版本 mcore) | 4k | Mcore | 1x8 | 26.0.0 | 【Ascend】 | 【Test】 |
| Mamba2 | 8B | mamba2(26.0.0 版本 mcore) | 4k | Mcore | 1x8 | 26.0.0 | 【Ascend】 | 【Test】 |
| Mamba2Hybrid | 8B | mamba2(26.0.0 版本 mcore) | 4k | Mcore | 1x8 | 26.0.0 | 【Ascend】 | 【Test】 |
| Mamba3 | / | mamba3(26.1.0 版本 fsdp2) | 4k | Mcore | 1x8 | 26.1.0 | 【Ascend】 | 【Test】 |
Mamba 系列注意事项
- Mamba2 系列开源模型未提供词表文件。内部测试使用的词表文件
mamba2_2.7b_from_8b.model为自定义设计,建议用户自行构建词表,训练效果不做保证。 - Mamba3 模型目前暂未开源,仓库仅提供可运行 Demo 示例。如需运行该 Demo,请按以下方式修改:
-
配置文件:复用
mamba2-2.7b的config.json,并新增以下两项配置:"model_type": "mamba2", "is_mimo": false其中
is_mimo可根据实际设置为false或true。 -
词表:建议用户自行构建,也可选用其他开源模型词表(如 Qwen3-Next),训练效果不做保证。
-
多模态模型
多模态大模型(图文理解、文生视频/图、语音识别等)由 MindSpeed MM 专项维护。如果需要进行多模态大模型的训练,请访问 MindSpeed MM 仓库获取详细的使用说明,当前 MindSpeed MM 支持的模型可参考其模型支持列表。
附:模型脚本环境变量速查
模型脚本中常见的昇腾环境变量说明如下(详见脚本环境变量介绍):
| 环境变量名称 | 环境变量描述 |
|---|---|
ASCEND_LAUNCH_BLOCKING |
1:强制算子采用同步模式运行,会导致性能下降,会屏蔽 task_queue 队列优化功能;0:会增加内存消耗,有 OOM 的风险。 |
ASCEND_SLOG_PRINT_TO_STDOUT |
0:关闭日志打屏,日志采用默认输出方式,保存在 log 文件中;1:开启日志打屏,日志不保存在 log 文件中,直接打屏显示。 |
HCCL_WHITELIST_DISABLE |
HCCL 白名单开关,1-关闭 / 0-开启。 |
HCCL_CONNECT_TIMEOUT |
设置 HCCL 超时时间,默认值为 120。 |
CUDA_DEVICE_MAX_CONNECTIONS |
定义了任务流能够利用或映射到的硬件队列的数量。 |
TASK_QUEUE_ENABLE |
控制开启 task_queue 算子下发队列优化的等级:0 关闭;1 开启 Level 1 优化;2 开启 Level 2 优化。 |
COMBINED_ENABLE |
0 关闭;1 开启,用于优化非连续两个算子组合类场景。 |
PYTORCH_NPU_ALLOC_CONF |
内存碎片优化开关,默认 expandable_segments:False,使能时配置为 expandable_segments:True,用于内存管理和碎片回收。 |
ASCEND_RT_VISIBLE_DEVICES |
指定哪些 Device 对当前进程可见,支持一次指定一个或多个 Device ID,无需修改应用程序即可调整所用 Device。 |
NPUS_PER_NODE |
配置一个计算节点上使用的 NPU 数量。 |
HCCL_SOCKET_IFNAME |
指定 HCCL Socket 通信走的网卡配置。 |
GLOO_SOCKET_IFNAME |
指定 Gloo Socket 通信走的网卡配置。 |
HCCL_LOGIC_SUPERPOD_ID |
指定当前设备的逻辑超节点 ID,如果走 ROCE,不同多机超节点 ID 不同,0~N。 |
CPU_AFFINITY_CONF |
开启粗/细粒度绑核,避免线程间抢占、提高缓存命中、避免跨 NUMA 节点的内存访问、减少任务调度开销。 |
NPU_ASD_ENABLE |
0 关闭检测;1 开启特征值检测并打印异常日志不告警;2 开启并告警;3 开启、告警并在 Device 侧 info 级日志记录过程数据。 |
TORCH_HCCL_ASYNC_ERROR_HANDLING |
使用 HCCL 作为通信后端时控制是否开启异步错误处理,默认值为 1;0 不开启,1 开启。 |
总结
MindSpeed-LLM 的 PyTorch 框架模型支持列表覆盖了从 0.5B 到 1T 参数的稠密、稀疏(MoE)与状态空间模型,并同时提供 Legacy、Mcore、FSDP2 三种训练后端与对应的示例脚本、高性能脚本。实际选型时建议遵循以下原则:
- 新任务优先选择 Mcore 后端(当前推荐实现,配套脚本与文档最完整);
- 依赖 PyTorch 原生分布式生态、或模型规模较大时,可评估 FSDP2 后端(参考 FSDP2 快速入门);
- 根据支持列表中“集群规模 × 序列长度”匹配自身硬件,并确认单 NPU 片上内存不低于 64GB;
- 对于
【Test】状态的模型,功能验证中如遇问题,可向项目 Issues 反馈。