Files
myWiki/concepts/semi-autoregressive-generation.md

41 lines
2.1 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: "Semi-Autoregressive Generation"
created: 2026-06-28
updated: 2026-06-28
type: concept
tags: [speculative-decoding, llm-inference, hybrid-architecture]
sources: [DSpark]
---
# Semi-Autoregressive Generation
半自回归生成是 [[DSpark]] 提出的混合草稿架构,将草稿生成分为两个阶段以融合[[parallel-drafting|并行草稿Parallel Drafting]]的速度优势和[[autoregressive-drafting|自回归草稿Autoregressive Drafting]]的质量优势。
## 架构
**并行阶段Parallel Stage**:并行骨干网络(基于 [[DFlash]] 的 [[kv-injection|KV 注入KV Injection]] 架构)执行单次前向传播,生成所有位置 $\gamma$ 的隐藏状态 $\{h_k\}$ 和基础 logits $\{U_k\}$。$T_{draft}$ 仍接近 $O(1)$。
**顺序阶段Sequential Stage**:轻量级顺序模块为每个草稿位置 $k$ 注入**前缀依赖的转移偏置** $B_k(x_0, x_{<k}, x_k)$形成因果块分布
$$P(X|x_0) = \prod_{k=1}^{\gamma} p_k(x_k | x_0, x_{<k})$$
其中每步采样基于基础 logits + 转移偏置
$$p_k(v|x_0, x_{<k}) = \frac{\exp(U_k(v) + B_k(x_0, x_{<k}, v))}{\sum_{u \in \mathcal{V}} \exp(U_k(u) + B_k(x_0, x_{<k}, u))}$$
因为顺序模块天然是串行的必须保持**计算轻量**$T_{sequential} \ll T_{parallel}$确保总草稿延迟仍由并行阶段主导
## 顺序块的两种实例化
- **[[markov-draft-head|马尔可夫草稿头Markov Draft Head]]**$B_k$ 仅依赖前一 token $x_{k-1}$通过低秩分解 $B=W_1 W_2$rank $r=256$)实现高效的大词汇表转移建模
- **[[rnn-draft-head|RNN 草稿头]]**通过门控循环单元积累完整的块内前缀历史$s_k = \sigma(W_g z_k) \odot s_{k-1} + (1-\sigma(W_g z_k)) \odot \tanh(W_c z_k)$
## 效果
Qwen3-{4B,8B,14B} DSpark 相对自回归 Eagle3 提升 26.7%-30.9%相对并行 DFlash 提升 16.3%-18.4%。关键在于融合了并行模型的高初始 token 能力和自回归模型的后缀连贯性
## 参考
- [[DSpark]]
- [[markov-draft-head|马尔可夫草稿头Markov Draft Head]]
- [[rnn-draft-head|RNN 草稿头]]