Glean 拾遗
日刊 /2026-07-06 / DeepSeek投机解码框架DSpark深度拆解:半自回归设计与置信度调度如何突破推理瓶颈

DeepSeek投机解码框架DSpark深度拆解:半自回归设计与置信度调度如何突破推理瓶颈

原文 mp.weixin.qq.com 收录 2026-07-06 06:00 阅读 89 min
AI 解读

本文是DeepSeek刚开源的投机解码框架DSpark的深度技术解析。作者从投机解码的数学原理(拒绝采样、加速比公式推导)讲起,系统梳理了从传统自回归草稿(Speculative Decoding/Sampling、BiLD、Self-Speculative)、树状投机(SpecInfer)、多头/特征层方法(Medusa、Lookahead、EAGLE系列)、MTP训练集成(Meta MTP、DeepSeek-V3 MTP),到并行扩散范式(DFlash、DDTree、JetSpec)的完整演进脉络。在此基础上,重点剖析DSpark的两个核心创新:1)半自回归生成(Semi-Autoregressive Generation):并行主干(DFlash)一次前向输出基础logits,轻量马尔可夫头/RNN头串行注入依赖,仅增加约1%起草时间却提升30%草稿质量;2)置信度调度验证(Confidence-Scheduled Verification):训练置信度头预测每位置条件接受概率,经序列化温度缩放校准后,硬件感知调度器将验证长度选择形式化为全局吞吐量最大化问题,在高并发下动态裁剪低置信度后缀。文章还揭示了生产部署中的关键适配:两步延迟的异步调度机制配合CUDA Graph回放,解决了因果性与硬件锯齿性能曲线间的冲突。DSpark已在DeepSeek-V4生产环境中替代MTP-1,在中等SLA下提升50%以上聚合吞吐量,严格SLA下维持基线无法达到的交互性水平。本文代码级细节丰富(包含训练代码逐行解析),适合一线推理系统工程师与AI Infra从业者深读。

原文 89 分钟
原文 mp.weixin.qq.com ↗
§ 1

DSpark is a speculative decoding framework recently open-sourced by DeepSeek. The core goal of the paper is to solve two main bottlenecks in current speculative decoding technology: draft quality degradation and low verification efficiency. In simple terms, although the current draft model can quickly generate a long string of candidate tokens, due to a lack of context dependency, the quality of the draft deteriorates further along the sequence, and the acceptance rate drops rapidly. At the same time, regardless of the draft quality, blindly submitting the entire long draft to the target model for verification wastes valuable computational resources on tokens that are likely to be rejected.

DSpark[1]是DeepSeek刚开源的一个投机解码(Speculative Decoding)框架. 论文的核心目标是解决当前投机解码技术中的两个主要瓶颈:草稿质量衰减和验证效率低下. 简单来说, 当前的draft model虽然能快速生成一长串候选token, 但由于缺乏上下文依赖, 导致草稿越往后, 质量越差, 接受率迅速下降. 同时, 无论草稿质量如何, 盲目地将整个长草稿交给目标模型进行验证, 会在大概率被拒绝的token上浪费宝贵的计算资源.

§ 2

To address these two problems, DSpark proposes two complementary innovative mechanisms:

Semi-Autoregressive Generation: To solve the draft quality problem, DSpark designs a hybrid architecture. It retains a computationally intensive parallel backbone network to quickly generate the 'skeleton' of all draft tokens at once; on top of this, it adds a lightweight sequential module that injects local dependency information in order while generating the draft. This design not only retains the high speed of parallel generation but also significantly improves the quality of the latter part of the draft by introducing correlations between tokens, slowing down the decay of the acceptance rate.

Confidence-Scheduled Verification: To solve the verification efficiency problem, DSpark introduces a dynamic scheduling mechanism. It trains a confidence head to predict the probability of each draft token being accepted. Then, a hardware-aware scheduler combines these confidence scores and the system's current real-time load to dynamically decide how long a draft to verify for each request. When the system load is low, longer drafts can be verified to pursue higher single-user speed; when the system load is high, low-confidence draft suffixes are automatically trimmed to avoid wasting compute on 'garbage' tokens, thereby stabilizing the overall system throughput.

针对这两个问题, DSpark提出了两个互补的创新机制:

半自回归生成 (Semi-Autoregressive Generation): 为了解决草稿质量问题, DSpark设计了一种混合架构. 它保留了一个计算量大的并行主干网络, 用于一次性快速生成所有草稿token的"骨架"; 然后在此基础上增加了一个轻量级的串行模块(Sequential Head), 在生成草稿时按顺序注入局部依赖信息. 这种设计既保留了并行生成的高速度, 又通过引入token间的关联性显著改善了草稿后半部分的质量, 减缓了接受率的衰减.

置信度调度验证 (Confidence-Scheduled Verification): 为了解决验证效率问题, DSpark引入了一个动态调度机制. 它训练了一个置信度头(Confidence Head) 来预测每个草稿词元被接受的概率. 然后, 一个硬件感知调度器(Hardware-Aware Scheduler) 会结合这些置信度分数和系统当前的实时负载(如GPU吞吐量)来动态决定每个请求应该验证多长的草稿. 当系统负载低时, 可以验证更长的草稿以追求更高的单用户速度; 当系统负载高时, 则会自动剪裁掉那些低置信度的草稿后缀, 避免在"垃圾"词元上浪费算力, 从而保证整个系统的吞吐量稳定.

§ 3

Let's start with the principles of speculative decoding, why the result of speculative decoding with a draft model is equivalent to the result of target model inference. Imagine you are chatting online with a learned but slow-typing expert (like an old professor). This old professor is our target model. Its characteristics are: authoritative but slow. To speed up the process, we give him a fast-reacting doctoral assistant. This assistant is the draft model. Its characteristics are: agile but unreliable. Speculative decoding is this 'professor + student' collaborative workflow: The professor writes the first word, the student speculatively guesses the following content, the professor marks the draft, accepts and corrects, and completes a round. The core idea is to exchange a large number of guesses from a cheap, fast draft model for a small number of efficient validations from the expensive, slow target model.

我们先从投机解码的原理谈起, 为什么一个草稿模型投机解码的结果和目标模型推理的结果是等价的. 想象一下你正在和一位学识渊博但打字很慢的专家在线聊天. 这位老教授就是我们的目标模型. 它的特点是: 权威但缓慢. 为了加速这个过程, 我们给他配一个反应飞快的博士生助手. 这个助手就是草稿模型. 它的特点是: 敏捷但不靠谱. 投机解码就是这套"教授+学生"的协同工作流程: 教授起草, 学生抢答, 教授批改, 接受并修正, 完成一轮. 核心思想: 用一个廉价、快速的草稿模型的大量猜测, 来换取昂贵、缓慢的目标模型少量但高效的验证.

§ 4

The underlying mathematical principle is rejection sampling. We have a target distribution p and a draft distribution q. By sampling from q and accepting with a certain probability, we can perfectly recover sampling from p. The acceptance probability at each step is min(1, p(x) / q(x)). The proof shows that the final distribution is exactly the target distribution p. For a token x, there are two paths: either the draft token is accepted ('great minds think alike'), or it is rejected and resampled from a residual distribution ('seek another wise counsel'). The sum of the probabilities of these two paths exactly equals p(x).

背后的数学原理是拒绝采样. 我们有目标分布p和草稿分布q. 通过从q中采样并以一定概率接受, 我们可以完美地恢复从p中采样. 每一步的接受概率是 min(1, p(x)/q(x)). 证明表明最终的分布恰好是目标分布p. 对于一个token x, 有两条路: 要么草稿被接受("英雄所见略同"), 要么被拒绝后从残差分布中重新采样("另请高明"). 这两条路径的概率之和正好等于 p(x).

§ 5

For example, in the DSpark code deepspec/eval/base_evaluator.py, there is a common verification function verify_draft_tokens. The algorithm process is:

  1. Send the sequence of draft tokens into the target model in parallel to get the probability distribution at each position.
  2. For each draft token position, calculate the acceptance probability min(1, p_target(x)/q_draft(x)), and decide whether to accept by comparing it with a random number.
  3. Use cumprod to implement prefix truncation: once a position is rejected, all subsequent positions are rejected.
  4. If a rejected token exists, sample a new token from the residual distribution; if all are accepted, sample a bonus token from the last position's distribution of the target model.
  5. Concatenate the accepted draft tokens and the newly sampled token as the final output.

例如在DSpark代码中deepspec/eval/base_evaluator.py中有一个常见的验证函数verify_draft_tokens, 算法流程:

  1. 将draft tokens序列一次性送入target model做并行前向传播, 得到每个位置的概率分布.
  2. 对每个draft token位置, 计算接受概率min(1, p_target(x)/q_draft(x)), 通过随机数与该概率比较决定是否接受.
  3. 使用cumprod实现前缀截断语义: 一旦某个位置被拒绝, 后续所有位置均被拒绝.
  4. 若存在被拒绝的token, 从残差分布中采样新token; 若全部接受, 则从target model最后位置的分布中采样一个bonus token.
  5. 拼接被接受的draft tokens + 新采样的token作为最终输出.
§ 6

Leviathan et al. established a theoretical analysis framework, revealing that the performance of speculative decoding is completely dominated by three core parameters:

Acceptance Rate α: Measures 'how reliable the draft is'. Formally, α = 1 - d_TV(p||q), where d_TV is the Total Variation Distance. Intuitively, α equals the 'overlap area' of the two distributions.

Cost Ratio c: Measures 'how cheap the draft is'. c = t_draft / t_target, the ratio of the draft model's single-step inference time to the target model.

Draft Length γ: Measures 'how many guesses per round'. If γ is too small, the speculative gain is limited; if too large, the acceptance probability of later tokens decreases exponentially.

The exact formula for the end-to-end speedup ratio is: (1 - α^γ) / (1 - α) / (cγ + 1).

Leviathan et al. 建立了完整的理论分析框架, 揭示投机解码的性能被三个核心参数完全支配:

接受率 α: 衡量"草稿有多靠谱". 形式上, α = 1 - d_TV(p||q), d_TV是全变差距离. 直觉上, α 等于两个分布的"重叠面积".

成本比 c: 衡量"起草有多便宜". c = t_draft / t_target, 草稿模型单步推理时间与目标模型的比值.

草稿长度 γ: 衡量"每轮猜多少个". 太小则投机收益有限; 太大则后面token的接受概率指数下降.

端到端加速比的精确公式是: (1 - α^γ) / (1 - α) / (cγ + 1).

§ 7

From the 2022 paper 'Fast Inference from Transformers via Speculative Decoding', the algorithm uses an independent autoregressive model with far fewer parameters than the target model to serially generate γ candidate tokens. Later, 'Accelerating Large Language Model Decoding with Speculative Sampling' used a draft model with a wide and shallow structure. BiLD abandoned the requirement for lossless probability, allowing minor quality loss and introducing the concept of dynamic draft length, which is the origin of DSpark's confidence scheduling. Self-Speculative Decoding uses the original model's 'layer skipping' method for drafting, and the complete original model for verification.

从2022年底的论文《Fast Inference from Transformers via Speculative Decoding》开始, 采用一个参数量远小于目标模型的独立自回归模型串行生成γ个候选token. 后来,《Accelerating Large Language Model Decoding with Speculative Sampling》采用了宽而浅的Draft Model. BiLD放弃了概率无损的要求, 允许微小质量损失, 并首次引入动态起草长度概念, 后续DSpark的置信度调度即源于此思想. Self-Speculative Decoding采用原始模型"跳层"的方式做Drafting, 完整的原始模型做Verification.

§ 8

SpecInfer breaks the limitation of a single candidate sequence, simultaneously considering multiple speculative candidates and organizing them into a token tree. It uses a tree parallel decoding mechanism to verify all sequences in the tree in a single LLM decoding step. Its draft model does not train a new model from scratch but directly uses pre-trained small models from the same family and uses a Boosting fine-tuning strategy. For the tree-based structure, by modifying the mask matrix method, the model can verify multiple sequences at once.

SpecInfer 不再局限于单一候选序列, 而是同时考虑多条推测候选, 并将它们组织为一棵token tree. 它使用树并行解码机制, 在单次LLM解码步骤中并行验证token tree中所有候选序列的正确性. Draft模型没有从头训练一个全新模型, 而是直接使用同族预训练小模型, 并采用Boosting微调策略. 针对Tree-based结构, 通过修改mask的矩阵方法, 使得模型可以一次验证多个sequence.

§ 9

Medusa does not use a separate small model but adds multiple Medusa heads after the last layer's embedding of the original model. It combines the predictions of each head to build a tree and verifies all candidates in a single forward pass using a tree attention mask. EAGLE's core idea is to perform autoregressive prediction at the feature level and eliminate sampling uncertainty by inputting the 'one-step-ahead' token. Its draft model consists of an embedding layer, LM head, and an autoregression head, achieving an acceleration ratio much higher than traditional methods.

Medusa没有使用独立的小模型, 而是采用在原模型的最后一层的Embedding后增加多个Medusa Head. 组合各个头预测构建成一颗树, 并通过tree attention mask在一次前向传播中验证所有候选. EAGLE的核心思想是在特征层进行自回归预测, 并通过输入"提前一步的token"来消除采样不确定性. 其Draft Model由Embedding层、LM Head和Autoregression Head组成, 加速比远超传统方案.

§ 10

EAGLE-2 introduces a dynamically adjustable draft tree, improving upon EAGLE-1's static tree structure. Its algorithm mainly includes two stages: Expand and Rerank. The Expand stage selects nodes with the highest value to expand, and the Rerank stage sorts all draft tokens and selects the top-m ones with the highest value. EAGLE-3 uses feature sequences from low, middle, and high layers for fusion processing. By breaking the information bottleneck of single-layer features, it improves the model's ability to predict distant future tokens. It also proposes a Training-Time Test improvement to handle different inputs during training and testing.

EAGLE-2引入了可动态调整的草稿树, 改进了EAGLE-1静态树结构. 算法主要包含Expand和Rerank两个阶段. Expand阶段选择价值最高的节点扩展, Rerank阶段对所有草稿token进行重排, 选择价值最高的top-m个. EAGLE-3在输入特征上采用了低、中、高层的特征序列融合处理, 打破了单层特征的信息瓶颈, 提升了预测更远token的能力. 它还提出Training-Time Test改进来处理训练和测试时不同输入的情况.

§ 11

Meta's MTP paper asks a question: why not imbue the model with speculative ability during the pre-training stage? By adding n independent output heads to simultaneously predict future n tokens, multi-token prediction not only improves the model's quality on downstream tasks but also allows these heads to directly act as drafts for speculative decoding during inference, achieving a unification of training enhancement and inference acceleration. DeepSeek-V3 MTP makes a key improvement by changing the parallel independent heads to sequential causal chains, which is closer to EAGLE's feature autoregressive concept. It proves that integrating multi-step prediction ability into pre-training can improve model quality and obtain a 'free lunch' for inference acceleration.

Meta的MTP论文提出了一个问题: 为什么不在预训练阶段就赋予模型投机能力?通过添加n个独立输出头同时预测未来n个token, 多token预测不仅提升了模型在下游任务上的质量, 还让这些输出头在推理时直接充当投机解码的草稿, 实现了训练增强与推理加速的统一. DeepSeek-V3 MTP做出了关键改进, 将并行独立头改为顺序因果链, 更贴近EAGLE的特征自回归理念. 它证明了将多步预测能力融入预训练, 既能提升模型本身的质量, 又能获得推理加速的"免费午餐".

§ 12

DFlash's breakthrough is this: why must the draft model be autoregressive? It repositions it as a parallel diffusion adapter. Its input is one anchor token plus γ MASK placeholders. Using bidirectional attention within the block, the model outputs predictions for all γ positions in a single forward pass. The key metric is that latency is independent of γ. Its second key innovation is KV injection: extracting hidden states from the target model at evenly spaced layers and fusing them into a contextual feature, then concatenating them into the Key and Value at each layer of the draft model. This allows the draft model to directly 'read' the target model's information at every layer.

DFlash的突破是: 为什么草稿模型必须是自回归的?它将草稿模型重新定位为一个并行的扩散适配器. 输入是一个锚点token加上γ个MASK占位符, 块内使用双向注意力, 一次性输出所有γ个位置的预测. 关键指标是延迟与γ无关. 第二个关键创新是KV注入: 从目标模型的等距层中提取隐藏状态, 融合为上下文特征, 然后在草稿模型的每一层拼接到Key和Value中. 这允许草稿模型在每一层直接"读取"目标模型的信息.

§ 13

During inference, after the target model performs a standard Prefill, the draft model generates all draft tokens in one forward pass. The target model then verifies the entire draft block in parallel. Unlike standard Speculative Sampling, DFlash adopts a simpler 'sample-then-compare' strategy because the diffusion model cannot produce per-position conditional probabilities. During training, it uses random anchor point sampling, sparse attention masks, and position-weighted loss to prioritize the optimization of earlier positions. Parameter sharing (embedding layer and LM head) is used to minimize trainable parameters.

在推理时, 目标模型执行一次标准Prefill后, 草稿模型通过一次前向传播生成所有草稿token. 目标模型随后并行验证整个草稿块. 与标准Speculative Sampling不同, DFlash采用了更简洁的"采样后比较"策略, 因为扩散模型无法产生逐位置条件概率. 训练时采用随机锚点采样、稀疏注意力掩码和位置加权损失, 以优先优化前面位置. 并采用参数共享(嵌入层和LM头)来最小化可训练参数量.

§ 14

DDTree does not discard the complete logits from the diffusion model's single forward pass. Instead, it builds a draft tree from these logits, selecting multiple paths under a fixed node budget B that are most likely to be accepted by the target model. Its core is the Best-First Heap search algorithm. It proves that a greedy algorithm is optimal: under the factorized distribution, the prefix probability is the product of probabilities at each position. By always expanding siblings and child nodes with the highest accumulated log-probability, it automatically satisfies the prefix closure property. The tree is then compiled into a format consumable by the target model (tree attention mask), allowing target model to verify the entire tree in one forward pass.

DDTree不丢弃扩散模型一次前向传播产出的完整logits, 而是从中构建一棵草稿树, 在固定节点预算B下选择最可能被目标模型接受的多条路径. 核心是Best-First Heap搜索算法. 它证明了贪心是最优的: 在因子化分布下, 前缀概率是各位置概率的乘积. 通过总是扩展累计对数概率最高的兄弟节点和子节点, 前缀闭合性自动满足. 随后将树结构编译为目标模型可消费的格式(树注意力掩码), 让目标模型在一次前向传播中验证整棵树.

§ 15

JetSpec addresses the fundamental contradiction exposed by DFlash: parallel generation sacrifices causality, causing the acceptance rate to decay rapidly along the draft block. JetSpec designs a tree-causal attention mask that achieves both parallel prediction and causal conditioning in a single forward pass. Each tree node can attend to itself and all its ancestors, but not to other nodes. This solves the 'causality-efficiency dilemma'. It uses a 5-layer draft head, feature fusion, and best-first search for tree building. It achieves a higher speedup ratio than DFlash+DDTree.

JetSpec直面DFlash暴露的根本矛盾: 并行生成牺牲了因果性, 导致接受率沿草稿块快速衰减. JetSpec通过设计树形因果注意力掩码, 在单次前向传递中同时实现并行预测和因果条件化: 每个树节点可关注自身和所有祖先, 但不能关注其他节点. 这解决了"因果性-效率困境". 它采用5层草稿头、特征融合和最佳优先搜索构建树, 取得了比DFlash+DDTree更高的加速比.

§ 16

DSpark adopts a semi-autoregressive structure, dividing draft generation into two phases. The first is the parallel stage: a parallel backbone network runs a single forward pass over the entire block, producing hidden states and base logits. DSpark makes a minor modification: treating the anchor itself as the first prediction position, so γ input tokens produce γ draft logits. The second is the sequential stage: it supplements the base logits with a prefix-dependent transfer bias, allowing each draft position to condition on previously sampled tokens within the block. This is implemented via a Markov head (first-order dependency) or an RNN head (longer history), ensuring the sequential module is lightweight so total draft latency is still dominated by the parallel stage.

DSpark采用半自回归结构, 将草稿生成分为两个阶段. 第一阶段是并行阶段: 一个并行主干网络在整个块上运行一次前向传播, 产生隐藏状态和基础logits. DSpark做了一个微小修改: 将锚点本身视为第一个预测位置, 因此γ个输入产生γ个草稿logits. 第二阶段是串行阶段: 为基础logits补充一个依赖于前缀的转移偏差, 允许每个草稿位置以块内先前已采样的token为条件. 通过马尔可夫头(一阶依赖)或RNN头(更长历史)实现, 确保串行模块计算轻量, 总的起草延迟仍然由并行阶段主导.

§ 17

DSpark introduces a confidence head that outputs a scalar estimate for each draft position: the conditional probability that the draft token will pass the target model's verification, given all previous tokens in the block are accepted. This is supervised by the analytical acceptance rate. A post-hoc calibration technique called Sequential Temperature Scaling (STS) corrects the neural network's overly confident predictions to provide accurate absolute probabilities. The hardware-aware prefix scheduler formalizes the verification length selection problem as a global throughput maximization problem. It globally sorts all candidate tokens by their calibrated survival probability and greedily admits tokens until the system throughput no longer increases, dynamically finding the optimal operating point for the current system load.

DSpark引入了一个置信度头, 为每个草稿位置输出标量估计值: 在块内所有先前token都已被接受的条件下, 该草稿token通过目标模型验证的条件概率. 使用解析接受率进行监督. 后处理校准技术序列化温度缩放(STS)校正神经网络的过于自信的预测, 提供精确的绝对概率. 硬件感知前缀调度器将验证长度选择问题形式化为一个全局吞吐量最大化问题. 将所有候选token按校准后的存活概率全局排序, 贪心准入直到系统吞吐量不再增加, 动态找到当前负载下的最佳工作点.

§ 18

Directly deploying Algorithm 1 into production exposes two fundamental conflicts: the discrete, stepped nature of real hardware capacity curves, and the need to know the batch size for the next step before the current step completes in zero-overhead scheduling. DSpark adjusts the scheduler to operate asynchronously. It uses the confidence head outputs from two steps ago to approximate the verification capacity for the next step. While approximate, this selection mechanism is order-preserving: the most confident draft tokens are always verified first. This design forms a causality barrier, maintaining lossless recovery of the target distribution while achieving maximum physical throughput. In production, DSpark replaces the MTP-1 baseline, achieving a 51-52% improvement in aggregate throughput under moderate SLA and significantly expanding the feasible interactivity frontier.

将算法1直接部署到生产环境中暴露了两个根本性冲突: 真实硬件的容量曲线是离散、阶梯状的; 在零开销调度中, 必须知道下一步的批处理大小. DSpark将调度器调整为异步操作, 使用两步前的置信度头输出来近似下一个验证容量. 这个选择机制在根本上是保序的: 最有信心的草稿token总是被优先验证. 这种设计形成一道因果屏障, 在保持对目标分布的精确恢复的同时, 实现了最大物理吞吐量. 在生产中, DSpark取代了MTP-1基线, 在中等SLA下实现51-52%的聚合吞吐量提升, 并显著扩展了可行的交互性前沿.

§ 19

Experiments show that parallel drafting models (DFlash) and semi-autoregressive drafting models (DSpark) often achieve longer acceptance lengths than fully autoregressive ones. This stems from a capacity advantage at position 1: parallel models can afford deeper networks due to their γ-independent latency, resulting in significantly higher accuracy at the first position, which has the highest leverage in the prefix-matching survival process. Follow-up position independence limits parallel models, causing rapid acceptance rate decay. DSpark's semi-autoregressive design inherits the high initial acceptance rate of deep parallel models while its lightweight serial head mitigates the typical rapid decay, maintaining a high and stable conditional acceptance rate throughout the draft block.

实验表明并行起草模型(DFlash)和半自回归起草模型(DSpark)通常能产生比完全自回归的起草模型更长的接受长度. 这源于位置1的容量优势: 并行模型由于延迟与γ无关, 可以负担更深的网络, 在第一个位置产生显著的准确率优势, 而第一个位置在前缀匹配的生存过程中具有最高的杠杆作用. 后续位置独立性是并行模型的局限, 导致接受率快速衰减. DSpark的半自回归设计继承了深度并行起草模型的高初始接受率, 同时轻量级串行头缓解了典型的快速衰减, 在整个草稿块中保持高而稳定的条件接受率.

§ 20

Experiments under static threshold sweeps show that the confidence head can identify low-value suffix tokens, with pruning being most significant on chat workloads. In the 'Chat' subplot, increasing the threshold reduces rejected tokens significantly, raising the acceptance rate from 45.7% to 95.7%. Reliability diagrams show that while the original model achieves strong discrimination (ROC-AUC 0.81-0.90), it is overly confident (ECE 3%-8%). Applying post-hoc STS reduces the average ECE to about 1%, producing reliable survival estimates crucial for the hardware-aware scheduler.

静态阈值扫描的实验显示置信度头能够识别价值较低的后缀token, 这种修剪在聊天工作负载上最为显著. 在"Chat"子图中, 提高阈值显著减少了被拒绝的token, 将接受率从45.7%提高到95.7%. 可靠性图表明, 原始模型虽然实现了强大的区分能力(ROC-AUC 0.81-0.90), 但过于自信(ECE 3%-8%). 应用后处理的STS将平均ECE降低到约1%, 产生了调度器所需的可靠存活估计.

§ 21

The first principle of speculative decoding can be captured by a formula: the average wall-clock latency per generated token is (t_draft(γ) + t_target) / N(γ), where N is the expected number of accepted tokens. The speedup ratio is (1 - α^γ) / (1 - α) / (cγ + 1). Key properties: when α is close to 1, all candidates are accepted; when α is close to 0, it degrades to standard autoregression; N is extremely sensitive to α. There are only three levers: reduce draft latency, improve acceptance rate, and more intelligent verification. A fundamental trade-off exists between the first two: autoregressive drafting has linear latency growth but high α, while parallel drafting has latency independent of γ but lower α. DSpark's semi-autoregressive design approaches the latency of parallel while achieving α between the two.

投机解码的第一性原理可以用一个公式精确描述: 平均每个生成token的墙上时钟延迟为 (t_draft(γ) + t_target) / N(γ), N是预期的接受token数. 加速比公式为 (1 - α^γ) / (1 - α) / (cγ + 1). 关键性质: 当α接近1时, 所有候选均被接受; 当α接近0时, 退化为标准自回归; N对α极其敏感. 有且仅有三条杠杆: 降低起草延迟、提高接受率、更智能地验证. 杠杆1和杠杆2之间存在根本性的架构权衡: 自回归起草时延迟线性增长但接受率高, 并行起草时延迟与γ无关但接受率低. DSpark的半自归设计延迟接近并行, 而接受率介于两者之间.

§ 22

The core question answered by the scheduling strategy is: given a batch of draft tokens, how many should be submitted to the target model for verification? This is formulated as an optimization problem: maximize the expected total accepted tokens multiplied by the hardware throughput at that batch size, by selecting the verification length for each request. DSpark's confidence scheduling uses the confidence head to estimate the conditional acceptance probability at each position. The prefix survival probability is the cumulative product of these per-step probabilities. The scheduler globally sorts all candidate tokens by this survival probability and greedily admits them until system throughput no longer increases, i.e., marginal benefit equals marginal cost.

调度策略回答的核心问题是: 给定一批草稿token, 应该提交多少给目标模型验证?这被形式化为一个优化问题: 通过选择每个请求的验证长度, 最大化预期接受token总数乘以在该batch size下的硬件吞吐量. DSpark的置信度调度利用置信度头估计每个位置的条件接受概率. 前缀存活概率是这些逐步概率的累积乘积. 调度器将所有候选token按存活概率全局排序, 贪心准入直到系统吞吐量不再增加, 即边际收益等于边际成本.

打开原文 ↗