Skip to main content
QUICK REVIEW

[论文解读] Medusa: Simple LLM Inference Acceleration Framework with Multiple Decoding Heads

Tianle Cai, Yuhong Li|arXiv (Cornell University)|Jan 19, 2024
Topic ModelingComputer Science被引用 11
一句话总结

Medusa 通过增加额外的解码头来并行预测多个标记,从而在树状注意力机制中并行处理候选项,并提供两种微调模式(Medusa-1 冻结骨干网络,Medusa-2 联合训练),实现 2.2x 至 3.6x 的加速。

ABSTRACT

Large Language Models (LLMs) employ auto-regressive decoding that requires sequential computation, with each step reliant on the previous one's output. This creates a bottleneck as each step necessitates moving the full model parameters from High-Bandwidth Memory (HBM) to the accelerator's cache. While methods such as speculative decoding have been suggested to address this issue, their implementation is impeded by the challenges associated with acquiring and maintaining a separate draft model. In this paper, we present Medusa, an efficient method that augments LLM inference by adding extra decoding heads to predict multiple subsequent tokens in parallel. Using a tree-based attention mechanism, Medusa constructs multiple candidate continuations and verifies them simultaneously in each decoding step. By leveraging parallel processing, Medusa substantially reduces the number of decoding steps required. We present two levels of fine-tuning procedures for Medusa to meet the needs of different use cases: Medusa-1: Medusa is directly fine-tuned on top of a frozen backbone LLM, enabling lossless inference acceleration. Medusa-2: Medusa is fine-tuned together with the backbone LLM, enabling better prediction accuracy of Medusa heads and higher speedup but needing a special training recipe that preserves the backbone model's capabilities. Moreover, we propose several extensions that improve or expand the utility of Medusa, including a self-distillation to handle situations where no training data is available and a typical acceptance scheme to boost the acceptance rate while maintaining generation quality. We evaluate Medusa on models of various sizes and training procedures. Our experiments demonstrate that Medusa-1 can achieve over 2.2x speedup without compromising generation quality, while Medusa-2 further improves the speedup to 2.3-3.6x.

研究动机与目标

  • 在不牺牲质量的前提下,通过减少解码步骤来提升大型语言模型的推理吞吐量。
  • 通过在骨干模型上利用额外的解码头,消除对单独草案模型的需求。
  • 提供灵活的训练方案以适应不同的资源与数据可用性场景。
  • 提供扩展(典型接受、自蒸馏)来在数据稀缺条件下提升效率。

提出的方法

  • 将 K 个解码头附加到骨干网络的最后隐藏状态,以预测后续标记。
  • 使用树状结构的注意力掩码以并行处理多个候选续接。
  • 用两种方案微调解码头:Medusa-1(冻结骨干)或 Medusa-2(骨干+解码头联训)。
  • 提供典型接受方案以选择可行候选项,而非依赖拒绝采样。
  • 在无可用数据时提供自蒸馏以生成训练数据,并讨论用于树构建的数据/校准方法。
Figure 1 : Overview of Medusa . Medusa introduces multiple heads on top of the last hidden states of the LLM, enabling the prediction of several subsequent tokens in parallel (Section 3.1.1 ). For training Medusa heads, the original model is either frozen ( Medusa -1, Section 3.2.1 ) or trained toge
Figure 1 : Overview of Medusa . Medusa introduces multiple heads on top of the last hidden states of the LLM, enabling the prediction of several subsequent tokens in parallel (Section 3.1.1 ). For training Medusa heads, the original model is either frozen ( Medusa -1, Section 3.2.1 ) or trained toge

实验结果

研究问题

  • RQ1多解码头如何在不改变骨干模型的情况下实现对多个未来标记的并行预测?
  • RQ2在保持或提升骨干性能的同时加速推理的有效训练策略(Medusa-1 与 Medusa-2)是什么?
  • RQ3所提的典型接受方案是否在提升解码效率的同时保持生成质量?
  • RQ4使用 Medusa 头在不同模型规模和训练方案下能达到的加速幅度是多少?
  • RQ5如自蒸馏和优化树构建这类扩展在数据稀缺条件下对性能有何影响?

主要发现

  • Medusa-1 在不牺牲生成质量的前提下实现超过 2.2x 的加速。
  • Medusa-2 可进一步将加速提升至 2.3x–3.6x。
  • 该方法在不同规模和训练过程的模型上均适用(如 Vicuna 7B、13B、33B、Zephyr-7B)。
  • 两种训练模式(冻结骨干 vs 联合训练)使在有限硬件条件或需要全面微调时的灵活部署成为可能。
  • 如自蒸馏和典型接受等扩展有助于在缺乏数据时提升效率。
Figure 2 : Tree Attention Illustrated. This visualization demonstrates the use of tree attention to process multiple candidates concurrently. As exemplified, the top-2 predictions from the first Medusa head and the top-3 from the second result in a total of $2\times 3=6$ candidates. Each of these ca
Figure 2 : Tree Attention Illustrated. This visualization demonstrates the use of tree attention to process multiple candidates concurrently. As exemplified, the top-2 predictions from the first Medusa head and the top-3 from the second result in a total of $2\times 3=6$ candidates. Each of these ca

阅读本论文

在 Nubint 阅读器中打开原文,边读边就任意段落提问。

在 Nubint 中阅读本论文

本解读由 AI 根据论文原文生成,引用前请核对原文。