SGLang对于deepseek的支持

添加分类

SGLang 和 DeepSeek 团队从第一天起就合作让 DeepSeek V3 FP8 在 NVIDIA 和 AMD GPU 上运行。SGLang 还支持MLA 优化DP 注意力,使 SGLang 成为运行 DeepSeek 模型的最佳开源 LLM 引擎之一。SGLang 是DeepSeek 官方团队推荐的推理引擎。

特别感谢美团搜索推荐平台团队、Baseten模型性能团队对模型的实现,以及DataCrunch提供的GPU资源。

关于SGLang对DeepSeek系列模型做的优化,请参考SGLang中DeepSeek模型优化

硬件推荐

  • 8 个 NVIDIA H200 GPU

如果您没有具有足够大内存的 GPU,请尝试多节点张量并行。下面有一个使用2 个 H20 节点的示例。

安装和启动

如果启动服务器时遇到错误,请确保权重已下载完成。建议提前下载或多次重启,直到下载完所有权重。

使用 Docker(推荐)

# Pull latest image
# https://hub.docker.com/r/lmsysorg/sglang/tags
docker pull lmsysorg/sglang:latest

# Launch
docker run --gpus all --shm-size 32g -p 30000:30000 -v ~/.cache/huggingface:/root/.cache/huggingface --ipc=host lmsysorg/sglang:latest \
    python3 -m sglang.launch_server --model deepseek-ai/DeepSeek-V3 --tp 8 --trust-remote-code --port 30000

对于高 QPS 场景,添加该--enable-dp-attention参数以提高吞吐量。

使用 pip

# Installation
pip install "sglang[all]>=0.4.1.post5" --find-links https://flashinfer.ai/whl/cu124/torch2.4/flashinfer

# Launch
python3 -m sglang.launch_server --model deepseek-ai/DeepSeek-V3 --tp 8 --trust-remote-code

对于高 QPS 场景,添加该--enable-dp-attention参数以提高吞吐量。

示例:使用 OpenAI API 发送请求

import openai
client = openai.Client(
    base_url="http://127.0.0.1:30000/v1", api_key="EMPTY")

# Chat completion
response = client.chat.completions.create(
    model="default",
    messages=[
        {"role": "system", "content": "You are a helpful AI assistant"},
        {"role": "user", "content": "List 3 countries and their capitals."},
    ],
    temperature=0,
    max_tokens=64,
)
print(response)

示例:使用两个 H20*8 节点提供服务

例如,有两个 H20 节点,每个节点有 8 个 GPU。第一个节点的 IP 是10.0.0.1,第二个节点的 IP 是10.0.0.2。请在两个命令中使用第一个节点的 IP 。

如果命令失败,请尝试设置GLOO_SOCKET_IFNAME参数。有关更多信息,请参阅常用环境变量

# node 1
python -m sglang.launch_server --model-path deepseek-ai/DeepSeek-V3 --tp 16 --dist-init-addr 10.0.0.1:5000 --nnodes 2 --node-rank 0 --trust-remote-code

# node 2
python -m sglang.launch_server --model-path deepseek-ai/DeepSeek-V3 --tp 16 --dist-init-addr 10.0.0.1:5000 --nnodes 2 --node-rank 1 --trust-remote-code

如果您有两个H100节点,其使用方法与前面提到的H20类似。

示例:使用两个 H200*8 节点和 docker 提供服务

有两个 H200 节点,每个节点有 8 个 GPU。第一个节点的 IP 是192.168.114.10,第二个节点的 IP 是。使用和192.168.114.11配置端点以将其暴露给另一个 Docker 容器,并设置与 的通信。带有 8 个设备的单个 H200 可以运行 DeepSeek V3,双 H200 设置只是为了演示多节点用法。--host 0.0.0.0--port 40000--dist-init-addr 192.168.114.10:20000

# node 1
docker run --gpus all \
    --shm-size 32g \
    --network=host \
    -v ~/.cache/huggingface:/root/.cache/huggingface \
    --name sglang_multinode1 \
    -it \
    --rm \
    --env "HF_TOKEN=$HF_TOKEN" \
    --ipc=host \
    lmsysorg/sglang:latest \
    python3 -m sglang.launch_server --model-path deepseek-ai/DeepSeek-V3 --tp 16 --dist-init-addr 192.168.114.10:20000 --nnodes 2 --node-rank 0 --trust-remote-code --host 0.0.0.0 --port 40000
# node 2
docker run --gpus all \
    --shm-size 32g \
    --network=host \
    -v ~/.cache/huggingface:/root/.cache/huggingface \
    --name sglang_multinode2 \
    -it \
    --rm \
    --env "HF_TOKEN=$HF_TOKEN" \
    --ipc=host \
    lmsysorg/sglang:latest \
    python3 -m sglang.launch_server --model-path deepseek-ai/DeepSeek-V3 --tp 16 --dist-init-addr 192.168.114.10:20000 --nnodes 2 --node-rank 1 --trust-remote-code --host 0.0.0.0 --port 40000

为了确保功能,我们包含了来自客户端 Docker 容器的测试。

docker run --gpus all \
    --shm-size 32g \
    --network=host \
    -v ~/.cache/huggingface:/root/.cache/huggingface \
    --name sglang_multinode_client \
    -it \
    --rm \
    --env "HF_TOKEN=$HF_TOKEN" \
    --ipc=host \
    lmsysorg/sglang:latest \
    python3 -m sglang.bench_serving --backend sglang --dataset-name random --random-input 1 --random-output 512 --random-range-ratio 1 --num-prompts 1 --host 0.0.0.0 --port 40000 --output-file "deepseekv3_multinode.jsonl"


选择支持方式
超值优惠
年费会员
原价: ¥365
限时: ¥199
全站资源无限下载
全年免费咨询
专属会员社群
轻量体验
月度会员
原价: ¥49
特惠: ¥29
更新资源下载
专属会员社群
不含咨询
交个朋友
体验会员
原价: ¥29
特惠: ¥9.9
单次下载或咨询
专属会员社群
微信扫码支持
支付宝扫码支持
客服微信
微信:mingzhang567