PrefillShare: A Shared Prefill Module for KV Reuse in Multi-LLM Disaggregated Serving

framework 2602.12029
disaggregated-servingkv-cache-reusemulti-agentprefix-cachingcache-conditioned-finetuning

PrefillShare: A Shared Prefill Module for KV Reuse in Multi-LLM Disaggregated Serving — L2 #

1. TL;DR #

在多模型 agent 工作流里,同一段共享上下文被每个专用模型各跑一遍 prefill 并各存一份 KV。PrefillShare 把模型拆成「冻结的共享 prefill 模块 + 各任务专用 decode 模块」,只用 cache-conditioned 微调训 decode 去读 base 的 KV,从而一次 prefill、一份 KV 跨模型复用。精度追平全量微调,p95 延迟降 4.5×、吞吐升 3.9×。


2. Q1 / Q2 / Q3 #

Q1 — 痛点 #

多智能体工作流常让多个专用模型(如 Planner → Coder → Reviewer)在同一份共享上下文上依次工作。但自回归推理里 KV cache 与模型参数强耦合:即便 prompt 完全相同,参数不同的两个模型 $M_i, M_j$($\theta_i \neq \theta_j$)在每一层产生的 key/value 表示都不同,缓存互不兼容。后果有二:

  1. 重复 prefill → 延迟恶化:每次切换模型都要重算 prefill,抬高 TTFT,并且在共享 serving stack 里 prefill 抢占正在 decode 的请求,制造 ITL 尖峰、恶化尾延迟。
  2. KV 重复存储 → 并发受限:每个模型各存一份整段 KV,内存随模型数 $N$ 线性膨胀,触发频繁 eviction 与 recompute。
  3. Disaggregated serving(把 prefill/decode 放到不同 GPU)能缓解 prefill-decode 干扰,但不能消除跨模型冗余——相同 prompt 在不同微调模型间仍然各算各存。作者自己的前作 ICaRus 虽然能做同 prompt KV 复用,但其 logical encoder 必须与 decode 同时运行,带来额外算力开销、高并发下扩展性差。

    Q2 — 方法 #

    将一个模型「分解」为两种推理角色:一个冻结的 base prefill 模块 $M_{\text{base}}$,只负责把共享上下文处理一次生成共享 KV cache $C_{\text{base}}$;以及多个任务专用 decode 模块 $M_{\text{dec}}$,各自消费同一份 $C_{\text{base}}$ 生成任务输出。关键的算法贡献是 cache-conditioned fine-tuning:冻结 prefill 模块,把 $C_{\text{base}}$ 当作常量条件信号,只微调 decode 模块去在这份「别人产生的 KV」上做 next-token 预测。系统侧再配一套 prefix-aware routing + cache handoff 管线,把请求按 User ID 钉在固定 prefill worker 上以保 prefix 局部性,跨模型切换时只做 partial prefill 增量扩展缓存。

    核心技术壁垒:让一个 decode 模块可靠地从另一套参数产生的 KV 表示上解码。朴素直接共享会在高共享比例下精度崩塌(Fig. 2)。PrefillShare 用「训练时就喂冻结 base 的 $C_{\text{base}}$」把训练分布与推理分布对齐,使 decode 学会对齐 base 的 KV 分布——这一 train-inference 一致性正是它能在 100% 共享下仍逼近全量微调精度的关键,且无需 base 与微调模型间的参数同步

    Q3 — 结果 #

    • 精度:在 math / coding / tool-calling 上,PrefillShare 与全量微调(Full-FT)差距在 1% 以内,且多处反超(如 Qwen3-8B HumanEval 83.5→86.6,HumanEval+ 74.3→80.5)。跨 1.7B/8B/14B 模型规模均稳定。
    • 服务:ReAct 上 p95 延迟降至 1/3.9、吞吐升 3.6×;Reflexion 上 p95 降至 1/4.5、吞吐升 3.9×。
    • 缓存命中:随并发上升,baseline 的 prefix cache hit ratio 峰值仅约 60% 后骤降(>40 并发),PrefillShare 稳定在近 89%。

    3. 架构 / 方法图 #

    3.1 系统范围(framework scope) #

    • 阶段覆盖:prefill 与 decode 都覆盖,并且显式拆分二者——这正是方法的立足点。
    • 服务 vs 训练:既有一个训练侧的 cache-conditioned fine-tuning 过程,又有一个推理侧的 disaggregated serving 管线;serving 侧建立在 vLLM 之上,采用 continuous batching。
    • 并行维度:论文关心的是「模型间共享」而非张量/流水并行;实验里每模型独占 prefill/decode GPU(baseline 8 GPU = 4 对;PrefillShare 同预算 4 prefill + 4 decode)。
    • 部署模式:多节点/单节点均可,但核心是 disaggregated prefill-decode——prefill pool 托管单一冻结 base,decode pool 托管多个专用模型。

    3.2 顶层对比(Fig. 1) #

    Figure 1: typical multi-model serving vs PrefillShare, fine-tuning and inference side by side

    Paper's Figure 1, verbatim(caption: "Comparison of a typical multi-model system and PrefillShare. ... PrefillShare decouples prefill and decoding into a shared prefill module and task-specific decode modules, fine-tuning only the decode modules ... achieving up to 4× higher throughput under high load.")

    这张图一次讲清两件事。左侧「Fine-Tuning」对比:典型系统里每个任务模型各自从 base 全量微调、各存 KV;PrefillShare 只把 base 当作冻结 prefill 模块(标注 "Frozen"),仅 "Update" 各 decode 模块,从而 N 个 decoder 共用一份 prompt KV。右侧「Inference」对比:baseline 因相同 prompt 上的重复 prefill + KV 爆炸式增长导致频繁 eviction 与重算;PrefillShare 用共享 KV 实现有效 prefix caching、避免早期缓存饱和。读者应注意:省的不是单次算力,而是随模型数放大的冗余

    3.3 请求生命周期 / 调度路径 #

    以下 sequence 图补足论文文字描述的 proxy 编排(Appendix B.1)——原文无对应示意图,故用 Mermaid 呈现结构:

    sequenceDiagram participant U as Client (User ID) participant P as Proxy (routing table) participant PW as Prefill worker (frozen base) participant DA as Decode worker A participant DB as Decode worker B U->>P: session request (Model A) P->>PW: route by User ID (pin for prefix locality) PW->>PW: full prefill -> C_base PW->>DA: handoff C_base DA-->>U: Y_A (decode from shared cache) U->>P: next agent same turn (Model B) P->>PW: route back to SAME prefill worker PW->>PW: cache hit -> partial prefill on new tokens only PW->>DB: handoff extended C_base DB-->>U: Y_B

    要点:scheduler = proxy,队列纪律是按 User ID 钉住 prefill worker(prefix-locality-aware routing),保证跨模型切换命中缓存而非从头重算;KV/memory manager 与 scheduler 分离——KV 由 vLLM 的 PagedAttention 分块管理,跨节点/跨 worker 的 cache handoff 走 GPU→GPU 传输,高并发时退化为 CPU staging(见 §7)。分配单元是 vLLM 的 KV block(page)。


    4. 作者证明 #

    论文无独立「性能建模」章节,但给出了自回归/KV 的形式化(Eqs. 1-4)、方法定义(Eqs. 5-7)与内存复杂度模型(Eqs. 8-9)。下面按 framework 要求复现记号表、物理意义与检查。

    记号表 #

    符号含义
    $X, Y$输入 prompt(长 $n$)/ 生成序列(长 $T$)
    $\theta$LLM 参数;$\theta_{\text{base}}$ 冻结 prefill,$\theta_{\text{dec}}$ 可训 decode
    $F_\theta(x, C_{\text{past}})$Transformer 前向:输入当前 token 与过去 cache,返回下一 token 与增量 cache
    $C_t$第 $t$ 步 KV cache 状态;$C_{\text{base}}$ 为共享 prefill cache
    $k_t, v_t$第 $t$ 步跨全层聚合的 key/value 张量
    $N$模型数
    $L_{\text{shared}}, L_{\text{unique}}$共享前缀长度 / 模型专属段长度

    关键方程与物理意义 #

    • 自回归似然与 KV 递推:$P(Y \mid X) = \prod_{t=1}^{T} P(y_t \mid X, y_{
    • 两相执行:prefill $(y_1, C_n) = F_\theta(X, \varnothing)$(compute-bound);decode $(y_t, \Delta C_t) = F_\theta(y_{t-1}, C_{n+t-2})$(memory-bound)。这一 compute/memory 二分正是 disaggregation 的物理依据。
    • Base prefill 只产 cache 不解码:$(\cdot, C_{\text{base}}) = F_{\theta_{\text{base}}}(X, \varnothing)$;decode 初始化 $C \leftarrow C_{\text{base}}$ 后 $(y_t, \Delta C_t) = F_{\theta_{\text{dec}}}(y_{t-1}, C)$。
    • 训练目标:$\mathcal{L}(\theta_{\text{dec}}) = -\sum_t \log P(y_t \mid y_{条件信号换成冻结 base 的 cache,梯度不流入 $\theta_{\text{base}}$。

    6 项最小检查 #

    1. 量纲/一致性:Eqs. 8-9 两端都是内存量($O(\cdot)$,单位 token·layer·bytes 同阶),仅系数结构不同,可比。
    2. 为何 base cache 当常量:若梯度流入 $\theta_{\text{base}}$,则 $C_{\text{base}}$ 不再跨模型稳定共享;停梯度保证了「一份 base、多个 decoder」的解耦——与「无需参数同步」的主张自洽。
    3. min vs sum / 分母排除:Eq. 9 的关键是共享前缀 $L_{\text{shared}}$ 不乘 $N$(只存一次),只有专属段 $N\cdot L_{\text{unique}}$ 随模型数增长;baseline(Eq. 8)则整段 $N\cdot(L_{\text{shared}}+L_{\text{unique}})$ 都乘 $N$。
    4. 单调性/边界:当 $L_{\text{shared}} \gg L_{\text{unique}}$,PrefillShare 内存主导项从 $N\cdot L_{\text{unique}}$ 变为 $L_{\text{shared}}$,对 $N$ 近似不敏感(内点最优在 $N$ 方向被抹平);baseline 对 $N$ 严格单调增。这是「共享上下文越长、模型越多,收益越大」的形式化来源。
    5. 一阶映射(把案例代入模型):四智能体、共享上下文远大于单模型输出段($L_{\text{shared}}\gg L_{\text{unique}}$,$N=4$)的场景下,Eq. 9 预测总 KV 内存约为「一份共享前缀 + 4 份小专属段」,而 baseline 约「4 份完整前缀」。这与 Fig. 4 中 baseline 命中率随并发骤降、PrefillShare 维持 ~89% 的定性表现一致:de-dup 存储直接转化为更高命中与更多可容并发。
    6. 反例/失效边界:模型显式承认 Eq. 9 是「理想去重」上界——高并发下 decode 侧 KV 压力触发 vLLM 的 CPU staging,实际吞吐在 ~110 并发处见顶回落(§7),此为实现层瓶颈而非模型缺陷。
    7. 精度侧无形式化证明——仅实证:作者用「只更新 decode 相当于一种严格正则化」定性解释 PrefillShare 偶尔反超 Full-FT,未给理论。一个形式化模型本可澄清:正则化收益 vs KV-mismatch 损失的权衡在何种任务/共享比例下净为正。

      5. 实验与数据 #

      5.1 共享比例与精度崩塌(Fig. 2) #

      Figure 2: GSM8K accuracy vs KV cache sharing ratio

      Paper's Figure 2, verbatim(caption: "GSM8K accuracy as a function of KV cache sharing ratio between the base and fine-tuned models. Naive sharing without cache-adaptive fine-tuning collapses at high sharing ratios, while PrefillShare preserves near Full-FT accuracy even at 100% sharing.")

      这是方法必要性的核心证据:x 轴共享比例 0→100%,朴素共享("Feature Mismatch (Accuracy Collapse)")随比例升高精度崩塌,而 PrefillShare 在 100% 共享下仍贴近 Full-FT baseline。读者应注意——若无 cache-conditioned 微调,共享本身是无法直接工作的。

      5.2 精度对照(Table 1 / Table 2) #

      Table 1: accuracy on math/coding/tool-calling for LLaMA3.1-8B and Qwen3-8B-Base

      Paper's Table 1, verbatim(caption: "Accuracy on math, coding, and tool-calling benchmarks ... PrefillShare achieves accuracy comparable to full fine-tuned models across all evaluated benchmarks.")

      关键数字(Full-FT → PrefillShare):LLaMA3.1-8B GSM8K 71.3→71.4、HumanEval 48.2→48.8;Qwen3-8B HumanEval 83.5→86.6、HumanEval+ 74.3→80.5(显著反超)。诚实之处:仍有若干格 PrefillShare 略输,见下 §6 workload 表脚注。

      Table 2: accuracy across model sizes Q3-1.7B/8B/14B on GSM8K/GSM+

      Paper's Table 2, verbatim(caption: "Accuracy of Full-FT and PrefillShare on GSM8K and GSM+ across model sizes ... indicating robustness to model scale.")

      Table 2 说明方法对规模不敏感:1.7B/8B/14B 三档 GSM8K/GSM+ 上 PrefillShare 与 Full-FT 基本持平(如 Q3-1.7B 75.0→75.4、Q3-14B GSM+ 66.7→67.5)。注意 L1 标注 Table 2 存在 OCR 对齐不确定性。

      5.3 端到端服务性能(Fig. 3) #

      Figure 3: serving performance under multi-model agent workloads, ReAct and Reflexion

      Paper's Figure 3, verbatim(caption: "Serving performance under multi-model agent workloads. ... PrefillShare outperforms the baseline in both patterns, with the gap widening as the session arrival rate increases, primarily due to rising prefix-cache miss rates in the baseline.")

      3 列指标(p95 延迟 / 吞吐 / TTFT)× 2 行模式(ReAct / Reflexion)。低负载两者相当;随到达率上升,baseline 尾延迟迅速膨胀、吞吐下滑,PrefillShare 因摊薄共享前缀而维持高吞吐、低尾延迟。这就是 4.5×/3.9× 头条数字的来源,且差距随负载扩大

      5.4 并发扫描与命中率(Fig. 4) #

      Figure 4: prefix cache hit ratio and throughput vs max concurrent sessions

      Paper's Figure 4, verbatim(caption: "Prefix cache hit ratio and throughput under varying max concurrent sessions. ... The baseline degrades beyond ≈40 sessions ... whereas PrefillShare sustains higher throughput over a wider range, with high-concurrency saturation driven by handoff overheads.")

      上图命中率、下图吞吐随 max concurrent sessions 变化。baseline 在约 40 并发后命中率峰值 ~60% 骤降、吞吐随之掉;PrefillShare 命中率稳定近 89%,吞吐持续上升,直到约 110 并发因 handoff 压力(而非命中率下降)见顶。这张图把「收益来自去重存储」与「饱和来自实现层 staging」清楚分离——是全文最具诊断价值的一张。

      5.5 换 backbone 复现(Fig. 5 / Fig. 6,Appendix B.3) #

      Qwen3-14B 复现 Fig. 3/4:吞吐、尾延迟、命中率的定性趋势一致,但TTFT 方向不同——因 PrefillShare 峰值吞吐操作点位于更高并发,prefill worker 负载更重,故 TTFT 可能上升,即使吞吐/尾延迟改善。方向非单调、依赖操作点。


      6. 论证链 #

      步骤论断(paper-internal)依据
      1KV 与参数强耦合:同 prompt 下 $\theta_i\neq\theta_j$ 产生互不兼容的 KV§2.2 formal argument
      2故多模型工作流必须各自重算 prefill 且各存 KV → 延迟+内存冗余;disaggregation 只解 prefill-decode 干扰、不解跨模型冗余§1 para 4-5
      3若把 base cache 当常量、只微调 decode 去消费它(Eq. 7),decode 可对齐 base KV 分布 → 100% 共享仍近 Full-FT(Fig. 2 反证朴素共享崩塌)§3.2 + Fig. 2
      4共享一次 prefill 后,内存主导项从 $N\cdot(L_{\text{shared}}{+}L_{\text{unique}})$ 变为 $L_{\text{shared}}{+}N\cdot L_{\text{unique}}$(Eqs. 8-9),$L_{\text{shared}}\gg L_{\text{unique}}$ 时近似独立于 $N$§3.3 Eqs. 8-9
      5去重存储 → 高并发下 prefix 命中率稳定(~89% vs baseline ~60% 骤降)→ 高吞吐、低尾延迟(4.5×/3.9×)§4.3 Fig. 3-4
      6剩余饱和(~110 并发吞吐回落)由 vLLM CPU-GPU KV staging 引起,非算法内在限制§4.3 + Appendix B.2

      6.1 Workload 表 — 何时赢、何时不赢 #

      Workload regimePrefillShareBaseline (per-model disaggregated)Why
      短 prompt、低并发与 baseline 相当相当共享前缀短、冗余少,摊薄收益不显著(§4.3 low-load)
      长共享上下文、高并发命中率 ~89%、吞吐/尾延迟大幅领先>40 并发后命中率崩、尾延迟膨胀$L_{\text{shared}}\gg L_{\text{unique}}$,去重把内存主导项从 $N\cdot L$ 降到 $L$(Eqs. 8-9)
      混合 prefill-decode / 极高并发~110 并发后吞吐回落更早饱和decode 侧 KV 压力触发 vLLM CPU staging(实现层,非算法)
      部分精度格点略输 Full-FTLLaMA GSM+ 49.3<49.8、HumanEval+ 45.1<45.7;Qwen GSM8K 84.8<85.8、GSM+ 64.5<65.7、Multiple 91.0<92.0

      7. 实现 cross-reference #

      论文提供实现描述但未公开代码仓库,原型建立在 vLLM disaggregated serving pipeline 之上:[实现未公开](无 file:line 可引)。以下为可复现的关键实现细节(源自正文与 Appendix B):

      • 调度/资源管理:粒度为 request/session 级;proxy 维护 User ID → prefill worker 的 routing table 以保 prefix 局部性;跨 agent 切换命中缓存后只做 partial prefill(仅新增 token)。KV 分配单元沿用 vLLM PagedAttention 的 block。准入控制方面,论文用 max concurrent sessions 作为并发上限旋钮,直接控制系统级 KV footprint(§4.3)。
      • API / 集成方式(framework §8-§10):面向 vLLM 生态,通过在 vLLM disaggregated engine 之上加一层 proxy-based orchestration(client-facing proxy + prefill pool + decode pool)实现;不是 fork 内核,而是外挂编排层 + 路由/handoff 逻辑。迁移路径:已跑 vLLM disaggregated 的部署,需引入「单一冻结 base 占据 prefill pool、decode pool 托管多个专用模型」的拓扑,并为每个专用模型做一次 cache-conditioned 微调。
      • 核心技术壁垒(§7 dedicated):最难复制的不是系统管线,而是让 decode 在冻结 base 的 KV 上可靠解码。这要求训练分布严格匹配推理时的 cache 使用——即用 $M_{\text{base}}$ 现算 $C_{\text{base}}$、停梯度、只训 $\theta_{\text{dec}}$(Eq. 7)。若训练时仍用自生成 cache,则 Fig. 2 的崩塌不可避免。这一 train-inference 对齐是 100% 共享仍保精度、且跨异构 decoder 免参数同步的根本原因。
      • 关键实现细节(易漏的两处 trick)
      • 同 worker 回钉 + partial prefill:同一 turn 内切到下一个 agent 时,proxy 把请求路由回同一个 prefill worker,命中已有前缀 KV,仅计算新增 token 的 KV 后再 handoff(Appendix B.1)——这是「TTFT 对 $L_{\text{shared}}$ 近似不敏感」得以成立的工程前提。
      • 高并发 staging 是 vLLM 层现象:吞吐在极高并发回落源于 vLLM 把部分 KV stage 到 CPU 再 reload(Appendix B.2),并非 shared-prefill 的固有限制;可用更严格准入控制 / decode-to-prefill 反压 / 每会话 GPU KV 预留缓解。
      §12 软件→硬件反推:不触发。PrefillShare 属纯软件框架(跨模型 KV 去重 + prefix-aware 路由 + cache handoff),未涉及持久 megakernel、cache-scope 控制或互连感知调度,故不产生对未来 ISA / cache 策略的硬件诉求。