APTQ: Attention-aware Post-Training Mixed-Precision Quantization for Large Language Models

Ziyi Guan, Hantao Huang, Yupeng Su, Hong Huang, Ngai Wong, Hao Yu · DOI

TL;DR

This paper introduces APTQ, a novel post-training quantization technique for Large Language Models (LLMs) that significantly reduces model size and computational cost for edge deployment. APTQ uniquely incorporates the nonlinear effects of attention mechanisms and uses Hessian trace for informed mixed-precision allocation, achieving near full-precision performance at ultra-low bitwidths.

What Problem Does This Paper Address?

Large Language Models (LLMs) have revolutionized natural language processing, but their massive size and computational demands make them impractical for deployment on resource-constrained edge devices. Traditional model compression techniques like pruning or architecture search often require expensive retraining. Post-training quantization (PTQ) methods offer a more efficient alternative by reducing the precision of model weights without retraining. However, existing PTQ methods, like GPTQ, often simplify the problem by only considering individual layer weights and neglecting the complex, nonlinear interactions within LLM components, particularly the attention mechanism. This oversight can lead to suboptimal quantization and performance degradation, especially at very low bitwidths.

Methods

APTQ introduces two key innovations:

  1. Attention-Aware Quantization: Unlike previous methods that treat each layer in isolation, APTQ considers the entire attention block, including the crucial softmax operation and matrix multiplications (Q, K, V, O matrices). It leverages gradients derived from the attention output to inform a second-order Hessian optimization strategy. This allows for a more nuanced quantization that accounts for the nonlinear impact of attention on the overall model.
  2. Hessian Trace-Based Mixed-Precision: APTQ employs the Hessian trace as a sensitivity metric to intelligently allocate different bitwidths (2-bit and 4-bit) across layers. Layers with higher Hessian trace values, indicating greater influence on the model's output, are assigned higher precision, while less sensitive layers can be quantized more aggressively. This mixed-precision approach optimizes for both model size and accuracy, achieving a balance that surpasses uniform quantization schemes. The algorithm is detailed in Algorithm 1, outlining a two-step process for 4-bit attention quantization followed by mixed-precision allocation.

Datasets

  • C4 dataset: Used for perplexity evaluation.
  • WikiText-2 dataset: Used for perplexity evaluation.
  • EleutherAI/lm-evaluation-harness: Used for zero-shot performance evaluation across tasks like PIQA, Hellaswag, ARC-Easy, ARC-Challenge, and WinoGrande.

Key Insights and Ideas

  • Attention is Key: The nonlinear nature of the attention mechanism is a critical bottleneck for accurate LLM quantization. Ignoring it leads to suboptimal results.
  • Hessian Trace as a Compass: The Hessian trace effectively quantifies layer sensitivity, providing a principled way to guide mixed-precision quantization for optimal resource allocation.
  • Beyond Layer-wise: Treating attention blocks holistically, rather than individual layers, unlocks significant improvements in quantization accuracy.
  • Ultra-Low Bitwidth Viability: APTQ demonstrates that achieving high performance at bitwidths significantly lower than 4-bit is possible with careful consideration of model architecture and sensitivity.

Key Results

  • Perplexity: APTQ achieves an average perplexity of 5.22 on the C4 dataset with an average bitwidth of 4 bits, nearly equivalent to full precision. Even at 3.0 bits, APTQ's perplexity remains comparable to GPTQ's 4-bit performance.
  • Zero-Shot Accuracy: APTQ achieves state-of-the-art zero-shot accuracy of 68.24% on LLaMa-7B and 70.48% on LLaMa-13B at an average bitwidth of 3.8 bits.
  • Mixed-Precision Advantage: APTQ consistently outperforms manual block-wise quantization schemes in terms of perplexity across various bit ratios.

Limitations and Future Work

  • Limitations: The paper focuses on specific LLM architectures (LLaMa) and quantization techniques. The computational cost of calculating Hessian information, even with approximations, might still be a consideration for extremely large models or real-time applications.
  • Future Work: The authors suggest that APTQ's effectiveness in achieving deeply quantized LLMs without sacrificing accuracy opens avenues for more resource-efficient deployment on edge devices. Further exploration into even lower bitwidths and broader model architectures could be beneficial.

Summary updated

BibTeX
@inproceedings{guan2024aptq,
  author = {Ziyi Guan and Hantao Huang and Yupeng Su and Hong Huang and Ngai Wong and Hao Yu},
  title = {{APTQ: Attention-aware Post-Training Mixed-Precision Quantization for Large Language Models}},
  booktitle = {DAC},
  year = {2024},
  doi = {10.1145/3649329.3658498},
}
Figure