Abstract
Transformers have set new benchmarks in Natural Language Processing (NLP), but their high computational demands hinder deployment on resource-constrained edge devices. We present HAT (Hardware-Aware Transformers), a framework that leverages Neural Architecture Search (NAS) to design specialized models for specific hardware targets like CPUs, GPUs, and IoT devices. By training a single "SuperTransformer" and utilizing hardware-specific latency predictors, HAT achieves up to 3× speedups and 3.7× smaller model sizes compared to standard Transformers, while reducing search costs by over 12,000× compared to previous automated methods.
The Challenge: Beyond FLOPs and One-Size-Fits-All
Deploying large-scale Transformers on edge devices often results in unacceptable latency. For instance, translating a short sentence using Transformer-Big on a Raspberry Pi can take up to 20 seconds. The authors identify two critical barriers to efficient deployment:
- The FLOPs Fallacy: Floating Point Operations (FLOPs) are frequently used as a proxy for model speed. However, as shown in the empirical data, models with identical FLOP counts can have drastically different latencies depending on the hardware architecture.
- Hardware Heterogeneity: Optimal model architectures vary significantly across devices. While increasing embedding dimensions might have negligible impact on a high-end GPU, it can severely bottleneck an ARM CPU due to cache limitations.
The HAT Framework
To address these challenges, HAT introduces a three-stage pipeline designed for efficiency and scalability:
- Expanded Design Space: HAT breaks traditional Transformer constraints by allowing heterogeneous layers (varying hidden dimensions and head numbers per layer) and introducing Arbitrary Encoder-Decoder Attention, where decoders can attend to any encoder layer.
- The SuperTransformer: Instead of the prohibitive cost of training thousands of candidate models, HAT trains a single "SuperTransformer" that encompasses all possible sub-networks. These sub-networks share weights, ensuring that training costs are incurred only once.
- Evolutionary Search with Latency Feedback: HAT employs a latency predictor—a simple neural network trained on real-world hardware measurements—to guide an evolutionary search. This process identifies the optimal sub-network that maximizes accuracy (BLEU score) within a specific hardware's latency budget.
Key Insights and Results
The HAT framework reveals distinct architectural "personalities" favored by different hardware:
- GPUs perform best with shallow and wide models, leveraging their massive parallelization capabilities.
- ARM CPUs favor deep and thin models to accommodate limited cache sizes.
On the WMT’14 En-De task for Raspberry Pi, HAT achieved a 3× speedup and 3.7× reduction in model size compared to the Transformer-Big baseline without sacrificing accuracy. Furthermore, HAT outperformed the Evolved Transformer with a 2.7× speedup while reducing the search cost from 250 GPU years to just a few days—a 12,041× improvement in efficiency.
Conclusion
HAT demonstrates that hardware-aware design is essential for efficient NLP. By moving beyond FLOPs and embracing hardware heterogeneity through weight-sharing SuperTransformers, we can deploy state-of-the-art models on everything from high-end servers to "TinyML" IoT devices. Future work will explore expanding the search space to include finer-grained attention parameters.
Summary updated