最近,DeepSeek-R1 凭借其强大的推理能力和开源特性,成为 AI 社区的热门模型。如果你想在高性能硬件上部署它,或者测试它的极限性能,这篇文章将带你一步步完成。本文将使用 SGLang 推理引擎和 8x NVIDIA H200 GPUs,展示 DeepSeek-R1 的部署和基准测试全流程。
为什么选择 SGLang 和 NVIDIA H200?
在动手之前,我们先聊聊为什么选它们:
-
SGLang 推理引擎
SGLang 是 DeepSeek 官方推荐的推理框架,专为 DeepSeek-V3 和 R1 优化。它支持多节点张量并行、MLA 优化、DP Attention、FP8 计算(W8A8 和 KV Cache)以及 Torch Compile,在开源框架中提供顶级的延迟和吞吐量性能。SGLang v0.4.1 已完美适配 NVIDIA 和 AMD GPU,未来还将推出 Multi-Token Prediction (MTP) 等功能,值得期待。 -
NVIDIA H200 GPUs
H200 是 NVIDIA 最新一代高性能 GPU,拥有 141GB HBM3 内存和超高带宽,完美适配像 DeepSeek-R1 这样参数量高达 671B 的大模型。相比 H100,H200 的内存容量提升了 76%,单机就能轻松跑 FP8 精度的推理任务。不过需要注意的是,目前国内由于政策限制,没有运营商敢直接上架 H100 或 H200。如果你想用这些顶级硬件,不妨找我采购——我提供 H200 三年质保,正规渠道,放心用!
部署 DeepSeek-R1 的步骤
1. 环境准备
我们用官方推荐的 SGLang Docker 镜像来简化部署。假设你已经有一台配置了 8x NVIDIA H200 GPUs 的机器,以下是具体操作:
拉取 SGLang 镜像
在你的 H200 服务器上运行:
docker pull lmsysorg/sglang:latest
创建 Docker 容器
运行以下命令,创建一个支持 DeepSeek-R1 的容器:
docker run --gpus all \
--shm-size 32g \
--network=host \
-v ~/.cache/huggingface:/root/.cache/huggingface \
--name deepseek_r1 \
-it \
--env "HF_TOKEN=$HF_TOKEN" \
--ipc=host \
lmsysorg/sglang:latest \
bash
--gpus all
:分配所有 8x H200 GPUs。-v ~/.cache/huggingface:/root/.cache/huggingface
:挂载缓存目录,节省下载时间。--env "HF_TOKEN=$HF_TOKEN"
:设置 Hugging Face Token(需提前导出)。-it bash
:进入交互式会话。
2. 启动 DeepSeek-R1 服务
进入容器后,启动服务:
python3 -m sglang.launch_server --model deepseek-ai/DeepSeek-R1 --tp 8 --trust-remote-code --enable-dp-attention
--tp 8
:利用 8 GPU 张量并行,充分发挥 H200 的性能。--enable-dp-attention
:激活优化,提升推理效率。
服务启动后,默认监听 30000 端口,可以通过 API 调用。
基准测试 DeepSeek-R1
测试命令
我们运行一个基准测试,批量大小 1,输入 128 token,输出 256 token:
python3 -m sglang.bench_one_batch --batch-size 1 --input 128 --output 256 --model deepseek-ai/DeepSeek-R1 --trust-remote-code --tp 8 --enable-torch-compile --torch-compile-max-bs 1
测试结果
以下是两次测试的结果:
测试 1
Prefill. latency: 1.91032 s, throughput: 67.00 token/s
Decode. latency: 1.04900 s, throughput: 0.95 token/s
Decode. latency: 0.02175 s, throughput: 45.99 token/s
Decode. latency: 0.02097 s, throughput: 47.69 token/s
Decode. latency: 0.02097 s, throughput: 47.68 token/s
Decode. latency: 0.02080 s, throughput: 48.07 token/s
Decode. median latency: 0.02097 s, median throughput: 47.68 token/s
Total. latency: 3.086 s, throughput: 44.07 token/s
测试 2
Prefill. latency: 0.19635 s, throughput: 651.90 token/s
Decode. latency: 0.02100 s, throughput: 47.62 token/s
Decode. latency: 0.02078 s, throughput: 48.13 token/s
Decode. latency: 0.02092 s, throughput: 47.80 token/s
Decode. latency: 0.02086 s, throughput: 47.93 token/s
Decode. latency: 0.02085 s, throughput: 47.97 token/s
Decode. median latency: 0.02098 s, median throughput: 47.67 token/s
Total. latency: 5.537 s, throughput: 69.35 token/s
结果分析
- Prefill 阶段:第一次测试延迟较高(1.91s),可能是模型首次加载权重导致。第二次测试延迟降至 0.196s,吞吐量提升至 651.90 token/s,说明缓存生效。
- Decode 阶段:中值延迟稳定在 0.02098s,吞吐量 ≈ 47.67 token/s,用户感知的响应速度非常快。
- 整体性能:H200 的高内存带宽和 SGLang 的优化(如 Torch Compile)显著提升了推理效率。
这些结果仅为初步测试,未完全调优 H200 专属内核,后续优化的潜力值得期待。
下一步
想复现以上步骤?你需要准备一台 8x NVIDIA H200 GPUs 的机器。由于国内目前没有运营商敢上架 H100 或 H200,我建议直接找我采购——我提供 H200 三年质保,正规渠道,质量有保障,私信我即可获取报价和详情。
优化建议
- 多节点部署:如果需要更大规模,可以尝试 SGLang 的多节点张量并行。
- 自定义内核:关注 SGLang 的优化计划(如 FusedMoE H200 调优),进一步提升性能。
- 监控与调整:使用工具(如 NVIDIA Nsight)监控 GPU 使用率,调整批量大小和推理参数。
总结
通过 SGLang 和 8x NVIDIA H200 GPUs,我们成功部署了 DeepSeek-R1,并完成了性能基准测试。测试结果显示,H200 的硬件优势结合 SGLang 的软件优化,能为 DeepSeek-R1 提供高效的推理支持。如果你对大模型部署感兴趣,不妨试试这个方案,欢迎在评论区分享你的体验或问题!