SGLang部署DeepSeek实战(H20):多机硬件资源、SSH连接与推理服务搭建

一、硬件资源

主机列表

连接方式

1
2
3
4
5
# node105
ssh -i .\id_rsa-h20 -p 65431 test001@36.170.52.76

# node131
ssh -i .\id_rsa-h20 -p 65432 test001@36.170.52.76

查看资源


二、部署方式

sglang安装

基于Sglang的部署方式如下, 两台机器安装sglang

1
2
pip install sgl-kernel --force-reinstall --no-deps
pip install "sglang[all]>=0.4.2.post3" --find-links https://flashinfer.ai/whl/cu124/torch2.5/flashinfer/

第一台机器执行时, nnodes=2, node-rank=0, dist-init-addr都是第一台机器的IP地址.

1
2
3
4
5
python3 -m sglang.launch_server \
--model-path ~/deepseek-V3/ \
--tp 16 --dist-init-addr 1.1.1.1:20000 \
--nnodes 2 --node-rank 0 \
--trust-remote-code --host 0.0.0.0 --port 8000

第二台机器执行时,–nnodes 2 –node-rank 1

1
2
3
4
5
python3 -m sglang.launch_server \
--model-path ~/deepseek-V3/ \
--tp 16 --dist-init-addr 1.1.1.1:20000 \
--nnodes 2 --node-rank 1 \
--trust-remote-code --host 0.0.0.0 --port 8000

sglang部署

Deepseek R1 模型存放位置:/data/DeepSeek-R1
Deepseek V3 模型存放位置:/data/DeepSeek-V3

1
2
3
4
5
# 在 node105 上执行如下命令:
nohup bash /data/deepseek/sglang_server1.sh fe21b93dd0234e64a8ab44d4c49cf365 &

# 在 node131 上执行如下命令:
nohup bash /data/deepseek/sglang_server2.sh fe21b93dd0234e64a8ab44d4c49cf365 &
sglang_server1.sh如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/bash

# detect apikey set
if [ $# -eq 0 ]; then
echo "Error! Please set [api-key] like: sglang_server.sh [api_key]"
exit 1
fi

# conda env
module load conda/24.11.3
source activate sglang

# unset proxy
unset http_proxy
unset https_proxy

# ib env
export NCCL_IB_HCA=mlx5_0:1,mlx5_3:1,mlx5_4:1,mlx5_7:1
export NCCL_NVLS_ENABLE=0
export NCCL_IB_DISABLE=0
export NCCL_SOCKET_IFNAME=ens12f0np0
export NCCL_DEBUG=INFO
export NCCL_IB_RETRY_CNT=7
export NCCL_IB_TIMEOUT=23

python -m sglang.launch_server \
--model-path /data/DeepSeek-V3 \
--served-model-name DeepSeek-V3 \
--context-length 131072 \
--mem-fraction-static 0.7 \
--trust-remote-code \
--host 0.0.0.0 \
--port 8000 \
--grammar-backend xgrammar \
--tp 16 \
--dist-init-addr 10.0.251.105:20000 \
--nnodes 2 \
--node-rank 0 \
--api-key $1 >> /data/deepseek/logs/${HOSTNAME}.log 2>&1
![](https://cdn.jsdelivr.net/gh/gkm0120/CDN/img/notion_3bae0dee.png)
sglang_server2.sh如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/bash


# detect apikey set
if [ $# -eq 0 ]; then
echo "Error! Please set [api-key] like: sglang_server.sh [api_key]"
exit 1
fi

# conda env
module load conda/24.11.3
source activate sglang

# unset proxy
unset http_proxy
unset https_proxy

# ib env
export NCCL_IB_HCA=mlx5_0:1,mlx5_3:1,mlx5_4:1,mlx5_7:1
export NCCL_NVLS_ENABLE=0
export NCCL_IB_DISABLE=0
export NCCL_SOCKET_IFNAME=ens12f0np0
export NCCL_DEBUG=INFO
export NCCL_IB_RETRY_CNT=7
export NCCL_IB_TIMEOUT=23

python -m sglang.launch_server \
--model-path /data/DeepSeek-V3 \
--served-model-name DeepSeek-V3 \
--context-length 131072 \
--mem-fraction-static 0.7 \
--trust-remote-code \
--host 0.0.0.0 \
--port 8000 \
--grammar-backend xgrammar \
--tp 16 \
--dist-init-addr 10.0.251.105:20000 \
--nnodes 2 \
--node-rank 1 \
--api-key $1 >> /data/deepseek/logs/${HOSTNAME}.log 2>&1
![](https://cdn.jsdelivr.net/gh/gkm0120/CDN/img/notion_8b2401a3.png) 服务调用
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import openai
client = openai.OpenAI(
base_url="http://127.0.0.1:8000/v1/",
api_key="fe21b93dd0234e64a8ab44d4c49cf365",
)


# Generate
chat_completion = client.chat.completions.create(
model="DeepSeek-V3",
messages=[
{"role": "system", "content": "你是人工智能助手"},
{"role": "user", "content": "对比一下中联和三一的旋挖钻,以表格的形式输出"}
],
)

print(chat_completion.choices[0].message.content)

token生成速度如下:

三、测试结果

H20、A100、阿里商用接口性能对比(256、512输入)

H20在长文本(2048、4096)下的性能

本文结束 感谢您的阅读