PC本地部署vllm gemma-2b

PC本地部署vLLM

vLLM是一个快速且易于使用的LLM推理和服务库。
vLLM具有以下特点:

  • 顶尖水准的服务吞吐量
  • PagedAttention对注意力关键和价值记忆的有效管理
  • 连续批处理传入请求
  • 使用CUDA/HIP图快速执行模型
  • 量化:GPTQ、AWQ、SqueezeLLM、FP8KV缓存
  • 优化的CUDA内核

vLLM具有灵活性,易于与以下组件一起使用:

  • 与流行的HuggingFace模型无缝集成
  • 具有各种解码算法的高吞吐量服务,包括并行采样、波束搜索等
  • 分布式推理的张量并行性支持
  • 流输出
  • 兼容OpenAI的API服务器
  • 支持NVIDIA GPU和AMD GPU

由于vllm不支持Windows系统,下文将讲述如何在WSL2(linux系统)上部署

1. WSL2安装

WSL安装可参考站内该文章WSL2安装(详细过程)
​​​​
:WSL版本必须为2,否则后续无法正常加载显卡驱动
WSL1与2版本差异

2. vllm安装

vllm官网建议安装cuda12.1,与conda管理python包。

  1. anaconda3下载链接,选择linux-x86安装包下载到本地即可。下载到指定目录后,例如我下载在D盘中,进入wsl2终端cd /mnt/dbash Anaconda3-2024.02-1-Linux-x86_64.sh即可开始安装。安装过程一路回车输入yes即可,注最后一步建议输yes,会将conda环境变量写入~/.bashrc文件中。
  2. conda国内清华源配置,vim ~/.condarc,输入如下内容
channels:
  - defaults
show_channel_urls: true
default_channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
  conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  pytorch-lts: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  1. 创建python环境conda create -n vllm python=3.9 -y
  2. 激活vllm conda环境conda activate vllm
  3. 配置pip国内清华源pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
  4. 待cuda下载完成后,pip install vllm安装vllm包。
  5. 安装vllm包后,再补齐一下pytorch2.3.0安装pip3 install torch torchvision torchaudio

3. cuda安装

  • 安装cuda前需在windows安装英伟达驱动,根据自己显卡情况安装。安装成功后,在windows的cmd终端或wsl2终端使用nvidia-smi应有正常回显。
  • cuda与驱动有如下参考信息,更详细情况可参考官方CUDA Toolkit and Corresponding Driver Versions,若版本不配套会导致功能无法正常使用。
    xxx

vllm官方使用cuda12.1版本,使用deb(network)安装方式安装,有如下命令。

wget https://developer.download.nvidia.com/compute/cuda/repos/wsl-ubuntu/x86_64/cuda-keyring_1.0-1_all.deb
sudo dpkg -i cuda-keyring_1.0-1_all.deb
sudo apt-get update
sudo apt-get -y install cuda

安装完毕后将cuda写入环境变量。

echo 'export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH' >> ~/.bashrc
echo 'export PATH=/usr/local/cuda/bin:$PATH' >> ~/.bashrc
source ~/.bashrc

使用nvcc -V有正常回显,cuda安装成功,验证cuda能否正常使用cd /usr/local/cuda/extras/demo_suite/ && ./deviceQuery && cd -,出现PASS打屏即保证cuda功能正常。

4. 功能验证

python3 -m vllm.entrypoints.openai.api_server --model /data/gemma_test/gemma-2b/ --dtype float16 --served-model-name gemma-2b --host 127.0.0.1 --port 8080

出现如下打屏,说明服务端启动成功。
vllm服务端打印

另起一终端输入如下命令,可得到模型输出。

curl http://127.0.0.1:8080/v1/completions \
    -H "Content-Type: application/json" \
    -d '{
        "model": "gemma-2b",
        "prompt": "请你介绍一下你自己"
    }'

vllm回复

由于本人显卡算力有限,vllm无法以gemma-2b训练的bf16格式加载权重,导致精度有所损失,问题回答结果不太正常。

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值