Files
myWiki/concepts/rnn-draft-head.md

36 lines
1.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: "RNN Draft Head"
created: 2026-06-28
updated: 2026-06-28
type: concept
tags: [speculative-decoding, draft-architecture, recurrent-neural-network]
sources: [DSpark]
---
# RNN Draft Head
RNN 草稿头是 [[DSpark]] 的[[semi-autoregressive-generation|半自回归生成Semi-Autoregressive Generation]]的顺序块变体,通过门控循环单元累积完整的块内前缀历史,相较[[markov-draft-head|马尔可夫草稿头Markov Draft Head]]能建模更长的 token 间依赖。
## 更新方程
在每个草稿步骤 $k$,拼接当前状态 $s_{k-1} \in \mathbb{R}^r$、前一 token 嵌入 $W_1[x_{k-1}] \in \mathbb{R}^r$、骨干隐藏 $h_k \in \mathbb{R}^d$ 形成输入 $z_k = [s_{k-1}; W_1[x_{k-1}]; h_k] \in \mathbb{R}^{2r+d}$,然后应用门控更新:
$$s_k = \sigma(W_g z_k) \odot s_{k-1} + (1 - \sigma(W_g z_k)) \odot \tanh(W_c z_k)$$
$$B_k(x_{<k}, \cdot) = W_2^\top \tanh(W_o z_k)$$
其中 $W_g, W_c, W_o \in \mathbb{R}^{(2r+d) \times r}$ 由单一线性投影联合参数化后拆分初始状态 $s_0 = 0$。
## 与马尔可夫头的对比
| 特性 | 马尔可夫头 | RNN |
|------|----------|--------|
| 依赖范围 | $x_{k-1}$ | 完整 $x_{<k}$ |
| 存储 | $O(|\mathcal{V}| \cdot r)$ | $O(|\mathcal{V}| \cdot r + r^2 + rd)$ |
| 每步计算 | 嵌入查找 + 向量乘 | 门控更新 + 三投影 |
| 适用场景 | 大多数通用场景 | 需要更长前缀依赖的场景 |
## 参考
- [[DSpark]]
- [[markov-draft-head|马尔可夫草稿头Markov Draft Head]]
- [[semi-autoregressive-generation|半自回归生成Semi-Autoregressive Generation]]