OpenPPL-LLM 推理部署
环境准备
基本配置
-
查看系统版本信息
lsb_release -a
以下为当前A800系统信息:
Distributor ID: Debian Description: Debian GNU/Linux 11 (bullseye) Release: 11 Codename: bullseye
-
安装gcc / cmake / git
apt-get install build-essential cmake git
-
分配存储空间
-
查看模型大小
du -sh
-
查看剩余存储空间
fdisk -l df -h
-
存储空间不足扩容
如果当前剩余的存储空间小于模型文件所需空间,需要对存储空间进行扩容。
-
扩充操作(略)
-
查看扩充后磁盘空间
fdisk -l
-
格式化
mkfs.ext4 -F /dev/vdb -m 0 -q -L gpt -J size=4096 -T largefile -i 16384
-
挂载
1. mount -o rw,nodiratime,noatime,data=writeback,nobarrier,lazytime,delalloc /dev/vdd /disk1
修改系统文件,保证开机挂载
# 查看 uuid blkid # 修改配置文件 vim /etc/fstab # 插入新分区信息 UUID=c779e832-6dde-4d11-8e44-7451119dda9d /disk1 ext4 rw,nodiratime,noatime,data=writeback,nobarrier,lazytime,delalloc
-
-
-
模型文件传输
-
共享盘挂载
# 建立挂载点文件夹 mkdir /mnt/models # 下载nfs sudo apt-get update sudo apt-get install nfs-common # 挂载,设置挂载状态为只读 mount -o ro -t nfs 10.10.11.11:/data/models /mnt/models
-
模型复制
# 复制文件夹需要添加选项 -r cp -r /mnt/models/modeldir save_dir # 进度监控 watch -n 3 progress
-
共享盘解除挂载
umount \mnt\models
-
注意
挂载共享盘时,必须设置挂载方式为只读;使用vs code进行ssh操作时,如果在挂载共享盘的情况下发生掉线,可能导致共享盘内容清空,因此,挂载共享盘进行文件传输的情况下应当避免使用vs code进行操作,文件传输结束之后应当尽快结束挂载。
-
python环境
-
安装anaconda
wget https://repo.anaconda.com/archive/Anaconda3-5.3.0-Linux-x86_64.sh chmod +x ./run.sh ./Anaconda3-5.3.0-Linux-x86_64.sh
-
配置ppl.pmx虚拟环境
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
cuda 配置
- 安装Nvidia驱动(略)
- 安装cuda工具(略)
MPICH 安装
Mopish工具用于多卡通信,属于选装项目。
-
下载软件包:https://www.mpich.org/
-
解压
tar -xvf mpich-4.0.2.tar.gz
-
配置安装
cd mpich-4.0.2/
- 如果没有 Fortran 编译器,则可以避免构建 MPI Fortran 库:
./configure --disable-fortran
- 编译安装
make; sudo make install
- 验证
mpiexec --version
模型转换
git clone https://github.com/openppl-public/ppl.pmx.git
cd ppl.pmx/model_zoo/llama/facebook
pip install -r requirements.txt # requirements
# MP属于可调节参数,应当等于文件中的pth个数
MP=1
OMP_NUM_THREADS=${MP} torchrun --nproc_per_node ${MP} \
Export.py --ckpt_dir /modeldisk/llama-2-7/7B/ \
--tokenizer_path /modeldisk/llama-2-7/tokenizer.model \
--export_path /modeldisk/llama7ppl/ \
--fused_qkv 1 --fused_kvcache 1 --auto_causal 1 \
--quantized_cache 1 --dynamic_batching 1
模型部署
问题:
- 服务器 cmake过程出现git clone 指令不能下载如何解决?
- 如何确定不同机器的PPLNN_CUDA_ARCHITECTURES和PPLCOMMON_CUDA_ARCHITECTURES 参数?
检查make版本,版本不能低于3.19
git clone https://github.com/openppl-public/ppl.llm.serving.git
cd ppl.llm.serving
./build.sh -DPPLNN_USE_LLM_CUDA=ON -DPPLNN_CUDA_ENABLE_NCCL=ON -DPPLNN_ENABLE_CUDA_JIT=OFF -DPPLNN_CUDA_ARCHITECTURES="'80;86;87'" -DPPLCOMMON_CUDA_ARCHITECTURES="'80;86;87'"
推理测试
-
启动server
./ppl-build/ppl_llm_server src/models/llama/conf/llama_7b_config_example.json
-
启动client
./ppl-build/client_sample 127.0.0.1:23333
-
QPS benchmark 测试
./ppl-build/client_qps_measure --target=127.0.0.1:23333 --tokenizer=/model_data/llama_fb/tokenizer.model --dataset=tools/samples_1024.json --request_rate=inf
测试结果记录
Llama 部署
- A800 lamma_v2_13b
OMP_NUM_THREADS=${MP} torchrun --nproc_per_node ${MP} Export.py --ckpt_dir /modeldisk/baichuan7b/ --export_path /modeldisk/baichuan7bppl/ --fused_qkv 1 --fused_kvcache 1 --auto_causal 1 --quantized_cache 1 --dynamic_batching 1
OMP_NUM_THREADS=1 torchrun --nproc_per_node 1 Export.py --ckpt_dir /modeldisk/chatglm-6b/ --tokenizer_path /modeldisk/Baichuan2-7B-chat/tokenizer.model --fused_qkv 1 --fused_kvcache 1 --auto_causal 1 --quantized_cache 1 --dynamic_batching 1 --export_path /modeldisk/chatglm-6b/
OMP_NUM_THREADS=${MP} torchrun --nproc_per_node ${MP} Export.py --ckpt_dir /modeldisk/chatglm-6b/ --export_path /modeldisk/chatglm6b_ppl/ --fused_qkv 1 --fused_kvcache 1 --quantized_cache 1 --dynamic_batching 1 --cache_layout 3
-
Llama 7b 目前服务器缺少paremeter.json文件,并且无法访问hugging face,无法下载需要文件。
-
Mac Studio端部署llama 问题,无法编译plann:
chatglm部署
-
Chatglm6b 部署:
-
Convert hugging model to pt model
python ConvertWeightToPmx.py --input_dir /modeldisk/Baichuan2-7B-chat/ --output_dir /modeldisk/baichuanppl/
export to ppl model
MP=1 OMP_NUM_THREADS=${MP} torchrun --nproc_per_node ${MP} Export.py --ckpt_dir /modeldisk/chatglm-6b/ --export_path /modeldisk/chatglm6b_ppl/ --fused_qkv 1 --fused_kvcache 1 --quantized_cache 1 --dynamic_batching 1 --cache_layout 3
-
build server and client ?
确实官方给定的json配置文件,直接修改llama7b的json后启动服务端出现以下问题:
-
Badichuan
-
Convert huggingface model to torch model
python ConvertBaichuan7BToPmx.py --input_dir /modeldisk/Baichuan2-7B-chat/ --output_dir /modeldisk/baichuanppl/
-
Export original model to ppl model
MP=1 OMP_NUM_THREADS=${MP} torchrun --nproc_per_node ${MP} Export7B.py --ckpt_dir /modeldisk/baichuan7b/ --export_path /modeldisk/baichuan7bppl/ --fused_qkv 1 --fused_kvcache 1 --auto_causal 1 --quantized_cache 1 --dynamic_batching 1 -tokenizer_path /modeldisk/Baichuan2-7B-chat/tokenizer.model --cache_layout 3
-
Start server and client runtime , ? 不存在官方提供的conf 文件,使用llama配置文件出现以下问题:
bai chuan: 需要访问hugging face 下载正确的模型
openppl 概念
GPU T4
OpenMMLab
NNX 开放标准,
网络动态特性
MMCV 算子
异构推理
我们现在会考察一系列推理框架,包括TensorRT-LLM、OpenPPL、DeepSpeed等,最终确定用哪个。
你这会可以先主要了解下TensorRT-LLM和OpenPPL,包括代码架构,部署流程等,大致了解下。
参考资料
https://nvidia.github.io/TensorRT-LLM/
https://docs.nvidia.com/deeplearning/triton-inference-server/user-guide/docs/index.html
https://github.com/NVIDIA/TensorRT-LLM
https://mp.weixin.qq.com/s/WWHk67gvxWJp4_8pGuv8Tg
https://mp.weixin.qq.com/s/lBkTwSQh0fWyjGlTPK1Omg
https://github.com/openppl-public/ppl.llm.serving
我要跑下边的这个代码
./build.sh -DPPLNN_USE_LLM_CUDA=ON -DPPLNN_CUDA_ENABLE_NCCL=ON -DPPLNN_ENABLE_CUDA_JIT=OFF -DPPLNN_CUDA_ARCHITECTURES=“‘80;86;87’” -DPPLCOMMON_CUDA_ARCHITECTURES=“‘80;86;87’”