一、vllm 准备工作
1. 环境配置
以下为 KVM 虚拟机配置:
| 系统 | CPU | 内存 | GPU |
|---|---|---|---|
| Ubuntu 22.04 | 32 核 | 64GB | V100 * 2 |
虚拟机 CPU 设置:
虚拟机 CPU 需要开启 avx 指令集。
-
编辑虚拟机配置:
# virsh edit i-mvlzfacx <cpu mode= custom match= exact check= full > <model fallback= forbid >Skylake-Server</model> <topology sockets= 4 cores= 16 threads= 1 /> <feature policy= require name= avx /> <feature policy= require name= avx2 /> <feature policy= require name= hypervisor /> </cpu> -
重新
define虚拟机并查看 CPU 信息:# lscpu | grep avx Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology cpuid pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch cpuid_fault pti fsgsbase bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx avx512f avx512dq rdseed adx smap clwb avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 arat
2. 安装 V100 驱动
-
更新系统并安装必要的软件包:
apt update apt install -y software-properties-common add-apt-repository ppa:graphics-drivers/ppa -y apt install ubuntu-drivers-common -
查看可以安装的驱动版本:
ubuntu-drivers devices -
删除已安装的 NVIDIA 驱动:
apt-get remove --purge ^nvidia-.* -
安装最新驱动或指定版本:
ubuntu-drivers install # 或者安装指定版本 apt install nvidia-driver-565 -
重启虚拟机。
-
查看 GPU 信息:
# nvidia-smi Mon Feb 24 08:43:47 2025 +-----------------------------------------------------------------------------------------+ | NVIDIA-SMI 565.57.01 Driver Version: 565.57.01 CUDA Version: 12.7 | |-----------------------------------------+------------------------+----------------------+ | GPU Name Persistence-M | Bus-Id Disp.A | Volatile Uncorr. ECC | | Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. | | | | MIG M. | |=========================================+========================+======================| | 0 Tesla V100-PCIE-16GB-LS On | 00000000:00:08.0 Off | 0 | | N/A 41C P0 26W / 250W | 1MiB / 16384MiB | 0% Default | | | | N/A | +-----------------------------------------+------------------------+----------------------+ | 1 Tesla V100-PCIE-16GB-LS On | 00000000:00:09.0 Off | 0 | | N/A 40C P0 29W / 250W | 1MiB / 16384MiB | 0% Default | | | | N/A | +-----------------------------------------+------------------------+----------------------+ +-----------------------------------------------------------------------------------------+ | Processes: | | GPU GI CI PID Type Process name GPU Memory | | ID ID Usage | |=========================================================================================| | No running processes found | +-----------------------------------------------------------------------------------------+
3. 安装 CUDA
-
下载并安装 CUDA 软件包:
# 下载 CUDA 软件包源 wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2404/x86_64/cuda-keyring_1.1-1_all.deb dpkg -i cuda-keyring_1.1-1_all.deb # 查看 CUDA 版本 apt policy cuda-toolkit # 安装 CUDA Toolkit apt install cuda-toolkit -
配置 CUDA 环境变量:
export CUDA_HOME=/usr/local/cuda export PATH=${CUDA_HOME}/bin:${PATH} export LD_LIBRARY_PATH=${CUDA_HOME}/lib64:$LD_LIBRARY_PATH -
查看 CUDA 版本:
# nvcc --version nvcc: NVIDIA (R) Cuda compiler driver Copyright (c) 2005-2025 NVIDIA Corporation Built on Wed_Jan_15_19:20:09_PST_2025 Cuda compilation tools, release 12.8, V12.8.61 Build cuda_12.8.r12.8/compiler.35404655_0
4. 安装 vLLM
在 conda 环境中创建虚拟环境并安装 vLLM:
-
创建
conda环境:conda create -n vllm python=3.12 -
安装 vLLM:
pip install vllm -i https://mirrors.aliyun.com/pypi/simple
5. 下载模型
由于无法直接从 Hugging Face 下载模型,使用 魔搭社区 下载。
-
安装 modelscope:
apt install modelscope -
下载 DeepSeek R1 模型:
modelscope download --model deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B --local /root/deepseek-r1-qwen-1.5b
二、单机试运行
1. 启动 vLLM 部署为 OpenAI API 协议的服务器:
启动成功后默认端口是 `8000`
```
# python -m vllm.entrypoints.openai.api_server --model /root/deepseek-r1-qwen-1.5b --served-model-name deepseek-qwen-1.5b --dtype=half --tensor-parallel-size 1 --max-model-len 1000 --trust-remote-code
INFO 02-21 13:17:27 launcher.py:31] Route: /v1/audio/transcriptions, Methods: POST
INFO 02-21 13:17:27 launcher.py:31] Route: /rerank, Methods: POST
INFO 02-21 13:17:27 launcher.py:31] Route: /v1/rerank, Methods: POST
INFO 02-21 13:17:27 launcher.py:31] Route: /v2/rerank, Methods: POST
INFO 02-21 13:17:27 launcher.py:31] Route: /invocations, Methods: POST
INFO: Started server process [5485]
INFO: Waiting for application startup.
INFO: Application startup complete.
```
2. 访问 API 进行测试: 使用 POST 请求测试服务器:
```
import requests
headers = {
"Content-Type": "application/json",
}
url = "http://localhost:8000/v1/chat/completions"
prompt = {
"model": deepseek-qwen-1.5b ,
"messages": [
{ role : "system", "content":"你好"},
],
"temperature": 0.6,
"top_p": 0.8
}
resp = requests.post(url, headers=headers, json=prompt, stream=False)
rep = resp.json()
print(rep)
```
返回结果示例:
```
# python test.py
{
id : chatcmpl-edc1865a63a743d19f2b145de0e6b1fa ,
object : chat.completion ,
created : 1740115918,
model : deepseek-qwen-1.5b ,
choices : [{
index : 0,
message : { role : assistant , content : 您好!您提到的“你好”是中文里常用的问候语,如果您有其他问题或需要协助,请随时告知我。 },
finish_reason : stop
}],
usage : { prompt_tokens : 5, completion_tokens : 37}
}
```
三、遇到的问题
1. 错误:For debugging consider passing CUDA_LAUNCH_BLOCKING=1 ERROR ...
- 初始以为是 CUDA 版本不一致的问题,重新安装了 CUDA Toolkit 并确保版本一致后,问题依旧存在。
- 最终通过开启虚拟机 CPU 的
avx指令集后,问题解决。
© 版权声明
文章版权归作者所有,未经允许请勿转载。
相关文章
暂无评论...



