Transformer-Lite: High-efficiency Deployment of Large Language Models on Mobile Phone GPUs

📄 arXiv: 2403.20041v3 📥 PDF

作者: Luchang Li, Sheng Qian, Jie Lu, Lunxi Yuan, Rui Wang, Qin Xie

分类: cs.CL

发布日期: 2024-03-29 (更新: 2024-07-05)

备注: 21 pages, 6 figures, fix "E0M4" spell mistake, fix FLOPS to TFLOPS


💡 一句话要点

提出Transformer-Lite以解决移动设备上LLM高效部署问题

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

关键词: 大型语言模型 移动设备 推理速度 优化技术 FP4量化 子张量技术 智能助手 实时翻译

📋 核心要点

  1. 现有的设备端LLM部署方法推理速度较慢,导致用户体验不佳,亟需高效解决方案。
  2. 本文提出了四种优化技术,包括动态形状推理支持、操作符优化、FP4量化和子张量技术,以提升推理效率。
  3. 实验结果显示,Transformer-Lite在预填充速度上超过10倍提升,解码速度提升2~3倍,显著优于现有基线。

📝 摘要(中文)

大型语言模型(LLM)广泛应用于智能助手、文本摘要、翻译和多模态任务。然而,当前的设备端LLM部署方法存在推理速度慢的问题,影响用户体验。为此,本文提出四种优化技术:基于符号表达的动态形状模型推理支持、操作符优化与执行优先级设置以提升推理速度、FP4量化方法M0E4以减少去量化开销,以及基于子张量的技术以消除LLM推理后KV缓存的复制需求。此外,我们在移动推理引擎Transformer-Lite中实现了这些方法,兼容Qualcomm和MTK处理器。实验表明,Transformer-Lite在不同架构和参数的LLM上表现优异,尤其在ChatGLM2 6B和Gemma 2B模型上实现了显著的速度提升。

🔬 方法详解

问题定义:本文旨在解决大型语言模型在移动设备上推理速度慢的问题,现有方法导致用户体验不佳,尤其是在资源受限的环境中。

核心思路:通过提出四种优化技术,旨在提升LLM在移动设备上的推理效率,确保用户能够流畅使用智能助手等应用。

技术框架:整体架构包括动态形状模型推理、操作符优化、FP4量化和子张量技术,形成一个高效的移动推理引擎Transformer-Lite,兼容主流移动处理器。

关键创新:最重要的创新在于M0E4量化方法和子张量技术,这些方法有效减少了去量化开销和KV缓存的复制需求,显著提升了推理速度。

关键设计:在技术细节上,采用符号表达支持动态形状推理,设置操作符执行优先级,并通过FP4量化降低内存占用,确保在移动设备上高效运行。

📊 实验亮点

实验结果表明,Transformer-Lite在ChatGLM2 6B模型上实现了121 token/s的预填充速度和14 token/s的解码速度,而在Gemma 2B模型上则达到了330 token/s和30 token/s的速度。与CPU基线FastLLM和GPU基线MLC-LLM相比,预填充速度提升超过10倍,解码速度提升2~3倍,显示出显著的性能优势。

🎯 应用场景

该研究的潜在应用领域包括智能手机上的智能助手、实时翻译、文本摘要等多种场景。通过提升LLM的推理速度,能够显著改善用户体验,推动移动AI应用的普及与发展,具有重要的实际价值和未来影响。

📄 摘要(原文)

The Large Language Model (LLM) is widely employed for tasks such as intelligent assistants, text summarization, translation, and multi-modality on mobile phones. However, the current methods for on-device LLM deployment maintain slow inference speed, which causes poor user experience. To facilitate high-efficiency LLM deployment on device GPUs, we propose four optimization techniques: (a) a symbolic expression-based approach to support dynamic shape model inference; (b) operator optimizations and execution priority setting to enhance inference speed and reduce phone lagging; (c) an FP4 quantization method termed M0E4 to reduce dequantization overhead; (d) a sub-tensor-based technique to eliminate the need for copying KV cache after LLM inference. Furthermore, we implement these methods in our mobile inference engine, Transformer-Lite, which is compatible with both Qualcomm and MTK processors. We evaluated Transformer-Lite's performance using LLMs with varied architectures and parameters ranging from 2B to 14B. Specifically, we achieved prefill and decoding speeds of 121 token/s and 14 token/s for ChatGLM2 6B, and 330 token/s and 30 token/s for smaller Gemma 2B, respectively. Compared with CPU-based FastLLM and GPU-based MLC-LLM, our engine attains over 10x speedup for the prefill speed and 2~3x speedup for the decoding speed.