读见

优化 H20-3e 上 DeepSeek-V4.1-Flash 的分离式预填充-解码与共置服务

原题Optimizing DeepSeek-V4.1-Flash PD & Colocate Serving on H20-3e

约 12 分钟约 2,845 字原文英文已翻译

读前速览

5 个要点

本文提出一套面向 H20-3e GPU 上 DeepSeek-V4.1-Flash 服务的全面优化策略,重点关注分离式预填充-解码架构与共置部署。通过上下文并行、FP8 DeepGEMM 评分和可拆分 CUDA 图等技术,相较基线配置,端到端平均延迟最多降低 65.5%,输出吞吐量提升至 2.91 倍。

  1. 分离式服务架构

    论文采用分离式架构,由不同 GPU 集群分别处理预填充和解码阶段,并通过 NVLink 连接。这种设计可以针对各阶段进行专门优化:预填充阶段采用上下文并行,解码阶段采用数据并行,以最大化吞吐量。

  2. 用于索引器的 FP8 DeepGEMM

    为加速预填充阶段,研究采用 FP8 DeepGEMM 处理索引器:将 FP4 键转换为 E4M3 格式,并以 FP8 执行评分操作,从而显著缩短初始 token 选择所需的计算时间。

  3. 可拆分 CUDA 图

    优化策略包括实现可拆分 CUDA 图。该技术捕获预填充流水线中可安全用于图执行的部分,使这些部分能够重复执行,而无需承担逐个启动内核的开销,从而提高预填充过程的整体效率。

  4. 张量并行 MoE

    研究对比了专家并行(EP)与张量并行 MoE。结果发现,张量并行 MoE 会将专家分片到所有 GPU 上,能够实现更均衡的工作负载,性能也略优于 EP;当路由分配不均时,EP 可能出现负载不平衡。

  5. 共置部署

    除分离式设置外,论文还评估了所有组件都运行在单个节点上的共置部署。结果显示,分离式设置的延迟最低,而共置设置的单 GPU 吞吐量更高,因此适用于特定场景。

完整摘要

本研究探讨了针对 DeepSeek-V4.1-Flash 模型的多种优化技术,重点面向 H20-3e GPU 架构,主要目标是在分离式服务设置中提升预填充和解码阶段的效率。关键优化包括在预填充阶段采用交错式上下文并行、对索引器进行 FP8 量化,以及使用可拆分 CUDA 图来减少内核启动开销。论文还研究了张量并行 MoE 和分页索引器块复用的影响。结果表明,延迟和吞吐量均有显著改善;最终配置的端到端平均延迟为 4.70 秒,输出吞吐量为每秒 2,465 个 token。

目录 · 20 节

查看原文
Siyuan Chen, Bingjia Wang, Bofeng Jiang, Yongxu Ai, and Kaixin Shen — Ant International AI Infra TeamNovember 19, 2026
On this page

概述Overview

我们通过调优预填充和解码并行度、借助预填充 CP 和有界 SWA 重放支持 BCG,并加速 Indexer 内核,优化了 H20-3e 上解耦式 DeepSeek-V4.1-Flash 推理服务。与 TP4 相比,最终配置将端到端平均延迟降低了 65.5%,输出吞吐量提升至 2.91 倍。We optimized disaggregated DeepSeek-V4.1-Flash serving on H20-3e by tuning prefill and decode parallelism, supporting BCG with prefill CP and bounded SWA replay, and speeding up Indexer kernels. Compared with TP4, the final configuration cut mean end-to-end latency by 65.5% and delivered 2.91× the output throughput.

我们的节点内 PD 部署在预填充和解码阶段各使用四块 GPU,并通过 NVLink 传输 KV 缓存。端到端平均延迟从 13.63 秒降至 4.70 秒,输出吞吐量从 847 tokens/s 提升至 2,465 tokens/s。预填充上下文并行与解码数据并行相结合带来了最大的性能提升,其次是 FP8 DeepGEMM 评分。Our intra-node PD deployment used four GPUs each for prefill and decode, with KV cache transfers over NVLink. Mean end-to-end latency fell from 13.63 s to 4.70 s, and output throughput rose from 847 to 2,465 tokens/s. Prefill context parallelism paired with decode data parallelism gave the largest gain, followed by FP8 DeepGEMM scoring.

Compared with TP4, the final PD configuration has 0.34× mean end-to-end latency, 0.16× mean time to first token, and 2.91× output throughput.

Cumulative configuration Mean E2E (ms) Output (tok/s) Mean TTFT (ms) Mean TPOT (ms) P99 E2E (ms)
TP4 baseline 13,633.80 846.76 12,037.73 3.20 21,306.70
1. Prefill CP + decode DP 7,547.46 (−44.64%) 1,537.90 5,156.84 (-57%) 4.79 14,012.91
2. FP8 DeepGEMM 5,294.89 (−29.85%) 2,200.82 2,662.13 (-48%) 5.28 11,016.82
3. Breakable CUDA Graphs 5,100.87 (−3.66%) 2,290.05 2,390.32 (-10%) 5.43 10,641.21
4. TP MoE 4,811.81 (−5.67%) 2,425.96 1,877.23 (-22%) 5.88 10,224.78
5. Larger prefill score tiles 4,773.97 (−0.79%) 2,450.67 1,838.15 (-2%) 5.88 10,284.72
6. Prefill selection fusion 4,774.47 (+0.01%) 2,440.68 1,802.77 (-2%) 5.96 10,221.00
7. Paged K-tile reuse 4,698.65 (−1.59%) 2,464.90 1,894.54 5.62 (-6%) 10,073.00

大部分延迟改善都发生在首个 token 生成之前。平均首 token 延迟(TTFT)从 12.04 秒降至 1.89 秒。首个 token 之后的平均每输出 token 时间(TPOT)从 3.20 毫秒升至 5.62 毫秒。在并发数固定的情况下,更快的预填充可以让解码阶段保持更繁忙,而更快的解码则可以释放客户端槽位来接收新的提示词。这可能会改变两个工作进程之间的排队情况。Most of the latency gain came before the first token. Mean time to first token (TTFT) fell from 12.04 s to 1.89 s. Mean time per output token after the first (TPOT) rose from 3.20 to 5.62 ms. At fixed concurrency, faster prefill can keep decode busier, and faster decode can free client slots for new prompts. That can shift queueing between the two workers.

在最初的实验扫描中,预填充队列的中位数从基线时的 15 个请求降至应用 CP 和 DP 后的 9 个,随后在应用 DeepGEMM 后降至 4 个,应用可中断图后降至 3 个。应用 TP MoE 后降至零。解码队列的中位数始终为零。In the original sweep, the median prefill queue fell from 15 requests at baseline to 9 after CP and DP, then to 4 after DeepGEMM and 3 after breakable graphs. It reached zero with TP MoE. The median decode queue stayed at zero.

测量设置Measurement Setup

路由器将每个请求依次送入预填充和解码阶段。工作节点通过节点内 Mooncake NVLink 直接传输 KV 状态。基线配置在两个工作节点上均运行 TP4 注意力和 EP4 MoE,并使用 eager BF16 Torch 进行预填充评分。所有运行均使用相同的 DeepSeek-V4.1-Flash 检查点、Humming W4A8 MoE、大小为 5 的 DSpark 块,以及 8,192 个 token 的预填充分块。The router sends each request through prefill and decode. The workers transfer the KV state directly over intra-node Mooncake NVLink. The baseline runs TP4 attention and EP4 MoE on both workers with eager BF16 Torch prefill scoring. All runs used the same DeepSeek-V4.1-Flash checkpoint, Humming W4A8 MoE, a DSpark block size of 5, and 8,192-token prefill chunks.

Workload Value
Requests and concurrency 256 requests, 24 in flight
Nominal input 61,440 shared tokens + 4,096 request-specific tokens
Output 500 tokens per request
Cache protocol 10 warmup requests, then a cache flush before measurement
Observed cache hit rate 93.21%

全部 256 个请求均已完成,每次运行都生成了 128,000 个输出 token。TP4 基线和步骤 1–3 是原始扫描中的单次运行。步骤 4–7 显示的是每种配置下所有已完成后续运行的平均值。E2E 百分比用于比较相邻行。P99 按每次运行分别计算,然后取平均值。All 256 requests completed and produced 128,000 output tokens in each run. The TP4 baseline and Steps 1–3 are single runs from the original sweep. Steps 4–7 show the mean of all completed follow-up runs for each configuration. The E2E percentages compare adjacent rows. P99 is calculated per run and then averaged.

1. 预填充 CP 和解码 DP1. Prefill CP and Decode DP

预填充阶段会处理单个长请求中的许多 token 行。交错式上下文并行会将这些行分配给不同的 rank,使四块 GPU 能够协同处理同一个请求。解码阶段有许多活跃请求,但每个请求的查询行数较少。数据并行注意力和数据并行 LM 头会将彼此独立的请求分配给不同的 rank。Prefill handles many token rows from a single long request. Interleaved context parallelism assigns those rows to different ranks so the four GPUs can work on the same request. Decode has many active requests with a small number of query rows each. Data-parallel attention and a data-parallel LM head assign independent requests to different ranks.

Worker Baseline attention Step 1 attention MoE in both
Prefill TP4 Interleaved CP4 EP4
Decode TP4 DP4 attention and LM head EP4

这一步中,平均 TTFT 从 12.04 秒降至 5.16 秒。平均 TPOT 从 3.20 毫秒升至 4.79 毫秒。Mean TTFT fell from 12.04 s to 5.16 s in this step. Mean TPOT rose from 3.20 to 4.79 ms.

服务结果。平均端到端耗时从 13,633.80 ms 降至 7,547.46 ms(−44.64%)。输出吞吐量从 846.76 tokens/s 提升至 1,537.90 tokens/s(+81.62%)。Serving result. Mean E2E went from 13,633.80 to 7,547.46 ms (−44.64%). Output throughput rose from 846.76 to 1,537.90 tokens/s (+81.62%).

2. 用于 Prefill 索引器的 FP8 DeepGEMM2. FP8 DeepGEMM for the Prefill Indexer

Indexer 会在选择少量键用于注意力计算之前,为可见键打分。在 Hopper 上,我们会为每个请求一次性收集打包的 FP4 键,将查询和键转换为 FP8 E4M3,并在每个预填充阶段的 Indexer 层中调用 DeepGEMM 的 fp8_mqa_logits。每个查询仍然只能访问其因果掩码和候选集合所允许的键。The Indexer scores visible keys before selecting a small subset for attention. On Hopper, we gather each request’s packed FP4 keys once, convert queries and keys to FP8 E4M3, and call DeepGEMM’s fp8_mqa_logits in each prefill Indexer layer. Each query can still see only the keys allowed by its causal mask and candidate set.

查询已经过 FP4 伪量化,因此我们将其转换为 E4M3,而不再应用额外的缩放。对于键,我们在 FP32 中应用 FP4 块的 2 的幂次缩放,并在转换前将数值钳制到 −448 至 +448。这样可以确保超出范围的数值仍为有限值。DeepGEMM 使用单位键缩放,因为块缩放已应用。The queries are already FP4 fake-quantized, so we cast them to E4M3 without applying another scale. For keys, we apply the FP4 block’s power-of-two scale in FP32 and clamp to −448 to +448 before casting. This keeps out-of-range values finite. DeepGEMM gets unit key scales because the block scales are already applied.

二的幂次缩放能够保留可精确表示的值。超出范围的键值会饱和,非常小的值可能会被舍入或发生下溢,而评分精度的变化可能会影响排名。在一次独立的预填充探测中,我们针对一个 64K 提示词,对 8 个 Indexer 层中的 64 行查询进行了采样。采样的 16,774,528 个键值中,没有一个需要截断。在这些相同行上,BF16 和 DeepGEMM 评分器选出的 top-k 条目有 99.08% 相同。The power-of-two scaling preserves exactly representable values. Out-of-range keys saturate, very small values can round or underflow, and the change in scoring precision can affect rankings. In a separate prefill probe on a 64K prompt, we sampled 64 query rows across 8 Indexer layers. None of the 16,774,528 sampled key values needed clamping. The BF16 and DeepGEMM scorers shared 99.08% of the selected top-k entries on those same rows.

Torch scores in BF16; DeepGEMM scores in E4M3 after scaling and clamping the FP4 keys

服务结果。平均 E2E 从 7,547.46 ms 降至 5,294.89 ms(−29.85%)。输出吞吐量从 1,537.90 tokens/s 提升至 2,200.82 tokens/s(+43.11%)。SGLang PR #49066Serving result. Mean E2E went from 7,547.46 to 5,294.89 ms (−29.85%). Output throughput rose from 1,537.90 to 2,200.82 tokens/s (+43.11%). SGLang PR #49066

3. 用于预填充的可中断 CUDA 图屑3. Breakable CUDA Graphs for Prefill

长 prefill 运行会启动许多小型内核。可中断 CUDA Graph 会捕获图安全的代码段并将它们一起重放,而需要实时元数据的操作则仍以 eager 模式运行。有界滑动窗口注意力(SWA)重放会在较短的解码器尾部运行后期层,并在整个扫描过程中保持启用。固定的实验分支支持与可中断图配合使用的交错式 prefill CP,并通过将尾部捕获到单独的图桶中实现有界重放。这种组合需要使用实验分支。实验分支实现:SGLang PR #40333、SGLang PR #43089。Long prefill runs launch many small kernels. Breakable CUDA Graphs capture the graph-safe stretches and replay them together, while operations that need live metadata stay eager. Bounded sliding-window attention (SWA) replay runs the late layers on the shorter decoder tail and stays enabled throughout the sweep. The pinned experiment branch supports interleaved prefill CP with breakable graphs and bounded replay by capturing the tail in separate graph buckets. This combination requires the experiment branch. Experiment branch implementation, SGLang PR #40333, SGLang PR #43089.

在步骤 3 中,捕获大小为 8,192 个 token、图上下文上限为 262,144 个 token 时,启动日志报告每个预填充 rank 占用 14.53–14.59 GB 的捕获内存,捕获耗时约 388 秒。上下文上限限制了捕获缓冲区的大小。SGLang PR #36534At step 3, with an 8,192-token capture size and a 262,144-token graph context cap, startup logs reported 14.53–14.59 GB of capture memory per prefill rank and about 388 s to capture. The context cap limits the size of capture buffers. SGLang PR #36534

服务结果。端到端平均耗时从 5,294.89 毫秒降至 5,100.87 毫秒(−3.66%)。输出吞吐量从 2,200.82 tokens/s 提升至 2,290.05 tokens/s(+4.05%)。Serving result. Mean E2E went from 5,294.89 to 5,100.87 ms (−3.66%). Output throughput rose from 2,200.82 to 2,290.05 tokens/s (+4.05%).

4. 张量并行 MoE4. Tensor-Parallel MoE

专家并行会将不同的专家分配到不同的 rank。当路由偏向少数几个专家时,这些专家所在的 rank 需要处理更多工作,而其他 rank 则会在 collective 处等待。张量并行 MoE 会将每个专家切分到全部四个 rank 上,因此路由不均衡不会再导致某一块 GPU 承担比其他 GPU 更多的专家计算工作。Expert parallelism assigns different experts to different ranks. When routing favors a few experts, their ranks do more work and the other ranks wait at the collective. Tensor-parallel MoE shards each expert across all four ranks, so uneven routing no longer puts more expert work on one GPU than another.

在单独的解码性能分析配置中,较早到达的 EP rank 在一次 all-reduce 时花了约 100 µs 等待较晚到达的 rank。在该配置中,TP 使专家 GEMM 略微变慢,但总验证时间基本不变。在预填充阶段,尽管 TP 下的专家 GEMM 更慢,下面分析的两个批次使用 EP 耗时 771 ms,使用 TP 则耗时 657 ms。In a separate decode profile, an early EP rank spent about 100 µs waiting for a late rank at an all-reduce. TP made the expert GEMMs slightly slower in that profile and left total verification time roughly unchanged. In prefill, the two profiled batches below took 771 ms with EP and 657 ms with TP despite slower expert GEMMs with TP.

Expert parallelExpert-parallel prefill timeline showing 770.7 ms for five requests and 16,119 tokens.
Tensor parallelTensor-parallel prefill timeline showing 656.5 ms for five requests and 16,104 tokens.
Separate prefill trace samples, both with five requests and about 16K tokens.

我们将其与使用 --moe-a2a-backend none 的 EP 进行了比较。该配置不支持 DeepEP 或 MegaMoE 的全对全通信。未来,我们计划测试启用全对全通信和专家并行负载均衡(EPLB)的 EP,目标是在保留更快 GEMM 的同时,平衡各 GPU 之间的工作负载。We compared against EP with --moe-a2a-backend none. This setup did not support DeepEP or MegaMoE all-to-all. In future work, we plan to test EP with all-to-all and expert parallel load balancing (EPLB), aiming to keep the faster GEMMs while balancing workload across GPUs.

服务结果。端到端平均延迟从 5,100.87 毫秒降至 4,811.81 毫秒(−5.67%)。输出吞吐量从 2,290.05 token/s 提升至 2,425.96 token/s(+5.93%)。Serving result. Mean E2E went from 5,100.87 to 4,811.81 ms (−5.67%). Output throughput rose from 2,290.05 to 2,425.96 tokens/s (+5.93%).

5. 更大的索引器评分卡片5. Larger Indexer Score Tiles

索引器会限制其临时得分矩阵的大小。对于 16K 个压缩键,64 MiB 的预算可容纳约 1,000 行查询,因此更大的批次需要在多个分块上重复执行打分和选择。将预填充上限提高到 2 GiB 后,更多行可以共用一个分块。此上限按 rank 计算,打分器在处理分块期间会占用这部分空间。使用 --mem-fraction-static 0.8 时,预填充 KV 容量保持为 1,945,088 个 token。The Indexer limits the size of its temporary score matrix. With 16K compressed keys, the 64 MiB budget fits about 1,000 query rows, so a larger batch repeats scoring and selection across tiles. Raising the prefill limit to 2 GiB lets more rows share a tile. The limit is per rank and the scorer uses the space while processing the tile. Prefill KV capacity stayed at 1,945,088 tokens with --mem-fraction-static 0.8.

服务结果。平均端到端耗时从 4,811.81 毫秒降至 4,773.97 毫秒(−0.79%),处于不同运行间的波动范围内。SGLang PR #49067Serving result. Mean E2E went from 4,811.81 to 4,773.97 ms (−0.79%), within the run-to-run variation. SGLang PR #49067

6. 融合预填选择与回写6. Fuse Prefill Selection and Writeback

Indexer 需要同时为后续层获取候选块 ID,并为注意力机制获取物理 KV 槽位。Triton 根据块的最高分数进行选择。对于较小的输入,它在一次启动中完成归约和选择;对于较宽的输入,则先并行归约,再进行选择。另一个独立的融合回写操作会过滤无效选项、对剩余位置排序,并在一次启动中将它们转换为 KV 槽位。选择器使用相同的分数,但在分数相同时可能会选出不同的块 ID。它会优先选择较小的块 ID,而 Torch topk 不保证平分时的顺序稳定。The Indexer needs both candidate block IDs for later layers and physical KV slots for attention. Triton selects blocks from their maximum scores. It reduces and selects in one launch on smaller inputs, and reduces in parallel before selecting on wider inputs. A separate fused writeback filters invalid picks, sorts the remaining positions, and translates them to KV slots in one launch. The selector uses the same scores and can pick different block IDs at ties. Its tie-break favors lower block IDs, while Torch topk does not promise a stable tie order.

Triton reduces the work for candidate publishing and fuses KV-slot writeback into one launch

服务结果。启用融合后,45 次运行的平均 TTFT 从 1,838.15 ms 降至 1,802.77 ms(−1.92%)。平均端到端延迟保持在约 4.77 s。SGLang PR #49069Serving result. Mean TTFT fell from 1,838.15 to 1,802.77 ms (−1.92%). Mean E2E stayed around 4.77 s across 45 runs with fusion enabled. SGLang PR #49069

7. 在验证期间重用分页索引器的 K 个图块7. Reuse Paged Indexer K Tiles During Verification

DSpark 在一次前向传递中验证同一请求中的多条查询行。这些查询行访问的键几乎相同。分页评分器将一个 FP4 K 瓦片加载并反量化为 BF16,然后在该请求的各条查询行之间重复使用。每一行仍会应用各自的因果限制。DSpark verifies several query rows from the same request in one forward pass. Those rows look at nearly the same keys. The paged scorer loads and dequantizes one FP4 K tile into BF16, then reuses it for the request’s query rows. Each row still applies its own causal limit.

Verify queries switch from one load and dequantization each to one shared BF16 key tile

推理服务结果。平均 TPOT 从 5.96 ms 降至 5.62 ms,平均 E2E 从 4,774.47 ms 降至 4,698.65 ms(−1.59%)。输出吞吐量提升了 0.99%。SGLang PR #49068Serving result. Mean TPOT fell from 5.96 to 5.62 ms, and mean E2E fell from 4,774.47 to 4,698.65 ms (−1.59%). Output throughput rose by 0.99%. SGLang PR #49068

后续测量Follow-up Measurements

对于步骤 4–7,为排除稳定性的影响,表中报告了并发数为 24 时所有已完成运行的均值和样本标准差。在这些步骤中,单次运行的平均 E2E 波动约为 1–1.6%。For Steps 4–7, in order to rule out the influence of steadiness the table reports the mean and sample standard deviation across all completed runs at concurrency 24. A single run’s mean E2E varied by roughly 1–1.6% at these steps.

Step Runs Mean E2E (ms) Output (tok/s) Mean TTFT (ms) Mean TPOT (ms)
4. TP MoE 3 4,811.81 ± 77.13 2,425.96 ± 38.96 1,877.23 ± 84.20 5.88 ± 0.31
5. Larger prefill score tiles 6 4,773.97 ± 53.94 2,450.67 ± 26.56 1,838.15 ± 23.77 5.88 ± 0.14
6. Prefill selection fusion 45 4,774.47 ± 48.24 2,440.68 ± 30.41 1,802.77 ± 40.21 5.96 ± 0.14
7. Paged K-tile reuse 6 4,698.65 ± 47.73 2,464.90 ± 43.53 1,894.54 ± 58.59 5.62 ± 0.18

我们还在相同的 256 个请求负载下调整了并发数,并验证了我们的优化在其他类型负载中的效果。We also varied concurrency on the same 256-request workload and verified the effectiveness of our opt on other types of workload.

Concurrency TP4 E2E (ms) Final E2E (ms) TP4 output (tok/s) Final output (tok/s)
8 4,798.86 2,690.09 826.73 1,462.65
16 9,178.42 3,678.99 854.19 2,121.03
24 13,563.03 4,698.65 853.98 2,464.90
32 17,843.62 6,097.87 852.97 2,502.19

8. 共置服务优化8. Colocate Serving Optimization

我们在一台配备四块 GPU 的工作节点上使用 DSpark,以 24 路并发运行了相同的请求负载。与 BF16 TP4 基线相比,平均端到端时间从 18.62 秒降至 7.96 秒(降低 57.26%),输出吞吐量则从 642 tokens/s 提升至 1,483 tokens/s(提高 130.79%)。We ran the same request workload at concurrency 24 on a single four-GPU worker with DSpark. Compared with the BF16 TP4 baseline, mean E2E fell from 18.62 s to 7.96 s (57.26% lower), and output throughput rose from 642 to 1,483 tokens/s (130.79% higher).

Cumulative configuration Mean E2E (ms) Output (tok/s)
TP baseline (BF16 prefill Indexer) 18,619.53 642.46
Prefill CP, decode TP (BF16 prefill Indexer) 12,499.25 (-33%) 949.97
FP8 DeepGEMM 9,727.21 (-22%) 1,222.38
Breakable CUDA Graphs 9,418.85 (-3%) 1,256.71
Paged K-tile reuse 8,694.89 (-8%) 1,367.96
Tensor-parallel MoE 8,632.46 (-1%) 1,377.49
Batch-wise prefill CP and decode DP 7,957.13 (-8%) 1,482.72

我们在同一个 worker 中加入了按批次划分的 prefill CP 和 decode DP。Prefill 仍将提示词 token 分配到四个 rank 上。在 decode 和目标验证期间,每个 rank 则处理一部分批次,并使用全部注意力头;随后 worker 会收集结果,并按批次顺序重新排列。We added batch-wise prefill CP and decode DP to the same worker. Prefill still splits prompt tokens across four ranks. During decode and target verification, each rank instead handles a slice of the batches with all attention heads, and the worker gathers the results back into batch order.

Both colocated configurations split prefill tokens; decode switches from splitting heads to splitting query rows

在 prefill CP 配置中加入 decode DP 后,平均端到端延迟降低了 7.82%,输出吞吐量提高了 7.64%。Decode DP 需要复制 KV 和 Indexer 键。使用相同的 --max-running-requests 64 时,启动日志显示,decode TP 下有 955,136 个 KV token 槽位,decode DP 下有 953,088 个。这些数量衡量的是 KV 池容量。支持的并发数还取决于活动序列的长度。SGLang PR #45729Adding decode DP to the prefill CP configuration cut mean E2E by 7.82% and raised output throughput by 7.64%. Decode DP requires replicated KV and Indexer keys. With the same --max-running-requests 64, the startup log reported 955,136 KV token slots with decode TP and 953,088 with decode DP. Those counts measure the KV pool. The supported concurrency also depends on the length of live sequences. SGLang PR #45729

对于此工作负载,共置配置的每 GPU 每秒输出令牌数更高(371 对 308)。八 GPU 的 PD 配置平均延迟更低(4.70 对 7.96 秒),总吞吐量也更高。For this workload, the colocated configuration produced more output tokens per second per GPU (371 vs. 308). The eight-GPU PD configuration delivered lower mean latency (4.70 vs. 7.96 s) and higher total throughput.

复现Reproduction

使用公共分支 SYChen123/sglang:v4.1/h20-dev-pd-blog 上的提交 b07c70112c175eb7ca3c157c7bbc7847cc398d7d。命令使用 DeepSeek-V4.1-Flash 检查点。H20 后续实验环境使用 PyTorch 2.14.1、Triton 3.8.0、sgl-deep-gemm==0.2.2、humming-kernels==0.1.12、mooncake-transfer-engine-cuda13==0.3.10.post2 和 sglang-router==0.3.2。在实验分支上,SGLANG_DSV41_TORCH_PREFILL_INDEXER=1 会选择 BF16 Torch 评分。要在 Hopper 上使用 FP8 DeepGEMM,请将其设为 0,并选择 SGLANG_DSV41_SM90_PREFILL_INDEXER=deepgemm。Use commit b07c70112c175eb7ca3c157c7bbc7847cc398d7d on the public SYChen123/sglang:v4.1/h20-dev-pd-blog branch. The commands use the DeepSeek-V4.1-Flash checkpoint. The H20 follow-up environment used PyTorch 2.14.1, Triton 3.8.0, sgl-deep-gemm==0.2.2, humming-kernels==0.1.12, mooncake-transfer-engine-cuda13==0.3.10.post2, and sglang-router==0.3.2. On the experiment branch, SGLANG_DSV41_TORCH_PREFILL_INDEXER=1 selects BF16 Torch scoring. To use FP8 DeepGEMM on Hopper, set it to 0 and select SGLANG_DSV41_SM90_PREFILL_INDEXER=deepgemm.

步骤 2 和 5–7 以及共置解码 DP 仍在上游评审中。四个 Indexer PR 分支的各自开关名称与下方消融表中的名称相同。请在固定的实验修订版本上运行这些命令;该版本还支持使用可中断计算图的 prefill CP 和有界 SWA 重放。FP8 DeepGEMM、分数预算、选择融合、K-tile 复用、共置解码 DP。Steps 2 and 5–7 and colocated decode DP are still under upstream review. The four Indexer PR branches use the same names for their respective switches as the ablation table below. Run these commands on the pinned experiment revision, which also supports prefill CP with breakable graphs and bounded SWA replay. FP8 DeepGEMM, score budget, selection fusion, K-tile reuse, colocated decode DP.

细分基线Disaggregated baseline

在同一台配备八块 GPU 的主机上,分别在不同终端中运行预填充和解码。Run prefill and decode in separate terminals on the same eight-GPU host.

Start baseline prefill (GPUs 0–3)
CUDA_VISIBLE_DEVICES=0,1,2,3 SGLANG_DSV41_TORCH_PREFILL_INDEXER=1 \
SGLANG_ENABLE_DSV41_ENGRAM_HOST_TABLE=1 SGLANG_DSV41_ENGRAM_HOST_TABLE_LAYOUT=per_rank \
SGLANG_HUMMING_INPUT_QUANT_CONFIG='{"dtype":"float8e4m3"}' \
SGLANG_HOST_IP=127.0.0.1 SGLANG_MOONCAKE_CUSTOM_MEM_POOL=INTRA_NODE_NVLINK \
MC_INTRA_NVLINK=true MC_INTRANODE_NVLINK=true SGLANG_SET_CPU_AFFINITY=1 \
SGLANG_JIT_DEEPGEMM_FAST_WARMUP=1 SGLANG_DISAGGREGATION_ALL_CP_RANKS_TRANSFER=1 \
SGLANG_OPT_DSV41_TRITON_PREFILL_SELECTION=0 SGLANG_OPT_DSV41_LARGE_INDEXER_SCORE_BUDGET=0 \
sglang serve --model-path deepseek-ai/DeepSeek-V4.1-Flash --served-model-name llm \
  --host 127.0.0.1 --port 9091 --trust-remote-code --language-model-only \
  --attention-backend dsv4 --tp 4 --ep-size 4 --moe-runner-backend humming --moe-a2a-backend none \
  --speculative-algorithm DSPARK --speculative-dspark-block-size 5 --enable-cache-report \
  --chunked-prefill-size 8192 --max-prefill-tokens 8192 --disable-prefill-cuda-graph \
  --enable-decoder-swa-bounded-replay --swa-full-tokens-ratio 0.1 --mem-fraction-static 0.8 \
  --tokenizer-worker-num 8 --detokenizer-worker-num 8 \
  --disaggregation-mode prefill --disaggregation-transfer-backend mooncake \
  --disaggregation-bootstrap-port 8998
Start baseline decode (GPUs 4–7)
CUDA_VISIBLE_DEVICES=4,5,6,7 \
SGLANG_ENABLE_DSV41_ENGRAM_HOST_TABLE=1 SGLANG_DSV41_ENGRAM_HOST_TABLE_LAYOUT=per_rank \
SGLANG_HUMMING_INPUT_QUANT_CONFIG='{"dtype":"float8e4m3"}' \
SGLANG_HOST_IP=127.0.0.1 SGLANG_MOONCAKE_CUSTOM_MEM_POOL=INTRA_NODE_NVLINK \
MC_INTRA_NVLINK=true MC_INTRANODE_NVLINK=true SGLANG_SET_CPU_AFFINITY=1 \
SGLANG_JIT_DEEPGEMM_FAST_WARMUP=1 SGLANG_DISAGGREGATION_ALL_CP_RANKS_TRANSFER=1 \
SGLANG_OPT_DSV41_VERIFY_INDEXER_BF16_K_REUSE=0 SGLANG_OPT_DSV41_LARGE_INDEXER_SCORE_BUDGET=0 \
sglang serve --model-path deepseek-ai/DeepSeek-V4.1-Flash --served-model-name llm \
  --host 127.0.0.1 --port 9092 --trust-remote-code --attention-backend dsv4 \
  --tp 4 --ep-size 4 --moe-runner-backend humming --moe-a2a-backend none \
  --speculative-algorithm DSPARK --speculative-dspark-block-size 5 --enable-cache-report \
  --mem-fraction-static 0.85 --max-running-requests 256 \
  --tokenizer-worker-num 8 --detokenizer-worker-num 8 \
  --disaggregation-mode decode --disaggregation-transfer-backend mooncake

解耦优化的Disaggregated optimized

Start optimized prefill (GPUs 0–3)
CUDA_VISIBLE_DEVICES=0,1,2,3 SGLANG_DSV41_TORCH_PREFILL_INDEXER=0 \
SGLANG_DSV41_SM90_PREFILL_INDEXER=deepgemm \
SGLANG_ENABLE_DSV41_ENGRAM_HOST_TABLE=1 SGLANG_DSV41_ENGRAM_HOST_TABLE_LAYOUT=per_rank \
SGLANG_HUMMING_INPUT_QUANT_CONFIG='{"dtype":"float8e4m3"}' \
SGLANG_HOST_IP=127.0.0.1 SGLANG_MOONCAKE_CUSTOM_MEM_POOL=INTRA_NODE_NVLINK \
MC_INTRA_NVLINK=true MC_INTRANODE_NVLINK=true SGLANG_SET_CPU_AFFINITY=1 \
SGLANG_JIT_DEEPGEMM_FAST_WARMUP=1 SGLANG_DISAGGREGATION_ALL_CP_RANKS_TRANSFER=1 \
SGLANG_OPT_DSV41_TRITON_PREFILL_SELECTION=1 SGLANG_OPT_DSV41_LARGE_INDEXER_SCORE_BUDGET=0 \
SGLANG_OPT_DSV41_LARGE_PREFILL_SCORE_BUDGET=1 \
sglang serve --model-path deepseek-ai/DeepSeek-V4.1-Flash --served-model-name llm \
  --host 127.0.0.1 --port 9091 --trust-remote-code --language-model-only \
  --attention-backend dsv4 --tp 4 --ep-size 1 --moe-runner-backend humming --moe-a2a-backend none \
  --speculative-algorithm DSPARK --speculative-dspark-block-size 5 --enable-cache-report \
  --chunked-prefill-size 8192 --max-prefill-tokens 8192 --enable-prefill-cp --cp-strategy interleave \
  --cuda-graph-backend-prefill breakable --cuda-graph-max-bs-prefill 8192 --cuda-graph-prefill-max-context 262144 \
  --enable-decoder-swa-bounded-replay --swa-full-tokens-ratio 0.1 --mem-fraction-static 0.8 \
  --tokenizer-worker-num 8 --detokenizer-worker-num 8 --disaggregation-mode prefill \
  --disaggregation-transfer-backend mooncake --disaggregation-bootstrap-port 8998
Start optimized decode (GPUs 4–7)
CUDA_VISIBLE_DEVICES=4,5,6,7 \
SGLANG_ENABLE_DSV41_ENGRAM_HOST_TABLE=1 SGLANG_DSV41_ENGRAM_HOST_TABLE_LAYOUT=per_rank \
SGLANG_HUMMING_INPUT_QUANT_CONFIG='{"dtype":"float8e4m3"}' \
SGLANG_HOST_IP=127.0.0.1 SGLANG_MOONCAKE_CUSTOM_MEM_POOL=INTRA_NODE_NVLINK \
MC_INTRA_NVLINK=true MC_INTRANODE_NVLINK=true SGLANG_SET_CPU_AFFINITY=1 \
SGLANG_JIT_DEEPGEMM_FAST_WARMUP=1 SGLANG_DISAGGREGATION_ALL_CP_RANKS_TRANSFER=1 \
SGLANG_OPT_DSV41_VERIFY_INDEXER_BF16_K_REUSE=1 SGLANG_OPT_DSV41_LARGE_INDEXER_SCORE_BUDGET=1 \
sglang serve --model-path deepseek-ai/DeepSeek-V4.1-Flash --served-model-name llm \
  --host 127.0.0.1 --port 9092 --trust-remote-code --attention-backend dsv4 \
  --tp 4 --dp 4 --enable-dp-attention --enable-dp-lm-head \
  --ep-size 1 --moe-runner-backend humming --moe-a2a-backend none \
  --speculative-algorithm DSPARK --speculative-dspark-block-size 5 --enable-cache-report \
  --mem-fraction-static 0.85 --max-running-requests 256 \
  --tokenizer-worker-num 8 --detokenizer-worker-num 8 \
  --disaggregation-mode decode --disaggregation-transfer-backend mooncake

PD 路由器PD router

两个工作进程都健康运行后,启动路由器。Start the router once both workers are healthy.

Start the PD router
python3 -m sglang_router.launch_router --pd-disaggregation \
  --prefill http://127.0.0.1:9091 8998 --decode http://127.0.0.1:9092 \
  --host 127.0.0.1 --port 9090 --worker-startup-timeout-secs 3600 \
  --disable-circuit-breaker --prefill-policy round_robin --decode-policy round_robin

PD消融实验PD ablations

这篇博客中的消融实验从 PD 基线开始,并按顺序应用各项更改。除非某一行明确更改了基线设置,否则都保持不变。解码预算仅在实验分支的第 5 步发生变化。The ablation experiments in this blog start with the PD baseline and apply the changes in order. Keep the baseline settings unless a row changes them. The decode budget changes in Step 5 only on the experiment branch.

PD ablation guide
Step Worker Change from the previous step
1. CP + DP Both Prefill adds --enable-prefill-cp --cp-strategy interleave. Decode adds --dp 4 --enable-dp-attention --enable-dp-lm-head.
2. DeepGEMM Prefill Set SGLANG_DSV41_TORCH_PREFILL_INDEXER=0 and SGLANG_DSV41_SM90_PREFILL_INDEXER=deepgemm.
3. BCG Prefill Replace --disable-prefill-cuda-graph with --cuda-graph-backend-prefill breakable --cuda-graph-max-bs-prefill 8192 --cuda-graph-prefill-max-context 262144.
4. TP MoE Both Set --ep-size 1.
5. Larger score tiles Both On prefill, set SGLANG_OPT_DSV41_LARGE_PREFILL_SCORE_BUDGET=1. On decode, set SGLANG_OPT_DSV41_LARGE_INDEXER_SCORE_BUDGET=1 to move from 128 to 512 MiB.
6. Selection fusion Prefill Set SGLANG_OPT_DSV41_TRITON_PREFILL_SELECTION=1.
7. Paged K-tile reuse Decode Set SGLANG_OPT_DSV41_VERIFY_INDEXER_BF16_K_REUSE=1.

共置基线Colocated baseline

四 GPU 工作进程直接监听基准测试端口。The four-GPU worker listens on the benchmark port directly.

Start the colocated baseline
CUDA_VISIBLE_DEVICES=0,1,2,3 \
SGLANG_ENABLE_DSV41_ENGRAM_HOST_TABLE=1 SGLANG_DSV41_ENGRAM_HOST_TABLE_LAYOUT=per_rank \
SGLANG_OPT_DSV41_TRITON_PREFILL_SELECTION=0 SGLANG_OPT_DSV41_LARGE_INDEXER_SCORE_BUDGET=0 \
SGLANG_HUMMING_INPUT_QUANT_CONFIG='{"dtype":"float8e4m3"}' \
SGLANG_DSV41_TORCH_PREFILL_INDEXER=1 SGLANG_OPT_DSV41_VERIFY_INDEXER_BF16_K_REUSE=0 \
sglang serve --model-path deepseek-ai/DeepSeek-V4.1-Flash --served-model-name llm \
  --host 127.0.0.1 --port 9090 --trust-remote-code --attention-backend dsv4 \
  --tp 4 --ep-size 4 --moe-runner-backend humming --moe-a2a-backend none \
  --speculative-algorithm DSPARK --speculative-dspark-block-size 5 --enable-cache-report \
  --chunked-prefill-size 8192 --max-prefill-tokens 8192 --disable-prefill-cuda-graph \
  --enable-decoder-swa-bounded-replay --cuda-graph-max-bs-decode 64 \
  --mem-fraction-static 0.8 --max-running-requests 64 \
  --enable-hierarchical-cache --hicache-ratio 2 --hicache-io-backend kernel --hicache-write-policy write_through

共置优化Colocated optimized

Start the optimized colocated worker
CUDA_VISIBLE_DEVICES=0,1,2,3 \
SGLANG_ENABLE_DSV41_ENGRAM_HOST_TABLE=1 SGLANG_DSV41_ENGRAM_HOST_TABLE_LAYOUT=per_rank \
SGLANG_OPT_DSV41_TRITON_PREFILL_SELECTION=0 SGLANG_OPT_DSV41_LARGE_INDEXER_SCORE_BUDGET=0 \
SGLANG_HUMMING_INPUT_QUANT_CONFIG='{"dtype":"float8e4m3"}' \
SGLANG_DSV41_TORCH_PREFILL_INDEXER=0 SGLANG_DSV41_SM90_PREFILL_INDEXER=deepgemm \
SGLANG_OPT_DSV41_VERIFY_INDEXER_BF16_K_REUSE=1 \
sglang serve --model-path deepseek-ai/DeepSeek-V4.1-Flash --served-model-name llm \
  --host 127.0.0.1 --port 9090 --trust-remote-code --attention-backend dsv4 \
  --tp 4 --ep-size 1 --moe-runner-backend humming --moe-a2a-backend none \
  --speculative-algorithm DSPARK --speculative-dspark-block-size 5 --enable-cache-report \
  --chunked-prefill-size 8192 --max-prefill-tokens 8192 --enable-prefill-cp --cp-strategy interleave \
  --enable-cp-decode-attn-tp --cp-decode-attn-mode dp --enable-decoder-swa-bounded-replay \
  --cuda-graph-backend-prefill breakable --cuda-graph-max-bs-prefill 8192 --cuda-graph-prefill-max-context 262144 \
  --cuda-graph-max-bs-decode 64 --mem-fraction-static 0.8 --max-running-requests 64 \
  --enable-hierarchical-cache --hicache-ratio 2 --hicache-io-backend kernel --hicache-write-policy write_through

基准测试Benchmark

Run the serving benchmark
python3 -m sglang.bench_serving --model deepseek-ai/DeepSeek-V4.1-Flash \
  --served-model-name llm --host 127.0.0.1 --port 9090 --backend sglang-oai \
  --dataset-name generated-shared-prefix \
  --num-prompts 256 --gsp-num-groups 1 --gsp-prompts-per-group 256 \
  --gsp-system-prompt-len 61440 --gsp-question-len 4096 --gsp-output-len 500 \
  --max-concurrency 24 --warmup-requests 10 --seed 42 --flush-cache --cache-report

GSM8K 准确率GSM8K accuracy

两种配置都使用 PD 路由器上的 chat 端点。在工作节点上启用 --reasoning-parser deepseek-v41 --enable-strict-thinking。评估器使用五个问题作为少样本示例,并对剩余的 1,314 个问题进行评分。Use the chat endpoint on the PD router for both configurations. Enable --reasoning-parser deepseek-v41 --enable-strict-thinking on the workers. The evaluator takes five questions for few-shot examples and scores the remaining 1,314.

Run GSM8K
python3 -m sglang.test.run_eval --eval-name gsm8k --api chat --num-examples 1319 \
  --host 127.0.0.1 --port 9090 --num-threads 256 --reasoning-effort high
PD configuration GSM8K 64K retrieval DSpark tokens / verify
TP4 baseline 96.50% (1,268/1,314) 10/10 5.368
Final 96.42% (1,267/1,314) 10/10 5.460

值得记下

  1. 与 TP4 相比,最终配置将端到端平均延迟降低了 65.5%,输出吞吐量达到其 2.91×。
  2. FP8 DeepGEMM 评分器与 BF16 评分器选出的 top-k 条目有 99.08% 相同,表明即使精度更低,其结果仍具有很高的保真度。
  3. 最终的共置配置实现了更高的单 GPU 每秒输出 token 数(371 vs. 308),体现了优化后流水线的效率。