Deja Vu: Contextual Sparsity for Efficient LLMs at Inference Time
Authors:
- Zichang LiuZLZichang Liu
- Jue WangJWJue Wang
- Tri DaoTDTri Dao
- Tianyi ZhouTZTianyi Zhou
- Binhang YuanBYBinhang Yuan
- Zhao SongZSZhao Song
- Anshumali ShrivastavaASAnshumali Shrivastava
- Ce ZhangCZCe Zhang
- Yuandong TianYTYuandong Tian
- Christopher ReCRChristopher Re
- Beidi ChenBCBeidi Chen
Preprint
Abstract
Large language models (LLMs) with hundreds of billions of parameters have sparked a new wave of exciting AI applications. However, they are computationally expensive at inference time. Sparsity is a natural approach to reduce this cost, but existing methods either require costly retraining, have to forgo LLM's in-context learning ability, or do not yield wall-clock time speedup on modern hardware. We hypothesize that contextual sparsity, which are small, input-dependent sets of attention heads and MLP parameters that yield approximately the same output as the dense model for a given input, can address these issues. We show that contextual sparsity exists, that it can be accurately predicted, and that we can exploit it to speed up LLM inference in wall-clock time without compromising LLM's quality or in-context learning ability. Based on these insights, we propose DejaVu, a system that uses a low-cost algorithm to predict contextual sparsity on the fly given inputs to each layer, along with an asynchronous and hardware-aware implementation that speeds up LLM inference. We validate that DejaVu can reduce the inference latency of OPT-175B by over 2X compared to the state-of-the-art FasterTransformer, and over 6X compared to the widely used Hugging Face implementation, without compromising model quality. The code is available at https://github.com/FMInference/DejaVu.Keywords
All Related Versions
This publication has 16 references indexed in Scilit:
- Tight Bounds for ℓ 1 Oblivious Subspace EmbeddingsACM Transactions on Algorithms, 2022
- The hardware lotteryCommunications of the ACM, 2021
- Billion-Scale Similarity Search with GPUsIEEE Transactions on Big Data, 2019
- APPROXIMATE NEAREST NEIGHBOR SEARCH IN HIGH DIMENSIONS2019
- Efficient and Robust Approximate Nearest Neighbor Search Using Hierarchical Navigable Small World GraphsIEEE Transactions on Pattern Analysis and Machine Intelligence, 2018
- Low-Rank Approximation and Regression in Input Sparsity TimeJournal of the ACM, 2017
- Approximate nearest neighbor algorithm based on navigable small world graphsInformation Systems, 2014
- Adaptive estimation of a quadratic functional by model selectionThe Annals of Statistics, 2000
- Extensions of Lipschitz mappings into a Hilbert space1984
- Error bounds for convolutional codes and an asymptotically optimum decoding algorithmIEEE Transactions on Information Theory, 1967