Skip to main content
QUICK REVIEW

[Paper Review] Medusa: Simple LLM Inference Acceleration Framework with Multiple Decoding Heads

Tianle Cai, Yuhong Li|arXiv (Cornell University)|Jan 19, 2024
Topic ModelingComputer Science11 citations
TL;DR

Medusa augments LLM inference with extra decoding heads to predict multiple tokens in parallel, using a tree-attention mechanism to parallelize candidate processing and two fine-tuning modes (Medusa-1 frozen backbone, Medusa-2 joint training) to achieve 2.2x to 3.6x speedups.

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.

Motivation & Objective

  • Increase inference throughput for large language models by reducing decoding steps without sacrificing quality.
  • Eliminate the need for a separate draft model by leveraging additional decoding heads on the backbone model.
  • Provide flexible training procedures to fit different resource and data availability scenarios.
  • Offer extensions (typical acceptance, self-distillation) to handle data-scarce settings and improve efficiency.

Proposed method

  • Attach K decoding heads to the last hidden state of the backbone to predict subsequent tokens.
  • Use a tree-structured attention mask to process multiple candidate continuations in parallel.
  • Fine-tune heads with two schemes: Medusa-1 (frozen backbone) or Medusa-2 (joint backbone+heads training).
  • Offer a typical acceptance scheme to select plausible candidates instead of relying on rejection sampling.
  • Provide self-distillation to generate training data when none is available, and discuss data/ calibration methods for tree construction.
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

Experimental results

Research questions

  • RQ1How can multiple decoding heads enable parallel prediction of several future tokens without changing the backbone model?
  • RQ2What are effective training strategies (Medusa-1 vs Medusa-2) to preserve or enhance backbone performance while accelerating inference?
  • RQ3Does the proposed typical acceptance scheme maintain generation quality while improving decoding efficiency?
  • RQ4What speedups are achievable across model sizes and training regimes using Medusa heads?
  • RQ5How do extensions like self-distillation and optimized tree construction impact performance under data-scarce conditions?

Key findings

  • Medusa-1 achieves over 2.2x speedup without sacrificing generation quality.
  • Medusa-2 can further improve speedups to 2.3x–3.6x.
  • The approach works across models of varying sizes and training procedures (e.g., Vicuna 7B, 13B, 33B, Zephyr-7B).
  • Two training modes (frozen backbone vs joint training) enable flexible deployment on limited hardware or with full fine-tuning.
  • Extensions such as self-distillation and typical acceptance help handle data absence and improve efficiency.
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

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.