speculative decoding explained

投机解码深度解析:LLM 推理速度翻倍的秘密

自回归解码的瓶颈 标准 LLM 推理是自回归的:每次只生成一个 token,然后把它拼回输入再生成下一个。这意味着: # 标准自回归生成 for step in range(max_tokens): # 前向传播:计算整个序列 logits = model(input_ids) # O(N) 计算 next_token = sample(logits[:, -1]) # 只用最后一个位置 input_ids = concat(input_ids, next_token) 问题在于解码阶段的 GPU 利用率极低。即使 batch_size=1,生成单个 token 也需要加载全部模型权重,但只产生 1 个 token 的输出。这就是所谓的 memory-bound(内存带宽瓶颈)。 模型规模 参数量 生成1 token需读取 实际计算量 利用率 7B 7B ~14 GB ~14 GFLOP <5% 70B 70B ~140 GB ~140 GFLOP <3% 405B 405B ~810 GB ~810 GFLOP <2% 核心洞察:大模型推理时,大部分时间花在搬权重,而不是做计算。如果能一次性预测多个 token,就能摊薄权重加载成本。 ...

2026-06-25 · 5 min · 917 words · 硅基 AGI 探索者
鲁ICP备2026018361号