[doc] update sp doc (#6055)

* update sp doc

* fix

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix

* fix

* fix

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
flybird11111
2024-09-11 17:25:14 +08:00
committed by GitHub
parent 13946c4448
commit a35a078f08
4 changed files with 350 additions and 0 deletions

View File

@@ -62,6 +62,25 @@
- [Megatron-LM: Training Multi-Billion Parameter Language Models Using Model Parallelism](https://arxiv.org/abs/1909.08053)
- [Chimera: Efficiently Training Large-Scale Neural Networks with Bidirectional Pipelines](https://arxiv.org/abs/2107.06925)
### 序列并行
序列并行是一种对于序列维度进行切分的并行策略它是训练长文本序列的有效方法。现成熟的序列并行方法包括megatron提出的序列并行DeepSpeed-Ulysses序列并行和ring-attention序列并行等。
#### megatron sp:
该序列并行方法是在张量并行的基础上实现的序列并行模型并行的每个gpu上样本独立且重复的对于非线性运算的部分如layernorm等无法使用张量并行的模块可以在序列维度将样本数据切分为多个部分每个gpu计算部分数据然后在计算attention及mlp等线性部分使用张量并行策略需要将activation汇总这样可以在模型进行切分的情况下进一步减少activation的内存占用需要注意的是该序列并行方法只能与张量并行一起使用。
#### DeepSpeed-Ulysses:
序列并行通过在序列维度上分割样本并利用all-to-all通信操作使每个GPU接收完整序列但仅计算注意力头的非重叠子集从而实现序列并行。该并行方法具有完全通用的attention可支持密集和稀疏的注意力。
alltoall是一个全交换操作相当于分布式转置的操作在attention计算之前将样本沿序列维度进行切分每个设备只有N/P的序列长度然而使用alltoall后qkv的子部分shape变为[N, d/p]在计算attention时仍考虑了整体的序列。
#### ring attention
ring attention思路类似于flash attention每个GPU只计算一个局部的attention最后将所有的attention块结果进行归约计算出总的attention。在Ring Attention中输入序列被沿着序列维度切分为多个块每个块由不同的GPU或处理器负责处理Ring Attention采用了一种称为“环形通信”的策略通过跨卡的p2p通信相互传递kv子块来实现迭代计算可以实现多卡的超长文本。在这种策略下每个处理器只与它的前一个和后一个处理器交换信息形成一个环形网络。通过这种方式中间结果可以在处理器之间高效传递而无需全局同步减少了通信开销。
相关论文:
[Reducing Activation Recomputation in Large Transformer Models](https://arxiv.org/pdf/2205.05198)
[DeepSpeed Ulysses: System Optimizations for Enabling Training of Extreme Long Sequence Transformer Models](https://arxiv.org/abs/2309.14509)
[Ring Attention with Blockwise Transformers for Near-Infinite Context](https://arxiv.org/pdf/2310.01889)
## 优化器相关的并行
@@ -90,3 +109,4 @@
- [ZeRO-Offload: Democratizing Billion-Scale Model Training](https://arxiv.org/abs/2101.06840)
- [ZeRO-Infinity: Breaking the GPU Memory Wall for Extreme Scale Deep Learning](https://arxiv.org/abs/2104.07857)
- [PatrickStar: Parallel Training of Pre-trained Models via Chunk-based Memory Management](https://arxiv.org/abs/2108.05818)
<!-- doc-test-command: echo -->