deepseek_v32部署

DeepSeek-V3.2 部署最佳实践指南

1. 硬件环境

项目 规格
GPU NVIDIA H200
部署拓扑 2P1D 离线分离部署
Prefill 实例 2 × 单机八卡(共 16 卡)
Decode 实例 2 机 16 卡(跨节点 TP=16)
总 GPU 数 4 台机器,32 张 H200

2. 环境变量配置

所有实例(Prefill 和 Decode)均需设置以下环境变量:

1
2
3
4
5
6
7
8
9
export NVSHMEM_BOOTSTRAP_UID_SOCK_IFNAME=eth0
export NVSHMEM_IB_TRAFFIC_CLASS=98
export NVSHMEM_IB_GID_INDEX=3
export SGLANG_DP_ATTENTION_HANDSHAKE_PORT_DELTA=30
export SGLANG_DISAGGREGATION_WAITING_TIMEOUT=80
export SGLANG_DISAGGREGATION_BOOTSTRAP_TIMEOUT=80
export SGLANG_DG_CACHE_DIR=/workspace/cache/deep_gemm_h200
export MC_IB_TC=98
export NCCL_IB_TC=98

关键环境变量说明

变量 作用
NVSHMEM_BOOTSTRAP_UID_SOCK_IFNAME NVSHMEM 通信使用的网络接口
NVSHMEM_IB_TRAFFIC_CLASS / NVSHMEM_IB_GID_INDEX InfiniBand 流量分类和 GID 索引,确保 IB 传输优先级
SGLANG_DP_ATTENTION_HANDSHAKE_PORT_DELTA DP Attention 节点间握手端口偏移量,避免端口冲突
SGLANG_DISAGGREGATION_WAITING_TIMEOUT 分离部署等待超时(秒)
SGLANG_DISAGGREGATION_BOOTSTRAP_TIMEOUT 分离部署引导超时(秒)
SGLANG_DG_CACHE_DIR DeepGemm 编译缓存目录,避免重复 JIT 编译
MC_IB_TC / NCCL_IB_TC Mooncake 和 NCCL 的 IB 流量分类,与 NVSHMEM 保持一致

几个设置成TC=98 表示使用 InfiniBand 的高优先级流量类别,确保 KV Transfer(Mooncake)和集合通信(NCCL)优先于其他流量

3. Prefill 实例启动

两个 Prefill 实例启动命令完全一致,分别在两台独立的单机八卡机器上执行。

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
41
42
43
44
45
46
47
48
49
python3 -m sglang.launch_server \
  --model-path deepseek-v3.2 \
  --host 0.0.0.0 \
  --port 8055 \
  --trust-remote-code \
  --served-model-name DeepSeek-V3.2 \
  \
  `# ===== PD分离配置 =====` \
  --disaggregation-mode prefill \
  --disaggregation-ib-device mlx5_0,mlx5_1,mlx5_2,mlx5_5,mlx5_6,mlx5_7,mlx5_8,mlx5_9 \
  --disaggregation-transfer-backend mooncake \
  \
  `# ===== 并行策略 =====` \
  --tensor-parallel-size 8 \
  --data-parallel-size 8 \
  --enable-dp-attention \
  --moe-dense-tp-size 1 \
  --enable-dp-lm-head \
  \
  `# ===== MoE 配置 =====` \
  --moe-a2a-backend deepep \
  --deepep-mode normal \
  --ep-num-redundant-experts 0 \
  --load-balance-method round_robin \
  --enable-expert-distribution-metrics \
  \
  `# ===== 内存与调度 =====` \
  --mem-fraction-static 0.8 \
  --max-running-requests 512 \
  --chunked-prefill-size 65536 \
  \
  `# ===== (EAGLE) =====` \
  --speculative-algorithm EAGLE \
  --speculative-num-steps 1 \
  --speculative-eagle-topk 1 \
  --speculative-num-draft-tokens 2 \
  \
  `# ===== Attention 与tool =====` \
  --attention-backend nsa \
  --tool-call-parser deepseekv32 \
  --reasoning-parser deepseek-v3 \
  \
  `# ===== debug =====` \
  --log-requests \
  --log-requests-level 0 \
  --collect-tokens-histogram \
  --enable-metrics \
  --enable-cache-report \
  --gc-warning-threshold-secs 0.1

Prefill 参数要点

参数 说明
--deepep-mode normal Prefill 使用 normal 模式,吞吐优先
--load-balance-method round_robin Prefill 侧使用轮询负载均衡
--chunked-prefill-size 65536 分块预填充大小,平衡延迟与吞吐
--max-running-requests 512 Prefill 并发请求上限
--enable-expert-distribution-metrics - 启用专家分布监控,辅助调优

4. Decode 实例启动

Decode 实例跨两个节点部署,TP=16,DP=16,两个节点需分别启动。

节点 0(node-rank 0)

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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
python3 -m sglang.launch_server \
  --model-path deepseek-v3.2 \
  --host 0.0.0.0 \
  --port 8055 \
  --trust-remote-code \
  --served-model-name DeepSeek-V3.2 \
  \
  `# ===== PD分离配置 =====` \
  --disaggregation-mode decode \
  --disaggregation-ib-device mlx5_0,mlx5_1,mlx5_2,mlx5_5,mlx5_6,mlx5_7,mlx5_8,mlx5_9 \
  --disaggregation-transfer-backend mooncake \
  \
  `# ===== 多节点配置 =====` \
  --dist-init-addr 10.93.161.35:19378 \
  --nnodes 2 \
  --node-rank 0 \
  \
  `# ===== 并行策略 =====` \
  --tensor-parallel-size 16 \
  --data-parallel-size 16 \
  --enable-dp-attention \
  --moe-dense-tp-size 1 \
  --enable-dp-lm-head \
  \
  `# ===== MoE 配置 =====` \
  --moe-a2a-backend deepep \
  --deepep-mode low_latency \
  --ep-num-redundant-experts 0 \
  --prefill-round-robin-balance \
  \
  `# ===== 内存与调度 =====` \
  --mem-fraction-static 0.8 \
  --max-running-requests 1024 \
  \
  `# ===== (EAGLE) =====` \
  --speculative-algorithm EAGLE \
  --speculative-num-steps 1 \
  --speculative-eagle-topk 1 \
  --speculative-num-draft-tokens 2 \
  \
  `# ===== Attention 与 tool =====` \
  --attention-backend nsa \
  --tool-call-parser deepseekv32 \
  --reasoning-parser deepseek-v3 \
  \
  `# ===== CUDA Graph =====` \
  --cuda-graph-bs 1 2 3 4 5 6 8 10 12 16 24 32 64 \
  \
  `# ===== debug =====` \
  --log-requests \
  --log-requests-level 0 \
  --collect-tokens-histogram \
  --enable-metrics \
  --enable-cache-report \
  --gc-warning-threshold-secs 0.1

节点 1(node-rank 1)

1
2
3
4
5
6
7
python3 -m sglang.launch_server \
   \
  `# ===== 别的都一样,多节点配置不同 =====` \
  --dist-init-addr 10.93.161.35:19378 \
  --nnodes 2 \
  --node-rank 1 \
  \

Decode 参数要点

参数 说明
--deepep-mode low_latency Decode 使用低延迟模式,降低 Token 生成延迟
--prefill-round-robin-balance - Decode 侧轮询从多个 Prefill 实例接收 KV
--max-running-requests 1024 Decode 并发请求上限,高于 Prefill 以支撑更多并发 decode
--cuda-graph-bs 1 2 3 4 5 6 8 10 12 16 24 32 64 CUDA Graph 捕获的 batch size 列表,减少 decode 阶段 kernel launch 开销
--dist-init-addr 10.93.161.35:19378 多节点分布式初始化地址(节点 0 的 IP:Port)
--nnodes 2 Decode 跨 2 个节点
--node-rank 0 / 1 节点序号

5. Prefill vs Decode 关键配置对比

配置项 Prefill Decode
--disaggregation-mode prefill decode
--tensor-parallel-size 8 16
--data-parallel-size 8 16
--deepep-mode normal(吞吐优先) low_latency(延迟优先)
--max-running-requests 512 1024
--load-balance-method round_robin -
--prefill-round-robin-balance - 启用
--chunked-prefill-size 65536 -
--enable-expert-distribution-metrics 启用 -
--cuda-graph-bs - 1 2 3 4 5 6 8 10 12 16 24 32 64
多节点 单节点 双节点(--nnodes 2

6. 部分参数解析

6.1 DP Attention + DeepEP

  • --enable-dp-attention:对 MoE 的 Attention 部分做数据并行,每个 DP rank 独立处理不同请求的 attention,提高吞吐
  • --moe-dense-tp-size 1:MoE 中 dense 层(shared expert)的 TP 大小为 1,配合 DP Attention 实现细粒度并行
  • --enable-dp-lm-head:LM Head 也做数据并行,减少通信开销
  • --moe-a2a-backend deepep:使用 DeepEP 做 All-to-All 通信,比默认 NCCL 更高效

6.2 NSA(Native Sparse Attention)

  • --attention-backend nsa:DeepSeek-V3.2 原生稀疏注意力,仅计算重要 token 的 attention,大幅降低长序列显存和计算开销

6.3 EAGLE 推测解码

  • --speculative-algorithm EAGLE:使用 EAGLE 算法进行推测解码
  • --speculative-num-steps 1 + --speculative-num-draft-tokens 2:保守配置,每次推测 2 个 token
  • --speculative-eagle-topk 1:Top-1 采样,减少推测开销