文档(金鹏): 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
|
||||
```
|
||||
@@ -0,0 +1,76 @@
|
||||
# 📊 文章摘要:PD 分离 (PD Disaggregation) — SGLang 框架
|
||||
|
||||
> **原文**:[2025-12-30_PD_分离_PD_Disaggregation_SGLang_框架.md](./2025-12-30_PD_分离_PD_Disaggregation_SGLang_框架.md)
|
||||
> **原文链接**:https://docs.sglang.com.cn/advanced_features/pd_disaggregation.html
|
||||
> **来源**:SGLang 官方文档
|
||||
> **作者**:未知
|
||||
> **发布日期**:2025-12-30
|
||||
> **摘要日期**:2026-08-06
|
||||
> **价值评级**:⭐⭐ 中
|
||||
|
||||
---
|
||||
|
||||
## 核心命题
|
||||
|
||||
> **PD 分离** — 将计算密集的 Prefill 与内存密集的 Decode 拆分为独立实例并跨机传输 KV,是长上下文、高并发推理的关键架构方向。
|
||||
|
||||
---
|
||||
|
||||
## 文章概要
|
||||
|
||||
SGLang 官方文档系统介绍了 PD 分离(Prefill/Decode 分离)架构:LLM 推理的 Prefill 阶段计算密集、Decode 阶段内存密集,统一引擎混排会导致 Prefill 频繁打断 Decode 造成生成延迟抖动,以及 DP Attention 负载失衡。方案源自 DistServe 论文思路,通过把两个阶段部署到独立 GPU 实例、经高速网络传输 KV Cache,实现各阶段独立调优。文档给出 Mooncake、NIXL、昇腾三套传输后端的单节点与 DeepSeek 多节点部署命令,以及 Router 负载均衡、NVLink 传输等高级配置。作为官方部署手册,工程可操作性极强,但未提供性能基准数据,收益需自行实测。
|
||||
|
||||
---
|
||||
|
||||
## 关键要点
|
||||
|
||||
1. **混排调度的两大痛点** — Prefill 中断(新批次打断正在进行的 decode)与 DP Attention 不平衡(不同 DP 工作进程负载错配)是统一引擎的核心缺陷,PD 分离逐一化解 `[分类: 共识]`
|
||||
2. **分阶段独立优化** — Prefill 按计算密集优化、Decode 按内存密集优化,设计依据为 DistServe 论文(arXiv:2404.12599)`[分类: 共识]`
|
||||
3. **三种传输后端** — Mooncake、NIXL、昇腾(ASCEND)覆盖英伟达与国产硬件生态,DeepSeek 多节点示例展示了 TP16×DP8 的真实规模配置 `[分类: 共识]`
|
||||
4. **Router 是规模化前提** — 大规模 PD 分离部署需 Router 实现负载均衡与容错,SGLang 提供独立 router 组件在 prefill/decode 实例间分配请求 `[分类: 共识]`
|
||||
5. **配置即显式权衡** — 放宽 bootstrap/waiting 超时意味着接受更大平均 TTFT,但 decode 节点断连时内存清理更慢;NVLink 传输专为 NVL72 部署建议,辅助数据暂走 TCP `[分类: 共识]`
|
||||
6. **国产硬件适配路径** — 昇腾后端经 mf_adapter 与 ASCEND_MF_STORE_URL 接入 mooncake 后端,体现 PD 分离架构的硬件中立性 `[分类: 未探索]`
|
||||
|
||||
---
|
||||
|
||||
## 批判性分析
|
||||
|
||||
### 假设前提
|
||||
|
||||
立论假设读者具备 LLM 推理与分布式部署基础;假定 KV 传输带宽足以覆盖 PD 分离的额外开销(否则收益被抵消);假定多实例部署带来的硬件与管理成本可以接受——这些前提在中小规模场景未必成立。
|
||||
|
||||
### 论据与逻辑
|
||||
|
||||
文档以 DistServe 论文为设计依据,逻辑自洽,但未给出 SGLang 实现下的任何实测性能对比(TTFT、吞吐提升的具体数字缺失),"提升效率"的结论依赖外部基准或读者自行验证;配置项的代价说明清晰,是本文质量较高之处。
|
||||
|
||||
### 边界与局限
|
||||
|
||||
仅适用于 SGLang 框架生态;单节点小规模场景下 PD 分离收益有限,却引入多端口、Router、RDMA 设备等运维负担;Mooncake/NIXL 为较新组件,生产稳定性有待验证;文档未展开 KV 传输带宽瓶颈与失败恢复机制等工程细节。
|
||||
|
||||
---
|
||||
|
||||
## 可引用金句
|
||||
|
||||
> "PD 分离通过将这两个阶段分开来解决这些问题,从而能够为每个阶段进行针对性优化。"
|
||||
|
||||
---
|
||||
|
||||
## 总体评价
|
||||
|
||||
**亮点**:
|
||||
- 官方一手部署文档,覆盖三种传输后端与国产硬件,示例完整(单节点/多节点/环境变量)可直接照做
|
||||
- 明确标注配置权衡与临时方案(如 NVLink 辅助数据暂走 TCP),工程透明度高
|
||||
|
||||
**不足**:
|
||||
- 无任何性能基准数据,无法量化收益;架构原理着墨少(主要指向外部论文),初学者理解门槛高
|
||||
- 未涉及失败恢复、运维监控等生产细节
|
||||
|
||||
**适用场景**:需要为长上下文、高并发推理服务实施 PD 分离的 SGLang 用户与平台工程师;作为该功能的部署手册与配置参考。
|
||||
|
||||
**关联建议**:阅读 DistServe 论文(arXiv:2404.12599)理解原理;对比 vLLM 的 PD 分离与 Mooncake/KVCache 池化项目;结合《GTC 解读:当我们谈论 AI 推理的 KV Cache》理解 PD 分离在全局 KV 存储体系中的位置。
|
||||
|
||||
---
|
||||
|
||||
## 配图
|
||||
|
||||

|
||||
Reference in New Issue
Block a user