Skip to content
🔗 分享本题
查看我的学习进度 →

推理框架专题第16题核心机制与工程取舍图解

🧠 图解记忆: Prefill 重计算、Decode 重带宽;规模够大且互联够快时,分池才可能产生真实收益。

💡 答案要点

背景问题:

  • Prefill阶段:计算密集型(大量矩阵运算),需要高算力
  • Decode阶段:访存密集型(带宽瓶颈),需要高带宽
  • 传统方案:Prefill和Decode混在同一个GPU上,互相干扰

PD分离解决方案:

传统方案(混合部署):
GPU A: [Prefill] [Decode] [Prefill] [Decode] → 互相争抢资源

PD分离方案( disaggregation):
GPU集群A(高算力): 专门处理所有Prefill请求
GPU集群B(高带宽): 专门处理所有Decode请求
      ↓                        ↓
  KV Cache传输 ←→ 高速网络(RDMA)

性能提升:

场景混合部署PD分离提升
长Prompt+短回复80 tok/s200 tok/s2.5x
短Prompt+长回复40 tok/s60 tok/s1.5x
高并发场景延迟抖动大稳定低延迟质量提升

适用场景:

  • 长上下文应用(RAG、知识库)
  • 高并发API服务
  • 追求稳定低延迟的生产环境

实现方案:

python
class DisaggregatedLLM:
    def __init__(self):
        self.prefill_cluster = PrefillEngine()   # A100/H100
        self.decode_cluster = DecodeEngine()     # H100/H200
        self.kv_transfer = RDMATransfer()       # 高速KV传输

    async def generate(self, prompt, max_tokens):
        # Step 1: Prefill(算力优先)
        prefill_result = await self.prefill_cluster.forward(prompt)

        # Step 2: 传输KV Cache(RDMA,高带宽)
        kv_cache = self.kv_transfer.send(prefill_result.kv_cache)

        # Step 3: Decode(带宽优先)
        tokens = [prefill_result.last_token]
        for _ in range(max_tokens):
            decode_result = await self.decode_cluster.forward(kv_cache, tokens[-1])
            tokens.append(decode_result.token)
            kv_cache = decode_result.kv_cache

        return tokens

面试话术:

"PD分离是2026年推理优化的重要方向。核心思想是'术业有专攻':Prefill吃算力,Decode吃带宽,把它们分开部署能最大化硬件效率。DeepSeek-V3和很多国产大厂都在用PD分离。面试时能说出PD分离的原理和适用场景,说明你对推理优化有实战理解。"

📚 参考:DistServe:Disaggregating Prefill and Decoding(PD 分离论文)