TEQ: Trainable Equivalent Transformation for Quantization of LLMs

Wenhua Cheng, Yiyang Cai, Kaokao Lv, Haihao ShenarXiv 2023 · DOI

Introduction

As Large Language Models (LLMs) scale to hundreds of billions of parameters, their memory footprint and computational demands present significant bottlenecks for deployment. Quantization—the process of converting high-precision FP32 weights into low-precision formats like Int4—is a standard mitigation strategy. However, a "quantization gap" persists: traditional Quantization-Aware Training (QAT) is computationally prohibitive for massive models, while Post-Training Quantization (PTQ) often suffers from accuracy degradation at 3 or 4 bits due to outlier channels.

TEQ (Trainable Equivalent Transformation) introduces a lightweight, data-driven method to bridge this gap. By training a tiny fraction of parameters (less than 0.1%) to mathematically redistribute weights before quantization, TEQ achieves state-of-the-art accuracy with zero additional computational overhead during inference.

Methodology

The core innovation of TEQ is the use of a "mathematical sleight of hand" known as an equivalent transformation. For any linear layer, the authors introduce a per-channel scaling vector $s$. By multiplying the weights by $s$ and the inputs (activations) by the inverse, $1/s$, the output remains mathematically identical at FP32 precision. However, this transformation allows the model to "squash" the range of weights or activations, making them significantly easier to quantize into low-bit integers.

The equivalent transformation mechanism: scaling weights and activations to preserve output while optimizing for quantization.

Unlike previous methods that rely on fixed heuristics to determine these scales, TEQ treats $s$ as a trainable parameter. During a lightweight training phase, the original model weights are frozen, and only the scaling vectors are optimized over approximately 1,000 steps. Once training is complete, these scales are "fused" into the weights and preceding layers (such as LayerNorm), ensuring the final deployed model maintains the original architecture's speed.

Experimental Setup

TEQ was trained using the pile-10k dataset, a subset of The Pile. Evaluation was conducted across several standard benchmarks, including Common Sense Reasoning (HellaSwag, WinoGrande, PIQA, LAMBADA) and Language Modeling perplexity (WikiText-2, PTB, C4).

Key Insights and Results

Layer Sensitivity and Parameter Distribution

Visualizing the trained scales reveals that the first and last layers of LLMs are significantly more sensitive to quantization loss than middle layers. While most trained scales remain near 1.0, the few that deviate are critical for protecting "outlier" channels that would otherwise induce massive quantization errors.

3D visualization of trainable transformation parameter magnitudes across different layers for BLOOM, OPT, and LLaMA models.

Performance Benchmarks

  • 4-bit (W4) Performance: On LLaMA-7B and OPT-13B, TEQ consistently outperformed standard Round-to-Nearest (RTN) quantization.
  • 3-bit (W3) Resilience: 3-bit quantization is notoriously difficult, yet TEQ showed significant gains. For LLaMA-7B, TEQ achieved 65.25% accuracy on common sense tasks, compared to 58.29% for GPTQ.
  • Orthogonality: TEQ is complementary to existing methods like GPTQ. Running TEQ first to optimize weight distribution followed by GPTQ refinement often yields the highest accuracy.

Conclusion and Future Work

TEQ provides a highly efficient path to low-bit quantization, requiring only about 20 minutes of training for a 7B parameter model on a single GPU. While the training process requires backpropagation—consuming more memory than pure PTQ—the resulting accuracy gains make it a compelling choice for high-performance deployment. Future work may explore extending TEQ to convolutional layers in computer vision and further optimizing the training memory footprint for even larger models.

Summary updated

BibTeX
@misc{cheng2023teq,
  author = {Wenhua Cheng and Yiyang Cai and Kaokao Lv and Haihao Shen},
  title = {{TEQ: Trainable Equivalent Transformation for Quantization of LLMs}},
  year = {2023},
  eprint = {2310.10944},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2310.10944},
}
Figure