[Paper Review] HAT: Hardware-Aware Transformers for Efficient Natural Language Processing
HAT proposes a hardware-aware neural architecture search framework to discover efficient Transformer models tailored for specific hardware platforms. By training a weight-shared SuperTransformer and using evolutionary search with real hardware latency feedback, HAT achieves up to 3× inference speedup and 3.7× smaller model size than Transformer-Big on Raspberry Pi-4, with 12,041× lower search cost than prior work and no accuracy loss.
Transformers are ubiquitous in Natural Language Processing (NLP) tasks, but they are difficult to be deployed on hardware due to the intensive computation. To enable low-latency inference on resource-constrained hardware platforms, we propose to design Hardware-Aware Transformers (HAT) with neural architecture search. We first construct a large design space with $ extit{arbitrary encoder-decoder attention}$ and $ extit{heterogeneous layers}$. Then we train a $ extit{SuperTransformer}$ that covers all candidates in the design space, and efficiently produces many $ extit{SubTransformers}$ with weight sharing. Finally, we perform an evolutionary search with a hardware latency constraint to find a specialized $ extit{SubTransformer}$ dedicated to run fast on the target hardware. Extensive experiments on four machine translation tasks demonstrate that HAT can discover efficient models for different hardware (CPU, GPU, IoT device). When running WMT'14 translation task on Raspberry Pi-4, HAT can achieve $ extbf{3} imes$ speedup, $ extbf{3.7} imes$ smaller size over baseline Transformer; $ extbf{2.7} imes$ speedup, $ extbf{3.6} imes$ smaller size over Evolved Transformer with $ extbf{12,041} imes$ less search cost and no performance loss. HAT code is https://github.com/mit-han-lab/hardware-aware-transformers.git
Motivation & Objective
- To address the challenge of deploying compute-intensive Transformers on resource-constrained hardware platforms such as CPUs, GPUs, and IoT devices.
- To overcome the limitations of FLOPs as a latency proxy, which fails to reflect actual hardware performance differences across platforms.
- To reduce the prohibitively high search cost of existing neural architecture search methods for Transformers, especially for hardware-specialized models.
- To enable efficient, accurate, and hardware-specialized Transformer models without sacrificing model performance.
Proposed method
- Construct a large search space with arbitrary encoder-decoder attention and heterogeneous Transformer layers to allow architectural diversity.
- Train a SuperTransformer that shares weights across all sub-networks (SubTransformers), enabling efficient joint training of all candidate architectures.
- Use evolutionary search with real-time hardware latency feedback to identify the optimal SubTransformer for each target hardware platform.
- Integrate a latency predictor trained on measured latency data to accelerate the search process and ensure hardware-aware optimization.
- Leverage the SuperTransformer's performance proxy to avoid retraining each SubTransformer from scratch, drastically reducing search cost.
- Combine HAT with model compression techniques like quantization and knowledge distillation to further improve efficiency.
Experimental results
Research questions
- RQ1Can hardware-aware neural architecture search significantly reduce inference latency on diverse hardware platforms such as CPUs, GPUs, and edge devices?
- RQ2Does replacing FLOPs with real hardware latency feedback lead to better-performing and more efficient Transformer models compared to FLOPs-based optimization?
- RQ3Can a weight-shared SuperTransformer effectively approximate the performance of sub-networks in a large architectural space, enabling low-cost architecture search?
- RQ4How does the combination of arbitrary encoder-decoder attention and heterogeneous layers improve model efficiency and performance across different hardware?
- RQ5Can HAT achieve superior efficiency gains with substantially reduced search cost compared to prior NAS-based approaches like Evolved Transformer?
Key findings
- On Raspberry Pi-4, HAT achieves 3× speedup and 3.7× smaller model size than Transformer-Big on the WMT’14 En-De translation task, with no performance loss.
- HAT reduces search cost by 12,041× compared to the Evolved Transformer while achieving 2.7× speedup and 3.6× smaller model size on the same task.
- HAT models trained for GPU are suboptimal on ARM CPU and vice versa, confirming that hardware-specific optimization is essential due to differing latency factors.
- With 4-bit quantization, HAT achieves a 25× reduction in model size on the WMT’14 En-Fr task, with only 0.1 BLEU score drop compared to the full-precision baseline.
- HAT’s 8-bit quantized model even outperforms its full-precision counterpart by 0.1 BLEU on the WMT’14 En-Fr task, demonstrating the effectiveness of the search process.
- The latency predictor trained on real hardware measurements enables accurate and fast feedback, making the evolutionary search both efficient and hardware-aware.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.