QServe: W4A8KV4 Quantization and System Co-design for Efficient LLM Serving

📄 arXiv: 2405.04532v3 📥 PDF

作者: Yujun Lin, Haotian Tang, Shang Yang, Zhekai Zhang, Guangxuan Xiao, Chuang Gan, Song Han

分类: cs.CL, cs.AI, cs.LG, cs.PF

发布日期: 2024-05-07 (更新: 2025-05-01)

备注: The first three authors contribute equally to this project and are listed in the alphabetical order. Yujun Lin leads the quantization algorithm, Haotian Tang and Shang Yang lead the GPU kernels and the serving system. Code is available at https://github.com/mit-han-lab/omniserve

🔗 代码/项目: GITHUB


💡 一句话要点

QServe:面向高效LLM服务的W4A8KV4量化与系统协同设计

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

关键词: 大语言模型 量化 推理加速 系统协同设计 低比特量化 GPU优化 LLM服务

📋 核心要点

  1. 现有INT4量化方法在GPU上反量化时开销大,导致无法有效加速云端大批量LLM服务。
  2. QServe提出QoQ量化算法(W4A8KV4),并结合渐进式量化和SmoothAttention,降低反量化开销并缓解精度损失。
  3. 实验表明,QServe显著提升了Llama-3-8B和Qwen1.5-72B在A100和L40S上的服务吞吐量,并降低了LLM服务成本。

📝 摘要(中文)

本文提出了一种名为QServe的系统,旨在加速大批量、云端LLM服务的推理。现有INT4量化方法在GPU上反量化权重或部分和时存在显著的运行时开销(20-90%),导致无法在云端LLM服务中获得性能提升。为了解决这个问题,本文引入了QoQ量化算法,即W4A8KV4量化,使用4比特权重、8比特激活和4比特KV缓存。QServe通过其推理库实现加速。QServe的关键在于,GPU上LLM服务的效率受到低吞吐量CUDA核心上操作的严重影响。基于此,QoQ算法引入了渐进式量化,从而降低W4A8 GEMM中的反量化开销。此外,开发了SmoothAttention以有效缓解4比特KV量化带来的精度下降。在QServe系统中,执行计算感知的权重重排序,并利用寄存器级并行性来减少反量化延迟。同时,使融合注意力变为内存受限,从而利用KV4量化带来的性能提升。实验结果表明,与TensorRT-LLM相比,QServe在A100上将Llama-3-8B的最大可实现服务吞吐量提高了1.2倍,在L40S上提高了1.4倍;在A100上将Qwen1.5-72B的最大可实现服务吞吐量提高了2.4倍,在L40S上提高了3.5倍。值得注意的是,L40S GPU上的QServe甚至可以实现比A100上的TensorRT-LLM更高的吞吐量。因此,QServe有效地将LLM服务的成本降低了3倍。

🔬 方法详解

问题定义:现有INT4量化方法在加速大语言模型(LLM)推理方面面临挑战,尤其是在云端大批量服务场景下。主要痛点在于,GPU上的反量化过程(包括权重和部分和的反量化)会引入显著的运行时开销,抵消了低精度量化带来的理论加速效果。这种开销使得INT4量化在低批量、边缘设备上的优势无法扩展到云端服务。

核心思路:QServe的核心思路是通过算法和系统协同设计,降低INT4量化带来的反量化开销,并缓解量化带来的精度损失。具体而言,QoQ量化算法通过渐进式量化降低W4A8 GEMM中的反量化开销,SmoothAttention则用于缓解4比特KV量化带来的精度下降。系统层面,通过计算感知的权重重排序和寄存器级并行性进一步减少反量化延迟,并将融合注意力操作优化为内存受限,从而充分利用KV4量化的优势。

技术框架:QServe的整体框架包含以下几个主要部分:1) QoQ量化算法:包括W4A8KV4量化、渐进式量化和SmoothAttention。2) QServe推理库:实现QoQ算法,并提供高效的LLM推理接口。3) 系统优化:包括计算感知的权重重排序、寄存器级并行性和融合注意力优化。整个流程是从模型量化开始,然后通过QServe推理库进行推理,并利用系统优化进一步提升性能。

关键创新:QServe的关键创新在于算法和系统的协同设计。QoQ量化算法通过渐进式量化降低了反量化开销,SmoothAttention缓解了精度损失。系统层面,计算感知的权重重排序和寄存器级并行性进一步减少了反量化延迟,融合注意力优化充分利用了KV4量化的优势。与现有方法相比,QServe不仅关注量化算法本身,还关注系统层面的优化,从而实现了更高的整体性能。

关键设计:QoQ量化算法的关键设计包括:1) W4A8KV4量化:使用4比特权重、8比特激活和4比特KV缓存。2) 渐进式量化:逐步降低量化精度,从而降低反量化开销。3) SmoothAttention:通过平滑注意力权重来缓解4比特KV量化带来的精度损失。系统优化方面,计算感知的权重重排序根据计算特性重新排列权重,寄存器级并行性利用寄存器并行加速反量化,融合注意力优化将注意力操作优化为内存受限。

🖼️ 关键图片

fig_0
fig_1
fig_2

📊 实验亮点

QServe在Llama-3-8B和Qwen1.5-72B模型上进行了实验,结果表明,与TensorRT-LLM相比,QServe在A100上将Llama-3-8B的最大可实现服务吞吐量提高了1.2倍,在L40S上提高了1.4倍;在A100上将Qwen1.5-72B的最大可实现服务吞吐量提高了2.4倍,在L40S上提高了3.5倍。更令人瞩目的是,L40S GPU上的QServe甚至可以实现比A100上的TensorRT-LLM更高的吞吐量,从而有效地将LLM服务的成本降低了3倍。

🎯 应用场景

QServe具有广泛的应用前景,可用于加速云端大语言模型服务,降低推理成本,提高服务吞吐量。该技术可应用于各种需要高性能LLM推理的场景,如智能客服、机器翻译、文本生成等。通过降低LLM服务的成本,QServe有望推动LLM技术的普及和应用。

📄 摘要(原文)

Quantization can accelerate large language model (LLM) inference. Going beyond INT8 quantization, the research community is actively exploring even lower precision, such as INT4. Nonetheless, state-of-the-art INT4 quantization techniques only accelerate low-batch, edge LLM inference, failing to deliver performance gains in large-batch, cloud-based LLM serving. We uncover a critical issue: existing INT4 quantization methods suffer from significant runtime overhead (20-90%) when dequantizing either weights or partial sums on GPUs. To address this challenge, we introduce QoQ, a W4A8KV4 quantization algorithm with 4-bit weight, 8-bit activation, and 4-bit KV cache. QoQ stands for quattuor-octo-quattuor, which represents 4-8-4 in Latin. QoQ is implemented by the QServe inference library that achieves measured speedup. The key insight driving QServe is that the efficiency of LLM serving on GPUs is critically influenced by operations on low-throughput CUDA cores. Building upon this insight, in QoQ algorithm, we introduce progressive quantization that can allow low dequantization overhead in W4A8 GEMM. Additionally, we develop SmoothAttention to effectively mitigate the accuracy degradation incurred by 4-bit KV quantization. In the QServe system, we perform compute-aware weight reordering and take advantage of register-level parallelism to reduce dequantization latency. We also make fused attention memory-bound, harnessing the performance gain brought by KV4 quantization. As a result, QServe improves the maximum achievable serving throughput of Llama-3-8B by 1.2x on A100, 1.4x on L40S; and Qwen1.5-72B by 2.4x on A100, 3.5x on L40S, compared to TensorRT-LLM. Remarkably, QServe on L40S GPU can achieve even higher throughput than TensorRT-LLM on A100. Thus, QServe effectively reduces the dollar cost of LLM serving by 3x. Code is available at https://github.com/mit-han-lab/omniserve.