A40 显卡2 专用 vLLM /MiniCPM-o 2.6 安装文档(附全流程排错指南)

324 阅读1分钟

A40 显卡2 专用 vLLM 安装文档(附全流程排错指南)

硬件环境: NVIDIA A40(显卡2,显存空间46064MiB)
目标:minicpmo 虚拟环境部署 vLLM 服务,适配 MiniCPM-o 2.6 模型


1. 环境准备

1.1. 确保系统环境符合要求

nvidia-smi

确认 NVIDIA 驱动 版本 ≥ 525.85.05,CUDA 版本 ≥ 11.8

nvcc --version

确保 CUDA 11.8 或更高

1.2. 创建并激活 Python 虚拟环境

conda create -n minicpmo python=3.10 -y
conda activate minicpmo

如果没有 Conda,可以使用 venv

python3 -m venv minicpmo
source minicpmo/bin/activate  # Linux/macOS

2. 安装 vLLM

2.1. 安装 PyTorch(需支持 A40)

pip install torch torchvision torchaudio -i https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple

验证:

python -c "import torch; print(torch.cuda.is_available(), torch.cuda.get_device_name(0))"

确保输出 True,且设备名称正确。

2.2. 安装 vLLM

pip install vllm -i https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple

若安装失败,可手动编译:

pip install ninja -i https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple
git clone https://github.com/vllm-project/vllm.git
cd vllm
pip install -e .

3. 下载 MiniCPM-o 2.6


用git:要提前安装 git-lfs 

git install lfs git clone www.modelscope.cn/models/Open…



* * *

## **4. 运行 vLLM 推理服务**

openbmb/MiniCPM-O-2_6B 对应上面下载的模型地址
设置 环境变量选择显卡
export CUDA_VISIBLE_DEVICES=1

vllm serve /root/minicpmo/MiniCPM-o-2_6 --dtype auto --max-model-len 2048 --api-key token-SHUXILMSSSDFDA12DADC --gpu_memory_utilization 1 --trust-remote-code


然后使用 API:

import requests response = requests.post( "http://localhost:8000/generate", json={"prompt": "你好,介绍一下你自己?", "max_tokens": 100} ) print(response.json())


* * *

## **5. 常见问题排查**

| 问题                                                    | 可能原因               | 解决方案                                                                               |
| ----------------------------------------------------- | ------------------ | ---------------------------------------------------------------------------------- |
| `torch.cuda.is_available()` 返回 `False`                | 驱动/CUDA 版本不匹配      | `nvidia-smi` 确保驱动 >= 525.85.05,CUDA >= 11.8                                        |
| `No module named vllm`                                | vLLM 未正确安装         | `pip install vllm -i https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple`         |
| `RuntimeError: CUDA out of memory`                    | 显存不足               | 降低 `gpu-memory-utilization` 或减少 `tensor-parallel-size`                             |
| `ModuleNotFoundError: No module named 'transformers'` | `transformers` 库缺失 | `pip install transformers -i https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple` |

* * *

**至此,vLLM 及 MiniCPM-o 2.6B 在 A40(显卡 2)上的安装和推理流程完成!** 🚀