Deja Vu: Contextual Sparsity for Efficient LLMs at Inference Time

📄 arXiv: 2310.17157v1 📥 PDF

作者: Zichang Liu, Jue Wang, Tri Dao, Tianyi Zhou, Binhang Yuan, Zhao Song, Anshumali Shrivastava, Ce Zhang, Yuandong Tian, Christopher Re, Beidi Chen

分类: cs.LG

发布日期: 2023-10-26

期刊: Proceedings of the 40th International Conference on Machine Learning, 2023, 919

🔗 代码/项目: GITHUB


💡 一句话要点

提出DejaVu以解决大规模语言模型推理效率问题

🎯 匹配领域: 支柱九:具身大模型 (Embodied Foundation Models)

关键词: 大规模语言模型 推理效率 上下文稀疏性 异步处理 硬件优化

📋 核心要点

  1. 现有大规模语言模型推理方法计算开销大,且无法有效利用稀疏性。
  2. 提出上下文稀疏性,通过输入依赖的注意力头和MLP参数集加速推理。
  3. DejaVu系统在不损害模型质量的情况下,显著降低了推理延迟,提升效率。

📝 摘要(中文)

大规模语言模型(LLMs)拥有数百亿参数,推动了新一波激动人心的AI应用。然而,它们在推理时计算开销巨大。稀疏性是一种自然的降低成本的方法,但现有方法往往需要昂贵的再训练,或放弃LLM的上下文学习能力,或在现代硬件上无法实现实际的时间加速。我们假设上下文稀疏性,即小的、依赖输入的注意力头和MLP参数集合,可以解决这些问题。我们展示了上下文稀疏性是存在的,可以被准确预测,并且可以利用它来加速LLM推理而不损害模型质量或上下文学习能力。基于这些见解,我们提出了DejaVu,一个使用低成本算法实时预测上下文稀疏性的系统,并实现了异步和硬件感知的推理加速。我们验证了DejaVu在不损害模型质量的情况下,可以将OPT-175B的推理延迟减少超过2倍,相比于最先进的FasterTransformer,减少超过6倍,相比于广泛使用的Hugging Face实现。

🔬 方法详解

问题定义:本论文旨在解决大规模语言模型在推理时的高计算成本问题。现有方法往往需要昂贵的再训练,或无法保持模型的上下文学习能力,导致效率低下。

核心思路:论文提出的核心思路是利用上下文稀疏性,即为特定输入选择小的注意力头和MLP参数集合,从而在保持输出质量的同时加速推理过程。

技术框架:DejaVu系统的整体架构包括实时预测上下文稀疏性的低成本算法,以及异步和硬件感知的推理实现。系统根据输入动态选择参数,优化推理效率。

关键创新:最重要的技术创新在于提出了上下文稀疏性的概念,并展示了其可预测性和可利用性。这与现有方法的本质区别在于,DejaVu无需再训练即可实现推理加速。

关键设计:在设计中,DejaVu采用了低成本的算法进行上下文稀疏性预测,并结合异步处理和硬件优化,确保在不同硬件平台上均能高效运行。

📊 实验亮点

实验结果表明,DejaVu在不损害模型质量的情况下,能够将OPT-175B的推理延迟减少超过2倍,相比于最先进的FasterTransformer,减少超过6倍,相比于广泛使用的Hugging Face实现,展现出显著的性能提升。

🎯 应用场景

该研究的潜在应用领域包括自然语言处理、对话系统、文本生成等。通过提高大规模语言模型的推理效率,DejaVu可以在实时应用中显著降低延迟,提升用户体验,推动AI技术在各行业的广泛应用。

📄 摘要(原文)

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.