Abstract
Large Language Models (LLMs) require significant computational resources, necessitating efficient compression techniques like Post-Training Quantization (PTQ). However, standard PTQ methods often struggle with ultra-low-bit scenarios, such as 4-bit weights and activations (W4A4), due to the limited flexibility of simple scaling and shifting transformations. This paper introduces AffineQuant, a novel quantization framework that utilizes full affine transformations to optimize weight distributions. By employing a "Gradual Mask" technique to ensure mathematical invertibility, AffineQuant achieves state-of-the-art accuracy in low-bit quantization without introducing computational overhead during inference.
Introduction
The deployment of Large Language Models (LLMs) on edge devices and consumer-grade hardware is primarily hindered by their immense memory and computational requirements. Quantization—the process of mapping high-precision floating-point values to low-precision integers—has emerged as a critical solution for reducing model size and accelerating inference.
While Post-Training Quantization (PTQ) is preferred for its efficiency (as it avoids full model retraining), current state-of-the-art methods like SmoothQuant and OmniQuant are limited by their reliance on simple linear transformations. These methods typically use diagonal scaling or translation to align weights with quantization grids. In extreme low-bit settings, such as W4A4, these simple transformations lack the degrees of freedom necessary to minimize quantization noise, leading to significant performance degradation.
Methodology
Equivalent Affine Transformations
AffineQuant moves beyond simple scaling by expanding the optimization space to high-dimensional affine matrices. The core principle relies on the mathematical identity:
$$XW = (XA^{-1})(AW)$$
By left-multiplying the weights ($W$) by an affine matrix ($A$) and right-multiplying the activations ($X$) by its inverse ($A^{-1}$), the output of the layer remains mathematically identical before quantization. This allows the weights ($AW$) to undergo rotation and repositioning, aligning them more effectively with the fixed points of a low-precision quantization grid.
Ensuring Invertibility via Gradual Mask (GM)
A significant challenge in using full matrices for transformation is ensuring that the matrix $A$ remains invertible. Unconstrained optimization of large matrices often results in singular matrices, leading to model collapse. AffineQuant addresses this using the Levy-Desplanques theorem, which guarantees that strictly diagonally dominant matrices are always invertible.
The authors implement a Gradual Mask (GM) strategy to maintain this stability:
- Initial Phase: Optimization is restricted to the diagonal elements of the matrix, mimicking simple scaling.
- Expansion Phase: Elements further from the diagonal are gradually "unfrozen" and optimized.
- Constraint: This progression ensures the matrix remains diagonally dominant and stable throughout the optimization process.
Experimental Setup
The researchers evaluated AffineQuant across the OPT and LLaMA (1 and 2) model families. Performance was measured using standard benchmarks:
- Language Modeling: Perplexity scores on WikiText2, C4, and PTB.
- Zero-shot Accuracy: Performance on PIQA, ARC (Easy and Challenge), WinoGrande, BoolQ, and HellaSwag.
Key Results and Insights
Performance Benchmarks
AffineQuant establishes a new state-of-the-art for PTQ, particularly in the W4A4 category:
- LLaMA2-7B (W4A4): The model achieved a perplexity of 15.76 on the C4 dataset, significantly outperforming OmniQuant’s 18.02.
- LLaMA-30B (W4A4): The average zero-shot accuracy reached 58.61%, a nearly 2% improvement over previous methods.
- Low-Bit Resilience: The advantage of AffineQuant becomes more pronounced as bit-width decreases, suggesting that complex transformations are essential for extreme compression.
Zero-Overhead Inference
A primary advantage of AffineQuant is that the transformation matrix $A$ can be mathematically "folded" into the existing model weights and preceding LayerNorm parameters once optimization is complete. Consequently, the final quantized model requires no additional computations at runtime, providing the benefits of rotation-based optimization with the speed of standard quantized inference.
Limitations and Future Work
Despite its success, AffineQuant introduces some complexities:
- Optimization Cost: Calculating matrix inverses during the PTQ phase is more computationally demanding than vector-based methods, increasing the time required for model preparation.
- Numerical Precision: To prevent "merge errors" when integrating the transformation matrix back into the weights, the authors recommend using double-precision (64-bit) floats during the optimization phase.
- Non-Linearity: The current framework is designed for linear layers. Future research is needed to extend these equivalent transformations to the non-linear components of MLP blocks.
Conclusion
AffineQuant demonstrates that the key to high-accuracy low-bit quantization lies in the flexibility of the weight transformation. By introducing rotation through affine matrices and ensuring stability via the Gradual Mask technique, AffineQuant bridges the gap between high-precision performance and low-precision efficiency, offering a robust path forward for deploying LLMs on resource-constrained hardware.
Summary updated