LLM-FP4: 4-Bit Floating-Point Quantized Transformers
作者: Shih-yang Liu, Zechun Liu, Xijie Huang, Pingcheng Dong, Kwang-Ting Cheng
分类: cs.CL, cs.AI, cs.AR, cs.CV
发布日期: 2023-10-25
备注: EMNLP 2023 Main Conference
期刊: Proceedings of the 2023 Conference on Empirical Methods in Natural Language Processing
DOI: 10.18653/v1/2023.emnlp-main.39
🔗 代码/项目: GITHUB
💡 一句话要点
提出LLM-FP4以解决大语言模型的4位浮点量化问题
🎯 匹配领域: 支柱九:具身大模型 (Embodied Foundation Models)
关键词: 量化技术 大语言模型 浮点量化 后训练量化 激活量化 Transformer模型 机器学习
📋 核心要点
- 现有的后训练量化方法主要基于整数,难以处理低于8位的浮点量化,限制了大语言模型的应用。
- 论文提出了一种新的4位浮点量化方法,通过优化量化参数和采用通道级激活量化来提高性能。
- 实验结果显示,LLM-FP4在常识推理任务中取得了63.1的平均分,显著优于之前的最先进模型,提升幅度达到12.7分。
📝 摘要(中文)
我们提出LLM-FP4,通过后训练方式将大语言模型(LLMs)的权重和激活量化为4位浮点值。现有的后训练量化(PTQ)方案主要基于整数,难以处理低于8位的位宽。与整数量化相比,浮点量化更具灵活性,能够更好地处理长尾或钟形分布,并已成为许多硬件平台的默认选择。我们构建了一个强大的浮点PTQ基线,通过搜索最佳量化参数来优化性能。此外,我们观察到激活分布中存在高通道间方差和低通道内方差的模式,这增加了激活量化的难度。我们首次能够将LLaMA-13B的权重和激活量化为4位,并在常识零-shot推理任务中取得63.1的平均分,仅比全精度模型低5.8,显著超越了之前的最先进水平12.7分。代码可在:https://github.com/nbasyl/LLM-FP4获取。
🔬 方法详解
问题定义:本论文旨在解决大语言模型在后训练量化过程中,现有方法在低于8位浮点量化时的性能不足问题。现有的整数基量化方法在处理激活分布时存在局限性,无法有效应对高通道间方差和低通道内方差的情况。
核心思路:论文提出的LLM-FP4方法通过将权重和激活量化为4位浮点值,利用浮点量化的灵活性来提高模型的性能。通过优化量化参数,尤其是指数位和裁剪范围,来增强量化效果。
技术框架:整体架构包括量化参数的搜索、通道级激活量化和权重的指数偏置重参数化。首先,构建强大的浮点PTQ基线,然后针对激活分布的特性进行优化。
关键创新:最重要的技术创新在于首次实现了对LLaMA-13B模型的权重和激活的4位浮点量化,且通过通道级激活量化有效解决了激活分布的挑战,显著提升了模型的推理能力。
关键设计:在量化过程中,选择了最佳的量化参数,并通过重参数化将激活的缩放因子转化为权重的指数偏置,确保了计算成本的微不足道。
🖼️ 关键图片
📊 实验亮点
实验结果表明,LLM-FP4在常识零-shot推理任务中取得了63.1的平均分,仅比全精度模型低5.8,显著超越了之前的最先进水平12.7分。这一成果展示了4位浮点量化在保持模型性能方面的潜力。
🎯 应用场景
该研究的潜在应用领域包括自然语言处理、机器翻译和对话系统等大语言模型相关任务。通过实现更高效的量化,LLM-FP4能够在资源受限的环境中部署大型模型,提升实际应用的可行性和效率。未来,随着硬件平台的不断发展,该方法有望在更多实际场景中得到应用。
📄 摘要(原文)
We propose LLM-FP4 for quantizing both weights and activations in large language models (LLMs) down to 4-bit floating-point values, in a post-training manner. Existing post-training quantization (PTQ) solutions are primarily integer-based and struggle with bit widths below 8 bits. Compared to integer quantization, floating-point (FP) quantization is more flexible and can better handle long-tail or bell-shaped distributions, and it has emerged as a default choice in many hardware platforms. One characteristic of FP quantization is that its performance largely depends on the choice of exponent bits and clipping range. In this regard, we construct a strong FP-PTQ baseline by searching for the optimal quantization parameters. Furthermore, we observe a high inter-channel variance and low intra-channel variance pattern in activation distributions, which adds activation quantization difficulty. We recognize this pattern to be consistent across a spectrum of transformer models designed for diverse tasks, such as LLMs, BERT, and Vision Transformer models. To tackle this, we propose per-channel activation quantization and show that these additional scaling factors can be reparameterized as exponential biases of weights, incurring a negligible cost. Our method, for the first time, can quantize both weights and activations in the LLaMA-13B to only 4-bit and achieves an average score of 63.1 on the common sense zero-shot reasoning tasks, which is only 5.8 lower than the full-precision model, significantly outperforming the previous state-of-the-art by 12.7 points. Code is available at: https://github.com/nbasyl/LLM-FP4.