20260706:新增一些文章

This commit is contained in:
2026-07-06 10:14:02 +08:00
parent 6021dea160
commit 24b006225b
194 changed files with 8512 additions and 91 deletions

35
concepts/kv-injection.md Normal file
View File

@@ -0,0 +1,35 @@
---
title: "KV Injection"
created: 2026-06-28
updated: 2026-06-28
type: concept
tags: [speculative-decoding, feature-transfer, draft-architecture]
sources: [DFlash, DSpark]
---
# KV Injection
KV 注入KV Injection是 [[DFlash]](及继承其骨干的 [[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 上超过浅层自回归草稿器的关键——目标模型的深层语义表示直接流向草稿模型。
## 参考
- [[DFlash]]
- [[DSpark]]
- [[parallel-drafting|并行草稿Parallel Drafting]]