文档(金鹏): 2026-08-06 章节 48 篇文章摘要归档
- 46 篇原文+摘要双文件归档(按 来源/作者 分层,复用本地归档 20 篇+新抓取 26 篇) - 即梦生成 9 组主题配图(大图+列表缩略图)存入 知识/金鹏/20260806/ - 章节重组为 9 个主题分组并挂接摘要引用
This commit is contained in:
@@ -0,0 +1,365 @@
|
||||
# PD 分离 (PD Disaggregation) — SGLang 框架
|
||||
|
||||
> **来源**:SGLang 官方文档
|
||||
> **作者**:未知
|
||||
> **发布日期**:2025-12-30
|
||||
> **原文链接**:https://docs.sglang.com.cn/advanced_features/pd_disaggregation.html
|
||||
|
||||
---
|
||||
|
||||
## 目录
|
||||
|
||||
- 什么是 PD 分离,为什么要使用它?
|
||||
- 统一调度存在的问题
|
||||
- 在 PD 分离模式下进行性能分析 (Profiling)
|
||||
- Router 集成
|
||||
- Mooncake
|
||||
- 环境要求
|
||||
- 用法
|
||||
- Llama 单节点
|
||||
- DeepSeek 多节点
|
||||
- 高级配置
|
||||
- NVLink 传输配置
|
||||
- Prefill 服务端配置
|
||||
- Decode 服务端配置
|
||||
- NIXL
|
||||
- 环境要求
|
||||
- 用法
|
||||
- Llama 单节点
|
||||
- DeepSeek 多节点
|
||||
- 昇腾 (ASCEND)
|
||||
- 用法
|
||||
- Llama 单节点
|
||||
- DeepSeek 多节点
|
||||
|
||||
## PD 分离
|
||||
|
||||
## 什么是 PD 分离,为什么要使用它?
|
||||
|
||||
大语言模型 (LLM) 推理包含两个不同的阶段:__Prefill (预填充)__ 和 __Decode (解码)__。Prefill 阶段是计算密集型的,处理整个输入序列;而 Decode 阶段是内存密集型的,管理用于逐个生成 token 的 Key-Value (KV) 缓存。传统上,这两个阶段在统一的引擎中处理,混合调度 prefill 和 decode 批次会导致效率低下。为了解决这些挑战,我们在 SGLang 中引入了 __Prefill 和 Decoding (PD) 分离__。
|
||||
|
||||
### 统一调度存在的问题
|
||||
|
||||
传统的统一引擎同时处理 prefill 和 decode 批次,这会导致两个显著问题:
|
||||
|
||||
1. __Prefill 中断__:新进入的 prefill 批次经常中断正在进行的 decode 批次,导致 token 生成出现大幅延迟。
|
||||
2. __DP Attention 不平衡__:在数据并行 (DP) 注意力机制中,一个 DP 工作进程可能正在处理 prefill 批次,而另一个同时处理 decode 批次,导致解码延迟增加。
|
||||
|
||||
PD 分离通过将这两个阶段分开来解决这些问题,从而能够为每个阶段进行针对性优化。
|
||||
|
||||
有关设计详情,请参阅[链接](https://arxiv.org/abs/2404.12599)(DistServe 论文)。
|
||||
|
||||
目前,我们支持 Mooncake 和 NIXL 作为传输引擎。
|
||||
|
||||
## 在 PD 分离模式下进行性能分析 (Profiling)
|
||||
|
||||
当您需要在 PD 分离模式下对 prefill 或 decode 工作进程进行性能分析时,请参阅"基准测试与性能分析"指南中的"在 PD 分离模式下进行性能分析"章节。由于 torch profiler 的限制,必须使用专用的命令行选项分别对 prefill 和 decode 工作进程进行分析。
|
||||
|
||||
## Router 集成
|
||||
|
||||
为了在大规模部署 PD 分离并实现负载均衡和容错,SGLang 提供了一个 Router (路由器)。Router 可以使用各种路由策略在 prefill 和 decode 实例之间分配请求。有关使用 PD 分离设置路由的详细信息(包括配置选项和部署模式),请参阅 [SGLang Router 文档](https://docs.sglang.ai/backend/router.html)。
|
||||
|
||||
## Mooncake
|
||||
|
||||
### 环境要求
|
||||
|
||||
```
|
||||
uv pip install mooncake-transfer-engine
|
||||
```
|
||||
|
||||
### 用法
|
||||
|
||||
### Llama 单节点
|
||||
|
||||
```
|
||||
python -m sglang.launch_server \
|
||||
--model-path meta-llama/Llama-3.1-8B-Instruct \
|
||||
--disaggregation-mode prefill \
|
||||
--port 30000 \
|
||||
--disaggregation-ib-device mlx5_roce0
|
||||
|
||||
python -m sglang.launch_server \
|
||||
--model-path meta-llama/Llama-3.1-8B-Instruct \
|
||||
--disaggregation-mode decode \
|
||||
--port 30001 \
|
||||
--base-gpu-id 1 \
|
||||
--disaggregation-ib-device mlx5_roce0
|
||||
|
||||
python -m sglang_router.launch_router --pd-disaggregation --prefill http://127.0.0.1:30000 --decode http://127.0.0.1:30001 --host 0.0.0.0 --port 8000
|
||||
```
|
||||
|
||||
### DeepSeek 多节点
|
||||
|
||||
```
|
||||
# prefill 0
|
||||
python -m sglang.launch_server \
|
||||
--model-path deepseek-ai/DeepSeek-V3-0324 \
|
||||
--disaggregation-ib-device ${device_name} \
|
||||
--disaggregation-mode prefill \
|
||||
--host ${local_ip} \
|
||||
--port 30000 \
|
||||
--trust-remote-code \
|
||||
--dist-init-addr ${prefill_master_ip}:5000 \
|
||||
--nnodes 2 \
|
||||
--node-rank 0 \
|
||||
--tp-size 16 \
|
||||
--dp-size 8 \
|
||||
--enable-dp-attention \
|
||||
--moe-a2a-backend deepep \
|
||||
--mem-fraction-static 0.8
|
||||
|
||||
# prefill 1
|
||||
python -m sglang.launch_server \
|
||||
--model-path deepseek-ai/DeepSeek-V3-0324 \
|
||||
--disaggregation-ib-device ${device_name} \
|
||||
--disaggregation-mode prefill \
|
||||
--host ${local_ip} \
|
||||
--port 30000 \
|
||||
--trust-remote-code \
|
||||
--dist-init-addr ${prefill_master_ip}:5000 \
|
||||
--nnodes 2 \
|
||||
--node-rank 1 \
|
||||
--tp-size 16 \
|
||||
--dp-size 8 \
|
||||
--enable-dp-attention \
|
||||
--moe-a2a-backend deepep \
|
||||
--mem-fraction-static 0.8
|
||||
|
||||
# decode 0
|
||||
python -m sglang.launch_server \
|
||||
--model-path deepseek-ai/DeepSeek-V3-0324 \
|
||||
--disaggregation-ib-device ${device_name} \
|
||||
--disaggregation-mode decode \
|
||||
--host ${local_ip} \
|
||||
--port 30001 \
|
||||
--trust-remote-code \
|
||||
--dist-init-addr ${decode_master_ip}:5000 \
|
||||
--nnodes 2 \
|
||||
--node-rank 0 \
|
||||
--tp-size 16 \
|
||||
--dp-size 8 \
|
||||
--enable-dp-attention \
|
||||
--moe-a2a-backend deepep \
|
||||
--mem-fraction-static 0.8 \
|
||||
--max-running-requests 128
|
||||
|
||||
# decode 1
|
||||
python -m sglang.launch_server \
|
||||
--model-path deepseek-ai/DeepSeek-V3-0324 \
|
||||
--disaggregation-ib-device ${device_name} \
|
||||
--disaggregation-mode decode \
|
||||
--host ${local_ip} \
|
||||
--port 30001 \
|
||||
--trust-remote-code \
|
||||
--dist-init-addr ${decode_master_ip}:5000 \
|
||||
--nnodes 2 \
|
||||
--node-rank 1 \
|
||||
--tp-size 16 \
|
||||
--dp-size 8 \
|
||||
--enable-dp-attention \
|
||||
--moe-a2a-backend deepep \
|
||||
--mem-fraction-static 0.8 \
|
||||
--max-running-requests 128
|
||||
```
|
||||
|
||||
### 高级配置
|
||||
|
||||
带有 Mooncake 的 PD 分离支持以下环境变量,用于对系统行为进行精细控制。
|
||||
|
||||
#### NVLink 传输配置
|
||||
|
||||
若要为使用 mooncake 后端的 KV cache 传输启用 NVLink 传输(建议在 NVL72 部署中使用),请设置以下环境变量。请注意,作为临时方案,辅助数据传输仍将使用 TCP。
|
||||
|
||||
```
|
||||
export SGLANG_MOONCAKE_CUSTOM_MEM_POOL=True
|
||||
export MC_FORCE_MNNVL=True
|
||||
```
|
||||
|
||||
#### Prefill 服务端配置
|
||||
|
||||
如果可以接受较大的平均 TTFT,可以执行 `export SGLANG_DISAGGREGATION_BOOTSTRAP_TIMEOUT=600`(10 分钟)以放宽超时条件。请注意,此设置会导致当运行中的 decode 节点断开连接时,prefill 实例需要更长时间来清理受影响的内存资源。
|
||||
|
||||
#### Decode 服务端配置
|
||||
|
||||
如果可以接受较大的平均 TTFT,可以执行 `export SGLANG_DISAGGREGATION_WAITING_TIMEOUT=600`(10 分钟)以放宽超时条件。
|
||||
|
||||
## NIXL
|
||||
|
||||
### 环境要求
|
||||
|
||||
通过 pip 安装。
|
||||
|
||||
或从源码构建 - 如果您已经安装了 UCX,可能需要这样做。
|
||||
|
||||
```
|
||||
git clone https://github.com/ai-dynamo/nixl.git
|
||||
cd nixl
|
||||
pip install . --config-settings=setup-args="-Ducx_path=/path/to/ucx"
|
||||
```
|
||||
|
||||
### 使用方法
|
||||
|
||||
### Llama 单节点
|
||||
|
||||
```
|
||||
python -m sglang.launch_server \
|
||||
--model-path meta-llama/Llama-3.1-8B-Instruct \
|
||||
--disaggregation-mode prefill \
|
||||
--port 30000 \
|
||||
--disaggregation-transfer-backend nixl
|
||||
|
||||
python -m sglang.launch_server \
|
||||
--model-path meta-llama/Llama-3.1-8B-Instruct \
|
||||
--disaggregation-mode decode \
|
||||
--port 30001 \
|
||||
--base-gpu-id 1 \
|
||||
--disaggregation-transfer-backend nixl
|
||||
|
||||
python -m sglang_router.launch_router --pd-disaggregation --prefill http://127.0.0.1:30000 --decode http://127.0.0.1:30001 --host 0.0.0.0 --port 8000
|
||||
```
|
||||
|
||||
### DeepSeek 多节点
|
||||
|
||||
```
|
||||
# prefill 0
|
||||
python -m sglang.launch_server \
|
||||
--model-path deepseek-ai/DeepSeek-V3-0324 \
|
||||
--disaggregation-transfer-backend nixl \
|
||||
--disaggregation-mode prefill \
|
||||
--host ${local_ip} \
|
||||
--port 30000 \
|
||||
--trust-remote-code \
|
||||
--dist-init-addr ${prefill_master_ip}:5000 \
|
||||
--nnodes 2 \
|
||||
--node-rank 0 \
|
||||
--tp-size 16 \
|
||||
--dp-size 8 \
|
||||
--enable-dp-attention \
|
||||
--moe-a2a-backend deepep \
|
||||
--mem-fraction-static 0.8
|
||||
|
||||
# prefill 1
|
||||
python -m sglang.launch_server \
|
||||
--model-path deepseek-ai/DeepSeek-V3-0324 \
|
||||
--disaggregation-transfer-backend nixl \
|
||||
--disaggregation-mode prefill \
|
||||
--host ${local_ip} \
|
||||
--port 30000 \
|
||||
--trust-remote-code \
|
||||
--dist-init-addr ${prefill_master_ip}:5000 \
|
||||
--nnodes 2 \
|
||||
--node-rank 1 \
|
||||
--tp-size 16 \
|
||||
--dp-size 8 \
|
||||
--enable-dp-attention \
|
||||
--moe-a2a-backend deepep \
|
||||
--mem-fraction-static 0.8
|
||||
|
||||
# decode 0
|
||||
python -m sglang.launch_server \
|
||||
--model-path deepseek-ai/DeepSeek-V3-0324 \
|
||||
--disaggregation-transfer-backend nixl \
|
||||
--disaggregation-mode decode \
|
||||
--host ${local_ip} \
|
||||
--port 30001 \
|
||||
--trust-remote-code \
|
||||
--dist-init-addr ${decode_master_ip}:5000 \
|
||||
--nnodes 2 \
|
||||
--node-rank 0 \
|
||||
--tp-size 16 \
|
||||
--dp-size 8 \
|
||||
--enable-dp-attention \
|
||||
--moe-a2a-backend deepep \
|
||||
--mem-fraction-static 0.8 \
|
||||
--max-running-requests 128
|
||||
|
||||
# decode 1
|
||||
python -m sglang.launch_server \
|
||||
--model-path deepseek-ai/DeepSeek-V3-0324 \
|
||||
--disaggregation-transfer-backend nixl \
|
||||
--disaggregation-mode decode \
|
||||
--host ${local_ip} \
|
||||
--port 30001 \
|
||||
--trust-remote-code \
|
||||
--dist-init-addr ${decode_master_ip}:5000 \
|
||||
--nnodes 2 \
|
||||
--node-rank 1 \
|
||||
--tp-size 16 \
|
||||
--dp-size 8 \
|
||||
--enable-dp-attention \
|
||||
--moe-a2a-backend deepep \
|
||||
--mem-fraction-static 0.8 \
|
||||
--max-running-requests 128
|
||||
```
|
||||
|
||||
## 昇腾 (ASCEND)
|
||||
|
||||
### 使用方法
|
||||
|
||||
通过设置 ASCEND_MF_STORE_URL 并使用 mf_adapter([下载链接](https://github.com/sgl-project/sglang/releases))来配合 ascend 后端使用
|
||||
|
||||
```
|
||||
pip install mf_adapter-1.0.0-cp311-cp311-linux_aarch64.whl --force-reinstall
|
||||
export ASCEND_MF_STORE_URL="tcp://xxx.xx.xxx.xxx:xxxx"
|
||||
```
|
||||
|
||||
使用 mooncake 后端,更多详情可以在 mooncake 章节中找到。
|
||||
|
||||
```
|
||||
export ENABLE_ASCEND_TRANSFER_WITH_MOONCAKE=true
|
||||
```
|
||||
|
||||
需要在容器环境变量中设置 ASCEND_NPU_PHY_ID
|
||||
|
||||
```
|
||||
export ASCEND_NPU_PHY_ID=xxx
|
||||
```
|
||||
|
||||
### Llama 单节点
|
||||
|
||||
```
|
||||
python -m sglang.launch_server \
|
||||
--model-path meta-llama/Llama-3.1-8B-Instruct \
|
||||
--disaggregation-mode prefill \
|
||||
--port 30000 \
|
||||
--disaggregation-transfer-backend ascend
|
||||
|
||||
python -m sglang.launch_server \
|
||||
--model-path meta-llama/Llama-3.1-8B-Instruct \
|
||||
--disaggregation-mode decode \
|
||||
--port 30001 \
|
||||
--base-gpu-id 1 \
|
||||
--disaggregation-transfer-backend ascend
|
||||
|
||||
python -m sglang_router.launch_router --pd-disaggregation --prefill http://127.0.0.1:30000 --decode http://127.0.0.1:30001 --host 0.0.0.0 --port 8000
|
||||
```
|
||||
|
||||
### DeepSeek 多节点
|
||||
|
||||
```
|
||||
# prefill 0
|
||||
python -m sglang.launch_server \
|
||||
--model-path deepseek-ai/DeepSeek-V3-0324 \
|
||||
--disaggregation-transfer-backend ascend \
|
||||
--disaggregation-mode prefill \
|
||||
--host ${local_ip} \
|
||||
--port 30000 \
|
||||
--trust-remote-code \
|
||||
--dist-init-addr ${prefill_master_ip}:5000 \
|
||||
--nnodes 1 \
|
||||
--node-rank 0 \
|
||||
--tp-size 16
|
||||
|
||||
# decode 0
|
||||
python -m sglang.launch_server \
|
||||
--model-path deepseek-ai/DeepSeek-V3-0324 \
|
||||
--disaggregation-transfer-backend ascend \
|
||||
--disaggregation-mode decode \
|
||||
--host ${local_ip} \
|
||||
--port 30001 \
|
||||
--trust-remote-code \
|
||||
--dist-init-addr ${decode_master_ip}:5000 \
|
||||
--nnodes 1 \
|
||||
--node-rank 0 \
|
||||
--tp-size 16
|
||||
```
|
||||
Reference in New Issue
Block a user