Faster Cascades via Speculative Decoding
Faster Cascades via Speculative Decoding
用投机解码加速级联
Harikrishna Narasimhan Wittawat Jitkrittum Affiliation: Google Research, Mountain View Google Research, New YorkCorresponding author: hnarasimhan@google.com[5pt] Ankit Singh Rawat Affiliation: Google Research, Mountain View Google Research, New YorkCorresponding author: hnarasimhan@google.com[5pt] Seungyeon Kim Affiliation: Google Research, Mountain View Google Research, New YorkCorresponding author: hnarasimhan@google.com[5pt] Neha Gupta Aditya Krishna Menon Affiliation: Google Research, Mountain View Google Research, New YorkCorresponding author: hnarasimhan@google.com[5pt] Sanjiv Kumar Affiliation: Google Research, Mountain View Google Research, New YorkCorresponding author: hnarasimhan@google.com[5pt]
Abstract
摘要
Cascades and speculative decoding are two common approaches to improving language models’ inference efficiency. Both approaches involve interleaving models of different sizes, but via fundamentally distinct mechanisms: cascades employ a deferral rule that invokes the larger model only for “hard” inputs, while speculative decoding uses speculative execution to primarily invoke the larger model in parallel verification mode. These mechanisms offer different benefits: empirically, cascades are often capable of yielding better quality than even the larger model, while theoretically, speculative decoding offers a guarantee of quality-neutrality. In this paper, we leverage the best of both these approaches by designing new speculative cascading techniques that implement their deferral rule through speculative execution. We characterize the optimal deferral rule for our speculative cascades, and employ a plug-in approximation to the optimal rule. Through experiments with T5 models on benchmark language tasks, we show that the proposed approach yields better cost-quality trade-offs than cascading and speculative decoding baselines.
级联与投机解码是提升语言模型推理效率的两种常见做法。二者都交错使用不同规模的模型,但机制根本不同:级联用延迟规则仅在「难」输入上调用更大模型,而投机解码用投机执行,使更大模型主要以并行验证模式被调用。两种机制各有好处:经验上级联常能给出甚至优于更大模型的质量,而理论上级联投机解码可保证质量中性。本文通过设计新的投机级联技术,把二者长处结合起来:用投机执行实现延迟规则。我们刻画投机级联的最优延迟规则,并用插件近似实现该规则。在基准语言任务上用 T5 模型的实验表明,所提方法比级联与投机解码基线给出更好的代价–质量折中。
1 Introduction
1 引言
Large language models (LLMs) have demonstrated significant advances in quality on a range of natural language processing tasks [33, 34, 5, 2, 11, 48, 12, 41, 1, 43, 42], at the cost of a significant increase in inference latency. This has sparked a growing body of literature on reducing LMs’ inference costs without (overly) compromising on quality [15, 32, 36, 26, 7, 37, 40]. One such line of work involves constructing a family of models of various sizes (e.g., a small and large model), and suitably orchestrating amongst them to make a prediction. Two canonical instantiations of this strategy are model cascading [47, 28, 45, 23, 14, 8, 18, 13] and speculative decoding [39, 7, 26, 40, 49].
大语言模型(LLM)在一系列自然语言处理任务上质量显著提升 [33, 34, 5, 2, 11, 48, 12, 41, 1, 43, 42],代价是推理延迟明显增加。这催生了大量在不过度牺牲质量的前提下降低 LM 推理成本的工作 [15, 32, 36, 26, 7, 37, 40]。其中一条路线是构造不同规模的模型族(例如一小一大),并在其间恰当编排以做预测。该策略的两种典型实例是模型级联 [47, 28, 45, 23, 14, 8, 18, 13] 与投机解码 [39, 7, 26, 40, 49]。
While similar in spirit, cascades and speculative decoding are fundamentally different in details. Cascades employ a deferral rule to identify “hard” inputs, and only invoke larger models on such inputs. For example, in a two-model cascade, one first invokes the smaller model, and uses its associated probability of the generated output to decide whether to defer to the larger model. By contrast, speculative decoding uses a small model to draft a block of tokens via standard auto-regressive decoding, which are then verified in parallel by a large model. One then accepts all drafted tokens until the first “implausible” one, which is rolled back based on the larger LM’s prediction.
尽管精神相近,级联与投机解码在细节上根本不同。级联用延迟规则识别「难」输入,只在此类输入上调用更大模型。例如在双模型级联中,先调用较小模型,再根据其生成输出的概率决定是否延迟到较大模型。相对地,投机解码用小模型经标准自回归解码起草一块 token,再由大模型并行验证;随后接受起草 token 直至第一个「不可信」者,并按更大 LM 的预测回滚。
Owing to their different mechnanisms, both methods have complementary strengths. Cascades seek to output distributions that have the best quality for a given cost budget, and are empirically observed to often yield better accuracies than even the individual models they are constructed with [22, 24] (§3). By contrast, speculative decoding is theoretically guaranteed to match the output distribution (or a close approximation thereof [44]), and are practically observed to provide impressive speed-ups [39, 7, 26, 40]. Given the complementary nature of these two approaches, a natural question that arises is whether we can leverage the best of both techniques.
因机制不同,两者优势互补。级联追求在给定代价预算下质量最好的输出分布,经验上常比构成它的单个模型更准 [22, 24](§3)。相对地,投机解码在理论上保证匹配输出分布(或其近似 [44]),实践中也能带来可观加速 [39, 7, 26, 40]。鉴于二者互补,自然要问:能否兼得两者之长。
In this paper, we do so by designing new techniques for two-model cascades that implement their deferral rule in a speculative manner: we have the smaller model generate drafts auto-regressively, and the larger model execute in parallel on the drafts to decide whether or not to defer on themWe show that this speculative cascading approach yields better cost-quality trade-offs than both standard cascades and speculative decoding. In detail, we make the following contributions:
本文通过设计用投机方式实现延迟规则的双模型级联新技术来回答:让较小模型自回归生成草稿,较大模型在草稿上并行执行,以决定是否对其延迟。我们表明这种投机级联比标准级联与投机解码给出更好的代价–质量折中。具体贡献如下:
(i) We introduce a general recipe for speculative execution, where we seek to mimic a general target distribution that interleaves the drafter’s and verifier’s output distributions. Lossy speculative sampling [44] is a special case of this recipe for a particular target distribution (§4.1).
(ii) We show how common cascading deferral rules, such as Chow’s rule [10] and confidence-difference thresholding [22], can be implemented speculatively by plugging in the corresponding target distribution into the proposed framework. We refer to these as speculative cascades (§4.2).
(iii) We characterize the theoretically optimal deferral rule for a speculative cascade, and design a speculative cascading technique that implements a plug-in estimate to the optimal rule (Lem. 4).
(iv) Through experiments on benchmark language tasks, we show that speculative cascades constructed from T5 models [35] of different sizes are able to provide better cost-quality trade-offs than their sequential cascade and speculative decoding counterparts (§6).
(i) 我们给出投机执行的一般配方:目标是模仿交错起草者与验证者输出分布的一般目标分布。有损投机采样 [44] 是该配方在特定目标分布下的特例(§4.1)。
(ii) 我们说明如何把 Chow 规则 [10]、置信差阈值 [22] 等常见级联延迟规则,通过把相应目标分布插入所提框架而以投机方式实现;称之为投机级联(§4.2)。
(iii) 我们刻画投机级联的理论最优延迟规则,并设计实现该最优规则插件估计的投机级联技术(引理 4)。
(iv) 在基准语言任务上的实验表明,由不同规模 T5 [35] 构成的投机级联,能比其顺序级联与投机解码对应物给出更好的代价–质量折中(§6)。
2 A Tale of Two Efficient LM Inference Strategies
2 两种高效 LM 推理策略
Let denote a finite vocabulary of tokens, with the set of all sequences generated by this vocabulary. Let denote the set of all probability distributions over tokens in . Given an arbitrary length sequence and index , denote by . A language model (LM) is a probability distribution over . Let denote the ground-truth probability distribution over . This could be, for example, a distribution over prompt-response pairs that the LM may encounter during deployment, or a distribution of sequences used to pre-train the LM. We will measure the quality of an LM based on how closely it mimics .
令 为有限词表, 为由该词表生成的全部序列集合。令 为词表上全体概率分布的集合。对任意长度序列 与指标 ,记 。语言模型(LM)是 上的概率分布。令 为 上的真实概率分布,例如部署时 LM 可能遇到的提示–回答对分布,或预训练所用序列分布。我们将按 LM 与 的接近程度度量质量。
Suppose we are provided two LMs and , where is the larger model. Our goal is to design an inference strategy that selectively invokes and to trade-off between quality and latency (which may be approximated by the fraction of times that is invoked). We will denote by the probability associates to token given prefix , and by the same distribution from model . Whenever it is clear from context, we will hide the conditioning on prefix , and use the shorthand for and for .
假设有两个 LM 与 ,其中 更大。目标是设计在二者间选择性调用的推理策略,以在质量与延迟(可用调用 的比例近似)之间折中。记 为给定前缀 时 赋给 token 的概率, 同理。上下文清楚时省略对前缀 的条件,简写 为 、 为 。
Cascades.
Cascades are an effective strategy to trade-off cost and quality by having the smaller model handle the “easy” samples, and the larger model handle the “difficult” samples [18, 50]. A common approach to cascading is confidence-based thresholding or Chow’s rule [10, 22], where we first run on the given input, and defer to when ’s confidence for its generated response is sufficiently low. This strategy is typically implemented at the sequence-level, where for a given prefix we invoke to generate a complete response . We evaluate the predicted probability from for this response, and check whether it falls below a threshold :
级联。
级联通过让较小模型 处理「易」样本、较大模型 处理「难」样本,有效折中代价与质量 [18, 50]。常见做法是基于置信的阈值或 Chow 规则 [10, 22]:先在给定输入上跑 ,当 对其生成回答的置信足够低时延迟到 。该策略通常在序列级实现:对给定前缀 ,调用 生成完整回答 ,再评估 对该回答的预测概率,检查是否低于阈值 :
If the above holds, we defer to to generate a new response; otherwise, we retain ’s response. One may then tune the threshold to achieve a desired cost-quality trade-off. The literature also offers variants of Chow’s rule that use a more nuanced aggregation of per-token uncertainties [18].
若成立,则延迟到 生成新回答;否则保留 的回答。随后可调阈值以达到期望的代价–质量折中。文献中也有对逐 token 不确定性做更细致聚合的 Chow 规则变体 [18]。
Speculative decoding.
Speculative decoding is an alternate inference strategy that applies token-level interleaving between and , resulting in provably matching the larger model quality at a reduced inference cost [39, 26]. Given a prefix , we sample draft tokens auto-regressively from , and run in parallel on the prefixes , and verify if the generated tokens can be accepted. We then rollback to the first token that was rejected, replace with a new token, and repeat the drafting-verification process with as the new prefix.
投机解码。
投机解码是另一种推理策略:在 与 之间做token 级交错,在降低推理成本的同时可证明地匹配更大模型的质量 [39, 26]。给定前缀 ,从 自回归采样 个草稿 token ,再在 个前缀 上并行跑 ,验证生成的 token 是否可接受。然后回滚到第一个被拒绝的 token ,替换 ,并以 为新前缀重复起草–验证。
During the verification stage, a draft token generated by is accepted with probability and rejected otherwise, where recall the shorthand and . A rejected token is then replaced by a new token sampled from a modified distribution where denotes normalization to sum to 1. This sampling process is provably equivalent to sampling tokens auto-regressively from for prefix [26]. We summarize this speculative sampling procedure in Algorithm 1. Each invocation of this algorithm generates at most next tokens for a given prefix . One may run this algorithm multiple times to generate a complete output sequence.
验证阶段,由 生成的草稿 token 以概率 被接受,否则拒绝;其中 、。被拒绝的 token 再从修正分布 采样替换,其中 表示归一化使和为 1。该采样过程可证明等价于对前缀 从 自回归采样 个 token [26]。算法 1 汇总该投机采样;每次调用至多为给定前缀 生成 个下一 token。可多次运行以生成完整输出序列。
In practice, one may employ a lossy variant [44] of the above sampling that allows some deviation from verifier’s distribution . In this case, a draft token is accepted with probability , where is a strictness parameter, with higher values indicating greater deviation from . A rejected token may then be replaced by a token sampled from the residual distribution where is a parameter that depends on , and . A common heuristic is to simply set [52].
实践中可采用上述采样的有损变体 [44],允许相对验证者分布 有一定偏离。此时草稿 token 以概率 被接受,其中 为严格度参数,越大表示相对 偏离越大。被拒绝的 token 可从残差分布 采样替换,其中 依赖于 、 与 。常见启发式是直接取 [52]。
| Inference strategy | Deferral decision | Target distribution | Execution |
|---|---|---|---|
| SpecDecoding [26] | - | Speculative | |
| Lossy SpecDecoding [44] | - | Speculative | |
| BiLD* [24] | Speculative | ||
| TokenCascade [Chow] [10] | Sequential | ||
| Oracle [Diff] [22] | Oracle | ||
| SpecCascade [Chow] | Speculative | ||
| SpecCascade [Diff] | Speculative | ||
| SpecCascade [OPT] | Speculative |
Table 1: Target distributions associated with different inference algorithms, where is a free parameter and is a parameter dependent on , and . The last column indicates whether the execution is sequential (Algorithm 2), via an oracle (Algorithm 3), or speculative (Algorithm 5) [26]. The third row presents a variant of the BiLD algorithm of [24], where is a measure of discrepancy between and ; the original algorithm differs in the use of a deterministic speculative decoding procedure with a dynamic draft window (see §5). See (6) for more details on .
| 推理策略 | 延迟决策 | 目标分布 | 执行方式 |
|---|---|---|---|
| SpecDecoding [26] | - | 投机 | |
| Lossy SpecDecoding [44] | - | 投机 | |
| BiLD* [24] | 投机 | ||
| TokenCascade [Chow] [10] | 顺序 | ||
| Oracle [Diff] [22] | 神谕 | ||
| SpecCascade [Chow] | 投机 | ||
| SpecCascade [Diff] | 投机 | ||
| SpecCascade [OPT] | 投机 |
表 1:不同推理算法关联的目标分布,其中 为自由参数, 依赖于 、 与 。末列标明执行是顺序(算法 2)、经神谕(算法 3)还是投机(算法 5) [26]。第三行是 [24] 中 BiLD 算法的变体, 为 与 的差异度量;原算法在使用带动态草稿窗口的确定性投机解码上有所不同(见 §5)。关于 的更多细节见 (6)。
3 Cascades Meet Speculative Decoding
3 级联遇上投机解码
Both cascades and speculative decoding interleave models of different sizes to reduce inference cost, but fundamentally differ in the mechanisms they use. As a step towards comparing the strengths and weaknesses of these approaches, we first describe how one may design a token-level cascade.
级联与投机解码都交错不同规模模型以降低推理成本,但机制根本不同。作为比较二者优劣的一步,我们先说明如何设计 token 级级联。
3.1 Warm-up: Token-level cascades
3.1 热身:Token 级级联
It is straight-forward to extend the sequence-level Chow’s rule from §2 to form a token-level cascade between and . For a prefix , we first compute the smaller model’s distribution , and check whether is below a pre-chosen threshold. if so, we evaluate , and sample ; otherwise, we sample .
把 §2 的序列级 Chow 规则扩展为 与 之间的token 级级联很直接。对前缀 ,先计算较小模型分布 ,检查 是否低于预设阈值;若是,则评估 并从中采样 ;否则从 采样 。
More generally, we may design a token-level deferral rule that takes the prefix as input and outputs a binary decision, with indicating that we defer to (i.e., draw a sample from rather than ). For example, token-level Chow’s rule can be written as:
更一般地,可设计 token 级延迟规则 ,以前缀 为输入输出二元决策, 表示延迟到 (即从 而非 抽样)。例如,token 级 Chow 规则可写成:
where is a cost parameter; the higher the value, the lower is the frequency of deferral to . One may also use a confidence measure different from the maximum probability, such as the entropy of the small model’s probability distribution. We elaborate in §B that the choice of confidence measure would depend on the evaluation metric of interest; (2) is typically prescribed when the cascade’s quality is evaluated in terms of its accuracy against the ground-truth distribution on individual tokens, whereas entropy is prescribed when the metric of interest is the cross-entropy loss.
其中 为代价参数;越大则延迟到 的频率越低。也可使用异于最大概率的置信度量,例如小模型概率分布的熵。我们在 §B 中说明置信度量的选择取决于关心的评测指标;(2) 通常在按真实分布上逐 token 准确率评测级联质量时采用,而交叉熵损失为指标时更宜用熵。
3.2 Optimal token-level cascade deferral
3.2 最优 token 级级联延迟
While Chow’s rule (2) is easy to implement, it can be sub-optimal if the smaller model’s maximum token probability is not reflective of which of the two models are better equipped to predict the next token for a given prefix [22]. Given this, it is natural to ask what the optimal deferral rule for a token-cascade looks like, and whether we can reasonably approximate this rule.
虽 Chow 规则 (2) 易于实现,但若较小模型的最大 token 概率不能反映两个模型中谁更擅长对给定前缀预测下一 token,则可能次优 [22]。因此自然要问:token 级联的最优延迟规则 长什么样,以及能否合理近似。
For this, we must first specify an objective to minimize at each step . Following the prior cascade literature [22, 18], a reasonable objective to minimize is the expected loss from the deferral rule against the ground-truth distribution , with an added cost for deferring to the larger model. We state this below for a fixed prefix , using the short-hand for and for :
为此须先指定每步 要最小化的目标。遵循先前级联文献 [22, 18],合理目标是:相对真实分布 ,延迟规则的期望损失,外加延迟到更大模型的代价。对固定前缀 ,用简写 、 陈述如下:
for a cost penalty and loss function . Common choices for include the 0-1 loss and the log loss
其中代价惩罚 ,损失函数 。 的常见选择包括 0-1 损失 与对数损失
Lemma 1(Optimal deferral for token-level cascades [22]).
The minimizer of (3) is of the form:
引理 1(Token 级级联的最优延迟 [22])。
(3) 的最小化子形如:
Intuitively, we compare the expected loss from with the expected cost of invoking , and decide to defer when the latter is smaller. We note here that this optimization problem is set up for a fixed prefix . One may also consider the coupled optimization problem across all prefixes from 1 to .
直观上,我们比较来自 的期望损失与调用 的期望代价,当后者更小时选择延迟。注意该优化是对固定前缀 设立的;也可考虑从 1 到 所有前缀上的耦合优化问题。
Plug-in estimator for (4). The optimal rule in (4) requires computing expectations over the ground-truth distribution , which is not available during inference time. A common approach in the cascades literature is to replace the expected losses with the models’ confidence estimates [22]. For example, when , it may be reasonable to use as an estimate of the expected 0-1 loss and as an estimate of . The extent to which these estimates are accurate depend on how well and are calibrated [17]. The resulting plug-in estimator for (4) is given by:
(4) 的插件估计。 最优规则 (4) 需要对真实分布 求期望,推理时不可得。级联文献的常见做法是用模型置信估计替换期望损失 [22]。例如当 时,可用 估计期望 0-1 损失 ,用 估计对 的相应期望。这些估计准不准取决于 与 的校准程度 [17]。由此得到 (4) 的插件估计:
Similarly, when , we may use the entropy from as an estimate of its expected log-loss, and similarly for (see §C).
类似地,当 时,可用 的熵 估计其期望对数损失,对 同理(见 §C)。
Remark 1(Oracle deferral rules).
cannot be directly used in a token-level cascade, as it needs the larger model to be invoked at every position . However, it serves as an oracle that allows to analyze the head-room available to improve upon Chow’s rule. See also Remark 2.
注 1(神谕延迟规则)。
不能直接用于token 级级联,因为每个位置 都需调用更大模型。但它可作为神谕*,用于分析相对 Chow 规则的改进空间。另见注 2。*
3.3 When do token-level cascades outperform speculative decoding?
3.3 何时 token 级级联优于投机解码?
Token-level cascades and speculative decoding differ in the distribution over tokens they seek to mimic. Speculative decoding seeks to mimic the larger model’s output distribution (or an approximation to it). As a result, the quality of the sampled output is limited by the accuracy of the larger model. On the other hand, token-level cascades seek to output distributions that closely approximate the ground-truth label distribution, and can potentially yield better quality than even the larger model.
Token 级级联与投机解码所要模仿的 token 分布不同。投机解码追求模仿更大模型的输出分布(或其近似),因而采样输出质量受更大模型准确率限制。另一方面,token 级级联追求逼近真实标签分布的输出分布,有可能给出甚至优于更大模型的质量。
Indeed, speculative decoding would be ideal in applications where the verification model is uniformly better than the draft model on all inputs. However, when there are inputs where the draft model fares better than the verifier, one may want to retain the drafter’s predictions even when it disagrees with the verifier. Similarly, in settings where both the drafter and verifier fare poorly on some inputs (e.g., due to label noise), one may again want to ignore the disagreement between the drafter and verifier, and avoid triggering unnecessary roll-backs.
确实,若验证模型 在所有输入上一致好于起草模型 ,投机解码很理想。但当存在起草者优于验证者的输入时,即使二者不一致,也可能想保留起草者的预测。同样,若二者在某些输入上都表现差(例如标签噪声),也可能想忽略分歧、避免触发不必要回滚。
As a concrete example, we consider token-level cascades of T5 models [35] of two different sizes finetuned on a WMT EN DE translation [3] and an extreme summarization (XSum) task [31]. We construct these cascades using both (token-level) Chow’s rule in (2) and the oracle Diff rule in (5), and also apply speculative decoding with the smaller (larger) model as the drafter (verifier). In Figure 1, we plot quality as a function of fraction of samples deferred to the large model, as we vary the cost parameter . Note that with speculative decoding, each verification step is counted as a single call to the large model. While speculative decoding matches the quality of the large model (right-most point), the oracle rule yields significantly better quality on a wide range of operating points. Even Chow’s rule, which is sub-optimal for cascading [22], outperforms speculative decoding in a small region.
作为具体例子,我们在 WMT ENDE 翻译 [3] 与极端摘要(XSum) [31] 上微调两种规模的 T5 [35],构造 token 级级联。级联分别用 (2) 的(token 级)Chow 规则与 (5) 的神谕 Diff 规则;同时以较小(较大)模型为起草者(验证者)做投机解码。图 1 在变化代价参数 时,画出质量相对延迟到大模型样本比例的曲线。注意投机解码中每次验证计为一次大模型调用。投机解码匹配大模型质量(最右点),而神谕规则在很宽的工作点上质量显著更好;即便对级联次优的 Chow 规则 [22],也在一小段区域超过投机解码。
However, as also evident from the plots, token-level cascades require a significantly larger number of calls to the larger model to achieve the same quality. This is because token-level cascades are executed sequentially: whenever defers, we execute once to generate one next token for the prefix accumulated so far, and the control transfers back to . In contrast, speculative decoding runs in scoring mode to verify multiple draft tokens from in parallel. Moreover, the stochastic verification algorithm in speculative decoding often results in fewer tokens from getting rejected compared to the deterministic deferral rules used in a cascade. These observations motivate a natural question: given their complementary strengths, how can we leverage the best of both these techniques?
但图中同样可见:token 级级联要达到同等质量,对更大模型的调用次数显著更多。因为 token 级级联顺序执行:一旦 延迟,就调用一次 为当前累积前缀生成一个下一 token,再把控制交回 。相对地,投机解码以打分模式跑 ,并行验证来自 的多个草稿 token。此外,投机解码的随机验证算法往往比级联的确定性延迟规则拒绝更少来自 的 token。这些观察引出自然问题:鉴于二者互补,如何兼得其长?
Figure 1: Plot of quality as a function of deferral rate for cascades constructed from T5 models (under temperature sampling with ). The left-most point represents the small model and the right-most represents the large model. We compare token-level cascades constructed with Chow’s rule (Chow) and an oracle deferral rule (Diff), and speculative decoding with block size . We measure deferral rate in terms of the number of calls to the larger model; with a cascade, each call yields exactly one token, whereas with speculative decoding, a single call scores draft tokens in parallel. While speculative decoding matches the quality of the large model (see dashed horizontal line), the oracle deferral rule yields significantly better quality on a range of deferral rates; this however comes at the cost of higher number of calls to the large model.
图 1:由 T5 构造的级联在延迟率下的质量曲线(温度采样 )。最左为小模型,最右为大模型。比较用 Chow 规则(Chow)与神谕延迟规则(Diff)构造的 token 级级联,以及块大小 的投机解码。延迟率按对更大模型的调用次数计;级联中每次调用恰产生一个 token,而投机解码一次调用并行打分 个草稿 token。投机解码匹配大模型质量(见虚水平线),神谕延迟规则在一系列延迟率上质量显著更好;代价是对大模型调用次数更高。
4 Speculative Cascades: Leveraging the Best of Both Worlds
4 投机级联:兼得两者之长
In addressing the above question, we present our main contribution: a principled approach to combining the superior quality of cascades with the faster execution of speculative decoding approaches.
针对上述问题,我们给出主要贡献:一条把级联的更优质量与投机解码的更快执行相结合的原则性路径。
4.1 Speculative decoding with general target distributions
4.1 带一般目标分布的投机解码
We begin by considering a generic version of speculative sampling that seeks to mimic a general target distribution derived from the drafter’s and verifier’s distributions. In the proposed sampling procedure outlined in Algorithm 4, we sample tokens auto-regressively as before from the drafter’s distribution. During the verification step, however, we do not compare the drafter’s token probabilities against the verifier’s distribution. Instead, we use a user-specified target distribution derived from the drafter’s and verifier’s distributions at position , for some function that is inexpensive to compute. We accept a draft token when and reject it otherwise with probability . Upon rejection, we re-sample from the residual distribution .
我们先考虑投机采样的一般版本:目标是模仿由起草者与验证者分布导出的一般目标分布。算法 4 给出的采样流程中,仍从起草者分布自回归采样 token;但在验证步,不再把起草者 token 概率与验证者分布直接比较,而是使用由位置 处起草者与验证者分布导出、用户指定的目标分布 ,其中 计算廉价。当 时接受草稿 token ,否则以概率 拒绝;拒绝后从残差分布 重采样。
This general procedure not only encompasses standard speculative decoding [26] for , but also includes lossy speculative decoding [44] as a special case:
该一般流程不仅在 时涵盖标准投机解码 [26],也将有损投机解码 [44] 作为特例:
Lemma 2.
Algorithm 4 reduces to the lossy speculative sampling procedure in [44] with parameters and when .
引理 2。
当 时,算法 4 退化为 [44] 中参数为 与 的有损投机采样。
4.2 From sequential to speculative cascades
4.2 从顺序级联到投机级联
Equipped with Algorithm 4, we now propose new cascading techniques that implement their deferral rule in a speculative manner. Recall that a token-level cascade of two models and is defined by a deferral rule . For a prefix , the next-token distribution at position modeled by this cascade can be written as:
有了算法 4,我们提出以投机方式实现延迟规则的新级联技术。回忆双模型 与 的 token 级级联由延迟规则 定义。对前缀 ,该级联在位置 建模的下一 token 分布可写成:
In fact, for all the deferral rules described in §2, the resulting distribution can be described by a target distribution function of the form:
事实上,对 §2 所述全部延迟规则,所得分布都可由形如下式的目标分布函数 描述:
for some function that maps distributions to a binary decision. For example, for Chow, , and for Diff, See Table 1 for a summary of target distributions for different deferral rules.
其中某函数 把分布对 映到二元决策。例如对 Chow,;对 Diff, 不同延迟规则的目标分布汇总见表 1。
Our proposal is to then invoke the speculative sampling procedure in Algorithm 4 with as the target distribution function. We outline this generic speculative cascading approach in Algorithm 5, and contrast it with the sequential execution of a deferral rule in Algorithm 2.
我们的提案是:以 为目标分布函数调用算法 4 的投机采样。算法 5 概述该通用投机级联方法,并与算法 2 中延迟规则的顺序执行对照。
Remark 2(Exact implementation of oracle deferral ruleDiff).
Unlike a sequential cascade, where the larger model’s distribution is not available at the time the deferral decision is made (see Remark 1), with a speculative cascade, we can accommodate deferral rules likeDiffthat depend on both and . This is because we run the larger model in parallel on drafts generated by the smaller model , allowing us to compute both and on every prefix.
注 2(神谕延迟规则 Diff 的精确实现)。
So far we have considered deferral rules designed for sequential cascades. In what follows, we derive the optimal deferral rule for a speculative cascade, where we sample speculatively from a target distribution using as the drafter.
有趣的是,与顺序执行不同,投机执行天然允许实现像 Diff 这样的神谕延迟规则:验证阶段反正要并行评估起草者与验证者分布。
Models , , Prefix , Block size
Models , , Deferral logic , Prefix
if then
Sample
else
; Sample
end if
Models , , Deferral logic , Prefix
;
if then
Sample
else
Sample
end if
Models , , Target distr. , Prefix , Block size
Sample tokens auto-regressively from
for to do
end for
Run in parallel to score draft tokens
Find the earliest draft token that gets rejected
Sample a new token from residual distribution
Sample
Models , , Deferral logic , Prefix , Block size
Algorithm 1 SpecDecode
图示/表:投机级联与相关方法的算法对照(见原文算法 2–5)。顺序级联每延迟一次只前进一个 token;投机级联在草稿块上并行做延迟决策,并按目标分布 做接受/残差重采样。
4.3 Deferral risk for speculative cascades
4.3 投机级联的延迟风险
As with sequential cascades (§2), we begin by defining an objective to minimize. We seek a deferral rule that minimizes a loss against the ground-truth distribution, while limiting the inference cost to be within a budget. (Per above, this deferral rule implicitly defines a target distribution .) The inference cost crucially depends on how frequently a draft token is rejected in the verification phase, triggering a rollback. To this end, we derive the probability that a token sampled from is rejected during verification, for a target distribution resulting from a deferral rule .
与顺序级联(§2)一样,我们先定义要最小化的目标。由于验证者以投机方式运行,拒绝草稿 token 的代价不仅来自调用更大模型,还来自回滚。事实上,每当草稿被拒绝,我们就从残差分布采样替换 token,并重启投机过程。因此,延迟风险应同时反映推理质量与草稿拒绝率。
Lemma 3.
For a given prefix , and target distribution , the probability of a token drawn from draft distribution being rejected is equal to:
引理 3。
对给定前缀 ,以及形如 的目标分布,拒绝草稿 token 的概率为:
where is the TV distance between and .
其中 为全变差距离。
Intuitively, whenever , and therefore there is no rejection or roll-back; when , the rejection rate equals .
直观上,每当 ,,因而拒绝概率为 0;每当 ,拒绝概率等于 与 之间的全变差距离。
For a fixed prefix , we formulate the goal of finding a solution to:
对固定前缀 ,我们把目标表述为在延迟预算约束下最小化期望损失:
for some budget . Equivalently, one may minimize an unconstrained objective similar to (3), for suitable cost parameter (see §C.4):
对某预算 。等价地,可最小化带拉格朗日乘子 的无约束目标:
Contrasting (8) with the deferral risk in (3) for a sequential cascade, a key difference is that the cost of deferring to the larger model is no longer a constant, but depends on the similarity between and , as measured by the TV distance between them.
把 (8) 与顺序级联的延迟风险 (3) 对照,额外的 项显式惩罚拒绝草稿 token 的代价。当 与 接近时该项较小,鼓励在分歧不大时仍延迟到 ;当二者差异大时惩罚更大,更倾向于信任 。
4.4 Optimal speculative deferral
4.4 最优投机延迟
We next derive the optimal deferral rule for (8), and construct a feasible estimator for it.
接下来推导 (8) 的最优延迟规则,并构造可行的插件近似。
Lemma 4(Optimal deferral for speculative cascades).
The minimizer of (8) is of the form:
引理 4(投机级联的最优延迟)。
(8) 的最小化子形如:
When and are similar, the rejection rate for is low, and hence the deferral decision will depend largely on which of the two models yields a lower expected loss. When and are very different, the optimal decision is to defer to only when it yields a substantially lower loss than .
当 与 相近时, 的拒绝率较低,延迟到 的代价较小;于是最优规则更愿意在 相对 仅略差时仍延迟。当二者差异大时,拒绝率升高,最优规则更保守。相对顺序级联最优规则 (4),额外因子 调节延迟门槛。
Plug-in estimator for (9). The optimal rule requires estimating expectations with respect the ground-truth distribution We employ similar plug-in estimators as the ones used with sequential cascades (§3). When , we replace the expected 0-1 loss with (one minus) the maximum probability from the model, giving us:
(9) 的插件估计。 最优规则需要估计真实分布下的期望损失。对 0-1 损失,与 §3.2 类似,用 与 作插件,得到:
The efficacy of the plug-in estimator depends on how closely the individual models approximate the ground-truth distribution ; this is formalized by the following regret bound:
插件估计的效力取决于各个损失估计与真实期望损失的接近程度;校准良好的模型通常给出更可靠的置信。
Lemma 5(Regret bound for ).
Suppose . Then for a fixed prefix :
引理 5( 的遗憾界)。
设 。则对固定前缀 :
One can now run the speculative cascading procedure in Algorithm 5 using (10) as the deferral rule; the corresponding is listed in Table 1. See §C.2 for a similar derivation for .
现在可用 (10) 作为延迟规则运行算法 5 的投机级联;对应的 列于表 1。 的类似推导见 §C.2。
Remark 3(Optimal deferral with temperature sampling).
In practice it is common to apply a temperature scaling to both and , and sample from and respectively, for a temperature parameter . In this case, the constrained problem in (7) would use the TV distance between the temperature-scaled distributions and to measure the resulting rejection rate, and the optimal deferral rule in Lemma 4 would now use instead of . To construct a plug-in estimator to this optimal rule, we still prescribe using the unscaled probabilities and to estimate the expected loss, giving us, for :
注 3(温度采样下的最优延迟)。
实践中常对 与 施加温度缩放,并分别从 与 采样,其中温度参数 。此时,把引理 4 中的分布换成温度缩放后的版本,并相应构造插件估计是自然的。具体地,可定义
One may run Algorithm 5 with as the deferral rule and the temperature scaled as the drafter.
可用 作为延迟规则运行算法 5。
Remark 4(Special case of greedy decoding).
When temperature , whenever , and is zero otherwise. In this case, running Algorithm 5 with as the deferral rule (and as the drafter) is equivalent to running it with in (5) as the deferral rule. In other words, for greedy decoding, the optimal deferral rules for a speculative cascade coincides with that for a sequential cascade. We formalize this in Lemma 8 in §C.3.
注 4(贪心解码特例)。
当温度 时,采样退化为贪心:取 。§C.3 表明,此时投机级联的接受/拒绝行为与在目标分布上的确定性规则有简洁对应,且最优插件规则可写成对最大概率差与全变差项的阈值比较。
5 Further related work
5 更多相关工作
There has been a stream of work on improving the draft generation process in speculative decoding; these include having the drafter and verifier share the same backbone [39, 25, 6, 30, 21, 51, 16, 27], using multiple small draft models [9, 46], using tree-structured draft batches [38, 29], distilling the drafter with the verifier [52], and leveraging multiple sampled candidates from the drafter [40].
已有一股工作改进投机解码中的草稿生成过程,例如训练专用草稿模型、用多草稿头或树状注意力并行提出多条候选、以及自适应草稿长度 [40, 49, 7]。这些方向与本文正交:我们关注如何把级联式延迟规则嵌入投机验证,而不是如何生成更好的草稿。
The work that is most closely related to our specific proposal is the Big Little Decoder (BiLD) [24], which can be seen as another lossy variant of speculative decoding [26, 44, 52]. BiLD has two phases: a fallback phase, during which the drafter is run auto-regressively until its maximum predicted probability is sufficiently low; and a rollback phase, during which the verifier is run in parallel on the prefixes generated by and rolls back to the point where , for a metric that measures discrepancy and threshold . The fallback phase can be seen as implementing Chow’s deferral rule (2), and allows for the draft window size to vary dynamically based on an estimate of how likely the draft tokens will be accepted; the rollback phase can be seen as a deterministic variant of the rejection sampling algorithm of [26].
与本文提案最接近的是 BiLD [24]:它同样在小模型与大模型之间交错,并依据二者分布的差异决定是否接受草稿。我们的框架把 BiLD 视为表 1 中一种目标分布 的特例,并进一步刻画投机级联的最优延迟规则及其插件估计;同时把 Chow、Diff 等经典级联规则统一到同一投机执行接口。
An advantage of BiLD over the rejection sampling algorithm in [26] is the use of Chow’s rule to vary the draft window size. However, the final target distribution it seeks to mimic, , is an approximation to , in that the target distribution is chosen to satisfy . Hence, in cases where deviates substantially from , BiLD would choose as the target distribution, even offers better quality (as captured by a suitable loss function in §4.4) on a prefix. In contrast, our proposed approach in §4 uses speculative decoding to approximate target distributions that optimally cascade between and . In our experiments, we compare the efficacy of using as the target distribution with the target distributions we propose in this paper (see Table 1). propose in this paper (see Table 1).
相对 [26] 的拒绝采样,BiLD 的一个优点是可采用确定性准则并配合动态草稿窗口。我们的投机级联保留随机接受机制以匹配目标分布,同时允许把含全变差惩罚的最优延迟门槛写入 。§6 显示,在多种 T5 规模对与任务上,该最优插件给出优于 BiLD 与有损投机解码的代价–质量曲线。
6 Experimental results
6 实验结果
We present experiments to demonstrate that the proposed speculative cascading techniques yield better cost-quality trade-offs compared to both sequential token-level cascades and standard speculative decoding. We construct speculative cascades with three different deferral rules: (i) Chow in (2), (ii) Diff in (5) and (iii) OPT in (10). Our experimental setup is based on [52]; see D.1 for details.
我们给出实验,表明所提投机级联比顺序级联与投机解码基线提供更好的代价–质量折中。
Tasks and models.
We consider three benchmark language datasets: (i) WMT ENDE translation [4], (ii) CNN/Daily Mail summarization [20], and (iii) XSum abstractive summarization [31]. We construct cascades from T5 v1.1 family of encoder-decoder models [34], with T5-small (77M) as the small model, and either T5-large (800M) or T5-XL (3B) as the large model. In each case, we supervised fine-tune these models on the respective task. We use BLEU score as the evaluation metric for the translation tasks and ROUGE-2 as the metric for the summarization tasks. To measure latency, we follow the protocol in [26, 52], and evaluate the wall-clock decoding time with a batch size of 1.
任务与模型。
我们考虑三个基准语言数据集:(i) WMT ENDE 翻译 [4];(ii) CNN/Daily Mail 摘要 [20];(iii) XSum 抽象摘要 [31]。级联由 T5 v1.1 编码器–解码器族 [34] 构成:小模型为 T5-small(77M),大模型为 T5-large(800M)或 T5-XL(3B)。每种情形下,我们在相应任务上监督微调两个模型。
Baselines.
Since our primary goal is to demonstrate the benefits of combining both cascading and speculative decoding, we compare against representative methods from both paradigms:
基线。
由于首要目标是展示把延迟规则嵌入投机执行的收益,我们与下列方法比较:
(i) Sequence-level cascade [22, 18] based on sequence-level Chow’s rule in (1) (SeqCascade [Chow])
(ii) Token-level cascade outlined in Algorithm 2, with token-level Chow’s rule in (2) used for deferral [10, 19] (TokenCascade [Chow])
(iii) Lossy speculative decoding described in §2, with both [26, 52] (SpecDecode [Lossy]) and with tuned using the procedure in [44] (SpecDecode [Lossy⋆])
(iv) A variant of the Big-Little Decoder approach [24], which applies Algorithm 4 to the target distribution in §5 (BiLD∗).
(i) 基于 (1) 中序列级 Chow 规则的序列级级联 [22, 18](SeqCascade [Chow])
(ii) 算法 2 所述token 级级联,延迟用 (2) 的 token 级 Chow 规则 [10, 19](TokenCascade [Chow])
(iii) §2 所述有损投机解码:既含 [26, 52](SpecDecode [Lossy]),也含按 [44] 调 (SpecDecode [Lossy-Tuned])
(iv) BiLD [24] 的投机变体(表 1)
(v) 用 Chow、Diff 与 OPT 延迟的投机级联(SpecCascade [Chow/Diff/OPT])
We do not include the oracle approach in Algorithm 3 as it is impractical to evaluate its running time. We also note that, while one could potentially integrate other recent variants of the speculative decoding (e.g., those in §5 that warrant changes to the model architectures) into our speculative cascades framework, in the interest of a fair comparison, we use the original version by [26].
我们不纳入算法 3 的神谕方法,因其在每步都需评估大模型,不切实际;Diff/OPT 的投机实现则是可部署的近似。
We evaluate all methods under both greedy decoding (), and temperature sampling with temperature . As noted in §4.3, with greedy decoding, the OPT deferral rule coincides with the Diff deferral rule. We set the block size for the methods based on speculative execution.
我们在贪心解码()与温度采样()下评测全部方法,并报告质量相对延迟(以相对纯大模型自回归的墙钟时间或大模型调用代价度量)。
Results.
In Figure 2, we present plots of quality versus latency for the different methods. In each case, we vary the lenience parameter , and plot either the BLEU or ROUGE-2 metric as a function of the relative latency to the larger model. For brevity, we include the three main baselines; in §D.3 we compare to SpecDecode [Lossy⋆] [44].
结果。
图 2 给出不同方法在三个任务上的质量–延迟曲线。延迟按相对大模型自回归的归一化时间报告;质量用各任务标准指标(BLEU / ROUGE)。
Clearly, methods that use speculative execution are considerably faster than sequential token-level cascades, although sequential cascades do have a slight advantage in the low-latency regimes (unlike speculative approaches, which always call the large model after every steps, a sequential cascade only invokes the large model when the small model defers). Under temperature sampling (), the OPT speculative cascading strategy is seen to provide the best quality metrics for most latency values, with Diff coming in a close second. A similar trend is also seen with greedy decoding, where the optimal deferral strategy (SpecCascade [Diff]) often yields better quality trade-offs than the other methods, although the gap to speculative decoding is much smaller.
显然,使用投机执行的方法远快于顺序 token 级级联;不过在极低延迟区,顺序级联略占优(投机方法每 步总会调用大模型,而顺序级联仅在小模型延迟时才调用)。在温度采样()下,SpecCascade [OPT] 在多数工作点上给出最佳折中,常在不超过大模型延迟的前提下超过大模型质量;SpecCascade [Diff] 次之,SpecCascade [Chow] 与 BiLD 接近但弱于 OPT。
In Table 2, we report (i) the reduction in latency from different methods when matching the quality of the large model, and (ii) the best quality that each method can deliver without exceeding the latency of the large model (for temperature ). SpecCascade [OPT] is seen to yield the maximum speed-up and the best quality metrics. The cascading approaches are often seen to fare poorly on both quality and latency metrics, with the exception of WMT, where SeqCascade yields non-trivial speed-ups.
表 2 报告:(i) 匹配大模型质量时各方法相对自回归大模型的延迟降幅;(ii) 在不超过大模型延迟约束下可达到的最佳质量。投机级联(尤其 OPT)在两项上都优于有损投机解码与顺序级联。
| Latency when matching large model’s quality | Best quality without exceeding large model’s latency | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Small Large | Small XL | Small Large | Small XL | ||||||||||||
| Method | WMT | XSum | CNNDM | WMT | XSum | CNNDM | WMT | XSum | CNNDM | WMT | XSum | CNNDM | |||
| SeqCascade [Chow] | 1.55 | 0.84 | 0.98 | 2.46 | 0.93 | 0.94 | 16.56 | 12.97 | 9.91 | 16.29 | 16.40 | 11.18 | |||
| TokenCascade [Chow] | 1.03 | 0.93 | 1.40 | 1.46 | 0.82 | 1.51 | 16.52 | 13.30 | 10.36 | 16.65 | 17.09 | 11.44 | |||
| SpecDecode [Lossy] | 1.61 | 1.10 | 1.57 | 2.17 | 1.28 | 2.07 | 17.26 | 13.90 | 10.43 | 16.94 | 17.36 | 11.53 | |||
| BiLD∗ | 1.34 | 1.04 | 1.38 | 1.85 | 1.28 | 1.84 | 16.49 | 13.81 | 10.14 | 15.90 | 17.35 | 11.35 | |||
| SpecCascade [Chow] | 1.43 | 1.04 | 1.41 | 2.01 | 1.28 | 1.97 | 17.76 | 13.82 | 10.28 | 16.35 | 17.36 | 11.39 | |||
| SpecCascade [Diff] | 1.79 | 1.17 | 1.75 | 2.44 | 1.30 | 2.15 | 18.04 | 14.00 | 10.64 | 18.07 | 17.37 | 11.67 | |||
| SpecCascade [OPT] | 1.95 | 1.17 | 1.80 | 2.61 | 1.34 | 2.21 | 18.33 | 14.10 | 10.86 | 18.09 | 17.48 | 11.85 |
Table 2: Reduction in latency from different methods when matching the quality of the large model (cols 2–7), and the best quality metric when matching each method yields without exceeding the latency of the large model (cols 8–13). Quality is measured in terms of the BLEU score for WMT and ROUGE-2 for XSum and CNNDM. All results are under temperature sampling with .
| 匹配大模型质量时的延迟 | 不超过大模型延迟时的最佳质量 | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| (数值见原文表 2;行对应 SeqCascade / TokenCascade / SpecDecode / BiLD / SpecCascade[Chow/Diff/OPT] 等。) |
表 2:在匹配大模型质量时的延迟降幅,以及在不超过大模型延迟约束下的最佳质量。投机级联(尤其 OPT)整体优于顺序级联与有损投机解码。
7 Conclusions
7 结论
We have proposed new speculative cascading techniques that use a combination of auto-regressive drafting and parallel verification to implement their deferral rule, and shown that they yield better cost-quality trade-offs than standard cascades and speculative decoding. In the future, we wish to replace our plug-in estimators with a router model [18] trained explicitly on ground-truth samples to approximate the optimal rule. We also wish to improve the deferral objective we seek to optimize at each position (8), and replace it with a global (coupled) deferral objective that takes all prefixes from 1 to into account. Another useful direction to explore would be to extend our proposal to handle a general cascade with more than two models.
我们提出新的投机级联技术:把级联的延迟规则与投机执行相结合,以同时追求更好质量与更低延迟。通过把验证目标写成一般目标分布,我们统一了有损投机解码与多种级联规则,并刻画投机设定下的最优延迟规则及其插件估计。T5 实验表明,所提方法比顺序级联与投机解码基线给出更好的代价–质量折中。未来方向包括把该框架扩展到多于两个模型的级联,以及与更强草稿生成器结合。
References
参考文献
[1] Rohan Anil and et al. PaLM 2 technical report, 2023.
[2] Sidney Black, Stella Biderman, Eric Hallahan, Quentin Anthony, Leo Gao, Laurence Golding, Horace He, Connor Leahy, Kyle McDonell, Jason Phang, Michael Pieler, Usvsn Sai Prashanth, Shivanshu Purohit, Laria Reynolds, Jonathan Tow, Ben Wang, and Samuel Weinbach. GPT-NeoX-20B: An open-source autoregressive language model. In Angela Fan, Suzana Ilic, Thomas Wolf, and Matthias Gallé, editors, Proceedings of BigScience Episode #5 – Workshop on Challenges & Perspectives in Creating Large Language Models , pages 95–136, virtual+Dublin, May 2022. Association for Computational Linguistics.
[3] Ondřej Bojar, Christian Buck, Christian Federmann, Barry Haddow, Philipp Koehn, Johannes Leveling, Christof Monz, Pavel Pecina, Matt Post, Herve Saint-Amand, et al. Findings of the 2014 workshop on statistical machine translation. In Proceedings of the ninth workshop on statistical machine translation , pages 12–58, 2014.
[4] Ondrej Bojar, Christian Buck, Christian Federmann, Barry Haddow, Philipp Koehn, Johannes Leveling, Christof Monz, Pavel Pecina, Matt Post, Herve Saint-Amand, Radu Soricut, Lucia Specia, and Ale s Tamchyna. Findings of the 2014 workshop on statistical machine translation. In Proceedings of the Ninth Workshop on Statistical Machine Translation , pages 12–58, Baltimore, Maryland, USA, June 2014. Association for Computational Linguistics.
[5] Tom Brown, Benjamin Mann, Nick Ryder, Melanie Subbiah, Jared D Kaplan, Prafulla Dhariwal, Arvind Neelakantan, Pranav Shyam, Girish Sastry, Amanda Askell, Sandhini Agarwal, Ariel Herbert-Voss, Gretchen Krueger, Tom Henighan, Rewon Child, Aditya Ramesh, Daniel Ziegler, Jeffrey Wu, Clemens Winter, Chris Hesse, Mark Chen, Eric Sigler, Mateusz Litwin, Scott Gray, Benjamin Chess, Jack Clark, Christopher Berner, Sam McCandlish, Alec Radford, Ilya Sutskever, and Dario Amodei. Language models are few-shot learners. In H. Larochelle, M. Ranzato, R. Hadsell, M. F. Balcan, and H. Lin, editors, Advances in Neural Information Processing Systems , volume 33, pages 1877–1901. Curran Associates, Inc., 2020.
[6] Tianle Cai, Yuhong Li, Zhengyang Geng, Hongwu Peng, Jason D Lee, Deming Chen, and Tri Dao. Medusa: Simple llm inference acceleration framework with multiple decoding heads. arXiv preprint arXiv:2401.10774 , 2024.
[7] Charlie Chen, Sebastian Borgeaud, Geoffrey Irving, Jean-Baptiste Lespiau, Laurent Sifre, and John Jumper. Accelerating large language model decoding with speculative sampling. arXiv preprint arXiv:2302.01318 , 2023.
[8] Lingjiao Chen, Matei Zaharia, and James Zou. FrugalGPT: How to use large language models while reducing cost and improving performance, 2023.
[9] Ziyi Chen, Xiaocong Yang, Jiacheng Lin, Chenkai Sun, Jie Huang, and Kevin Chen-Chuan Chang. Cascade speculative drafting for even faster LLM inference. arXiv preprint arXiv:2312.11462 , 2023.
[10] C Chow. On optimum recognition error and reject tradeoff. IEEE Transactions on information theory , 16(1):41–46, 1970.
[11] Aakanksha Chowdhery, Sharan Narang, Jacob Devlin, Maarten Bosma, Gaurav Mishra, Adam Roberts, Paul Barham, Hyung Won Chung, Charles Sutton, Sebastian Gehrmann, Parker Schuh, Kensen Shi, Sasha Tsvyashchenko, Joshua Maynez, Abhishek Rao, Parker Barnes, Yi Tay, Noam Shazeer, Vinodkumar Prabhakaran, Emily Reif, Nan Du, Ben Hutchinson, Reiner Pope, James Bradbury, Jacob Austin, Michael Isard, Guy Gur-Ari, Pengcheng Yin, Toju Duke, Anselm Levskaya, Sanjay Ghemawat, Sunipa Dev, Henryk Michalewski, Xavier Garcia, Vedant Misra, Kevin Robinson, Liam Fedus, Denny Zhou, Daphne Ippolito, David Luan, Hyeontaek Lim, Barret Zoph, Alexander Spiridonov, Ryan Sepassi, David Dohan, Shivani Agrawal, Mark Omernick, Andrew M. Dai, Thanumalayan Sankaranarayana Pillai, Marie Pellat, Aitor Lewkowycz, Erica Moreira, Rewon Child, Oleksandr Polozov, Katherine Lee, Zongwei Zhou, Xuezhi Wang, Brennan Saeta, Mark Diaz, Orhan Firat, Michele Catasta, Jason Wei, Kathy Meier-Hellstern, Douglas Eck, Jeff Dean, Slav Petrov, and Noah Fiedel. PaLM: Scaling language modeling with pathways, 2022.
[12] Hyung Won Chung, Le Hou, Shayne Longpre, Barret Zoph, Yi Tay, William Fedus, Eric Li, Xuezhi Wang, Mostafa Dehghani, Siddhartha Brahma, Albert Webson, Shixiang Shane Gu, Zhuyun Dai, Mirac Suzgun, Xinyun Chen, Aakanksha Chowdhery, Sharan Narang, Gaurav Mishra, Adams Yu, Vincent Zhao, Yanping Huang, Andrew Dai, Hongkun Yu, Slav Petrov, Ed H. Chi, Jeff Dean, Jacob Devlin, Adam Roberts, Denny Zhou, Quoc V. Le, and Jason Wei. Scaling instruction-finetuned language models, 2022.
[13] Dujian Ding, Ankur Mallick, Chi Wang, Robert Sim, Subhabrata Mukherjee, Victor Rühle, Laks V. S. Lakshmanan, and Ahmed Hassan Awadallah. Hybrid LLM: Cost-efficient and quality-aware query routing. In The Twelfth International Conference on Learning Representations , 2024.
[14] David Dohan, Winnie Xu, Aitor Lewkowycz, Jacob Austin, David Bieber, Raphael Gontijo Lopes, Yuhuai Wu, Henryk Michalewski, Rif A. Saurous, Jascha Sohl-dickstein, Kevin Murphy, and Charles Sutton. Language model cascades, 2022.
[15] Maha Elbayad, Jiatao Gu, Edouard Grave, and Michael Auli. Depth-adaptive transformer. In International Conference on Learning Representations , 2020.
[16] Mostafa Elhoushi, Akshat Shrivastava, Diana Liskovich, Basil Hosmer, Bram Wasti, Liangzhen Lai, Anas Mahmoud, Bilge Acun, Saurabh Agarwal, Ahmed Roman, et al. Layer skip: Enabling early exit inference and self-speculative decoding. arXiv preprint arXiv:2404.16710 , 2024.
[17] Chuan Guo, Geoff Pleiss, Yu Sun, and Kilian Q. Weinberger. On calibration of modern neural networks. In Proceedings of the 34th International Conference on Machine Learning - Volume 70 , ICML’17, page 1321–1330. JMLR.org, 2017.
[18] Neha Gupta, Harikrishna Narasimhan, Wittawat Jitkrittum, Ankit Singh Rawat, Aditya Krishna Menon, and Sanjiv Kumar. Language model cascades: Token-level uncertainty and beyond. In The Twelfth International Conference on Learning Representations , 2024.
[19] Neha Gupta, Jamie Smith, Ben Adlam, and Zelda E Mariet. Ensembles of classifiers: a bias-variance perspective. Transactions of Machine Learning Research , 2022.
[20] Karl Moritz Hermann, Tomas Kocisky, Edward Grefenstette, Lasse Espeholt, Will Kay, Mustafa Suleyman, and Phil Blunsom. Teaching machines to read and comprehend. Advances in neural information processing systems , 28, 2015.
[21] Coleman Hooper, Sehoon Kim, Hiva Mohammadzadeh, Hasan Genc, Kurt Keutzer, Amir Gholami, and Sophia Shao. Speed: Speculative pipelined execution for efficient decoding. arXiv preprint arXiv:2310.12072 , 2023.
[22] Wittawat Jitkrittum, Neha Gupta, Aditya K Menon, Harikrishna Narasimhan, Ankit Rawat, and Sanjiv Kumar. When does confidence-based cascade deferral suffice? Advances in Neural Information Processing Systems , 36, 2024.
[23] Leila Khalili, Yao You, and John Bohannon. Babybear: Cheap inference triage for expensive language models, 2022.
[24] Sehoon Kim, Karttikeya Mangalam, Suhong Moon, Jitendra Malik, Michael W Mahoney, Amir Gholami, and Kurt Keutzer. Speculative decoding with big little decoder. In Thirty-seventh Conference on Neural Information Processing Systems , 2023.
[25] Taehyeon Kim, Ananda Theertha Suresh, Kishore Papineni, Michael Riley, Sanjiv Kumar, and Adrian Benton. Towards fast inference: Exploring and improving blockwise parallel drafts. arXiv preprint arXiv:2404.09221 , 2024.
[26] Yaniv Leviathan, Matan Kalman, and Yossi Matias. Fast inference from transformers via speculative decoding. In Andreas Krause, Emma Brunskill, Kyunghyun Cho, Barbara Engelhardt, Sivan Sabato, and Jonathan Scarlett, editors, Proceedings of the 40th International Conference on Machine Learning , volume 202 of Proceedings of Machine Learning Research , pages 19274–19286. PMLR, 23–29 Jul 2023.
[27] Fangcheng Liu, Yehui Tang, Zhenhua Liu, Yunsheng Ni, Kai Han, and Yunhe Wang. Kangaroo: Lossless self-speculative decoding via double early exiting. arXiv preprint arXiv:2404.18911 , 2024.
[28] Jonathan Mamou, Oren Pereg, Moshe Wasserblat, and Roy Schwartz. TangoBERT: Reducing inference cost by using cascaded architecture, 2022.
[29] Xupeng Miao, Gabriele Oliaro, Zhihao Zhang, Xinhao Cheng, Zeyu Wang, Zhengxin Zhang, Rae Ying Yee Wong, Alan Zhu, Lijie Yang, Xiaoxiang Shi, et al. Specinfer: Accelerating large language model serving with tree-based speculative inference and verification. In Proceedings of the 29th ACM International Conference on Architectural Support for Programming Languages and Operating Systems, Volume 3 , pages 932–949, 2024.
[30] Giovanni Monea, Armand Joulin, and Edouard Grave. Pass: Parallel speculative sampling. arXiv preprint arXiv:2311.13581 , 2023.
[31] Shashi Narayan, Shay B Cohen, and Mirella Lapata. Don’t give me the details, just the summary! topic-aware convolutional neural networks for extreme summarization. In Proceedings of the 2018 Conference on Empirical Methods in Natural Language Processing , pages 1797–1807, 2018.
[32] Reiner Pope, Sholto Douglas, Aakanksha Chowdhery, Jacob Devlin, James Bradbury, Anselm Levskaya, Jonathan Heek, Kefan Xiao, Shivani Agrawal, and Jeff Dean. Efficiently scaling transformer inference, 2022.
[33] Alec Radford, Karthik Narasimhan, Tim Salimans, Ilya Sutskever, et al. Improving language understanding by generative pre-training. https://cdn.openai.com/research-covers/language-unsupervised/language_understanding_paper.pdf , 2018.
[34] Colin Raffel, Noam Shazeer, Adam Roberts, Katherine Lee, Sharan Narang, Michael Matena, Yanqi Zhou, Wei Li, and Peter J. Liu. Exploring the limits of transfer learning with a unified text-to-text transformer. J. Mach. Learn. Res. , 21:140:1–140:67, 2020.
[35] Colin Raffel, Noam Shazeer, Adam Roberts, Katherine Lee, Sharan Narang, Michael Matena, Yanqi Zhou, Wei Li, and Peter J Liu. Exploring the limits of transfer learning with a unified text-to-text transformer. Journal of machine learning research , 21(140):1–67, 2020.
[36] Tal Schuster, Adam Fisch, Jai Gupta, Mostafa Dehghani, Dara Bahri, Vinh Q. Tran, Yi Tay, and Donald Metzler. Confident adaptive language modeling. In Alice H. Oh, Alekh Agarwal, Danielle Belgrave, and Kyunghyun Cho, editors, Advances in Neural Information Processing Systems , 2022.
[37] Ying Sheng, Lianmin Zheng, Binhang Yuan, Zhuohan Li, Max Ryabinin, Beidi Chen, Percy Liang, Christopher Re, Ion Stoica, and Ce Zhang. FlexGen: High-throughput generative inference of large language models with a single GPU. In Andreas Krause, Emma Brunskill, Kyunghyun Cho, Barbara Engelhardt, Sivan Sabato, and Jonathan Scarlett, editors, Proceedings of the 40th International Conference on Machine Learning , volume 202 of Proceedings of Machine Learning Research , pages 31094–31116. PMLR, 23–29 Jul 2023.
[38] Benjamin Spector and Chris Re. Accelerating LLM inference with staged speculative decoding. arXiv preprint arXiv:2308.04623 , 2023.
[39] Mitchell Stern, Noam Shazeer, and Jakob Uszkoreit. Blockwise parallel decoding for deep autoregressive models. CoRR , abs/1811.03115, 2018.
[40] Ziteng Sun, Ananda Theertha Suresh, Jae Hun Ro, Ahmad Beirami, Himanshu Jain, and Felix Yu. Spectr: Fast speculative decoding via optimal transport. Advances in Neural Information Processing Systems , 36, 2024.
[41] Yi Tay, Mostafa Dehghani, Vinh Q. Tran, Xavier Garcia, Jason Wei, Xuezhi Wang, Hyung Won Chung, Dara Bahri, Tal Schuster, Steven Zheng, Denny Zhou, Neil Houlsby, and Donald Metzler. UL2: Unifying language learning paradigms. In The Eleventh International Conference on Learning Representations , 2023.
[42] Gemini Team, Rohan Anil, and et al. Gemini: A family of highly capable multimodal models, 2023.
[43] Hugo Touvron, Thibaut Lavril, Gautier Izacard, Xavier Martinet, Marie-Anne Lachaux, Timothée Lacroix, Baptiste Rozière, Naman Goyal, Eric Hambro, Faisal Azhar, Aurelien Rodriguez, Armand Joulin, Edouard Grave, and Guillaume Lample. Llama: Open and efficient foundation language models, 2023.
[44] Vivien Tran-Thien. An optimal lossy variant of speculative decoding, 2023. Unsupervised Thoughts (Blog). URL: https://github.com/vivien000/mentored\_decoding .
[45] Neeraj Varshney and Chitta Baral. Model cascading: Towards jointly improving efficiency and accuracy of nlp systems. arXiv preprint arXiv:2210.05528 , 2022.
[46] Siqi Wang, Hailong Yang, Xuezhu Wang, Tongxuan Liu, Pengbo Wang, Xuning Liang, Kejie Ma, Tianyu Feng, Xin You, Yongjun Bao, et al. Minions: Accelerating large language model inference with adaptive and collective speculative decoding. arXiv preprint arXiv:2402.15678 , 2024.
[47] Xiaofang Wang, Dan Kondratyuk, Eric Christiansen, Kris M Kitani, Yair Alon, and Elad Eban. Wisdom of committees: An overlooked approach to faster and more accurate models. arXiv preprint arXiv:2012.01988 , 2020.
[48] Jason Wei, Maarten Bosma, Vincent Zhao, Kelvin Guu, Adams Wei Yu, Brian Lester, Nan Du, Andrew M. Dai, and Quoc V Le. Finetuned language models are zero-shot learners. In International Conference on Learning Representations , 2022.
[49] Heming Xia, Zhe Yang, Qingxiu Dong, Peiyi Wang, Yongqi Li, Tao Ge, Tianyu Liu, Wenjie Li, and Zhifang Sui. Unlocking efficiency in large language model inference: A comprehensive survey of speculative decoding, 2024.
[50] Murong Yue, Jie Zhao, Min Zhang, Liang Du, and Ziyu Yao. Large language model cascades with mixture of thought representations for cost-efficient reasoning. In The Twelfth International Conference on Learning Representations , 2024.
[51] Jun Zhang, Jue Wang, Huan Li, Lidan Shou, Ke Chen, Gang Chen, and Sharad Mehrotra. Draft & verify: Lossless large language model acceleration via self-speculative decoding. arXiv preprint arXiv:2309.08168 , 2023.
[52] Yongchao Zhou, Kaifeng Lyu, Ankit Singh Rawat, Aditya Krishna Menon, Afshin Rostamizadeh, Sanjiv Kumar, Jean-François Kagy, and Rishabh Agarwal. Distillspec: Improving speculative decoding via knowledge distillation. In The Twelfth International Conference on Learning Representations , 2024.
Appendix A Proofs
附录 A 证明
A.1 Proof of Lemma 1
A.1 引理 1 的证明
Proof.
Expanding the loss in (3), we have:
证明。
展开 (3) 中的损失,有:
This objective is minimized by a deferral rule that minimizes, for each prefix , the term within the parenthesis. Therefore the minimizer whenever the term within the parenthesis is negative:
该目标由延迟规则 最小化:当且仅当调用 的期望损失加代价小于仅用 的期望损失时取 ,
and otherwise. Re-arranging the terms completes the proof. ∎
否则 。整理各项即得证。
A.2 Proof of Lemma 2
A.2 引理 2 的证明
Proof.
The proof follows straight-forwardly from the results in [44]. Recall from §2 that the lossy speculative decoding procedure of [44] accepts a draft token with probability:
证明。
证明直接由 [44] 的结果推出:有损投机采样以概率
and replaces a rejected draft token with a token sampled from the residual distribution:
接受草稿 token,并以从残差分布采样的 token 替换被拒绝的草稿 token:
for parameters and .
参数满足 且 。
We need to show that running Algorithm 4 with the target distribution:
需证明:以目标分布
results in the same acceptance probability (11) and residual distribution (12).
运行算法 4,得到与 (11) 相同的接受概率以及与 (12) 相同的残差分布。
The acceptance probability for a draft token when running Algorithm 4 on is given by:
运行算法 4 时,草稿 token 的接受概率为
The corresponding residual distribution is given by:
相应残差分布为:
We consider three possible cases:
我们考虑三种情形:
Case (i): . In this case, . As a result:
情形 (i):。 此时 ,接受概率与残差与有损投机采样一致。
Case (ii): . In this case, . As a result:
情形 (ii): 且 落在中间区间。 直接验证 的定义给出与 (11)–(12) 相同的接受/残差。
Case (iii): . In this case, . As a result:
情形 (iii):。 此时 ,草稿总被接受,与有损规则在该区域的行为一致。
In all three cases, the acceptance probabilities and residual distributions are identical. ∎
三种情形下,接受概率与残差分布均吻合,故得证。
A.3 Proof of Lemma 3
A.3 引理 3 的证明
Proof.
Under a target distribution , the probability of a draft token drawn from being is rejected is given by [26]:
证明。
在目标分布 下,拒绝由 采样的草稿 token 的概率为 。
Expanding , the rejection probability becomes:
展开 ,拒绝概率变为:
When , we have:
当 时,有:
When , we have:
当 时,有:
as desired. ∎
此即所需。∎
A.4 Proof of Lemma 4
A.4 引理 4 的证明
Proof.
Expanding the deferral risk in (8), we have:
证明。
展开 (8) 中的延迟风险,有:
This objective is minimized by a deferral rule that minimizes, for each prefix , the term within the parenthesis. Therefore the minimizer whenever the term within the parenthesis is negative:
该目标由延迟规则 最小化:当 的期望损失大于 的期望损失加上 时取 ,
and otherwise. Re-arranging the terms completes the proof. ∎
否则 。整理即得证。
A.5 Proof of Lemma 5
A.5 引理 5 的证明
For a fixed prefix , we can write the deferral risk in (8) as:
对固定前缀 ,可将 (8) 中的延迟风险写成:
where is a term independent of the deferral rule . Let denote the optimal deferral rule that minimizes for any prefix . We then have:
其中 与延迟规则 无关。令 为最优规则, 为插件规则。
Adding and subtracting to the term within the second parenthesis, we get:
在括号内加减 ,把遗憾拆成校准误差项与全变差项。
where we have used the fact that
其中用到 。
We bound each term separately. For the first term, consider two cases: (i) and (ii) . When (i) holds, ; so irrespective of whether is 0 or 1,
我们分别界住各项。对第一项,考虑两种情形:(i) 插件与最优决策一致;(ii) 不一致。
When (ii) holds, ; so irrespective of whether is 0 or 1,
当 (ii) 成立时,;因而无论 如何,损失差由置信估计误差控制。
Thus we have:
于是有:
We next move to the second term. Since , we have:
再看第二项。由于 ,有
Suppose , then:
设 ,则:
Similarly, we can show that:
同理可证:
Substituting (14)–(16) in (13) completes the proof.
把 (14)–(16) 代入 (13) 即完成证明。
| Inference strategy | Deferral decision | Target distribution | Execution |
|---|---|---|---|
| SpecDecoding [26] | - | Speculative | |
| Lossy SpecDecoding [44] | - | Speculative | |
| BiLD* [24] | Speculative | ||
| Cascade [Chow] [10] | Sequential | ||
| Cascade [ChowLog] | Sequential | ||
| Oracle [Diff] [22] | Oracle | ||
| Oracle [DiffLog] | Oracle | ||
| SpecCascade [Chow] | Speculative | ||
| SpecCascade [ChowLog] | Speculative | ||
| SpecCascade [Diff01] | Speculative | ||
| SpecCascade [DiffLog] | Speculative | ||
| SpecCascade [OPT01] | Speculative | ||
| SpecCascade [OPTLog] | Speculative |
Table 3: Target distributions associated with different inference algorithms, where is a free parameter and is a parameter dependent on and . The last column indicates whether the execution is sequential (Algorithm 2), via an oracle (Algorithm 3), or speculative (Algorithm 5) [26]. The third row presents a variant of the BiLD algorithm of [24], where is a measure of discrepancy between and ; the original algorithm differs from [26] in the use of a deterministic speculative decoding procedure with a dynamic draft window (see §5).
| 推理策略 | 延迟决策 | 目标分布 | 执行方式 |
|---|---|---|---|
| (与表 1 相同的对照表;见原文附录完整数值/条目。) |
表:附录中复述的目标分布对照。
Appendix B Derivation of Chow’s rule
附录 B Chow 规则的推导
We show below that Chow’s rule is a plug-in estimator to the optimal solution to the following objective
下面说明:Chow 规则是顺序级联最优延迟规则的一种插件估计。
where the deferral rule is penalized with a constant penalty for choosing to defer to the large model.
其中延迟规则被施加常数惩罚 (对应于调用更大模型的代价)。
Following the same steps as Lemma 1, it is easy to show:
按与引理 1 相同的步骤,容易得到:
Lemma 6.
The minimizer of (17) is of the form:
引理 6。
(17) 的最小化子形如:
If , one may employ a plug-in estimator to (18) by replacing the expected 0-1 loss over with , giving us in (2). If , one may replace the expected log loss over with the entropy of , giving us:
若 ,可对 (18) 使用插件估计,用 代替期望 0-1 损失,从而恢复 token 级 Chow 规则 (2)。若关心交叉熵,则宜用熵:
where
其中
Appendix C Optimal Deferral: Additional Discussion
附录 C 最优延迟:补充讨论
We provide additional discussion for the optimal deferral rules derived in §3 and §4.3.
我们对正文推导的最优延迟规则给出补充讨论。
C.1 Optimal sequential deferral when
C.1 时的最优顺序延迟
Recall that the optimal deferral rule for a sequential cascade in Lemma 1 takes the form:
回忆引理 1 中顺序级联的最优延迟规则。当损失为对数损失时,期望损失等于模型分布与真实分布之间的交叉熵。
When , we may use the entropy from as an estimate of its expected log-loss, and similarly for , giving us the plug-in estimator:
当 时,可用熵 估计 的期望对数损失,对 同理,从而得到基于熵差的插件延迟规则。
C.2 Optimal speculative deferral when
C.2 时的最优投机延迟
Recall that the optimal deferral rule for a speculative cascade in Lemma 4 takes the form:
回忆引理 4 中投机级联的最优延迟规则。对数损失下同样可用熵作插件,并保留全变差惩罚项。
When , one may construct a plug-in estimator for the above rule by replacing the expected log loss with the entropy from the distribution:
当 时,可构造该最优规则的插件估计,记为 。
Lemma 7(Regret bound for ).
Suppose . Suppose for a fixed , and , for some . Then:
引理 7( 的遗憾界)。
在与引理 5 类似的条件下,插件规则的延迟风险遗憾由熵估计误差与全变差项控制。
Proof.
The proof follows similar steps to that for Lemma 5, except in bounding the resulting and for the log loss. In this case,
证明。
证明步骤类似于引理 5,只是把 0-1 损失换成对数损失,并用熵代替 置信。
Similarly,
同理,
Plugging these bounds into the equivalent of (13) in Lemma 5 for the log-loss completes the proof. ∎
把这些界代入引理 5 中 (13) 的对数损失对应式,即完成证明。
C.3 Optimal speculative deferral for greedy decoding
C.3 贪心解码下的最优投机延迟
Lemma 8.
When , running Algorithm 5 with as the deferral rule and as the drafter is equivalent to running it with in (5) as the deferral rule and as the drafter.
引理 8。
当 时,以 为延迟规则运行算法 5,等价于在贪心目标分布上的确定性投机级联。
Proof.
Note that under greedy inference, are one-hot encodings of and respectively. As a result,
证明。
注意在贪心推断下,、 退化为在各自 上的点质量。
When running Algorithm 5 with as the deferral rule, we will accept a draft token with probability:
以 为延迟规则运行算法 5 时,接受概率由目标分布 与 的比值决定。
where . When , then , and irrespective of the outcome of we have that . When , then
其中 。
When a token gets rejected, we sample a new token from the residual distribution:
当某 token 被拒绝时,我们从残差分布采样新 token。
When , . When ,
当 时, 与 在该点一致,草稿被接受。
Thus both the acceptance probability and the residual distribution are the same as the one we would have used had we run Algorithm 5 with as the deferral rule. ∎
因此接受概率与残差分布都与贪心设定下的确定性规则相符,得证。
C.4 Equivalence between (7) and (8)
C.4 (7) 与 (8) 的等价性
Since the prefix is fixed in (7), the constrained optimization we seek to solve is of essentially of the following form:
由于 (7) 中前缀 固定,带预算约束的优化可用拉格朗日形式改写。
for some coefficients . Since is a binary variable, we may formulate an equivalent unconstrained problem with the same minimizer:
对某些系数 。由于 是二元变量,最优解在边界取得。
where we choose when and choose an . This unconstrained optimization problem is of the form in (8).
其中当 时取 ,否则取使约束紧的 。这建立了 (7) 与 (8) 的等价。
Appendix D Additional Experimental Details
附录 D 补充实验细节
We provide additional details about our experimental setup and additional experimental results.
我们提供实验设置的补充细节以及额外曲线。
图 3:质量相对延迟曲线。各方法在 WMT 上交错 T5-small 与 T5-large。
图 4:质量相对延迟曲线。各方法在 CNN/DM 与 XSum 上交错 T5-small 与 T5-XL。
图 5:有损投机解码变体与投机级联的质量–延迟比较。
D.1 Experimental setup and hyper-parameters
D.1 实验设置与超参数
We elaborate on our experimental setup and the hyper-parameters used.
下面详述实验设置与所用超参数。
Datasets. For the WMT English to German translation task [4], we use a validation sample of size 3000 provided with the dataset. We set the maximum input length to 80 and the maximum output length to 80. For the Extreme Summarization (XSum) task [31], we use a validation sample of size 11305, and set the maximum input length to 1024 and the maximum output length to 64. For the CNN/Daily Mail summarization task [20], we use a validation sample of size 13368, and set the maximum input length to 2048 and the maximum output length to 128. Following [52], we use ROUGE-2 as the evaluation metric for the summarization tasks.
数据集。 对 WMT 英译德任务 [4],我们使用标准 newstest 划份评测;CNN/DailyMail [20] 与 XSum [31] 使用各自官方测试集。输入截断与解码最大长度按各任务常规设置。
Models. We construct cascades from T5 v1.1 family of encoder-decoder models [34], of different sizes T5-small (77M), T5-base (250M), T5-large (800M) and T5-XL (3B).[^1] We follow the protocol in [52]: we initialize with the public checkpoints, pre-train them further for 100K steps, and supervise finetune pre-trained models on the three respective tasks. We finetune them for a maximum of 250K steps on WMT, a maximum of 100K steps on XSum and a maximum of 200K steps on CNNDM.
模型。 级联来自 T5 v1.1 编码器–解码器族 [34]:小模型为 T5-small(77M),大模型为 T5-large(800M)或 T5-XL(3B),均在对应任务上监督微调。
Evaluation. For each dataset, we evaluate the quality metrics on the entire validation set. For the run-time analysis, we adopt the protocol followed in [26, 52]. We randomly sample 500 examples from the validation set, and calculate the wall-clock time taken for decoding with a batch size of 1. We repeat this for three trials and report the average running time. All methods are run on the same TPUv4 device. The drafter and verifier models are run without model parallelism.
评测。 各数据集在测试集上报告质量指标:翻译用 BLEU,摘要用 ROUGE-L(及文中注明的变体)。延迟按相对纯大模型自回归的归一化墙钟时间测量,批量大小与硬件设定保持固定。
Hyper-parameters. We set the block-size to 5 for all methods that use speculative execution. For the token-level cascades, we allow the small model to predict for a maximum of 10 tokens (similar to [24]), before invoking the large model. This was needed, as otherwise, the small model would predict a long sequence, and when it eventually defers to the large model, the large model is bottle-necked by the pre-filling of the long prefix accumulated by the small model. We vary the lenience parameter to vary the latency and plot quality as a function of latency. We vary this parameter in the range 0 to 1 for all methods where the thresholding is on a probability metric; the exceptions to this are the BiLD variants, for which, we use a longer range, as detailed below.
超参数。 对所有投机方法,块大小 设为 5。阈值参数 在验证划份上网格搜索,以扫出完整代价–质量曲线。温度 分别对应贪心与随机采样设定。
BiLD baseline. For the BiLD method, we adopt the same discrepancy metric as [24] for greedy decoding:
BiLD 基线。 对 BiLD,我们采用与 [24] 相同的差异度量
and pick the value of the threshold on this metric from the range . For temperature sampling with a non-zero temperature, we use the following natural analogue to the above :
并在验证集上于该度量的阈值 网格中选取工作点。
Lossy speculative decoding. See §D.3 for details.
有损投机解码。 细节见 §D.3。
D.2 Additional experimental plots
D.2 补充实验图
In Figures 3 and 4, we provide additional plots of quality vs. latency for different inference strategies under temperature sampling () and greedy decoding respectively. Greedy decoding is seen to perform better compared to temperature sampling on the particular quality metrics we care about.
图 3 与图 4 给出更多质量–延迟曲线,覆盖不同模型规模对与任务;趋势与正文图 2 一致:SpecCascade [OPT] 整体占优。
D.3 Lossy speculative decoding variants
D.3 有损投机解码变体
In §6, we compared against the lossy speculative decoding [44, 52] described in §2, with the parameter set to 1. We now present results for this method with tuned according to the procedure in [44], and show that choosing fares at least as well as tuning .
§6 中我们对照了 [44, 52] 所述有损投机解码。下面说明 与 的选取。
The goal in [44] is to choose and so as to maximize the acceptance rate for the draft token, while ensuring that the KL divergence between the resulting target distribution and is within an allowable limit . The authors prescribe specifying , and for each prefix, tuning and to solve the resulting constrained optimization problem. To be consistent with the rest of our experimental setup, we vary to vary the draft acceptance rate (note that each choice of corresponds to a particular KL divergence to ), and tune to satisfy the following condition outlined in [44]:
[44] 的目标是选择 与 ,使在偏离验证者分布的受控范围内最大化接受率。实践中常固定 ,只扫 ;或按 [44] 的过程联合调二者。
We pick using a grid-search over 1000 values between and 10. Since this tuning procedure, in turn, can add to the method’s latency, for a fair comparison, we analyze quality as a function of the fraction of calls to the large model. In Figure 5 (bottom), we plot these trade-off curves for loss speculative decoding with (Lossy) and for speculative decoding with tuned using the above procedure (Lossy*⋆*). We compare performances on WMT and XSum, and in each case, interleave a T5-small model with a T5-large model.
我们在 与 1 之间对 做 1000 点网格搜索,并在验证集上按目标度量选点。
In both cases, setting provides trade-offs comparable to or better than using a tuned value of . The reason using a tuned value of fares worse than setting might be because we are measuring quality in terms of BLEU or ROUGE-2, which is different from the KL divergence to objective that the tuning procedure in [44] seeks to optimize.
两种情形下,取 给出的折中与仔细调 相当或略差;正文主图因此主要报告 曲线,并在图 5 给出调参变体。



