[Paper Review] Real-Time Execution of Large-scale Language Models on Mobile
This paper proposes a compiler-aware neural architecture search framework that co-optimizes BERT model accuracy and inference latency for mobile devices by integrating compiler-level optimizations into the NAS loop. The framework achieves up to 7.8× speedup over TensorFlow Lite on mobile GPU with only 0.5–2% accuracy loss, enabling real-time inference of large-scale transformer models on consumer mobile hardware.
Pre-trained large-scale language models have increasingly demonstrated high accuracy on many natural language processing (NLP) tasks. However, the limited weight storage and computational speed on hardware platforms have impeded the popularity of pre-trained models, especially in the era of edge computing. In this paper, we seek to find the best model structure of BERT for a given computation size to match specific devices. We propose the first compiler-aware neural architecture optimization framework. Our framework can guarantee the identified model to meet both resource and real-time specifications of mobile devices, thus achieving real-time execution of large transformer-based models like BERT variants. We evaluate our model on several NLP tasks, achieving competitive results on well-known benchmarks with lower latency on mobile devices. Specifically, our model is 5.2x faster on CPU and 4.1x faster on GPU with 0.5-2% accuracy loss compared with BERT-base. Our overall framework achieves up to 7.8x speedup compared with TensorFlow-Lite with only minor accuracy loss.
Motivation & Objective
- To address the challenge of deploying large-scale pre-trained language models like BERT on resource-constrained mobile devices with real-time latency requirements.
- To close the gap between hardware-aware neural architecture search and actual compiler optimizations, which often render NAS results ineffective on deeply layered models.
- To co-optimize model architecture and compiler-level optimizations (e.g., layer fusion) to achieve low-latency, high-accuracy inference on mobile CPUs and GPUs.
- To enable real-time execution of BERT variants on both mobile CPU and GPU—previously unsupported by major frameworks like TensorFlow Lite.
Proposed method
- Introduces a compiler-aware neural architecture search (NAS) framework that integrates compiler optimizations into the NAS loop, ensuring generated models meet real-time and resource constraints.
- Employs a controller-trainer paradigm to search for optimal BERT architectures with respect to accuracy and latency, using fine-tuning on GLUE benchmarks for rapid evaluation.
- Applies a novel layer fusion technique to reduce intermediate tensor memory and computation overhead, significantly improving performance on both CPU and GPU.
- Uses a two-stage training process: first training a deep-and-narrow BERT variant (28 blocks), then distilling it into a more efficient student model using knowledge distillation.
- Generates optimized inference code via a compiler pipeline that analyzes model structure and applies device-specific optimizations, including fused layer execution.
- Evaluates models on real mobile devices (e.g., Samsung Galaxy S20, S10) using HuggingFace and custom compilation pipelines to measure real-world latency and accuracy.
Experimental results
Research questions
- RQ1Can compiler-aware neural architecture search co-optimize model structure and compilation for real-time inference of large BERT models on mobile devices?
- RQ2Does layer fusion significantly reduce inference latency on mobile CPUs and GPUs, especially for deep transformer models?
- RQ3Can a NAS framework that includes compiler feedback achieve better latency and accuracy trade-offs than traditional hardware-aware NAS or existing inference frameworks like TFLite?
- RQ4Is real-time inference of BERT variants possible on mobile GPUs, and how does it compare to CPU execution and TFLite?
Key findings
- The proposed framework achieves up to 7.8× speedup over TensorFlow Lite on mobile GPU, with BERT(ours) with NAS being 5.2× faster on CPU and 4.1× faster on GPU than BERT BASE.
- With only 0.5–2% accuracy loss, the optimized BERT model outperforms BERT BASE and MobileBERT in both latency and accuracy on GLUE benchmarks.
- Layer fusion reduces intermediate memory traffic and accelerates execution, achieving up to 2.4× speedup on GPU and 2.0× on CPU compared to TFLite.
- The framework is the first to support real-time BERT inference on mobile GPU, which was previously unsupported by TFLite.
- Even without compiler optimizations, the baseline model performs comparably to TFLite on CPU, but GPU performance degrades significantly—highlighting the necessity of compiler-level optimization.
- The NAS-optimized model (BERT(ours) with NAS) achieves 1.49× and 1.53× speedup over MobileBERT on CPU and GPU, respectively, with only 0.4–1% accuracy decrease.
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.