> **环境说明**:海光 DCU,DTK 26.04,vLLM 镜像版本 `0.18.1-ubuntu22.04-dtk26.04-py3.10`,使用 Docker 容器部署。
> 包含大语言模型(Qwen3.8-27B)、Embedding、Reranker(含 VL 多模态重排)的部署与测试。
---
## 目录
1. [启动 vLLM 容器](#1-启动-vllm-容器)
2. [模型下载(ModelScope)](#2-模型下载modelscope)
3. [Qwen3.8-27B 部署与测试](#3-qwen38-27b-部署与测试)
4. [Qwen3-VL-Embedding-8B 部署与测试](#4-qwen3-vl-embedding-8b-部署与测试)
5. [Qwen3-VL-Reranker-8B 部署与测试](#5-qwen3-vl-reranker-8b-部署与测试)
---
## 1. 启动 vLLM 容器
```bash
docker run --name <容器名> -it \
--network=host \
--ipc=host \
--shm-size=200G \
--device=/dev/kfd \
--device=/dev/mkfd \
--device=/dev/dri \
-v /opt/hyhal:/opt/hyhal \
-v /home/user1/model:/model \
--group-add video \
--cap-add=SYS_PTRACE \
--security-opt seccomp=unconfined \
harbor.sourcefind.cn:5443/dcu/admin/base/vllm:0.18.1-ubuntu22.04-dtk26.04-py3.10 \
/bin/bash
```
**参数说明:**
| 参数 | 说明 |
| -------------------------------------- | -------------------------------------- |
| `--network=host` | 使用宿主机网络,端口直接暴露 |
| `--ipc=host` / `--shm-size=200G` | 共享内存,多卡通信必需 |
| `--device=/dev/kfd /dev/mkfd /dev/dri` | 海光 DCU 设备透传 |
| `-v /opt/hyhal:/opt/hyhal` | 挂载海光 HAL 库 |
| `-v /home/user1/model:/model` | 模型目录映射(宿主机 → 容器 `/model`) |
| `--group-add video` | 加入 video 组,访问 DCU 设备 |
| `--cap-add=SYS_PTRACE` | 调试能力,部分推理框架需要 |
> 容器内模型路径:宿主机 `/home/user1/model` 映射为容器内 `/model`
---
## 2. 模型下载(ModelScope)
进入容器后,使用 `modelscope` 下载所需模型,统一存放到 `/home/user1/model` 目录。
```bash
# Qwen3.8-27B(完整版)
modelscope download --model Qwen/Qwen3.8-27B --local_dir /home/user1/model/Qwen3.8-27B
# Qwen3-VL-Embedding-8B(多模态向量化)
modelscope download --model Qwen/Qwen3-VL-Embedding-8B --local_dir /home/user1/model/Qwen3-VL-Embedding-8B
# Qwen3-VL-Reranker-8B(多模态重排)
modelscope download --model Qwen/Qwen3-VL-Reranker-8B --local_dir /home/user1/model/Qwen3-VL-Reranker-8B
```
> 下载前确保已安装 modelscope:`pip install modelscope`
---
## 3. Qwen3.8-27B 部署与测试
### 3.1 启动命令
```bash
HIP_VISIBLE_DEVICES=3,4 vllm serve /model/Qwen3.8-27B \
--host 0.0.0.0 \
--port 8000 \
--served-model-name qwen3.8-27b \
--tensor-parallel-size 2 \
--mm-encoder-tp-mode data \
--enable-auto-tool-choice \
--tool-call-parser qwen3_coder \
--reasoning-parser qwen3 \
--speculative-config '{"method":"mtp","num_speculative_tokens":3}' \
--gpu_memory_utilization=0.95 \
--enable-prefix-caching \
--enable-chunked-prefill \
--enable-prompt-tokens-details
```
**关键参数说明:**
| 参数 | 说明 |
| -------------------------------- | -------------------------------- |
| `HIP_VISIBLE_DEVICES=3,4` | 使用第 3、4 号 DCU 卡 |
| `--tensor-parallel-size 2` | 2 卡张量并行 |
| `--mm-encoder-tp-mode data` | 多模态编码器 TP 模式为 data 并行 |
| `--enable-auto-tool-choice` | 启用自动工具调用 |
| `--tool-call-parser qwen3_coder` | Qwen3 工具调用解析器 |
| `--reasoning-parser qwen3` | Qwen3 推理(思维链)解析器 |
| `--speculative-config` | MTP 投机解码,加速 3 个 token |
| `--gpu_memory_utilization=0.95` | GPU 显存利用率 95% |
| `--enable-prefix-caching` | 前缀缓存,复用相同前缀 KV Cache |
| `--enable-chunked-prefill` | 分块预填充,提升长文本吞吐 |
### 3.2 测试
```bash
curl http://127.0.0.1:8000/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "qwen3.8-27b",
"messages": [{"role": "user", "content": "简单介绍一下人工智能"}],
"temperature": 0.7,
"stream": true
}'
```
---
## 4. Qwen3-VL-Embedding-8B 部署与测试
### 4.1 启动命令
```bash
HIP_VISIBLE_DEVICES=5 vllm serve /model/Qwen3-VL-Embedding-8B \
--runner pooling \
--host 0.0.0.0 \
--port 8001 \
--served-model-name qwen3-vl-embedding-8b \
--max-model-len 8192 \
--gpu-memory-utilization 0.47
```
**关键参数说明:**
| 参数 | 说明 |
| ------------------------------- | --------------------------------------- |
| `--runner pooling` | 使用 pooling 模式(Embedding 模型必需) |
| `--max-model-len 8192` | 最大上下文长度 8192 |
| `--gpu-memory-utilization 0.47` | 显存利用率 47%,与 Reranker 共享单卡 |
### 4.2 测试
```bash
curl -s http://127.0.0.1:8001/v1/embeddings \
-H "Content-Type: application/json" \
-d '{
"model": "qwen3-vl-embedding-8b",
"input": "这是一个用于测试 vLLM embedding 服务是否正常的句子。"
}'
```
---
## 5. Qwen3-VL-Reranker-8B 部署与测试
### 5.1 启动命令
```bash
HIP_VISIBLE_DEVICES=5 vllm serve /model/Qwen3-VL-Reranker-8B \
--runner pooling \
--hf-overrides '{"architectures": ["Qwen3VLForSequenceClassification"], "classifier_from_token": ["no", "yes"], "is_original_qwen3_reranker": true}' \
--max-model-len 4096 \
--port 8002 \
--served-model-name qwen3-vl-reranker-8b \
--gpu-memory-utilization 0.47
```
**关键参数说明:**
| 参数 | 说明 |
| ----------------------------------------- | -------------------------------------- |
| `--runner pooling` | pooling 模式(Reranker 模型必需) |
| `--hf-overrides` | 覆盖模型配置,指定序列分类架构和分类头 |
| `--chat-template qwen3_vl_reranker.jinja` | 使用 Qwen3 VL Reranker 专用对话模板 |
| `--max-model-len 4096` | 最大上下文长度 4096 |
| `--gpu-memory-utilization 0.47` | 与 Embedding 共享 5 号卡,各占约 47% |
> **注意**:Embedding 和 Reranker 同时运行在 5 号卡上,两者显存利用率各设为 0.47,合计不超过单卡显存。
### 5.2 测试
```bash
curl -s http://127.0.0.1:8002/v1/rerank \
-H "Content-Type: application/json" \
-d '{
"model": "qwen3-vl-reranker-8b",
"query": "什么是人工智能?",
"documents": [
"人工智能是研究、开发用于模拟、延伸和扩展人的智能的理论、方法、技术及应用系统的一门新的技术科学。",
"机器学习是人工智能的一个分支,它使计算机能够从数据中学习并做出决策。",
"今天天气很好,适合出去散步。"
]
}'
```
---
## 6. 端口与资源分配汇总
| 模型 | DCU 卡号 | 端口 | 显存利用率 | 模式 |
| --------------------- | -------- | ---- | ---------- | -------------------- |
| Qwen3.8-27B | 3, 4 | 8000 | 0.95 | 文本生成(2卡TP) |
| Qwen3-VL-Embedding-8B | 5 | 8001 | 0.47 | Embedding(pooling) |
| Qwen3-VL-Reranker-8B | 5 | 8002 | 0.47 | Reranker(pooling) |