TL;DR
This paper introduces NAS-BERT, a novel approach that uses Neural Architecture Search (NAS) to compress BERT models. Unlike previous methods, NAS-BERT generates a range of compressed models with varying sizes and latencies, all trained on the general pre-training task, making them adaptable to diverse downstream applications and hardware constraints without task-specific fine-tuning.
What Problem Does This Paper Address?
Large pre-trained language models like BERT have revolutionized NLP, but their massive size and computational demands make them impractical for deployment on resource-constrained devices like mobile phones or edge servers. Existing compression techniques often produce models of a fixed size, which isn't ideal for scenarios with varying memory and latency requirements. Furthermore, many methods require task-specific fine-tuning for compression, which is laborious and limits reusability. This paper tackles the challenge of creating BERT compression methods that are both task-agnostic (usable across many tasks) and adaptive (producing models of different sizes and latencies).
Methods
The core of NAS-BERT is a Neural Architecture Search (NAS) framework. Here's a breakdown of their key techniques:
- Supernet Design: They construct a large "supernet" that encompasses a vast search space of potential BERT architectures. This space includes variations in multi-head attention, feed-forward networks, and separable convolutions, with different hidden sizes and kernel configurations.
- Task-Agnostic Pre-training: Crucially, the supernet is trained on the standard self-supervised pre-training tasks (like Masked Language Model), not on specific downstream tasks. This ensures the resulting compressed models are generalizable.
- Block-wise Search and Distillation: To manage the computational cost of training such a large supernet, they divide it into blocks. Each block is trained independently using knowledge distillation from a pre-trained BERT teacher model. The teacher's hidden states are used to guide the student block's learning.
- Progressive Shrinking: To further optimize search efficiency, they employ a "progressive shrinking" technique. This dynamically prunes less promising architectures from the search space during training. To ensure diversity in model sizes and latencies, architectures are grouped into "bins" based on these characteristics, and pruning is applied within each bin.
- Performance Approximation: For efficient model selection, they use performance approximation for latency and loss, avoiding the need to fully evaluate every single candidate architecture.
Datasets
- Training: The paper mentions using English Wikipedia plus BookCorpus (16GB) for pre-training the supernet.
- Evaluation: The primary evaluation dataset is the GLUE benchmark, which includes tasks like COLA, SST-2, MRPC, STS-B, QQP, MNLI, QNLI, and RTE. They also mention using a dev set for validation during the progressive shrinking process.
Key Insights and Ideas
- NAS for Compression is Powerful: The paper demonstrates that NAS can effectively discover novel, efficient architectures for BERT compression, outperforming hand-designed baselines.
- Task-Agnosticism is Achievable: Training on the pre-training task alone is sufficient to produce models that generalize well to various downstream tasks, eliminating the need for task-specific compression.
- Adaptive Size is Key for Deployment: The ability to generate models with a spectrum of sizes and latencies is critical for practical deployment across diverse hardware.
- Block-wise Training and Progressive Shrinking are Essential: The sheer scale of BERT and the NAS search space necessitates these techniques to make the training feasible and efficient. Without them, the computational cost would be prohibitive.
Key Results
NAS-BERT successfully generates lightweight BERT models with varying parameter counts (from 5M to 60M).
- Accuracy Improvement: NAS-BERT models consistently outperform hand-designed BERT baselines of similar sizes across most GLUE tasks. For instance, NAS-BERT5 achieves better accuracy than BERT5, with the gap widening for smaller models.
- Speedup: The compressed models offer significant speedups. For example, NAS-BERT60 achieves a 2.2x speedup over BERTbase, while NAS-BERT5 achieves a remarkable 23.6x speedup.
- Comparison to Prior Work: NAS-BERT achieves competitive or superior results compared to other state-of-the-art BERT compression methods like DistilBERT, MiniLM, and TinyBERT, often without relying on complex distillation strategies.
Limitations and Future Work
- Computational Cost: While NAS-BERT significantly reduces the cost compared to naive NAS, training the supernet on the pre-training task remains computationally intensive.
- Hyperparameter Tuning: The paper mentions that the choice of hyperparameters for block division, binning, and shrinking was based on empirical studies and preliminary experiments, suggesting potential for further optimization.
- Future Work: The authors suggest exploring more advanced search spaces and NAS methods to achieve even better performance. They also hint at further improvements through more sophisticated distillation techniques.
Summary updated