NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Exploring the Performance and Efficiency of Transformer Models for NLP on Mobile Devices

Ioannis Panopoulos, Sokratis Nikolaidis, Stylianos I. Venieris, Iakovos S. Venieris · DOI

Abstract

Transformer-based architectures have revolutionized Natural Language Processing (NLP), yet their deployment on mobile devices remains significantly less optimized compared to traditional Convolutional Neural Networks (CNNs). This paper presents a systematic benchmarking of various Transformer models—including BERT variants, DistilBERT, and GPT-2—on mobile hardware using the TensorFlow Lite (TFLite) framework. We evaluate performance across multiple dimensions: quantization strategies, hardware delegates (CPU, GPU, NPU), and device-specific constraints. Our findings highlight a persistent "deployment gap," where standard hardware accelerators often struggle with the dynamic attention mechanisms of Transformers. We provide insights into the trade-offs between latency, memory footprint, and model accuracy, offering a roadmap for more efficient mobile NLP deployment.

Introduction

In contemporary Deep Learning, Transformers have established themselves as the gold standard for accuracy in tasks ranging from sequence classification to text generation. However, the majority of research focuses on scaling these models for massive server-side clusters. On mobile devices (MDs), Transformers remain "second-class citizens." Unlike CNNs, which have benefited from years of mobile-specific architectural optimizations like depthwise separable convolutions, Transformers are inherently computationally heavy and memory-intensive.

Mobile deployment is complicated by strict battery limits, thermal constraints, and the heterogeneous nature of mobile processors (CPUs, GPUs, and NPUs). This study addresses the lack of a systematic understanding of how these models behave when running locally on a smartphone, identifying the bottlenecks that prevent Transformers from achieving the same efficiency gains as their vision-based counterparts.

Methodology

Benchmarking Framework

The researchers constructed a comprehensive benchmark using TensorFlow Lite (TFLite) to evaluate a diverse suite of Transformer variants. The models tested included:

  • Encoder-only: BERT Tiny, DistilBERT, MobileBERT, and RoBERTa Tiny.
  • Decoder-only: GPT-2.

Evaluation Dimensions

  1. Quantization: The study tested half-precision (FP16), 8-bit dynamic range (DR8), and 8-bit fixed-point (FX8) quantization to measure the impact of model compression on execution speed and predictive accuracy.
  2. Hardware Delegates: Execution was tested on the CPU (utilizing the XNNPACK library with varying thread counts), the GPU, and specialized accelerators via the Android Neural Networks API (NNAPI), including the Hexagon DSP and various NPUs.
  3. Target Devices: Benchmarks were performed on two representative devices: the mid-tier Samsung Galaxy A71 and the high-end Samsung Galaxy S20 FE.

Datasets and Tasks

Models were evaluated on two distinct NLP tasks to ensure broad applicability:

  • Sequence Classification: Utilizing the Emotions dataset, which consists of Twitter messages categorized into six emotional states.
  • Text Generation: Utilizing the LAMBADA dataset to evaluate next-token prediction capabilities.

Key Insights and Analysis

The Accelerator Compatibility Gap

A primary finding of this research is that Transformers are currently "accelerator-unfriendly." While CNNs see massive performance boosts on mobile GPUs and NPUs, Transformers often experience marginal or even negative speedups. Most mobile hardware accelerators are hard-coded for the fixed, localized data access patterns of convolutions. The global, dynamic attention mechanisms of Transformers do not map efficiently to these specialized circuits, often defaulting execution back to the CPU.

The Pitfalls of Quantization

While quantization is a standard tool for mobile optimization, its application to Transformers is fraught with trade-offs:

  • Accuracy Degradation: 8-bit fixed-point (FX8) quantization significantly reduces memory usage but can be catastrophic for accuracy. In some instances, model accuracy plummeted from ~93% to below 35% when moved to a GPU delegate or subjected to aggressive quantization.
  • Memory Paradox: Surprisingly, FP16 models required at least 70% more memory than standard FP32 models in certain tests, while offering no significant latency advantage on the CPU.

Optimization Nuances

The study found that "out-of-the-box" configurations are rarely optimal. For example, while TFLite defaults to XNNPACK for CPU execution, manual tuning of CPU thread counts frequently outperformed default settings. Furthermore, models specifically designed for mobile efficiency, such as MobileBERT, demonstrated superior resilience, maintaining accuracy on GPU delegates where other models failed.

Results Summary

  • Latency: Integer quantization (DR8 and FX8) provided the most consistent CPU speedups, reaching up to 2.32x for DistilBERT.
  • Memory: Moving to 8-bit fixed-point (FX8) reduced RAM requirements by approximately 3x across most architectures.
  • Hardware Performance: On the Samsung A71, the GPU delegate only successfully accelerated a small subset of models (e.g., RoBERTa Tiny). For many others, the GPU was actually slower than a well-tuned CPU implementation.

Conclusion and Future Work

To bridge the deployment gap for mobile Transformers, the authors suggest several critical paths for future research:

  1. Mobile-Friendly Layers: There is a need to redesign Transformer layers for hardware compatibility. This includes replacing complex activation functions like GELU with ReLU and swapping Layer Normalization for Batch Normalization to better suit mobile hardware pipelines.
  2. Dynamic Execution: Future mobile AI frameworks should support "opportunistic inference," dynamically switching between CPU and GPU/NPU based on real-time thermal states and resource availability.
  3. Hardware-Aware Architecture Search: Rather than porting server-side models, researchers should focus on developing architectures that are co-designed with the constraints of mobile accelerators in mind.

Summary updated

BibTeX
@inproceedings{panopoulos2023exploring,
  author = {Ioannis Panopoulos and Sokratis Nikolaidis and Stylianos I. Venieris and Iakovos S. Venieris},
  title = {{Exploring the Performance and Efficiency of Transformer Models for NLP on Mobile Devices}},
  booktitle = {ISCC},
  year = {2023},
  doi = {10.1109/iscc58397.2023.10217850},
}
Figure