DFRot: Achieving Outlier-Free and Massive Activation-Free for Rotated LLMs with Refined Rotation

📄 arXiv: 2412.00648v4 📥 PDF

作者: Jingyang Xiang, Sai Qian Zhang

分类: cs.LG, stat.ML

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

备注: Accepeted bythe 2nd Conference on Language Modeling (COLM 2025). Source code \url{https://github.com/JingyangXiang/DFRot}


💡 一句话要点

DFRot:通过精炼旋转实现旋转LLM的无异常值和无大规模激活

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

关键词: 大型语言模型 模型量化 旋转量化 异常值消除 低精度计算

📋 核心要点

  1. 现有LLM量化方法在低精度下性能下降,尤其受到异常值和大规模激活的影响,导致精度损失。
  2. DFRot通过加权损失函数和正交Procrustes变换优化旋转矩阵,减少异常值和优化大规模激活的量化。
  3. 实验表明,DFRot在LLaMA3-70B模型上,W4A4KV4和W4A4KV16配置下,困惑度分别提升了0.98和0.95。

📝 摘要(中文)

本文研究了旋转激活和权重矩阵以减少大型语言模型(LLM)中异常值影响的方法,尤其是在模型量化方面。先前的研究表明,在低精度量化场景(如4位权重和4位激活,W4A4)中,随机Hadamard变换比随机正交变换能获得更高的精度。然而,这种现象背后的原因尚不清楚。本文发现,这些变换在消除常见token的异常值方面表现出显著的改进,并实现了相似的量化误差。精度差异的主要原因在于,随机Hadamard变换可以略微减少具有大规模激活的token的量化误差,而随机正交变换会增加量化误差。由于这些token的极端稀有性及其对模型精度的关键影响,我们将其视为一个长尾优化问题,并因此构建了一种简单而有效的方法:加权损失函数。此外,我们提出了一种旋转矩阵的优化策略,该策略涉及量化参数的交替优化,同时采用正交Procrustes变换来细化旋转矩阵。这使得旋转后的激活值的分布更利于量化,特别是对于具有大规模激活的token。我们的方法通过实现双重自由,即无异常值和无大规模激活,来增强旋转LLM,称为DFRot。大量的实验证明了DFRot的有效性和效率。通过仅使用单个样本调整旋转矩阵,DFRot在LLaMA3-70B的W4A4KV4和W4A4KV16上分别实现了0.98和0.95的困惑度改进,该模型以其量化挑战而闻名。

🔬 方法详解

问题定义:论文旨在解决旋转量化LLM时,由于激活值中的异常值和大规模激活值对量化精度产生负面影响的问题。现有的旋转量化方法,例如使用随机正交变换,在处理具有大规模激活的token时,反而会增加量化误差,导致整体性能下降。

核心思路:论文的核心思路是通过优化旋转矩阵,使得旋转后的激活值分布更适合量化,从而减少异常值的影响,并降低大规模激活值的量化误差。具体来说,通过加权损失函数来优化量化参数,并使用正交Procrustes变换来精炼旋转矩阵。

技术框架:DFRot方法主要包含两个关键模块:1) 加权损失函数:针对具有大规模激活的token,赋予更高的权重,从而在训练过程中更加关注这些token的量化误差。2) 旋转矩阵优化:采用交替优化策略,首先优化量化参数,然后使用正交Procrustes变换来精炼旋转矩阵,使得旋转后的激活值分布更利于量化。

关键创新:该方法最重要的创新点在于,它将旋转矩阵的优化与量化参数的优化相结合,并针对具有大规模激活的token设计了加权损失函数。这种方法能够有效地减少异常值的影响,并降低大规模激活值的量化误差,从而提高整体的量化精度。与现有方法相比,DFRot能够更有效地利用旋转变换的优势,实现更好的量化效果。

关键设计:加权损失函数的设计是关键。论文根据token的激活值大小,动态调整其在损失函数中的权重。此外,正交Procrustes变换的使用也至关重要,它能够保证旋转矩阵的正交性,并使得旋转后的激活值分布更加均匀,从而提高量化精度。具体的权重设置和Procrustes变换的迭代次数等参数需要根据具体模型和数据集进行调整。

🖼️ 关键图片

fig_0
fig_1
fig_2

📊 实验亮点

DFRot在LLaMA3-70B模型上进行了实验,结果表明,通过仅使用单个样本调整旋转矩阵,DFRot在W4A4KV4和W4A4KV16配置下,困惑度分别提升了0.98和0.95。这一结果表明,DFRot能够显著提高量化模型的精度,尤其是在对量化具有挑战性的模型上。

🎯 应用场景

DFRot方法可应用于各种需要低精度量化的大型语言模型部署场景,例如移动设备、边缘计算和资源受限的服务器。通过提高量化模型的精度,DFRot能够降低模型大小和计算复杂度,从而实现更高效的模型推理,并降低部署成本。该方法对于推动LLM在资源受限环境中的应用具有重要意义。

📄 摘要(原文)

Rotating the activation and weight matrices to reduce the influence of outliers in large language models (LLMs) has recently attracted significant attention, particularly in the context of model quantization. Prior studies have shown that in low-precision quantization scenarios, such as 4-bit weights and 4-bit activations (W4A4), randomized Hadamard transforms can achieve significantly higher accuracy than randomized orthogonal transforms. Notably, the reason behind this phenomenon remains unknown. In this paper, we find that these transformations show substantial improvement in eliminating outliers for common tokens and achieve similar quantization error. The primary reason for the accuracy difference lies in the fact that randomized Hadamard transforms can slightly reduce the quantization error for tokens with massive activations while randomized orthogonal transforms increase the quantization error. Due to the extreme rarity of these tokens and their critical impact on model accuracy, we consider this a long-tail optimization problem, and therefore construct a simple yet effective method: a weighted loss function. Additionally, we propose an optimization strategy for the rotation matrix that involves alternating optimization of quantization parameters while employing orthogonal Procrustes transforms to refine the rotation matrix. This makes the distribution of the rotated activation values more conducive to quantization, especially for tokens with massive activations. Our method enhances the Rotated LLMs by achieving dual free, Outlier-Free and Massive Activation-Free, dubbed as DFRot. Extensive experiments demonstrate the effectiveness and efficiency of DFRot. By tuning the rotation matrix using just a single sample, DFRot achieves a perplexity improvement of 0.98 and 0.95 on W4A4KV4 and W4A4KV16, respectively, for LLaMA3-70B, a model known for its quantization challenges.