已合并
【readme】增加异步DDP、Alibi、swiglu融合算子 readme #242
zhao-yifan27创建于 2024年4月29日
【readme】增加异步DDP、Alibi、swiglu融合算子 readme #242
已合并
zhao-yifan27创建于 2024年4月29日
zyf_1合入到master
6 个文件变更+72-2
MREADME.md+3-2
@@ -117,19 +117,20 @@ AscendSpeed 是针对华为昇腾设备的大模型加速库。
117| Megatron 序列并行 | [link](https://github.com/NVIDIA/Megatron-LM) |117| Megatron 序列并行 | [link](https://github.com/NVIDIA/Megatron-LM) |
118| Megatron 重计算 | [link](https://github.com/NVIDIA/Megatron-LM) |118| Megatron 重计算 | [link](https://github.com/NVIDIA/Megatron-LM) |
119| Megatron 分布式优化器 | [link](https://github.com/NVIDIA/Megatron-LM) |119| Megatron 分布式优化器 | [link](https://github.com/NVIDIA/Megatron-LM) |
120-| Megatron 异步DDP | [link](https://github.com/NVIDIA/Megatron-LM) |120+| Megatron 异步DDP | [link](docs/features/async-ddp.md) |
121| Ascend TP 重计算通信优化 | [link](docs/features/recomputation-communication.md) |121| Ascend TP 重计算通信优化 | [link](docs/features/recomputation-communication.md) |
122| Ascend 内存碎片优化 | [link](docs/features/memory-fragmentation.md) |122| Ascend 内存碎片优化 | [link](docs/features/memory-fragmentation.md) |
123| Ascend 自适应选择重计算 | [link](docs/features/adaptive-recompute.md) |123| Ascend 自适应选择重计算 | [link](docs/features/adaptive-recompute.md) |
124| Ascend 计算通信并行优化 | [link](docs/features/communication-over-computation.md) |124| Ascend 计算通信并行优化 | [link](docs/features/communication-over-computation.md) |
125| Ascend BF16 参数副本复用 | [link](docs/features/reuse-fp32-param.md) |125| Ascend BF16 参数副本复用 | [link](docs/features/reuse-fp32-param.md) |
126| Ascend rms_norm 融合算子 | [link](docs/features/rms_norm.md) |126| Ascend rms_norm 融合算子 | [link](docs/features/rms_norm.md) |
127+| Ascend swiglu 融合算子 | [link](docs/features/swiglu.md) |
127| Ascend rotary_embedding 融合算子 | [link](docs/features/rotary-embedding.md) |128| Ascend rotary_embedding 融合算子 | [link](docs/features/rotary-embedding.md) |
128| Ascend MoE token重排性能优化 | [link](docs/features/token-rearrange.md) |129| Ascend MoE token重排性能优化 | [link](docs/features/token-rearrange.md) |
129| 【Prototype】Ulysses 长序列并行 | [link](docs/features/ulysses-context-parallel.md) |130| 【Prototype】Ulysses 长序列并行 | [link](docs/features/ulysses-context-parallel.md) |
130| 【Prototype】Ring Attention 长序列并行 | [link](docs/features/ring-attention-context-parallel.md) |131| 【Prototype】Ring Attention 长序列并行 | [link](docs/features/ring-attention-context-parallel.md) |
131| 【Prototype】Ascend MC2 | [link](docs/features/mc2.md) |132| 【Prototype】Ascend MC2 | [link](docs/features/mc2.md) |
132-| 【Prototype】alibi | 暂无 |133+| 【Prototype】alibi | [link](docs/features/alibi.md) |
133| 【Prototype】其他昇腾亲和优化 | 暂无 |134| 【Prototype】其他昇腾亲和优化 | 暂无 |
134 135 
135# 自定义算子136# 自定义算子
Adocs/features/alibi.md+25-0
@@ -0,0 +1,25 @@
1+# Alibi 位置编码
2+ 
3+## 问题分析
4+ 
5+当大模型在训练和预测时的输入长度不一致时,模型的泛化能力会下降。若外推能力不佳,大模型在处理长文本或多轮对话时的效果就会受到限制。正弦位置编码的外推能力比较弱,RoPE(Rotary Position Embedding)的外推能力有一定提高但仍然有限。
6+ 
7+## 解决方案
8+ 
9+支持Alibi位置编码,提高模型外推能力。
10+ 
11+### 解决思路:
12+ 
13+Alibi算法给attention score添加了一个预设的线性偏置矩阵(如下图所示),使模型能够理解输入之间的相对位置关系。由于位置信息直接作用于attention score上,位置性差异被突出,使模型具有较强的外推能力。
14+<p align="center"> <img src="../../sources/images/alibi.png" height="180px" width="400px"></p>
15+ 
16+[原文链接](https://arxiv.org/pdf/2108.12409)
17+ 
18+ 
19+## 使用方法
20+ 
21+设置`--position-embedding-type alibi`即可调用该算法。
22+ 
23+## 使用效果
24+ 
25+模型外推能力提高。
Adocs/features/async-ddp.md+27-0
@@ -0,0 +1,27 @@
1+# 异步DDP
2+ 
3+## 问题分析
4+ 
5+大模型训练过程中,通常会使用数据并行。在进行梯度更新时,数据并行组中的通信(未开启分布式优化器时为AllReduce,开启时为ReduceScatter)要等反向计算完成后再进行。这样的串行执行顺序会造成计算和通信流存在一定的空闲等待时间,导致执行效率较低。
6+ 
7+## 解决方案
8+ 
9+通过将计算和通信任务分别拆分成更细粒度的子任务来实现相互的流水掩盖。并行原理如下图所示:
10+<p align="center"> <img src="../../sources/images/async_ddp.png" height="250px" width="680px"></p>
11+ 
12+### 解决思路:
13+ 
14+设置一个Bucket,存储反向计算的结果。每当Bucket存满时立刻执行桶中结果的通信任务,后续反向计算可以和这部分通信并行执行,从而增大计算和通信流的利用率,提高执行效率。
15+ 
16+## 使用场景
17+ 
18+使用该特性的前提是模型开启数据并行和虚拟流水并行,脚本中设置了`----num-layers-per-virtual-pipeline-stage N`
19+ 
20+## 使用方法
21+ 
22+设置`--overlap-grad-reduce`即可调用该算法。
23+ 
24+## 使用效果
25+ 
26+开启该特性可以提升性能。
27+ 
Adocs/features/swiglu.md+17-0
@@ -0,0 +1,17 @@
1+# swiglu融合优化
2+ 
3+## 问题分析
4+swiglu常见于LLaMA、LLaMA2、Baichuan等LLM模型中的激活层,由于torch侧没有提供swiglu算子的接口,因此在模型中通常是以自定义的形式出现,这种形式的执行效率相对较低。
5+ 
6+## 解决方法
7+Ascendspeed对将swiglu操作合并成一个算子,减少数据传输和临时存储。算子接口见[link](../ops/swiglu.md)。
8+ 
9+## 使用场景
10+模型使用swiglu作为MLP层激活函数,脚本中设置了`--swiglu`
11+ 
12+## 使用方法
13+设置`--used-fused-swiglu`即可调用swiglu融合算子。
14+ 
15+## 使用效果
16+开启融合算子可以节省内存,提升性能。
17+ 
Asources/images/alibi.png+0-0
Asources/images/async_ddp.png+0-0