Skip to main content
QUICK REVIEW

[论文解读] SmoothQuant: Accurate and Efficient Post-Training Quantization for Large Language Models

Guangxuan Xiao, Ji Lin|arXiv (Cornell University)|Nov 18, 2022
Topic Modeling被引用 97
一句话总结

SmoothQuant 提供无需训练的 8-bit 权重和激活量化 (W8A8) 用于大型语言模型,通过将激活量化难度迁移到权重,使在极大型 LLM 上实现高效的 INT8 GEMM,精度损失极小。

ABSTRACT

Large language models (LLMs) show excellent performance but are compute- and memory-intensive. Quantization can reduce memory and accelerate inference. However, existing methods cannot maintain accuracy and hardware efficiency at the same time. We propose SmoothQuant, a training-free, accuracy-preserving, and general-purpose post-training quantization (PTQ) solution to enable 8-bit weight, 8-bit activation (W8A8) quantization for LLMs. Based on the fact that weights are easy to quantize while activations are not, SmoothQuant smooths the activation outliers by offline migrating the quantization difficulty from activations to weights with a mathematically equivalent transformation. SmoothQuant enables an INT8 quantization of both weights and activations for all the matrix multiplications in LLMs, including OPT, BLOOM, GLM, MT-NLG, Llama-1/2, Falcon, Mistral, and Mixtral models. We demonstrate up to 1.56x speedup and 2x memory reduction for LLMs with negligible loss in accuracy. SmoothQuant enables serving 530B LLM within a single node. Our work offers a turn-key solution that reduces hardware costs and democratizes LLMs. Code is available at https://github.com/mit-han-lab/smoothquant.

研究动机与目标

  • 识别大型语言模型中的量化瓶颈,特别是激活异常值。
  • 开发一种无需训练的 PTQ 方法,在不损失精度的情况下实现 W8A8 量化。
  • 为 Transformer 块提供一个对硬件友好的端到端量化流程。
  • 在多种开源 LLM 及不同尺度设置上证明其适用性。
  • 提供一个交钥匙解决方案,降低服务成本并实现大模型部署。

提出的方法

  • 引入一个按通道的激活平滑变换,将 X 除以平滑因子 s,同时等效地缩放 W 以保持 Y = X W 等价为 hat{X} hat{W}。
  • 定义迁移强度 alpha,在激活和权重之间平衡量化难度,且 s_j = max(|X_j|)^alpha / max(|W_j|)^(1-alpha)。
  • 使用一个小型校准集离线标定 s 和量化步长,使推理阶段能够进行静态按通道平滑。
  • 将 SmoothQuant 应用于 Transformer 块,将计算密集型算子(线性层和 BMM)量化为 INT8,同时将轻量级运算保持在 FP16。
  • 将 SmoothQuant 集成到 PyTorch/HuggingFace 与 FasterTransformer,并使用 CUTLASS INT8 GEMM 内核实现端到端 INT8 推理。
  • 提供一个三档高效谱(O1–O3)用于量化设置,在精度与速度之间取舍。

实验结果

研究问题

  • RQ1PTQ 是否能够在无需再训练的情况下实现极大型 LLM 的无损 W8A8 量化?
  • RQ2在不采用硬件不兼容的逐通道激活量化的前提下,如何缓解激活异常值?
  • RQ3是否存在一个在硬件友好方式下将量化难度从激活迁移到权重的数学等价变换?
  • RQ4在不同的 LLM 家族与尺度下,SmoothQuant 在精度、速度和内存方面的表现如何?
  • RQ5将 SmoothQuant 集成到生产框架中时,实际部署带来的好处(延迟和内存)是什么?

主要发现

  • SmoothQuant 在 W8A8 量化下,维持 OPT-175B 及其他大型模型的 FP16 精度。
  • 三种渐进模式(O1–O3)提供从对硬件友好到高度激进的量化,并具有可观的加速和内存下降。
  • 在 PyTorch 与 FasterTransformer 上,SmoothQuant 的推理速度可达到最高 1.56x,相较 FP16 约节省 2x 内存,且精度损失可忽略。
  • 它使得非常大模型(MT-NLG 530B)在单节点使用一半显卡即可实现 W8A8 量化,延迟相近。
  • SmoothQuant 实现 LLaMA 模型的无损 W8A8 量化(WikiText-2 perplexity),并在 OPT、BLOOM、GLM 及指令微调变体上表现稳健。
  • 将激活异常值与计算内核解耦,确保注意力与前馈层的所有 GEMM 为 INT8,同时在某些运算中保留 FP16。

更好的研究,从现在开始

从论文设计到论文写作,大幅缩短您的研究时间。

无需绑定信用卡

本解读由 AI 生成,并经人工编辑审核。