[论文解读] Fast Inference from Transformers via Speculative Decoding
本文提出带有猜测采样的推测解码,以通过并行运行一个较小的近似模型并复用其输出,同时保持目标模型的输出分布,从而在不重新训练的情况下实现对 T5-XXL 的 2x-3x 墙钟时间加速。
Inference from large autoregressive models like Transformers is slow - decoding K tokens takes K serial runs of the model. In this work we introduce speculative decoding - an algorithm to sample from autoregressive models faster without any changes to the outputs, by computing several tokens in parallel. At the heart of our approach lie the observations that (1) hard language-modeling tasks often include easier subtasks that can be approximated well by more efficient models, and (2) using speculative execution and a novel sampling method, we can make exact decoding from the large models faster, by running them in parallel on the outputs of the approximation models, potentially generating several tokens concurrently, and without changing the distribution. Our method can accelerate existing off-the-shelf models without retraining or architecture changes. We demonstrate it on T5-XXL and show a 2X-3X acceleration compared to the standard T5X implementation, with identical outputs.
研究动机与目标
- 为大型自回归 Transformer 提供更快的推理动机,因为解码是顺序且缓慢的。
- 提出一种让近似模型与目标模型并行运行以生成推测标记的方法。
- 确保最终输出与目标模型的分布一致,且无需重新训练或架构变更。
- 提供理论指导和跨任务的实证证据,展示在真实模型上的实际加速。
提出的方法
- 定义同一任务的目标模型 Mp 与较小的近似模型 Mq。
- 从 Mq 生成 gamma 个候选标记,并在与 Mp 并行的推测采样中评估,以保持 Mp 的分布。
- 使用采样调整确保最终输出分布与 Mp 相同,可能在每一步发出多达 gamma+1 个标记。
- 在 alpha(接受概率)和成本系数 c 对 Mq 的影响下分析加速,推导出最优 gamma。
- 证明墙钟时间的改进遵循取决于 alpha、gamma 和 c 的公式,并确定何时实现加速。
- 在翻译、摘要、对话等任务上进行经验验证,并与 T5-XXL 的 T5X 基线进行比较。
实验结果
研究问题
- RQ1在不改变输出的情况下,猜测解码能将大规模 Transformer 的推理加速多少?
- RQ2近似质量(alpha)与加速之间的关系,以及 gamma 的选择应如何?
- RQ3在不同的近似模型和采样设置下,墙钟时间与计算资源的权衡行为如何?
主要发现
- 在 T5-XXL 上相对于 T5X,输出保持一致的前提下实现了 2x-3x 的墙钟时间加速。
- 加速与接受率 alpha 相关;较高质量的近似(较大 alpha)在合适的 gamma 下能带来更大收益。
- 近似成本很低(如 unigram/bigram)的近似仍然提供可观的加速,尽管不如更大规模的近似模型。
- 理论分析给出期望生成标记的数量和墙钟时间改进的公式,指导在给定 alpha 和硬件成本 c 时的 gamma 选择。
阅读本论文
在 Nubint 阅读器中打开原文,边读边就任意段落提问。
在 Nubint 中阅读本论文本解读由 AI 根据论文原文生成,引用前请核对原文。