通过vllm 部署qwen2 模型

主要是一个简单测试

安装vllm

  • pip 模式安装

部分包比较大, 注意时间, 最好使用一个加速, 目前阿里云的似乎有限速了,可以试试清华的https://pypi.tuna.tsinghua.edu.cn/simple

python -m venv venv
source venv/bin/ac
source  venv/bin/activate
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple   vllm 

openai兼容api 模式运行qwen2

使用modelscope 进行模型的下载

  • 配置modelscope
export VLLM_USE_MODELSCOPE=True
  • 运行qwen2 7b 模式
    相对比较慢,所以推荐配置上边的东西,同时会进行模型的下载,模型都比较大
python -m vllm.entrypoints.openai.api_server \
    --model qwen/Qwen2-7B-Instruct \
    --host 0.0.0.0 \
    --port  8080 

可能的问题:
ImportError('libcuda.so.1: cannot open shared object file: No such file or directory'), 这个目前属于waring ,暂时可以不用处理
缺少modelscope,因为配置了VLLM_USE_MODELSCOPE 所以还需要安装modelscope pip install -i https://pypi.tuna.tsinghua.edu.cn/simple modelscope
而且可能还会有提示缺少nvidia 驱动相关的,安装处理如下
cuda.repo

[cuda-rhel9-x86_64]
name=cuda-rhel9-x86_64
baseurl=https://developer.download.nvidia.com/compute/cuda/repos/rhel9/x86_64
enabled=1
gpgcheck=1
gpgkey=https://developer.download.nvidia.com/compute/cuda/repos/rhel9/x86_64/D42D0685.pub

安装

sudo dnf install epel-release
sudo dnf clean all
sudo dnf install nvidia-driver nvidia-settings  cuda-drivers
// 注意之后reboot 下系统

ValueError: Bfloat16 is only supported on GPUs with compute capability of at least 8.0. Your Tesla T4 GPU has compute capability 7.5. You can use float16 instead by explicitly setting thedtype flag in CLI, for example: --dtype=half
运行配置参数修改

python -m vllm.entrypoints.openai.api_server \
    --model qwen/Qwen2-7B-Instruct \
    --api-key qwen2demo \
    --host 0.0.0.0 \
    --dtype half \
    --port  8080  

Nvidia 内核模块加载问题,可选的通过自己配置下
sudo dkms autoinstall sudo modprobe nvidia 之后可以通过nvidia-smi 或者lsmod |grepnvidia 进行验证内核模块是否加载成功

  • api 访问
curl http://localhost:8080/v1/chat/completions \
    -H "Content-Type: application/json" \
    -d '{
    "model": "Qwen2-7B-Instruct",
    "messages": [
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "LoRA 是什么"}
    ]
    }'
  • gpu 信息查看

 

说明

vllm 比较适合进行多机多卡运行模式,对于单机模式,ollama 还是优先选择,至少比较简单快速,对于多节点部署模式需要依赖ray,同时注意GPU 版本的选择,推荐还是使用较新的,老版本的,处理就是慢, 关于GPU 配置部分ollama 的安装shell 还是很值得学习参考的

参考资料

https://docs.vllm.ai/en/stable/getting_started/quickstart.html
https://www.modelscope.cn/home
https://www.modelscope.cn/models/qwen/Qwen2-7B-Instruct/summary
https://docs.vllm.ai/en/stable/serving/distributed_serving.html
https://docs.vllm.ai/en/stable/serving/env_vars.html
https://discuss.luxonis.com/d/3868-libcudaso1-issue-in-colab/5
https://stackoverflow.com/questions/54249577/importerror-libcuda-so-1-cannot-open-shared-object-file
https://github.com/vllm-project/vllm/issues/1369

posted on 2024-07-19 08:00  荣锋亮  阅读(85)  评论(0编辑  收藏  举报

导航