Skip to content

About

Kimi K2 SGLang PD Disaggregation on AWS EFA (p5en H200) + AWS Capacity Block provisioning skill

Resources

Stars

2 stars

Watchers

0 watching

Forks

Latest commit

 

History

14 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Kimi K2 SGLang PD Disaggregation on AWS EFA

在 AWS p5en.48xlarge (H200) 集群上,使用 SGLang + UCCL-EP + Mooncake 部署 Kimi-K2-Instruct (1T/32B MoE) 的 Prefill-Decode 分离推理方案。

本仓库包含两部分:

  • kimi-k2-sglang 推理部署 — 模型推理的完整脚本、Dockerfile 和配置
  • aws-capacity-block — AWS EC2 Capacity Block 集群自动化配置工具(购买、启动、EFA 网络、弹性 IP)

架构概览

                    ┌──────────────┐
                    │   Router     │
                    │  (port 8080) │
                    └──────┬───────┘
                           │
              ┌────────────┴────────────┐
              ▼                         ▼
    ┌──────────────────┐     ┌──────────────────┐
    │  Prefill Cluster  │     │  Decode Cluster   │
    │  2× p5en.48xlarge │────▶│  2× p5en.48xlarge │
    │  EP16 / TP16      │ KV  │  EP16 / TP16      │
    │  deepep-mode:     │cache│  deepep-mode:      │
    │    normal         │     │    low_latency     │
    └──────────────────┘     └──────────────────┘
  • Prefill → Decode: Mooncake Transfer Engine (EFA 协议) 传输 KV cache
  • MoE Expert 通信: UCCL-EP (DeepEP 兼容,原生支持 EFA)
  • 节点间网络: AWS EFA (16× EFA NICs per node)

关键组件版本

组件 版本
SGLang 0.5.8.post1 (lmsysorg/sglang:latest)
UCCL-EP latest (替代 DeepEP 1.2.1)
Mooncake latest (EFA enabled)
EFA Installer 1.47.0
NCCL v2.29.3-1
GDRCopy 2.5.1 (lib only)
DeepGEMM 内置于 SGLang (JIT 编译)

前置条件

  • 4× p5en.48xlarge (或其他支持 EFA 的 GPU 实例)
  • 实例需在同一 AZ / 子网
  • 安全组必须配置 EFA 自引用规则(见下方"安全组配置"一节)
  • 模型已下载到每台机器的 NVMe: /opt/dlami/nvme/Kimi-K2-Instruct (~960GB)
  • Docker 镜像已构建

文件说明

├── Dockerfile                # Docker 镜像构建文件
├── start_prefill.sh          # v1: Prefill 节点启动脚本 (纯 EP16/TP16)
├── start_decode.sh           # v1: Decode 节点启动脚本 (纯 EP16/TP16)
├── start_prefill_v2.sh       # v2: Prefill 节点 (+ dp_attention, redundant experts)
├── start_decode_v2.sh        # v2: Decode 节点  (+ dp_attention, redundant experts)
├── patch_sglang_efa.sh       # SGLang Mooncake EFA 协议补丁 (幂等)
├── bench_prefill.sh          # Prefill 性能压测
├── bench_decode.sh           # Decode 性能压测
├── bench_e2e.sh              # 端到端性能压测
├── Dockerfile.b200            # B200 Docker 镜像 (dev-cu13 + EFA + Mooncake)
├── start_prefill_b200.sh      # B200 Prefill (单节点 8×B200, EP8/TP8/DP8)
├── start_decode_b200.sh       # B200 Decode  (单节点 8×B200, EP8/TP8/DP8)
├── start_standalone_b200.sh   # B200 Standalone 非PD (deepep-mode=auto)
├── start_prefill_v2_h100.sh   # v2 Prefill (H100 4-node 适配)
├── start_decode_v2_h100.sh    # v2 Decode  (H100 4-node 适配)
├── deepseek-r1/                        # DeepSeek-R1 专用目录
│   ├── benchmark-report.md             #   H100 三种配置 Benchmark 对比报告
│   ├── start_prefill_h100.sh           #   Prefill (H100, PD分离+DeepEP)
│   ├── start_decode_h100.sh            #   Decode (H100, PD分离+DeepEP)
│   ├── start_standalone_h100_2node.sh  #   2-node Standalone (无DeepEP基线)
│   ├── start_standalone_h100_4node.sh  #   4-node Standalone (不可行,供参考)
│   ├── bench_e2e.sh                    #   E2E benchmark
│   ├── bench_prefill.sh               #   Prefill-heavy benchmark
│   └── bench_decode.sh                #   Decode-heavy benchmark
├── nvidia-fabricmanager-fix.md     # Fabric Manager 修复文档
├── nvidia-fabricmanager-fix-cn.md  # Fabric Manager 修复文档 (中文)
└── README.md                 # 本文件

v1 vs v2 脚本

特性 v1 v2
dp_attention 无 --dp-size 16 --enable-dp-attention --enable-dp-lm-head
冗余专家 0 16
CUDA Graph 禁用 Decode: --cuda-graph-max-bs 64; Prefill: 禁用
DeepGEMM 预编译 无 启动前预编译
deepep-config JSON 文件 无 (使用默认)
Decode mem-fraction 0.85 0.6
Decode max-running-requests — 2048 (128 per dp_rank × 16)
DEEPEP_NUM_MAX_DISPATCH_TOKENS_PER_RANK — 128 (默认值,适配 2 节点)
Prefill chunked-prefill-size 65536 131072 (dp_attention 下实际生效 8192)

v2 更接近 LMSYS Blog 的配置。注意 Blog 使用 12 个 decode 节点 (96 GPUs), 本方案仅 2 个 decode 节点 (16 GPUs),因此 max-running-requests 和 SGLANG_DEEPEP_NUM_MAX_DISPATCH_TOKENS_PER_RANK 需按比例缩小。 如果遇到 EP group 超时,请回退到 v1 脚本。

安全组配置

⚠️ 关键: EFA 使用 OS-bypass 传输,CIDR 规则 (0.0.0.0/0) 对 EFA 流量无效。 安全组必须有自引用 (self-referencing) 规则,否则 EFA RDMA 无法工作。

必需的规则:

方向 协议 端口 来源/目标
Inbound All All 安全组自身 (sg-xxxx)
Outbound All All 安全组自身 (sg-xxxx)
Inbound TCP 22 0.0.0.0/0 (SSH)
Outbound All All 0.0.0.0/0 (互联网)

添加缺失的 outbound 自引用规则:

aws ec2 authorize-security-group-egress \
    --group-id sg-YOUR_SG_ID \
    --protocol -1 --port -1 \
    --source-group sg-YOUR_SG_ID \
    --region us-east-2

快速开始

1. 构建 Docker 镜像

docker build -t kimi-k2-sglang -f Dockerfile .

构建约 30-40 分钟(主要耗时:NCCL、Mooncake、UCCL-EP 编译)。

2. 设定节点 IP

启动前需设定环境变量(每次 capacity block 实例 IP 会变):

# 查看 4 台机器的私有 IP
aws ec2 describe-instances --region us-east-2 \
    --filters "Name=instance-type,Values=p5en.48xlarge" "Name=instance-state-name,Values=running" \
    --query 'Reservations[*].Instances[*].[InstanceId,PrivateIpAddress]' --output table

# 选定 2 台作为 Prefill, 2 台作为 Decode
export PREFILL_LEADER_IP="<Prefill Leader 的私有 IP>"
export DECODE_LEADER_IP="<Decode Leader 的私有 IP>"

3. 启动 Prefill 节点

Prefill Leader (rank=0):

docker run -d --name kimi-k2 \
    --runtime=nvidia --gpus all --network host \
    --privileged --shm-size=600g \
    -v /opt/dlami/nvme/Kimi-K2-Instruct:/models/Kimi-K2-Instruct:ro \
    -v /opt/dlami/nvme/.cache_deep_gemm:/root/.cache/deep_gemm \
    -v /home/ubuntu:/host \
    -e NODE_RANK=0 \
    -e PREFILL_LEADER_IP=$PREFILL_LEADER_IP \
    kimi-k2-sglang \
    bash /host/kimi-k2-sglang/start_prefill_v2.sh

Prefill Worker (rank=1):

docker run -d --name kimi-k2 \
    --runtime=nvidia --gpus all --network host \
    --privileged --shm-size=600g \
    -v /opt/dlami/nvme/Kimi-K2-Instruct:/models/Kimi-K2-Instruct:ro \
    -v /opt/dlami/nvme/.cache_deep_gemm:/root/.cache/deep_gemm \
    -v /home/ubuntu:/host \
    -e NODE_RANK=1 \
    -e PREFILL_LEADER_IP=$PREFILL_LEADER_IP \
    kimi-k2-sglang \
    bash /host/kimi-k2-sglang/start_prefill_v2.sh

4. 启动 Decode 节点

Decode Leader (rank=0):

docker run -d --name kimi-k2 \
    --runtime=nvidia --gpus all --network host \
    --privileged --shm-size=600g \
    -v /opt/dlami/nvme/Kimi-K2-Instruct:/models/Kimi-K2-Instruct:ro \
    -v /opt/dlami/nvme/.cache_deep_gemm:/root/.cache/deep_gemm \
    -v /home/ubuntu:/host \
    -e NODE_RANK=0 \
    -e DECODE_LEADER_IP=$DECODE_LEADER_IP \
    kimi-k2-sglang \
    bash /host/kimi-k2-sglang/start_decode_v2.sh

Decode Worker (rank=1):

docker run -d --name kimi-k2 \
    --runtime=nvidia --gpus all --network host \
    --privileged --shm-size=600g \
    -v /opt/dlami/nvme/Kimi-K2-Instruct:/models/Kimi-K2-Instruct:ro \
    -v /opt/dlami/nvme/.cache_deep_gemm:/root/.cache/deep_gemm \
    -v /home/ubuntu:/host \
    -e NODE_RANK=1 \
    -e DECODE_LEADER_IP=$DECODE_LEADER_IP \
    kimi-k2-sglang \
    bash /host/kimi-k2-sglang/start_decode_v2.sh

5. 启动 Router

在任一节点上运行:

docker run -d --name sglang-router \
    --network host \
    kimi-k2-sglang \
    python3 -m sglang_router.launch_router \
    --host 0.0.0.0 --port 8080 \
    --pd-disaggregation \
    --prefill http://$PREFILL_LEADER_IP:30000 \
    --decode http://$DECODE_LEADER_IP:30000 \
    --policy random

6. 验证服务

curl http://$PREFILL_LEADER_IP:8080/v1/chat/completions \
    -H "Content-Type: application/json" \
    -d '{
        "model": "moonshotai/Kimi-K2-Instruct",
        "messages": [{"role": "user", "content": "Hello, who are you?"}],
        "max_tokens": 64
    }'

7. 运行 Benchmark

export ROUTER_URL="http://$PREFILL_LEADER_IP:8080"
export PREFILL_URL="http://$PREFILL_LEADER_IP:30000"
export DECODE_URL="http://$DECODE_LEADER_IP:30000"

# 端到端
bash bench_e2e.sh 200 64

# Prefill profiling
bash bench_prefill.sh 200 64

# Decode profiling
bash bench_decode.sh 200 64

启动顺序

⚠️ 重要: 必须按以下顺序启动,否则分布式初始化会超时。

  1. Prefill Leader + Worker — 同时启动
  2. 等待 Prefill 完成 DeepGEMM warmup(v2 有预编译步骤,之后还有 JIT 编译)
  3. Decode Leader + Worker — 同时启动
  4. 等待 Decode 完成 warmup
  5. Router — 最后启动

查看启动日志: docker logs -f kimi-k2

重启前必须先删除旧容器: Docker 的 --name 参数即使容器已退出或崩溃,名字仍被占用。 重启前务必先执行:

docker rm -f kimi-k2          # 删除推理容器
docker rm -f sglang-router    # 删除 Router 容器(如在同一节点)

如果 docker rm -f 卡住(GPU 进程未退出),需要重启 Docker daemon:

sudo systemctl restart docker && sleep 3 && docker rm -f kimi-k2

性能基准

测试环境: 4× p5en.48xlarge, 2P2D, EP16/TP16/DP16

v2 E2E (input=2000, output=100, 200 prompts, concurrency=64)

指标 E2E Prefill profile Decode profile
Request throughput 5.55 req/s 4.10 req/s 3.64 req/s
Input token throughput 5,852 tok/s 4,321 tok/s 3,837 tok/s
Output token throughput 294 tok/s 217 tok/s 192 tok/s
Total token throughput 6,146 tok/s 4,538 tok/s 4,029 tok/s
Mean TTFT 1,883 ms 8,232 ms 5,666 ms
Median TTFT 1,191 ms 7,812 ms 4,754 ms
Mean TPOT 216 ms 79 ms 95 ms
Median ITL 27 ms 30 ms 26 ms
P99 ITL 57 ms 805 ms 442 ms

v2 Prefill 压测 (input=2000, output=10, 1000 prompts, concurrency=512)

chunked-prefill-size (设定/实际) Input tok/s Per-node Req/s
65536 / 4096 8,442 4,221 8.36
131072 / 8192 35,105 17,553 34.77
524288 / 32768 7,481 3,741 7.41

注意: --enable-dp-attention 会将 chunked-prefill-size 自动除以 dp_size。 例如设定 131072,dp_size=16 时实际生效 8192。最优值 8192 与 UCCL-EP benchmark 的 --num-tokens=4096 量级一致,更大的值会超出 EFA Memory Region 注册限制。

v1 (参考)

指标 E2E
Request throughput 2.96 req/s
Input token throughput 3,123 tok/s
Output token throughput 157 tok/s
Total token throughput 3,280 tok/s
Mean TTFT 1,721 ms
Median TTFT 1,347 ms
Mean TPOT 266 ms
Mean ITL 269 ms
P99 ITL 544 ms

v1 → v2 提升

指标 v1 v2 变化
Total token throughput 3,280 tok/s 6,146 tok/s +87%
Request throughput 2.96 req/s 5.55 req/s +87%
Median TTFT 1,347 ms 1,191 ms -12%
Mean TPOT 266 ms 216 ms -19%
Median ITL 269 ms 27 ms -90%

关键改进: Decode 启用 --cuda-graph-max-bs 64(v1 全局禁用), SGLANG_DEEPEP_NUM_MAX_DISPATCH_TOKENS_PER_RANK 从 480 降至 128, max-running-requests 从 7680 降至 2048,适配 2 节点 decode 配置。 Prefill chunked-prefill-size 从 65536 调至 131072(实际 8192), prefill 吞吐提升 4x。

关键配置说明

为什么不用原版 DeepEP?

原版 DeepEP 1.2.1 仅支持 InfiniBand RDMA,不支持 AWS EFA。UCCL-EP 是 DeepEP 的 drop-in 替换,原生支持 EFA 的 libfabric 传输。

CUDA Graph 配置

--cuda-graph-bs 480 在 UCCL-EP 下编译会卡死(batch size 过大)。 Decode 使用 --cuda-graph-max-bs 64(上游 2 节点配置推荐值)可正常工作, 带来 TPOT 2.5x、ITL 3x 的改善。Prefill 仍使用 --disable-cuda-graph。

chunked-prefill-size 调优

LMSYS Blog 使用 --chunked-prefill-size 524288(InfiniBand 环境)。 在 EFA 环境下,--enable-dp-attention 会将该值自动除以 dp_size, 因此设定值和实际生效值不同:

设定值 实际值 (÷dp_size 16) Prefill input tok/s
65536 4096 8,442
131072 8192 35,105
524288 32768 7,481

实际生效 8192 是 EFA + UCCL-EP 的最优点,与 UCCL-EP benchmark 的 --num-tokens=4096 量级一致。更大的值会因 EFA Memory Region 注册限制 (fi_enable: Cannot allocate memory)导致性能骤降。

dp_attention 兼容性 (v1 vs v2)

v1 脚本不使用 dp_attention (dp_size=1),纯 EP16/TP16 经验证可稳定工作。

v2 脚本启用 dp_attention (dp_size=16),更接近 LMSYS Blog 配置,但 dp_size > 1 会改变 EP group 的构建方式,可能导致 UCCL-EP 跨节点 dispatch 超时。 遇到 timeout 时请回退到 v1。

EFA 网络配置

p5en.48xlarge 的主网络接口是 enp71s0(不是 eth0),有 16 个 EFA NICs。

关键环境变量(已内置在启动脚本中):

GLOO_SOCKET_IFNAME=enp71s0        # GLOO 使用主网络接口
FI_PROVIDER=efa                    # libfabric 使用 EFA provider
FI_EFA_USE_DEVICE_RDMA=1          # 启用 EFA RDMA
MOONCAKE_PROTOCOL=efa             # Mooncake 使用 EFA 传输(需 patch)
NVSHMEM_REMOTE_TRANSPORT=libfabric # NVSHMEM 使用 libfabric (仅多节点 EP)
NVSHMEM_LIBFABRIC_PROVIDER=efa    # NVSHMEM libfabric 使用 EFA (仅多节点 EP)
# 注意: B200 单节点 EP 部署不能设置 NVSHMEM 变量,否则会 segfault

Mooncake EFA 补丁

SGLang 内置的 Mooncake 初始化代码硬编码了 "rdma" 协议。patch_sglang_efa.sh 将其改为读取 MOONCAKE_PROTOCOL 环境变量,支持 efa / tcp / rdma。该脚本是幂等的,重复运行不会重复修改。

故障排查

EFA RDMA 不通 (NCCL 卡住 / fi_pingpong 超时)

最常见原因: 安全组缺少 outbound 自引用规则。EFA OS-bypass 流量不受 CIDR 规则 (0.0.0.0/0) 控制,只认安全组自引用规则。

验证方法:

# 检查安全组 outbound 是否有自引用
aws ec2 describe-security-groups --group-ids sg-YOUR_SG_ID --region us-east-2 \
    --query 'SecurityGroups[0].IpPermissionsEgress[?UserIdGroupPairs[0].GroupId==`sg-YOUR_SG_ID`]'

# 如果为空, 添加:
aws ec2 authorize-security-group-egress --group-id sg-YOUR_SG_ID \
    --protocol -1 --port -1 --source-group sg-YOUR_SG_ID --region us-east-2

DeepEP timeout (dispatch CPU)

RuntimeError: DeepEP error: timeout (dispatch CPU)

常见原因:

  • 安全组 EFA 规则缺失 → 见上
  • 两个节点的 UCCL-EP proxy 未正确建立连接 → 重启两个节点
  • dp_size > 1 改变了 EP group 构建 → 回退到 v1 (纯 EP/TP)
  • CUDA Graph batch size 过大 → Decode 用 --cuda-graph-max-bs 64,不要用 480

Disaggregated request without bootstrap room id

Invalid request: Disaggregated request received without bootstrap room id

请求需要经过 Router,不能直接发到 Prefill/Decode 节点。

Mooncake 连接失败

检查 MOONCAKE_PROTOCOL=efa 是否设置,以及 patch_sglang_efa.sh 是否已执行。

下载模型

# 每台机器上执行(约 960GB,建议用 NVMe)
pip install huggingface_hub[hf_transfer]
HF_HUB_ENABLE_HF_TRANSFER=1 huggingface-cli download \
    moonshotai/Kimi-K2-Instruct \
    --local-dir /opt/dlami/nvme/Kimi-K2-Instruct

AWS Capacity Block 工具

aws-capacity-block/ 目录包含 AWS EC2 Capacity Block 的自动化配置工具,用于快速配置 GPU 集群。

功能

  • 搜索可用的 Capacity Block 报价
  • 购买 Capacity Block
  • 启动 GPU 实例并配置 EFA 网络接口(p5en 支持 16 个 EFA NIC)
  • 自动分配和绑定 Elastic IP

用法

python3 aws-capacity-block/scripts/launch_capacity_block.py \
    --region us-east-2 \
    --instance-type p5en.48xlarge \
    --ami ami-072e84550201d412a \
    --key-name your-key \
    --security-group sg-xxx \
    --subnet subnet-xxx \
    --capacity-reservation-id cr-xxx \
    --count 4 \
    --volume-size 500 \
    --tag P5EN \
    --efa-interfaces 16

详见 aws-capacity-block/SKILL.md。

DeepSeek-R1 on H100 (p5.48xlarge)

本仓库同时支持在 4× p5.48xlarge (H100 80GB) 上部署 DeepSeek-R1 (~642GB FP8 MoE)。 由于 H100 显存仅 80GB(vs H200 的 141GB),需要针对性调参。

文件 (位于 deepseek-r1/ 目录)

文件 说明
start_prefill_h100.sh Prefill (H100, PD分离+DeepEP)
start_decode_h100.sh Decode (H100, PD分离+DeepEP)
start_standalone_h100_2node.sh 2-node Standalone (无DeepEP, 基线)
start_standalone_h100_4node.sh 4-node Standalone (不可行, 供参考)
bench_e2e.sh E2E benchmark
bench_prefill.sh Prefill-heavy benchmark
bench_decode.sh Decode-heavy benchmark
benchmark-report.md 三种配置 Benchmark 对比报告

详细的三种配置 (2P2D+DeepEP / 2-node Standalone / 4-node Standalone) 性能对比 见 deepseek-r1/benchmark-report.md。 核心结论: DeepEP 提供 94x E2E 吞吐提升,4-node 部署需要 DeepEP (FP8 约束限制 TP≤16)。

H100 vs H200 关键参数差异

参数 Kimi-K2 on H200 DeepSeek-R1 on H100 说明
mem-fraction-static (prefill) 0.849 0.82 H100 显存紧张,需留更多给激活值
mem-fraction-static (decode) 0.6 0.82 H200 的 0.6×141=84GB 够用,H100 的 0.6×80=48GB 不够,会 OOM
chunked-prefill-size 131072 65536 降低内存压力 (dp-attention 自动调整为 4096)
max-running-requests (prefill) 1024 512 限制并发降低显存峰值
max-total-tokens (prefill) 131072 65536 限制 KV cache 总量

Docker 启动命令

与 Kimi-K2 相同的 docker run 模板,仅替换模型路径和脚本:

# Prefill Leader (rank=0)
docker run -d --name deepseek-r1 \
    --gpus all --privileged --shm-size=600g --net=host \
    -v /opt/dlami/nvme:/models \
    -v /opt/dlami/nvme/.cache_deep_gemm:/root/.cache/deep_gemm \
    -v /home/ubuntu:/host \
    -e PREFILL_LEADER_IP=$PREFILL_LEADER_IP \
    -e NODE_RANK=0 \
    <ECR_IMAGE> \
    bash /host/kimi-k2-sglang/deepseek-r1/start_prefill_h100.sh

# Decode Leader (rank=0)
docker run -d --name deepseek-r1 \
    --gpus all --privileged --shm-size=600g --net=host \
    -v /opt/dlami/nvme:/models \
    -v /opt/dlami/nvme/.cache_deep_gemm:/root/.cache/deep_gemm \
    -v /home/ubuntu:/host \
    -e DECODE_LEADER_IP=$DECODE_LEADER_IP \
    -e NODE_RANK=0 \
    <ECR_IMAGE> \
    bash /host/kimi-k2-sglang/deepseek-r1/start_decode_h100.sh

Router

docker run -d --name sglang-router \
    --net=host \
    -v /opt/dlami/nvme:/models:ro \
    <ECR_IMAGE> \
    python3 -m sglang_router.launch_router \
        --model-path /models/DeepSeek-R1 \
        --port 30080 \
        --pd-disaggregation \
        --prefill http://$PREFILL_LEADER_IP:30000 \
        --decode http://$DECODE_LEADER_IP:30000

H100 性能基准

测试环境: 4× p5.48xlarge (H100 80GB), 2P2D, DeepSeek-R1, v2 config

E2E (input=4096, output=128, 50 prompts, request-rate=8)

指标 值
Successful requests 50/50
Input token throughput 925.79 tok/s
Output token throughput 26.58 tok/s
Total token throughput 952.37 tok/s
Mean TTFT 26,772 ms
Mean TPOT 720.70 ms

Prefill 压测 (input=2000, output=10, 200 prompts, concurrency=8)

指标 值
Successful requests 200/200
Input token throughput 525.58 tok/s
Mean TTFT 12,733 ms
Mean TPOT 687.38 ms

H100 已知问题

  1. DeepEP timeout (dispatch CPU): Prefill 在高并发 (>=16) 下容易触发 DeepEP 跨节点 MoE dispatch 超时。根本原因是 H100 80GB 显存紧张,激活值 + DeepEP all-to-all buffer 竞争剩余 ~14GB 显存。concurrency=8 可稳定运行,>=32 大概率 crash。

  2. Prefill OOM: mem-fraction-static=0.88 (与 Kimi-K2 H200 的 0.849 类似) 会在 高并发 prefill 时 OOM (CUDA_ERROR_OUT_OF_MEMORY in kv_b_proj)。 已降至 0.82 缓解。

  3. Decode mem-fraction-static: H200 参考值 0.6 在 H100 上 OOM (0.6×80=48GB < 模型 54GB)。 已调至 0.82。

  4. DeepGEMM cache: 必须挂载 -v /opt/dlami/nvme/.cache_deep_gemm:/root/.cache/deep_gemm, 否则每次重启需重新编译 (~10-20 分钟)。有 cache 后编译 <1 分钟。

  5. 启动顺序: 建议 4 节点同时启动。如果只重启 Prefill,Decode 可能因丢失 PD 连接 导致新 Prefill 的 PD warmup 超时,此时需全部重启。

Kimi-K2 on B200 (p6-B200, 单节点 EP)

在 2× p6-B200 实例 (8× NVIDIA B200 192GB/179GB usable) 上部署 Kimi-K2-Instruct, 1 节点 Prefill + 1 节点 Decode,单节点 EP(EP=8, 通过 NVLink 通信), 跨节点 KV cache 通过 Mooncake + EFA 传输。

与 H200 多节点 EP 的关键差异

H200 (p5en, 4 节点) B200 (p6, 2 节点)
GPU 数/节点 8 8
VRAM/GPU 141 GB 179 GB
EP 模式 跨 2 节点 (EP=16, UCCL-EP) 单节点 (EP=8, NVLink)
TP/DP TP=16, DP=16 TP=8, DP=8
基础镜像 lmsysorg/sglang:latest (CUDA 12) lmsysorg/sglang:dev-cu13 (CUDA 13, sm_100)
DeepEP 节点间 NVSHMEM + EFA 不需要 (NVLink only)
NVSHMEM env vars 需要设置 必须不设置 (会导致 segfault)

新增文件

文件 说明
Dockerfile.b200 基于 dev-cu13 + EFA 1.47 + GDRCopy 2.5.1 + Mooncake(EFA)
start_prefill_b200.sh Prefill: EP8/TP8/DP8, deepep-mode=normal, mem=0.88
start_decode_b200.sh Decode: EP8/TP8/DP8, deepep-mode=low_latency, mem=0.85, cuda-graph-max-bs=64
start_standalone_b200.sh Standalone (非PD): EP8/TP8/DP8, deepep-mode=auto, cuda-graph-max-bs=64

Docker 镜像构建

docker build -t kimi-k2-sglang-b200 -f Dockerfile.b200 .

构建约 20-30 分钟。基于 lmsysorg/sglang:dev-cu13,添加 EFA 和 Mooncake(EFA)。

启动

# Prefill 节点
docker run -d --name kimi-k2-prefill \
    --gpus all --ipc=host --net=host --ulimit memlock=-1 \
    --device=/dev/infiniband --privileged \
    -v /opt/dlami/nvme/Kimi-K2-Instruct:/models/Kimi-K2-Instruct \
    -v /opt/dlami/nvme/.cache_deep_gemm:/root/.cache/deep_gemm \
    -v /home/ubuntu:/host \
    kimi-k2-sglang-b200 \
    bash /host/kimi-k2-sglang/start_prefill_b200.sh

# Decode 节点
docker run -d --name kimi-k2-decode \
    --gpus all --ipc=host --net=host --ulimit memlock=-1 \
    --device=/dev/infiniband --privileged \
    -v /opt/dlami/nvme/Kimi-K2-Instruct:/models/Kimi-K2-Instruct \
    -v /opt/dlami/nvme/.cache_deep_gemm:/root/.cache/deep_gemm \
    -v /home/ubuntu:/host \
    kimi-k2-sglang-b200 \
    bash /host/kimi-k2-sglang/start_decode_b200.sh

# Router (在 Prefill 容器内)
docker exec -d kimi-k2-prefill bash -c '
python3 -m sglang_router.launch_router \
    --port 8080 --host 0.0.0.0 \
    --pd-disaggregation \
    --prefill http://<PREFILL_IP>:30000 \
    --decode http://<DECODE_IP>:30000 \
    --prometheus-port 29100'

B200 关键参数

参数 Prefill Decode 说明
mem-fraction-static 0.88 0.85 模型+DeepEP+EPLB占140GB,仅剩32GB
cuda-graph-max-bs 禁用 64 受限于~15GB剩余显存
max-total-tokens 262144 90819 (自动) Decode KV cache 仅~16GB
max-running-requests 1024 256 (自动) 受 KV cache 限制
chunked-prefill-size 65536 - dp_attention 自动调整为 8192
deepep-mode normal low_latency -
ep-num-redundant-experts 8 8 必须能被 ep_size=8 整除

B200 内存分布 (每 GPU)

Total VRAM:           179 GB
Model weights:       ~126 GB  (FP8, EP=8 sharding)
DeepEP + EPLB:        ~14 GB  (low_latency buffers + redundant experts)
KV cache:             ~16 GB  (decode, mem=0.85)
CUDA graph + act:     ~15 GB  (cuda-graph-max-bs=64)
Free:                  ~8 GB

B200 性能基准

测试环境: 2× p6-B200, 1P1D, EP8/TP8/DP8, Kimi-K2-Instruct

Prefill (input=2000, output=10, 1000 prompts, concurrency=512)

指标 值
Input token throughput 62,772 tok/s
Request throughput 62.18 req/s
Mean TTFT 7,034 ms
P99 TTFT 14,402 ms

Decode (input=200, output=500, 1000 prompts, concurrency=512)

指标 无 CUDA graph cuda-graph-max-bs=32 cuda-graph-max-bs=64
Output tok/s 1,947 2,552 2,736
Peak tok/s 3,052 3,316 8,612
Mean TPOT 175 ms 163 ms 135 ms
P99 TPOT 320 ms 232 ms 179 ms
Mean ITL 170 ms - 137 ms

与 LMSYS Blog 对比 (per-node)

指标 LMSYS Blog (H200, 多节点EP) B200 单节点EP
Prefill input tok/s 56,000 62,772
Decode output tok/s 24,000 2,736

Prefill 已超过 Blog 数值。Decode 差距大的根本原因:Blog 用 12 个 decode 节点做多节点 EP (EP=16+),每 GPU 模型更小,有更多内存给 KV cache 和 CUDA graph (batch size 480+)。 单节点 EP 下模型占 140GB/GPU,KV cache 仅 16GB,max_running_requests 被限制到 256。

B200 Standalone (非 PD 分离) 模式

使用 start_standalone_b200.sh 可在单台 B200 上运行非 PD 分离模式。 关键配置:--deepep-mode auto,使 SGLang 根据 batch 类型动态切换:

  • Prefill batch → normal mode (高吞吐 all-to-all)
  • Decode batch → low_latency mode (低延迟 dispatch)
  • CUDA graph 不会被禁用(仅 --deepep-mode normal 会强制禁用)
docker run -d --name kimi-k2-standalone \
    --gpus all --ipc=host --net=host \
    -v /opt/dlami/nvme:/models \
    -v /opt/dlami/nvme/.cache_deep_gemm:/root/.cache/deep_gemm \
    -v /home/ubuntu:/host \
    kimi-k2-sglang-b200 \
    bash /host/kimi-k2-sglang/start_standalone_b200.sh

Standalone vs PD 分离性能对比

测试环境: B200 单节点 (EP8/TP8/DP8), deepep-mode=normal (无 CUDA graph)

测试类型 指标 PD 分离 (2台) Standalone (1台, 无CUDA graph)
Prefill-heavy (in=2000, out=10, c=512) Input tok/s 62,772 51,163
Decode-heavy (in=200, out=500, c=512) Output tok/s 2,736 1,613
Decode-heavy TPOT 135 ms 205 ms

注意: Standalone 测试使用 --deepep-mode normal (无 CUDA graph)。 已更新脚本为 --deepep-mode auto 以启用 CUDA graph,待下次测试验证。 预期 decode 性能会有显著提升。

deepep-mode 选择指南

模式 CUDA Graph 适用场景 说明
normal 禁用 Prefill-only 高吞吐 all-to-all,但 prefill-heavy 时 dispatch token 无限制
low_latency 启用 Decode-only 低延迟,但 dispatch token 受 SGLANG_DEEPEP_NUM_MAX_DISPATCH_TOKENS_PER_RANK 限制,prefill 大 batch 会卡死
auto 启用 Standalone (prefill+decode) 动态切换:extend batch→normal, decode batch→low_latency

B200 已知问题

  1. NVSHMEM segfault: 不能设置 NVSHMEM_REMOTE_TRANSPORT=libfabric 或 NVSHMEM_LIBFABRIC_PROVIDER=efa。单节点 DeepEP 只需 NVLink,设置这些变量会导致 NVSHMEM 初始化时 fi_getinfo segfault。

  2. Docker 容器难以停止: GPU 容器 docker stop/rm -f 经常卡住。 解决方法:sudo systemctl restart docker && docker rm -f <name>

  3. Router tokenizer 加载失败: Kimi-K2 使用 tiktoken 格式,router 的 tokenizer 加载器不支持。不影响路由功能,可忽略。

  4. Router prometheus-port 冲突: 默认 29000 端口被 NCCL/SGLang 占用, 需指定 --prometheus-port 29100。

  5. compile_deep_gemm 内存不足: 必须在 compile 步骤中传 --mem-fraction-static 0.88, 否则 SGLang 自动计算的值 (~0.75) 在 B200 上可能不够。

许可

本方案仅供技术验证和基准测试。模型使用需遵循 Moonshot AI / DeepSeek 的许可条款。

About

Kimi K2 SGLang PD Disaggregation on AWS EFA (p5en H200) + AWS Capacity Block provisioning skill

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages