目录

Windows本地部署Qwen2-VL

目录

背景

Windows下本地部署Qwen2-VL,宿主机4张显卡。

无界面后端

容器内启动脚本start.sh

1
2
3
4
5
6
7
#!/bin/bash

# 设置文件权限
chmod -R 755 /root/.cache/huggingface/hub/models--Qwen--Qwen2-VL-7B-Instruct

# 启动模型服务器
python -m vllm.entrypoints.openai.api_server --served-model-name Qwen2-VL-7B-Instruct --model Qwen/Qwen2-VL-7B-Instruct --tensor_parallel_size=4 --limit-mm-per-prompt image=10

Dockerfile文件

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
FROM qwenllm/qwenvl:latest

# 环境变量设置
ENV CUDA_VISIBLE_DEVICES=0,1,2,3
ENV HF_ENDPOINT=https://hf-mirror.com

# 更新 huggingface_hub
RUN pip install -U -i https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple huggingface_hub

# 将启动脚本添加到镜像中
COPY start.sh /start.sh
RUN chmod +x /start.sh

# 暴露端口
EXPOSE 8000

# 使用启动脚本作为 ENTRYPOINT
ENTRYPOINT ["/start.sh"]

执行

1
2
docker build -t qwen2vl:latest .
docker run --ipc=host --gpus all --name qwen2 -itd -v /c/Users/Administrator/.cache:/root/.cache -p 12123:8000 qwen2vl:latest

其中--ipc=host为必填项,-v为选填,此处使用是因为模型已经在宿主机下载好,映射以进行复用。

1
curl http://localhost:12123/v1/chat/completions -H "Content-Type: application/json" -d '{"model":"Qwen2-VL-7B-Instruct","messages":[{"role":"system","content":"You are a helpful assistant."},{"role":"user","content":[{"type":"image_url","image_url":{"url":"https://modelscope.oss-cn-beijing.aliyuncs.com/resource/qwen.png"}},{"type":"text","text":"What is the text in the illustrate?"}]}]}'

Web界面

在open-webui的“管理面板”的“外部连接”页面添加上述模型的访问。 OpenAI API中填入http://192.168.2.128:12123/v1,API KEY填入EMPTY

其他坑

每次启动这个容器(模型),都会到huggingface上校验一次模型文件,所以与https://hf-mirror.com必须畅通的,比如代理clash关闭前未将系统代理改回无代理等,会导致无法启动容器。