HAQ: Hardware-Aware Automated Quantization With Mixed Precision

Kuan Wang, Zhijian Liu, Yujun Lin, Ji Lin, Song Han

Abstract

Model quantization is a widely used technique to compress and accelerate deep neural network (DNN) inference. Emergent DNN hardware accelerators begin to support mixed precision (1-8 bits) to further improve the computation efficiency, which raises a great challenge to find the optimal bitwidth for each layer: it requires domain experts to explore the vast design space trading off among accuracy, latency, energy, and model size, which is both time-consuming and sub-optimal. There are plenty of specialized hardware for neural networks, but little research has been done for specialized neural network optimization for a particular hardware architecture. Conventional quantization algorithm ignores the different hardware architectures and quantizes all the layers in a uniform way. In this paper, we introduce the Hardware-Aware Automated Quantization (HAQ) framework which leverages the reinforcement learning to automatically determine the quantization policy, and we take the hardware accelerator's feedback in the design loop. Rather than relying on proxy signals such as FLOPs and model size, we employ a hardware simulator to generate direct feedback signals (latency and energy) to the RL agent. Compared with conventional methods, our framework is fully automated and can specialize the quantization policy for different neural network architectures and hardware architectures. Our framework effectively reduced the latency by 1.4-1.95x and the energy consumption by 1.9x with negligible loss of accuracy compared with the fixed bitwidth (8 bits) quantization. Our framework reveals that the optimal policies on different hardware architectures (i.e., edge and cloud architectures) under different resource constraints (i.e., latency, energy and model size) are drastically different. We interpreted the implication of different quantization policies, which offer insights for both neural network architecture design and hardware architecture design.

Introduction

Quantization—reducing the number of bits used to represent weights and activations—is essential for deploying deep neural networks (DNNs) on resource-constrained devices like smartphones or IoT sensors. However, most conventional methods use uniform quantization, where every layer gets the same number of bits (e.g., 8-bit).

The reality is that different layers in a network have different levels of redundancy. Some can survive at 2-bit precision, while others need 6-bit to maintain accuracy. This is Mixed Precision. The challenge is that the search space for mixed precision is astronomical (e.g., $8^{100}$ possibilities for a ResNet-50). Furthermore, common "proxy" metrics like FLOPs (Floating Point Operations) or model size are often poor indicators of actual performance. A model with fewer FLOPs might actually run slower on specific hardware due to memory bandwidth bottlenecks or cache misses.

The HAQ Framework

The authors propose the HAQ framework, which treats quantization as a reinforcement learning (RL) problem.

The HAQ framework uses a DDPG agent to determine quantization policies based on direct feedback from hardware simulators.
  1. The RL Agent: They use a Deep Deterministic Policy Gradient (DDPG) agent. The agent traverses the network layer-by-layer. For each layer, it receives a "state" (layer dimensions, number of parameters, etc.) and outputs an "action" (the bitwidth for weights and activations).
  2. Hardware-in-the-Loop: Instead of guessing performance, the framework uses hardware simulators (like BISMO for FPGAs or BitFusion for ASICs) to provide direct feedback. If a proposed quantization policy exceeds a specific latency or energy budget, the framework automatically adjusts the bitwidths until the constraint is met.
  3. The Reward Function: After the agent picks bitwidths for the whole network, the model is quantized and fine-tuned for one epoch. The resulting validation accuracy is fed back to the RL agent as a reward signal.

Results and Insights

The framework was evaluated on the ImageNet classification dataset using popular architectures including MobileNet-V1, MobileNet-V2, and ResNet-50.

HAQ achieves a better accuracy-latency trade-off compared to fixed 8-bit quantization for MobileNets.
  • Hardware Specialization: A quantization policy optimized for an "Edge" device (low memory bandwidth, small batch size) performs poorly on a "Cloud" device (high bandwidth, large batch size). HAQ learns to specialize the policy for the specific hardware architecture.
  • Latency and Energy: Compared to a fixed 8-bit baseline, HAQ reduced latency by 1.4× to 1.95× and achieved a 1.9× reduction in energy consumption.
  • Memory-Bound Realization: On edge devices, HAQ discovered that depthwise convolution layers are often memory-bound. To compensate, the RL agent assigned fewer bits to activations in these layers to reduce memory traffic. On cloud devices, where bandwidth is higher, the agent was more generous with bits for these same layers.
  • Accuracy vs. Model Size: When compared to "Deep Compression" (a popular k-means based quantization method), HAQ provided significantly higher accuracy at the same model size. For example, at a high compression ratio on MobileNet-V1, HAQ achieved 57.14% Top-1 accuracy compared to Deep Compression's 37.62%.

Conclusion

HAQ demonstrates that automated, hardware-aware quantization is superior to manual tuning or uniform bitwidth strategies. By incorporating direct hardware feedback into the RL loop, the framework discovers non-intuitive bitwidth distributions that specialize for specific hardware constraints. While the search cost remains a factor, the efficiency gains in latency and energy make HAQ a powerful tool for deploying DNNs on the edge. Future work may extend this philosophy to co-designing neural architectures and quantization policies simultaneously.

Summary updated

BibTeX
@inproceedings{wang2019haq,
  author = {Kuan Wang and Zhijian Liu and Yujun Lin and Ji Lin and Song Han},
  title = {{HAQ: Hardware-Aware Automated Quantization With Mixed Precision}},
  booktitle = {IEEE/CVF Conference on Computer Vision and Pattern Recognition},
  year = {2019},
  url = {https://openreview.net/forum?id=brDcgbST8Y_},
}
Figure