Files
myWiki/concepts/kv-injection.md

1.3 KiB
Raw Permalink Blame History

title, created, updated, type, tags, sources
title created updated type tags sources
KV Injection 2026-06-28 2026-06-28 concept
speculative-decoding
feature-transfer
draft-architecture
DFlash
DSpark

KV Injection

KV 注入KV InjectionDFlash(及继承其骨干的 DSpark)中使用的目标模型上下文特征注入技术。草稿模型在 prefill 阶段从目标模型的选定层提取隐藏状态,经过投影后注入草稿模型的每一层。

机制

上下文特征提取

H_{ctx} = \text{RMSNorm}\left(W_c [H^{(l_1)}; ...; H^{(l_m)}]\right)

其中 W_c \in \mathbb{R}^{d \times md} 是共享投影矩阵,\{l_1, ..., l_m\} 是选定的目标模型层。

层内注入:在草稿模型的每一层的 key 和 value 计算中,将注入的上下文特征沿序列维度拼接到草稿块表示之前:

K_i = [W_i^K H_{ctx}; W_i^K H_d], \quad V_i = [W_i^V H_{ctx}; W_i^V H_d]

块内所有位置双向注意力到彼此及注入的目标上下文。

效果

KV 注入使得草稿模型能利用目标模型的丰富上下文表示,大幅提升预测质量。这是并行草稿器能在位置 1 上超过浅层自回归草稿器的关键——目标模型的深层语义表示直接流向草稿模型。

参考