# ModelLink
**Repository Path**: zhangjunyi08/ModelLink
## Basic Information
- **Project Name**: ModelLink
- **Description**: 昇腾大模型仓库
- **Primary Language**: Python
- **License**: MIT
- **Default Branch**: master
- **Homepage**: https://gitee.com/ascend/ModelLink/
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 1117
- **Created**: 2024-05-21
- **Last Updated**: 2024-05-29
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
简体中文 |
English
ModelLink旨在为华为 [昇腾芯片](https://open.codehub.huawei.com/OpenBaize/Ascend/ascendspeed/files?ref=master&filePath=examples%2Fbaichuan%2Fpretrain_baichuan_zero_7B.sh&isFile=true) 上的大语言模型提供端到端的解决方案, 包含模型,算法,以及下游任务。
## ModelLink解决方案概览
---
### 支持功能
当前ModelLink支撑大模型使用功能:
* [制作预训练数据集](#jump11)/[制作指令微调数据集](#jump12)
* [预训练](#jump13)/[全参微调](#jump14)/[低参微调](#jump15)
* [流式推理/人机对话](#jump16)
* [评估基线数据集](#jump17)
* [加速算法/融合算子/并行策略](#jump18)
* [基于昇腾芯片采集Profiling数据](#jump19)
* [Huggingface与Megatron-LM权重转换](#jump20)
强化学习等特性持续研发中....
### 支持模型
当前ModelLink支持下列模型的预训练以及微调:
### 脚本命名规则
| 脚本 | 规则 |
|:-----------------:|:------:|
| pretrain_xxx.sh | 预训练脚本 |
| tune_xxx.sh | LoRA脚本 |
| generate_xxx.sh | 推理脚本 |
| xxxx_chat_xx.sh | 对话脚本 |
| evaluation_xxx.sh | 评估脚本 |
---
## 模型版本与性能说明
上述列表中支持的模型,我们在[examples](./examples/)文件夹中提供了各模型的训练脚本和readme说明,里面有详细的模型训练、推理、评估流程。
【需要注意模型使用时的配套环境版本,参考如下】
| 软件 | [版本](https://www.hiascend.com/zh/) |
| :-----------------------: |:----------------------------------:|
| Python | 3.8 |
| driver | Ascend HDK 23.0.0 |
| firmware | Ascend HDK 23.0.0 |
| CANN | CANN 7.0.0 |
| torch | 2.1.0、2.2.0 |
| torch_npu | release v5.0.0 |
【基于现版本我们实测的性能情况统计如下】
模型 |
参数 |
集群规模 |
精度模式 |
性能 |
参考性能 |
Aquila |
7B |
1x8 |
BF16 |
2849 |
2874 |
Aquila2 |
7B |
1x8 |
FP16 |
3323 |
2673 |
Baichuan |
7B |
1x8 |
FP16 |
2685 |
2036 |
13B |
1x8 |
FP16 |
1213 |
862 |
Baichuan2 |
7B |
1x8 |
BF16 |
2664 |
3969 |
13B |
1x8 |
BF16 |
1668 |
2062 |
Bloom |
7B1 |
1x8 |
FP16 |
2034 |
2525 |
176B |
12x8 |
BF16 |
100 |
107 |
CodeLlama |
34B |
2x8 |
BF16 |
837 |
762 |
InternLM |
7B |
1x8 |
BF16 |
2776 |
2854 |
65B |
4x8 |
BF16 |
341 |
414 |
LLaMA |
7B |
1x8 |
FP16 |
3600 |
3804 |
13B |
1x8 |
FP16 |
1895 |
2012 |
33B |
4x8 |
FP16 |
621 |
776 |
65B |
4x8 |
BF16 |
348 |
426 |
LLaMA2 |
7B |
1x8 |
BF16 |
4200 |
3850 |
13B |
1x8 |
BF16 |
1990 |
1920 |
34B |
2x8 |
BF16 |
690 |
796 |
70B |
8x8 |
BF16 |
350 |
339 |
LLaMA3 |
8B |
1x8 |
BF16 |
2483 |
2674 |
70B |
8x8 |
BF16 |
283 |
-- |
Qwen |
7B |
1x8 |
BF16 |
2499 |
2867 |
14B |
1x8 |
BF16 |
1560 |
1578 |
72B |
16x8 |
BF16 |
285 |
345 |
Yi |
34B |
2x8 |
BF16 |
809 |
730 |
Mixtral |
8x7B |
2x8 |
BF16 |
487 |
610 |
Mistral |
7B |
1x8 |
BF16 |
2806 |
2734 |
Qwen1.5 |
7B |
1x8 |
BF16 |
2548 |
2578 |
---
## 加速算法与融合算子
ModelLink支持张量并行、流水线并行、序列并行、重计算、分布式优化器等多种加速算法和融合算子,下表为各种加速特性对应的使能开关:
| 加速特性 | 使能参数 |
|:------------------------------------:|:------------------------------:|
| 张量并行 | --tensor-model-parallel-size |
| 流水线并行 | --pipeline-model-parallel-size |
| 流水并行动态划分 | --num-layer-list |
| 序列并行 | --sequence-parallel |
| 重计算 | --recompute-granularity |
| 分布式优化器 | --use-distributed-optimizer |
| DDP allreduce 掩盖 | --overlap-grad-reduce |
| DDP allgather 掩盖 | --overlap-param-gather |
| Flash attention | --use-flash-attn |
| Fused rmsnorm | --use-fused-rmsnorm |
| Fused swiglu | --use-fused-swiglu |
| mc2 | --use-mc2 |
| Fused rotary
position embedding | --use-fused-rotary-pos-emb |
| Sliding Window Attention | --sliding-window |
```bash
torchrun $DISTRIBUTED_ARGS pretrain_gpt.py \
--tensor-model-parallel-size ${TP} \
--pipeline-model-parallel-size ${PP} \
--num-layer-list 1,2,2,2,1 \
--sequence-parallel \
--recompute-granularity full \
--recompute-method block \
--recompute-num-layers 72 \
--use-distributed-optimizer \
--use-flash-attn \
--use-fused-rmsnorm \
--use-fused-swiglu \
--overlap-grad-reduce \
--overlap-param-gather \
--use-fused-rotary-pos-emb \
--use-mc2 \
--sliding-window 4096 \
... \
...
```
---
## 基于昇腾芯片采集Profiling数据
Modellink支持基于昇腾芯片采集profiling数据,以提供对模型运行情况的分析,主要API如下:
```bash
--profile # 打开profiling采集数据开关
--profile-step-start 5 # 指定开启采集数据的步骤
--profile-step-end 6 # 指定结束采集数据的步骤,实际采集步数为 end-start,不包含end
--profile-ranks 0 1 2 3 4 # 指定采集数据的卡号,默认为0,可以设置为 0 1 2 3 4 5 6 7 8 9 列表指定全局卡号
--profile-level level2 # 数据采集水平,level0, 1, 2, 级别越高采集信息越多,默认为level0
--profile-with-cpu # 是否采集CPU数据,加入参数采集
--profile-with-stack # 采集指令运行堆栈,加入参数采集
--profile-with-memory # 是否采集内存,加入参数采集
--profile-record-shapes # 是否采集计算shape,加入参数采集
--profile-save-path ./profile_dir # profiling数据采集保存路径
```
## 致谢
---
ModelLink由华为公司的下列部门联合贡献 :
- 昇腾计算产品部
- 计算算法部
- 计算研究部
- 开源计算工具部
- 公共开发部
- 全球技术服务部
感谢来自社区的每一个PR,欢迎贡献 ModelLink
---
## 安全声明
[ModelLink安全声明](https://gitee.com/ascend/ModelLink/wikis/%E5%AE%89%E5%85%A8%E5%A3%B0%E6%98%8E)