OpenPPL-LLM 推理部署

OpenPPL-LLM 推理部署

环境准备

基本配置

  1. 查看系统版本信息

    lsb_release -a
    

    以下为当前A800系统信息:

    Distributor ID:	Debian
    
    Description:	Debian GNU/Linux 11 (bullseye)
    
    Release:	11
    
    Codename:	bullseye
    
  2. 安装gcc / cmake / git

    apt-get install build-essential cmake git
    
  3. 分配存储空间

    1. 查看模型大小

      du -sh
      
    2. 查看剩余存储空间

      fdisk -l
      df -h
      
    3. 存储空间不足扩容

      如果当前剩余的存储空间小于模型文件所需空间,需要对存储空间进行扩容。

      1. 扩充操作(略)

      2. 查看扩充后磁盘空间

        fdisk -l
        
      3. 格式化

        mkfs.ext4 -F /dev/vdb -m 0 -q -L gpt -J size=4096 -T largefile -i 16384
        
      4. 挂载

        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
        
        
        
  4. 模型文件传输

    1. 共享盘挂载

      # 建立挂载点文件夹
      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
      
    2. 模型复制

      # 复制文件夹需要添加选项 -r
      cp -r /mnt/models/modeldir save_dir
      # 进度监控
      watch -n 3 progress  
      
    3. 共享盘解除挂载

      umount \mnt\models
      
    4. 注意

      挂载共享盘时,必须设置挂载方式为只读;使用vs code进行ssh操作时,如果在挂载共享盘的情况下发生掉线,可能导致共享盘内容清空,因此,挂载共享盘进行文件传输的情况下应当避免使用vs code进行操作,文件传输结束之后应当尽快结束挂载。

python环境

  1. 安装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
    
  2. 配置ppl.pmx虚拟环境

    pip install -r requirements.txt -i  https://pypi.tuna.tsinghua.edu.cn/simple
    

cuda 配置

  1. 安装Nvidia驱动(略)
  2. 安装cuda工具(略)

MPICH 安装

Mopish工具用于多卡通信,属于选装项目。

  1. 下载软件包:https://www.mpich.org/

  2. 解压

    tar -xvf mpich-4.0.2.tar.gz
    
  3. 配置安装

cd mpich-4.0.2/
  1. 如果没有 Fortran 编译器,则可以避免构建 MPI Fortran 库:
./configure --disable-fortran
  1. 编译安装
make; sudo make install
  1. 验证
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

模型部署

问题:

  1. 服务器 cmake过程出现git clone 指令不能下载如何解决?
  2. 如何确定不同机器的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'"

推理测试

  1. 启动server

    ./ppl-build/ppl_llm_server src/models/llama/conf/llama_7b_config_example.json
    
  2. 启动client

    ./ppl-build/client_sample 127.0.0.1:23333
    
  3. 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 部署
  1. 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

  1. Llama 7b 目前服务器缺少paremeter.json文件,并且无法访问hugging face,无法下载需要文件。

  2. Mac Studio端部署llama 问题,无法编译plann:

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

chatglm部署
  1. Chatglm6b 部署:

    1. 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 
      
    2. build server and client ?

      确实官方给定的json配置文件,直接修改llama7b的json后启动服务端出现以下问题:

      外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

Badichuan
  1. Convert huggingface model to torch model

    python ConvertBaichuan7BToPmx.py --input_dir /modeldisk/Baichuan2-7B-chat/ --output_dir /modeldisk/baichuanppl/
    
  2. 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
    
  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’”

  • 17
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值