有奖捉虫:办公协同&微信生态&物联网文档专题 HOT
Angel-Tilearn 由 tiacc_training 升级而来,提供兼容 huggingface 生态的大模型训练加速能力,支持手工 cuda 算子结合自动编译优化的计算优化能力,支持兼容原生的 DDP 的通信加速能力,用户无需修改原生的使用代码可直接进行使用。此外支持优化器融合、CPU/GPU亲和性优化、自适应混合精度等通用训练加速能力和模型压缩能力,用户仅需增加几行代码便可使用。




一、Tilearn.llm 大模型训练加速

1.1 环境相关

推荐使用平台内置镜像:tilearn-llm0.4.2-torch2.1-deepspeed0.10.0-py3.10-cuda12.1-gpu



在镜像内更新最新的 tilearn.llm 和 tilearn.ops 包(可选)
pip3 uninstall -y tilearn.llm tilearn.ops
pip3 install tilearn-llm -i https://pypi.tuna.tsinghua.edu.cn/simple
(or pip3 install tilearn.llm -i https://pypi.tuna.tsinghua.edu.cn/simple)
pip3 install tilearn.ops -i https://g-bnvx3728-pypi.pkg.coding.net/tione/tilearn/simple
在自定义镜像使用需满足以下条件:
基于 nvcr.io/nvidia/pytorch:23.07-py3 制作的自定义镜像,镜像中的 torch.__version__=='2.1.0a0+b5021ba'
或基于平台镜像tilearn-llm0.4.2-torch2.1-deepspeed0.10.0-py3.10-cuda12.1-gpu制作的自定义镜像
其他情况请联系加速团队进行支持


1.2 使用文档

主要介绍大模型计算优化能力,通用训练加速能力详细使用文档(通信优化、优化器融合、CPU/GPU 亲和性优化、自适应混合精度)可参考 Tilearn.llm 使用说明

以 llama 模型为例,计算优化使用方法-代码修改如下:
### TILEARN.LLM
from tilearn.llm.transformers import LlamaForCausalLM

### 模型接口与标准huggingface一致
model = LlamaForCausalLM.from_pretrained(...)
使用 AutoModelForCausalLM 接口
### TILEARN.LLM
from tilearn.llm.transformers import AutoModelForCausalLM

### 模型接口与标准huggingface一致
model = AutoModelForCausalLM.from_pretrained(...)
特殊说明:
由于 baichuan1 13B 和 baichuan2 13B 会产生冲突,目前 tilearn.llm.transformers.AutoModelForCausalLM 默认开启了 baichuan1 13B,如果需要使用 baichuan2 13B,需要在启动训练脚本中设置环境变量:export TILEARN_LLM_BAICHUAN_13B=2
目前加速已经支持的模型llama、bloom、baichuan1、baichuan2,详情请参考 Tilearn.llm使用说明

1.3 加速效果





二、tiacc_training旧版训练加速

tilearn.llm>=0.7.12,tilearn.ops>=0.2.0.1已经支持旧版 tiacc_training 加速能力(Tilearn.llm使用说明第2节-通用训练加速功能介绍)
使用新的平台镜像 tilearn-llm0.4.2-torch2.1-deepspeed0.10.0-py3.10-cuda12.1-gpu 可直接使用旧版功能

2.1 环境相关

推荐使用平台内置 torch 镜像和 tensorflow 镜像:
torch 镜像: ti-acc2.0-torch1.9-py3.8-cuda11.1-gpu



tensorflow 镜像: ti-acc1.0-tf1.15-py3.6-cuda10.0-gpu




2.2 使用 DDP 分布式训练通信优化(PyTorch+DPP)

以兼容原生 DDP 的方式启动训练脚本,无需进行训练代码的修改,启动命令参考示例如下:
python3 -u -m tiacc_training.distributed.launch --nproc_per_node $GPUS_PER_NODE --nnodes $NNODES --node_rank $NODE_RANK --master_addr $MASTER_ADDR --master_port $MASTER_PORT main.py
DDP 分布式训练通信优化实测效果: (加速效果在多机多卡场景方有体现,单机多卡场景与原生 DDP 性能无异。)
硬件环境
模型
GPU 卡数
原生DDP(examples/sec per V100)
TI-ACC通信优化(examples/sec per V100)
腾讯云GN10Xp.20XLARGE320
resnext50_32x4d
1(单机)
227
227
8(单机)
215
215
16(双机)
116
158.6

2.3 使用自适应混合精度优化(PyTorch)

import torch.cuda.amp as amp
import tiacc_training.torch
scaler = amp.GradScaler()
#实例化自适应混合精度策略类的对象
policy = tiacc_training.torch.tiacc_torch_warp.MixedPrecision_TrainingPolicy(policy,start_step,hold_step,end_step,interval_time,interval_hold_time)
#根据输入的参数得到当前epoch是否需要开启混合精度
mixed_precision = policy.enable_mixed_precision(epoch,lr=lr,loss=loss,scaler=scaler)
with amp.autocast(enabled=mixed_precision):
outputs = model(inputs)
loss = criterion(outputs, targets)
scaler.scale(loss).backward()
scaler.step(optimizer)
scaler.update()
自适应混合精度优化实测效果:
硬件环境
模型
GPU 卡数
原生PyTorch(examples/sec per V100)
TI-ACC 数据 IO 优化(examples/sec per V100)
TI-ACC 数据 IO+自适应混合精度优化(examples/sec per V100)
腾讯云GN10Xp.20XLARGE320
resnet50 mmcls
8(单机)
70.8
350.5
379.2
centernet mmdet
8(单机)
26.4
28.6
30.6

2.4 使用优化后的 embedding 变量构造(TensorFlow+PS)

# 启动容器
docker run -itd --name tiacc-rec-fm --network=host --ipc=host ccr.ccs.tencentyun.com/ti-platform/tensorflow:1.15.5-py3-rec-0121
# 进入容器
docker exec -it tiacc-rec-fm bash
# 原生tensorflow embedding使用方法
cd wideanddeep && bash start_all.sh --fm
# tiacc lookup优化使用方法
cd wideanddeep && bash start_all.sh --tiacc --fm
embedding 变量构造+lookup 计算优化实测效果:
硬件环境
模型
GPU 卡数
原生 TensorFlow(global_steps/sec per V100)
TI-ACC 优化后(global_steps/sec per V100)
腾讯云GN10Xp.20XLARGE320
DeepFM
16(双机)
41.9 - 56
96.1 - 103.3
Wide & Deep
16(双机)
49.9 - 69
120 - 128