facebookresearch/LayerSkip
Code for "LayerSkip: Enabling Early Exit Inference and Self-Speculative Decoding", ACL 2024
What it solves
LayerSkip addresses the computational cost and latency of Large Language Model (LLM) inference. It enables faster token generation by allowing the model to "exit early" from its deep stack of layers during the draft stage of generation, reducing the number of calculations required for each token.
How it works
LayerSkip uses a training recipe that allows a single model to act as both a draft model and a verification model. It implements self-speculative decoding, where the model exits at a specified layer (the exit_layer) to quickly generate draft tokens. These tokens are then verified by the full model in a single pass, significantly speeding up the process compared to standard autoregressive decoding.
Who it’s for
This project is for AI researchers and developers who want to increase the inference speed of Llama-based models without sacrificing correctness, particularly for generation tasks like summarization and coding.
Highlights
- Self-Speculative Decoding: Uses the same model for both drafting and verification, eliminating the need for a separate, smaller draft model.
- Early Exit Inference: Allows users to specify which layer to exit at to balance speed and accuracy.
- Broad Model Support: Provides pre-trained checkpoints for various Llama 2, Llama 3, Llama 3.2, and CodeLlama models.
- Integration: Integrated into Hugging Face
transformersand PyTorchtorchtune. - Evaluation Tools: Includes scripts for benchmarking, correctness verification, and hyperparameter sweeping to find the optimal exit layer and number of speculations.
Related
- Dispatch
- Project
- Project
- Dispatch
- Project