HAT: Hardware-Aware Transformers for Efficient Natural Language Processing

Hanrui Wang, Zhanghao Wu, Zhijian Liu, Han Cai, Ligeng Zhu, Chuang Gan, Song Han

Introduction: The Efficiency Gap

Transformers have revolutionized Natural Language Processing, but their computational demands make them difficult to deploy on resource-constrained edge devices. A common pitfall in optimizing these models is the reliance on Floating-point operations (FLOPs) as a proxy for efficiency. However, FLOPs are often a misleading metric because they do not correlate consistently with actual measured latency across different hardware platforms.

Figure 4: Latency vs. FLOPs across different hardware platforms demonstrates that the same FLOP count can result in vastly different latencies depending on architecture and device.

As illustrated in Figure 4, hardware platforms exhibit unique bottlenecks. For instance, increasing embedding dimensions significantly impacts ARM CPU latency but has a negligible effect on Nvidia GPUs. This "hardware pickiness" necessitates specialized architectures tailored to specific devices rather than a one-size-fits-all approach.

The HAT Framework

Hardware-Aware Transformers (HAT) is a framework designed to automate the creation of these specialized models using Neural Architecture Search (NAS) with significantly reduced overhead. The process involves three main stages:

  1. Defining a Large Design Space: HAT introduces flexibility by allowing heterogeneous layers (where different layers have different numbers of heads or hidden dimensions) and arbitrary encoder-decoder attention, breaking the traditional information bottleneck.
  2. Training a SuperTransformer: Instead of training thousands of candidate models, HAT trains a single "SuperTransformer" that encompasses all possible sub-networks. Through weight-sharing, any "SubTransformer" can be extracted and evaluated without additional training.
  3. Hardware-Aware Evolutionary Search: To find the best model for a specific device, HAT uses a Latency Predictor—a simple neural network trained on a small dataset of architecture-latency pairs—to provide instant feedback to an evolutionary search engine.
Figure 1: The HAT framework overview, showing the transition from a unified SuperTransformer to specialized SubTransformers for diverse hardware.

Key Results and Insights

HAT was evaluated on standard machine translation benchmarks (WMT’14, WMT’19, IWSLT’14) across three distinct hardware platforms: Raspberry Pi-4 (ARM CPU), Intel Xeon CPU, and Nvidia TITAN Xp GPU.

  • Speed and Efficiency: On a Raspberry Pi, HAT achieved a 3x speedup and was 3.7x smaller than Transformer-Big while maintaining the same BLEU score.
  • Search Cost Revolution: By training the SuperTransformer once, the search cost dropped by over 12,000x compared to previous methods like the Evolved Transformer. The total GPU-hours required for HAT is roughly equivalent to training a single standard Transformer-Big.
  • Hardware Specialization: The search revealed distinct architectural preferences: GPUs favor wide and shallow models to maximize parallelism, while ARM CPUs perform better with deep and thin models.

Conclusion

HAT demonstrates that hardware-specific optimization is essential for efficient NLP deployment. By leveraging weight-sharing and latency predictors, the framework makes high-performance, specialized models accessible without the need for massive compute clusters. Future work will look to extend this hardware-aware approach to other architectures like BERT and GPT.

Summary updated

BibTeX
@inproceedings{wang2020hat,
  author = {Hanrui Wang and Zhanghao Wu and Zhijian Liu and Han Cai and Ligeng Zhu and Chuang Gan and Song Han},
  title = {{HAT: Hardware-Aware Transformers for Efficient Natural Language Processing}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2020},
  doi = {10.18653/v1/2020.acl-main.686},
}
Figure