1774597379
This commit is contained in:
@@ -0,0 +1,172 @@
|
||||
# 第一步:准备环境与配置下载源
|
||||
|
||||
`DeepSeek-R1-Distill-Qwen-32B` 的模型权重(BF16/FP16精度)大约需要占用 **64GB 的磁盘空间** 和 **约 65GB 的显存**。
|
||||
|
||||
**A800 80GB 显存完美支持该模型单卡运行**,但**系统盘(30GB)空间不足**,因此将模型下载到数据盘(`/root/autodl-tmp`)中。
|
||||
|
||||
通过国内镜像站下载,并**强制将缓存路径设置在数据盘**,防止系统盘撑爆导致实例死机。
|
||||
|
||||
在终端中依次执行以下命令:
|
||||
|
||||
```bash
|
||||
# 1. 进入数据盘目录
|
||||
cd /root/autodl-tmp
|
||||
|
||||
# 2. 必须:设置 Hugging Face 缓存目录到数据盘
|
||||
export HF_HOME=/root/autodl-tmp/hf_cache
|
||||
|
||||
# 3. 设置 Hugging Face 国内镜像加速下载
|
||||
export HF_ENDPOINT=https://hf-mirror.com
|
||||
|
||||
# 4. 安装 huggingface-cli 及加速传输依赖
|
||||
pip install -U huggingface_hub hf_transfer
|
||||
|
||||
如果遇到风险
|
||||
pip install -U huggingface_hub hf_transfer --break-system-packages
|
||||
|
||||
export HF_HUB_ENABLE_HF_TRANSFER=1
|
||||
```
|
||||
|
||||
# 第二步:下载模型
|
||||
|
||||
**方式一**
|
||||
|
||||
使用 `huggingface-cli` 将模型直接下载到数据盘的指定文件夹中。下载大概需要十几到几十分钟(约 64 GB)。
|
||||
|
||||
```bash
|
||||
hf download deepseek-ai/DeepSeek-R1-Distill-Qwen-32B --local-dir /root/autodl-tmp/DeepSeek-R1-32B
|
||||
|
||||
hf download deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B --local-dir /root/autodl-tmp/DeepSeek-R1-1.5B
|
||||
|
||||
hf download deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B --local-dir /root/autodl-tmp/DeepSeek-R1-Distill-Qwen-7B
|
||||
```
|
||||
|
||||
**方式二**
|
||||
|
||||
```bash
|
||||
python - <<'PY'
|
||||
import os
|
||||
from huggingface_hub import snapshot_download
|
||||
|
||||
os.environ["HF_ENDPOINT"] = "https://hf-mirror.com"
|
||||
os.environ["HF_HOME"] = "/root/autodl-tmp/hf_cache"
|
||||
os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "1"
|
||||
|
||||
print("⏳ 开始下载模型...")
|
||||
path = snapshot_download(
|
||||
repo_id="deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B",
|
||||
local_dir="/root/autodl-tmp/DeepSeek-R1-1.5B",
|
||||
)
|
||||
|
||||
print("✅ 下载完成,模型目录:", path)
|
||||
PY
|
||||
```
|
||||
|
||||
# 第三步:安装并启动 vLLM 推理框架
|
||||
|
||||
**1. 安装 vLLM:**
|
||||
|
||||
```bash
|
||||
pip install vllm
|
||||
```
|
||||
|
||||
**2. 开启后台运行:**
|
||||
|
||||
使用 `screen` 创建一个叫 `vllm_server` 的后台窗口:
|
||||
|
||||
```bash
|
||||
创建
|
||||
screen -U -S vLLM
|
||||
|
||||
列表
|
||||
screen -U -ls
|
||||
|
||||
重新进入
|
||||
screen -U -r 89505.vllm_server
|
||||
|
||||
退出
|
||||
screen -U -S 7394 -X quit
|
||||
|
||||
离开
|
||||
Ctrl-a d
|
||||
```
|
||||
|
||||
**3. 启动类似 OpenAI 的 API 服务:**
|
||||
|
||||
注意:我们将端口设为 `6006`,这是 AutoDL 官方支持对外暴露的默认端口
|
||||
|
||||
前台
|
||||
|
||||
```bash
|
||||
python -m vllm.entrypoints.openai.api_server \
|
||||
--model /root/autodl-tmp/DeepSeek-R1-Distill-Qwen-7B \
|
||||
--served-model-name deepseek-r1 \
|
||||
--tensor-parallel-size 1 \
|
||||
--max-model-len 131072 \
|
||||
--gpu-memory-utilization 0.95 \
|
||||
--reasoning-parser deepseek_r1 \
|
||||
--tool-call-parser qwen3_xml \
|
||||
--enable-auto-tool-choice \
|
||||
--port 6006
|
||||
```
|
||||
|
||||
后台
|
||||
|
||||
```bash
|
||||
deepseek-ai/DeepSeek-R1-Distill-Qwen-7B
|
||||
|
||||
screen -U -L -Logfile /root/vllm_server.log -dmS vllm_server bash -c 'python -m vllm.entrypoints.openai.api_server \
|
||||
--model /root/autodl-tmp/DeepSeek-R1-32B \
|
||||
--served-model-name deepseek-r1 \
|
||||
--tensor-parallel-size 1 \
|
||||
--max-model-len 8192 \
|
||||
--gpu-memory-utilization 0.95 \
|
||||
--port 6006'
|
||||
|
||||
screen -U -L -Logfile /root/vllm_server.log -dmS vllm_server bash -c 'python -m vllm.entrypoints.openai.api_server \
|
||||
--model /root/autodl-tmp/DeepSeek-R1-1.5B \
|
||||
--served-model-name deepseek-r1 \
|
||||
--tensor-parallel-size 1 \
|
||||
--max-model-len 131072 \
|
||||
--gpu-memory-utilization 0.95 \
|
||||
--port 6006'
|
||||
|
||||
screen -U -L -Logfile /root/vllm_server.log -dmS vllm_server bash -c 'python -m vllm.entrypoints.openai.api_server \
|
||||
--model /root/autodl-tmp/DeepSeek-R1-Distill-Qwen-7B \
|
||||
--served-model-name deepseek-r1 \
|
||||
--tensor-parallel-size 1 \
|
||||
--max-model-len 131072 \
|
||||
--gpu-memory-utilization 0.95 \
|
||||
--port 6006'
|
||||
```
|
||||
|
||||
```
|
||||
可以决定
|
||||
--reasoning-parser deepseek_r1
|
||||
```
|
||||
|
||||
**参数解释:**
|
||||
|
||||
- `--max-model-len 8192`:限制最大上下文为 8K token(因为模型本身 64G,A800 剩约 15G 显存留给 KV Cache,8K 是比较安全且不会 OOM 的长度)。
|
||||
- `--gpu-memory-utilization 0.95`:允许 vLLM 使用 95% 的显存。
|
||||
- `--served-model-name`:客户端调用时填写的模型名称。
|
||||
|
||||
等待终端显示 `Uvicorn running on http://0.0.0.0:6006` 字样,即代表部署成功。
|
||||
|
||||
# 第四步:测试调用 (与 OpenAI API 完全兼容)
|
||||
|
||||
您可以在同一个实例新开一个终端,或者直接在当前终端输入以下命令进行测试:
|
||||
|
||||
```bash
|
||||
curl http://localhost:6006/v1/chat/completions \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"model": "deepseek-r1",
|
||||
"messages":[
|
||||
{"role": "system", "content": "你是一个有用的AI助手。"},
|
||||
{"role": "user", "content": "请用Python写一个快速排序算法。"}
|
||||
],
|
||||
"max_tokens": 1024,
|
||||
"temperature": 0.6
|
||||
}'
|
||||
```
|
||||
Reference in New Issue
Block a user