Prefill-Decode Resource Divergence(Prefill vs Decode 资源分歧)
定义
LLM 推理的两个阶段——Prefill 和 Decode——对硬件资源的需求正交:Prefill 是 compute-bound,Decode 是 memory-bandwidth-bound。Reasoning-centric 工作负载(OSL ≫ 10k)将 >99% wall-clock time 花在 decode,使系统长期处于低 arithmetic intensity 的低效状态。
两阶段特性对比
| Dimension | Prefill | Decode |
|---|---|---|
| Compute Type | Matrix-Matrix (GEMM) + tiled attention | Matrix-Vector (GEMV) |
| Attention Kernel | FlashAttention / FlashAttention-2 / FlashAttention-3(IO-aware prefill;H100 FP8) | FlashDecoding / FlashDecoding++ |
| Arithmetic Intensity | High(reuse weights across all tokens) | 极低(每 token 读全部 weights + KV) |
| Bottleneck | Compute (FLOPS) | Memory Bandwidth + Capacity |
| SM Occupancy | High | Low / Variable |
| HBM BW Utilization | Low (≈20-30%) | High (≈85% for 8B) |
| Latency Proxy | TTFT | TPOT |
| Reasoning Share | <1% | >99% |
核心矛盾
同一加速器(如 H200)无法同时最优化两个阶段:
- Prefill 需要高 TFLOP tensor cores,HBM 带宽不是瓶颈
- Decode 需要高 HBM 带宽和容量,tensor cores 大量闲置
推理模型的出现使这一矛盾尖锐化:
- Standard chat(OSL ≈ 500):prefill 占比尚可
- Reasoning(OSL ≫ 10k):>99% 时间在 decode 的低效 regime
实测数据(H200)
Small Model (8B)
- Prefill: HBM BW util ≈30%, high SM occupancy
- Decode: HBM BW util ≈85%, variable SM occupancy
- 两者呈”两台不同机器”的行为
Frontier Model
- 405B Decode: HBM BW util ≈65% (weights reads dominate)
- 671B Decode: HBM BW util ≈50-60% (sync/routing latency, 非 bandwidth bound)
- 大模型 decode 的 low BW util 说明瓶颈已从纯带宽转向 sync 开销
Reasoning 的乘数效应
KV Cache 增长
- KV cache 线性增长 with OSL
- Decode KV 是 persistent(prefill KV 是 transient)
- 8B: 20M token aggregate output → 2 TB KV demand
- 405B: 1.05 MB/token → batch=1K with long context = 100% saturation
Agentic AI 进一步放大
Agent 工作负载将推理从单条长链变为多步有状态执行:
- Planner / executor / verifier / retrieval / tool calls 各维护 KV state
- Fan-out × branching depth × tool interaction → multiplicative memory demand
- CPU-GPU tight coupling:CPU 维持 agent environments, tool execution, per-agent state
- 瓶颈从 isolated GPU → system-wide(HBM + host DRAM 同时受压)
硬件解耦方向
论文提出将 prefill 和 decode 物理解耦到不同硬件:
Prefill Tier
- 高 TFLOP accelerators(compute-optimized)
- Moderate HBM bandwidth 即可
- 可以接受 cost-optimized memory subsystem
Decode Tier
- Memory-centric hierarchy
- HBM → DDR/LP → CXL → NVMe tiered KV placement
- 3D-stacked memory(如 D-Matrix SRAM-based)缓解 KV read bandwidth
- HBF (High-Bandwidth Flash):增容但有 read/write asymmetry + power 挑战
3D-stacked AI chip 视角(Voxel 论文)
Voxel 在 3D-Stacked AI Chip 上量化了两阶段对设计旋钮的不同响应:
| 设计旋钮 | Prefill(compute/NoC-bound) | Decode(memory-bound) |
|---|---|---|
| DRAM 带宽 | 扩 BW 收益有限 | 显著降 latency,~10 TBps 后平台 |
| NoC 带宽 | 低于 32 B/cycle 显著拖慢 | 不敏感 |
| Per-core SRAM | 大 SRAM 收益有限(FLOPS 已饱和) | 大 SRAM 利于 prefetch,BW 饱和后递减 |
| Compute paradigm | compute-shift 相对 SPMD 46.73% 提升 | paradigm 差异仍存在但 NoC 非主瓶颈 |
| Core 数量 | 过多 core 加剧 bank 冲突 | 同上,能效可能下降 |
绑定互连
- NVLink + optical interconnects 跨 tier 低延迟
- Explicit KV placement, migration, proactive eviction
与现有概念的关联
这一发现为以下已有 wiki 概念提供了实证基础:
- Disaggregated Inference — Prefill/Decode 解耦是该概念的阶段层变体
- Heterogeneous Inference — 不同阶段用不同硬件是异构推理的核心动机
- Inference Capacity Trap — Decode 阶段是 capacity trap 的主战场
- Reasoning Cliff — Decode 的 KV 线性增长导致 cliff
- Parallelism Transition Point — 不同阶段的 optimal parallelism 不同(prefill: DP; decode: TP)
- DSpark Speculative Decoding — decode 步 speculative 提高有效 τ(DeepSeek-V4 生产 +57–85% tok/s/user)
- FlashDecoding++ — GPU kernel 层:异步 partial softmax + flat GEMM + 启发式 GEMV/GEMM dataflow(相对 FlashDecoding ~1.37×)
- FlashAttention — IO-aware 精确 attention 起源(NeurIPS 2022)
- FlashAttention-2 — prefill/训练 IO-aware attention(相对 FA ~2×,73% A100 峰值)
- FlashAttention-3 — Hopper 异步 + FP8(740 TFLOPs/s,相对 FA2 1.5–2×)
- 3D-Stacked AI Chip — 3D 堆叠缓解 BW wall,prefill/decode 对 DRAM/NoC/SRAM 响应不同
- WaferLLM System — 晶圆级 mesh:decode GEMV + KV shift vs GPU PagedAttention
- Linear Attention Evolution — 2026-07 Kimi K3 引入 KDA(O(1) 状态)替代 O(N) KV cache,从根本上改变 decode bandwidth 格局
- Moonshot AI Kimi K3 — K3 是首个用 KDA+MLA 混合架构大规模验证”decode 不再是 O(N) bandwidth-bound”的模型
- MOCAP Prefill Pipelining — prefill-only WSC:chunked pipeline 专攻长上下文 prefill
- GEMM vs GEMV in LLM Inference — 算子形状、算术强度、Roofline、Prefill/Decode 对应
- SSD and NVMe Storage System — KV spill 至 NVMe tier 的延迟与带宽
相关概念
- Disaggregated Inference — 模块层和阶段层的解耦推理
- Heterogeneous Inference — 异构硬件针对不同推理阶段
- Inference Capacity Trap — Decode 阶段的 KV 饱和问题
- Reasoning Cliff — KV 增长的时序行为
- FlashDecoding++ — decode kernel 层(attention/flat GEMM)
- FlashAttention — IO-aware 精确 attention 起源
- FlashAttention-2 — prefill/训练 attention kernel
- Superscalar CPU Research (2023-2026) — Constable/Prophet 与 memory-bound decode
- Constable Load Elimination — KV cache likely-stable load
- FlashAttention-3 — Hopper prefill/训练 + FP8
- WaferLLM System — WSE-2 上 MeshGEMV/decode 与 KV shift
- Kv Cache — KV cache 是 decode 阶段的核心资源
2026-09-24:弹性边界
Crossflow 显示静态 P/D 分池跟不上相位比波动(分钟 peak-to-mean 最高 4.7×;agentic 小时比中位 24.5×)。角色固定、边界用 decode 租约弹性化后,吞吐 geomean +16.2–17.4%。
Encode 第三轴(MLLM EPD,2026-09-29)
文本侧 Prefill/Decode 正交之外,EAServe 指出 MLLM Encode 再引入短前向、批–延迟敏感的第三轴:入口饥饿与 encode GPU 空转并存;仅加微批会淹没下游(Table 1)。Encode-aware 调度把入口利用率拉到约 80%,P99 TTFT(image, Λ=2)相对 Dynamo 233.8→10.8 s。
并行度也随阶段分歧(2026-10-07)
并行策略三分账(Dell,8×A100):prefill 下 TP8 约 40% TTFT 耗在 NCCL,PP 更优;decode 下 PP 气泡主导,TP 更优;decode 有效 NVLink 带宽仅 ~150 GB/s(理论 25%),延迟受限。PD 分离后两侧应各选并行度。
具身 VLA:瓶颈看动作张量形状(2026-10-07)
VLA 负载刻画(ASPLOS’27):batch-1 闭环下,去噪动作头 GEMM 落在 RTX 4090 屋脊点(163.9 FLOP/B)下方,骨干与视频 DiT 在上方——资源分歧由 动作张量维度 而非 prefill/decode 阶段决定;自回归 OpenVLA 的 6 次 cached decode 仍占 E2E 67%。
同一阵列按阶段换形状与量化(2026-10-08)
DynaCore 不拆两类芯片,而是让脉动阵列在 prefill(方阵、W8A8)与 decode(扁平 1×1024 + Split-K、W4A16)间逐批切换;vs FIGLUT TTFT 3.50×、TPOT 36.55×,精度相对 FP16 平均掉 0.07%。
Citations
[1] Understanding_Inference_Scaling_for_LLMs.pdf [2] arXiv:2609.31551 — EAServe [3] arXiv:2610.05305 — Parallelism compute–comm trade-offs [4] arXiv:2610.05062 — VLA workload characterization [5] arXiv:2610.07443 — DynaCore