step1 创建模型存放目录

$ mkdir -p /home/bpae/docker/qwen2.5vl-72b
$ sudo chown $USER /home/bpae/docker/qwen2.5vl-72b/ 
$ chmod 755 -R /home/bpae/docker/qwen2.5vl-72b/

step2 下载大模型

#使用国内modelscopoe下载大模型
$ pip install modelscope

#将模型下载到指定目录
$ modelscope download --model Qwen/Qwen2.5-VL-72B-Instruct-AWQ --local_dir /home/bpae/docker/Qwen2.5-VL-72B-Instruct-AWQ

step3 拉取官方vllm镜像

#建议使用官方vllm镜像源
$ docker pull vllm/vllm-openai #官方最新镜像,拉取最慢,要耐心等待

$ docker pull egs-registry.cn-hangzhou.cr.aliyuncs.com/egs/vllm:0.8.2-pytorch2.6-cu124-20250328      #阿里云镜像,版本较低

step4 启动大模型

#编写脚本启动Qwen2.5-VL-72B-Instruct-AWQ大模型

vim qwen72B.sh

#!/bin/bash
export PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True
docker run -d \
  --name Qwen2.5-VL-72B-Instruct-AWQ \
  --gpus '"device=1,5,6,7"' \  #指定GPU卡
  --ipc=host \
  -p 8000:8000 \
  -v /home/bpae/docker/Qwen2.5-VL-72B-Instruct-AWQ:/models/Qwen2.5-VL-72B-Instruct-AWQ \ 
  vllm/vllm-openai:latest \
  --model /models/Qwen2.5-VL-72B-Instruct-AWQ \
  --quantization awq \
  --tensor-parallel-size 4 \  #4张卡,故指定张量并行数为4
  --dtype float16 \
  --gpu-memory-utilization 0.95 \  #设置GPU卡内存限制
  --limit-mm-per-prompt image=5,video=3 \  #限制提交最大的图片数量和视频数量
  --max-model-len 32768 \
  --trust-remote-code


#启动
./qwen72B.sh

#查看日志
docker logs -f Qwen2.5-VL-72B-Instruct-AWQ

step5 测试大模型是否可用

#编写python脚本
#编写测试脚本,需要提前有相关图片
import requests
import base64

# 读取图片并转换为 base64
with open("/home/bpae/aa.png", "rb") as f:  #/home/bpae/aa.png图片所在路径
    image_b64 = base64.b64encode(f.read()).decode("utf-8")

# 发送图文请求
url = "http://localhost:8000/v1/chat/completions"
payload = {
    "model": "/models/Qwen2.5-VL-72B-Instruct-AWQ",
    "messages": [
        {
            "role": "user",
            "content": [
                {"type": "text", "text": "描述一下这张图片的内容"},
                {"type": "image_url", "image_url": {"url": f"data:image/jpeg;base64,{image_b64}"}}
            ]
        }
    ]
}

response = requests.post(url, json=payload)
print(response.json())

#运行脚本
python3 qwen72.py

更多推荐