Files
rocm_vllm_nightly/README.md
T

114 lines
4.4 KiB
Markdown
Raw Normal View History

2026-03-29 05:06:19 +08:00
# ROCm vLLM 容器化推理项目
2026-03-29 16:19:26 +08:00
基于镜像 `docker.1ms.run/vllm/vllm-openai-rocm:latest` 的 Python + vLLM 推理服务,适配双 AMD R9700 32G GPU。
2026-03-29 05:06:19 +08:00
## 项目目标
- 提供可容器化部署的模型推理 API
2026-03-29 16:19:26 +08:00
- 使用 vLLM + ROCm 在 AMD GPU 上执行推理
2026-03-29 05:22:25 +08:00
- 暴露 `8001` OpenAI 标准协议接口,兼容 OpenClaw 调用
2026-03-29 05:06:19 +08:00
## 目录结构
```text
.
├── app
│ ├── config.py
2026-03-29 05:09:37 +08:00
│ ├── model_catalog.py
2026-03-29 05:31:19 +08:00
│ ├── start_openai.py
2026-03-29 05:06:19 +08:00
│ └── schemas.py
├── .dockerignore
2026-03-29 05:09:37 +08:00
├── config.json
2026-03-29 05:06:19 +08:00
├── docker-compose.yml
├── Dockerfile
└── requirements.txt
```
## 配置项
2026-03-29 05:31:19 +08:00
项目只读取一个配置文件:`config.json`。
- `services.openai.host` / `services.openai.port`:OpenAI 协议服务监听地址与端口(默认 `0.0.0.0:8001`)
2026-03-30 01:03:20 +08:00
- `public_model_name`:对外固定模型名,切换底层模型时可保持调用方参数不变
2026-03-30 02:50:24 +08:00
- `reasoning_enabled`:思考推理开关,默认 `false`(关闭)
2026-03-29 16:49:09 +08:00
- `api_key`:OpenAI 接口访问密钥
2026-03-29 05:31:19 +08:00
- `tensor_parallel_size`:张量并行数,双卡建议 `2`
- `dtype`:推理精度,默认 `bfloat16`
2026-03-29 05:47:30 +08:00
- `model_root`:本地模型根目录,建议 `/opt/model`
- `offline_mode`:保留字段,当前实现固定只走离线本地模型
2026-03-29 05:35:20 +08:00
- `models.selected`:当前生效模型,留空时回退到 `models.default`
2026-03-29 05:06:19 +08:00
2026-03-29 05:09:37 +08:00
## config.json 说明
`config.json` 采用以下结构:
2026-03-29 05:35:20 +08:00
- `models.default`:默认模型名
- `models.selected`:当前生效模型名
- `models.profiles`:模型配置集合
2026-03-30 02:50:24 +08:00
- 每个模型必须包含:`local_path`,并建议补充 `ctx`、`max_num_seqs`、`max_tokens`、`dtype`、`quantization`、`reasoning_parser`
2026-03-29 05:09:37 +08:00
启动时会按以下优先级选模型:
2026-03-29 05:35:20 +08:00
1. `config.json` 中 `models.selected`
2. `config.json` 中 `models.default`
2026-03-29 05:09:37 +08:00
模型被选中后,会自动覆盖运行参数,包括:
2026-03-29 05:47:30 +08:00
- `model_name` ← `local_path`(相对路径会自动拼接 `model_root`)
2026-03-29 05:09:37 +08:00
- `max_model_len` ← `ctx`
- `max_num_seqs` ← `max_num_seqs`
- `max_tokens` ← `max_tokens`
- `gpu_memory_utilization` ← `gpu_util`
- `trust_remote_code` ← `trust_remote`
- `enforce_eager` ← `enforce_eager`
2026-03-29 05:06:19 +08:00
## 部署步骤
2026-03-29 05:35:20 +08:00
1. 修改 `config.json` 中的 `models.selected` 与服务参数。
2026-03-29 05:06:19 +08:00
2026-03-29 05:31:19 +08:00
2. 构建并启动容器:
2026-03-29 05:06:19 +08:00
```bash
docker compose up -d --build
```
2026-03-29 16:49:09 +08:00
3. 验证 OpenAI 协议服务:
2026-03-29 05:22:25 +08:00
```bash
2026-03-29 05:47:30 +08:00
curl http://localhost:<services.openai.port>/v1/models
2026-03-29 05:22:25 +08:00
```
## OpenAI 协议示例(8001)
```bash
curl -X POST "http://localhost:8001/v1/chat/completions" \
-H "Content-Type: application/json" \
2026-03-29 05:31:19 +08:00
-H "Authorization: Bearer <config.json中的api_key>" \
2026-03-30 01:03:20 +08:00
-d "{\"model\":\"Qwen_local_model\",\"messages\":[{\"role\":\"user\",\"content\":\"你好,介绍一下你自己\"}],\"temperature\":0.7}"
2026-03-29 05:22:25 +08:00
```
## OpenClaw 调用说明
- Base URL 使用 `http://<服务器IP>:8001/v1`
2026-03-29 05:31:19 +08:00
- API Key 使用 `config.json` 中 `api_key`
2026-03-30 01:03:20 +08:00
- 模型名固定使用 `config.json` 中 `public_model_name`(默认 `Qwen_local_model`)
2026-03-30 02:50:24 +08:00
- 若要启用思考推理,将 `config.json` 中 `reasoning_enabled` 设为 `true`
2026-03-29 05:22:25 +08:00
- 若使用工具调用,`config.json` 中应配置 `tool_call_parser` 与 `enable_auto_tool_choice`
2026-03-29 05:47:30 +08:00
- 服务强制离线模式,不会回退到 Hugging Face 远程下载
2026-03-29 05:35:20 +08:00
- 所有路径按 Ubuntu 规范填写,本地模型建议使用 `/opt/model/<模型目录>`
2026-03-29 05:22:25 +08:00
2026-03-29 05:06:19 +08:00
## 双 AMD R9700 调优建议
- 首选 `TENSOR_PARALLEL_SIZE=2`
- 首次部署建议设置 `GPU_MEMORY_UTILIZATION=0.90`,稳定后再调高
- 若模型较大且吞吐压力高,可逐步调低 `MAX_MODEL_LEN` 或 `MAX_NUM_SEQS`
- 确保宿主机已正确安装 ROCm 驱动并暴露 `/dev/kfd` 与 `/dev/dri`
2026-03-29 05:57:45 +08:00
## 常见故障排查
2026-03-29 16:19:26 +08:00
- 报错 `model type ... Transformers does not recognize this architecture` 时,说明当前模型与镜像内依赖不兼容,建议更换模型或升级镜像版本。
2026-03-29 17:32:12 +08:00
- 报错 `model config (gptq) does not match quantization argument (gptq_marlin)` 时,将该模型配置改为 `dtype=float16` 且 `quantization=gptq`。
2026-03-30 01:03:20 +08:00
- 报错 `RPC call to sample_tokens timed out` 或出现 `GPU core dump` 时,先下调模型配置为更稳参数:`ctx=32768`、`max_num_seqs=4`、`max_tokens=2048`、`gpu_util=0.90`,并开启 `enforce_eager=true`。
2026-03-29 16:19:26 +08:00
- 若模型目录存在但仍加载失败,检查挂载路径是否为 `/opt/model:/opt/model:ro`,并确认容器内可见模型文件。
- 如果看到 `No services to build`,说明未触发重建;需要先执行 `docker compose build --no-cache` 再 `up`。