1、LLM 训练推理加速在阿里巴巴的实践杨斯然/刘侃大语言模型训练和Megatron-LLaMA框架大语言模型训练的过程大语言模型训练的算法和问题大语言模型中的模型并行Megatron-LLaMA框架的计算和通信并行Megatron-LLaMA框架的3D并行调优Megatron-LLaMA框架应用到LLaMA模型中小结大语言模型的应用大语言模型:训练过程预训练有监督微调强化学习数万亿 token数万 prompt/response文本标注数据人工反馈上百万GPU小时大语言模型训练:算法和问题GPUGPU梯度梯度模型样本样本2.梯度同步3.模型更新1.梯度计算需求限制模型存储13B模型:156GB6
2、5B模型:780GB显存容量:80GB梯度同步13B模型:52GB65B模型:260GB网络带宽:100GB/sDeepSpeed:ZeRO优化器1.优化状态切分到数据并行的各个rank上2.部分通信和梯度计算并行3.激活重算,节省梯度计算过程显存大语言模型训练:模型并行参考文献:1.Megatron-LM:Training Multi-Billion Parameter Language Models Using Model Parallelism2.Efficient Large-Scale Language Model Training on GPU Clusters Using Meg
3、atron-LMMegatron-LM:3D模型并行1.MLP层和Attention层切分到多张卡上,通常用NVLink互联2.模型的分为多个Stage,切分到多台机器上 3.分布式优化器Megatron-LLaMA框架:计算通信并行Reduce ScatterAllgatherFWBWFWBWFWBWFWBWAdamReduce ScatterAllgatherFWBWFWBWReduce ScatterAdamMegatron-LM 分布式优化器时间线Megatron-LLaMA通信遮盖分布式优化器时间线Megatron-LLaMA参数分片和梯度更新Megatron-LLaMA框架:计算通
4、信并行256 x A100 80GB512 x A100 80GBMegatron-LLaMA1890(23.9 天)1845(12.2 天)Megatron-LM1630(27.8 天)1430(15.8 天)LLaMA-13B 训练时间Megatron-LLaMA框架:3D并行调优Reduce ScatterAllgatherWarmupCooldownAdamSteadyMegatron-LLaMA通信遮盖应用到Pipeline并行Tensor并行开销:正比于TP SizePipeline并行开销:正比于(PP Size-1)交错Pipeline并行开销:正比于(PP Size-1)/V
5、参考文献:Efficient Large-Scale Language Model Training on GPU Clusters Using Megatron-LMMegatron-LLaMA框架:LLaMA模型应用sh tools/checkpoint_conversion/hf_to_megatron.shtorchrun-nproc_per_node=8 pretrain_llama.py -tensor-model-parallel-size 2 -pipeline-model-parallel-size 1 -overlapped-distributed-optimizer -r
6、educe-bucket-size 4e8 -tokenizer-type=PretrainedFromHFsh tools/checkpoint_conversion/megatron_to_hf.sh优化器设置通信分片设置Tokenizer设置大语言模型训练:小结大语言模型的训练需要消耗大量的GPU资源算力、显存、通信是三大核心瓶颈框架可以提供在这三者之间平衡和优化的手段Megatron-LLaMA通过在Megatron-LM的基础上进行通信/计算模式优化同时提供LLaMA相关结构以及HuggingFace生态