Source-linked AI summary

MNN: A Universal and Efficient Inference Engine

Xiaotang Jiang, Huan Wang, Yiliu Chen, Ziqi Wu, Lichuan Wang, Bin Zou, Yafeng Yang, Zongyang Cui, Yu Cai, Tianhang Yu, Chengfei Lv, Zhihua Wu

arXiv:2002.12418v1cs.CVcs.DCcs.LG

TL;DR

Mobile inference engines must address model compatibility, device diversity, and resource constraints. MNN combines pre-inference, kernel optimization, and backend abstraction to target universal and efficient mobile deployment. The paper reports favorable on-device performance and broad adoption, while identifying ongoing areas for improvement.

  • Problem

    Mobile inference engines face challenges in model compatibility, device diversity, and limited mobile resources.

  • Method

    MNN combines pre-inference for runtime scheme selection, kernel optimization, and backend abstraction for hybrid scheduling and extensible deployment.

  • Results

    MNN achieves favorable on-device inference performance and has been extensively adopted in mobile applications.

  • Takeaways & Limitations

    MNN offers a semi-automated mobile inference design intended to balance universality and efficiency across deployment settings.

  • Takeaways & Limitations

    MNN remains under active improvement, including auto-tuning, model compression, user tools, and additional language support.

Abstract

from arXiv · show

Deploying deep learning models on mobile devices draws more and more attention recently. However, designing an efficient inference engine on devices is under the great challenges of model compatibility, device diversity, and resource limitation. To deal with these challenges, we propose Mobile Neural Network (MNN), a universal and efficient inference engine tailored to mobile applications. In this paper, the contributions of MNN include: (1) presenting a mechanism called pre-inference that manages to conduct runtime optimization; (2)deliveringthorough kernel optimization on operators to achieve optimal computation performance; (3) introducing backend abstraction module which enables hybrid scheduling and keeps the engine lightweight. Extensive benchmark experiments demonstrate that MNN performs favorably against other popular lightweight deep learning frameworks. MNN is available to public at: https://github.com/alibaba/MNN.

1 INTRODUCTION

MNN addresses mobile inference challenges spanning model compatibility, device diversity, and resource limits by combining runtime optimization, kernel optimization, and backend abstraction. The resulting engine targets universality, efficiency, and lightweight deployment.

  • Challenges: Mobile inference engines must handle model compatibility, device diversity, and constrained memory and computation power.Models come from multiple frameworks and devices range from single-core CPUs to accelerators across varied software environments.
  • Design goals: A capable mobile inference engine should combine universality across models and devices with efficient inference and low memory and energy use.
  • Contributions: MNN introduces pre-inference to perform runtime optimization through online cost evaluation and optimal scheme selection.
  • Contributions: MNN applies improved algorithms and data layouts for in-depth kernel optimization of widely used operations.
  • Contributions: MNN uses backend abstraction to enable hybrid scheduling while keeping the engine lightweight; integration adds 400 ∼600KB to application binary size.
  • Adoption: MNN has been extensively adopted in mobile applications, and its complete project is open-sourced.

2 RELATED WORK

Prior mobile inference approaches trade off universality, lightweight deployment, optimization coverage, or update flexibility. MNN is positioned against these approaches through a semi-automated search architecture.

  • Platform frameworks: CoreML and NNAPI support mobile hardware, but their platform and operating-system requirements limit universality across existing phones and embedded devices.CoreML requires iOS 11+ and NNAPI requires Android 8.1+.
  • Lightweight frameworks: TF-Lite and Caffe2 support many devices but their external acceleration dependencies can increase application binary size and add unnecessary overhead.
  • Manual search: NCNN, MACE, and Anakin use manually optimized, case-by-case operators to remain lightweight and efficient, but this approach is time-consuming and difficult to extend to emerging operators.
  • Automated search: TVM automates graph- and operator-level optimization and scales across models and devices, but its model-specific runtime requires code regeneration when models change.
  • Related techniques: Graph DSL, operator fusion, and replacement methods are described as orthogonal to MNN's contributions and partly referenced by it.

3 MOBILE NEURAL NETWORK (MNN)

MNN combines offline model conversion with on-device runtime optimization, operator-level kernels, and a uniform backend abstraction. Its design targets efficient inference across convolution schemes, memory-management strategies, hardware backends, and model workloads.

  • Architecture: MNN converts models from different frameworks into .mnn format while applying graph optimizations such as fusion, replacement, and quantization.
  • Pre-inference: Pre-inference evaluates computation costs using operator inputs and backend properties to select schemes dynamically from a solution pool.It also supports preparation-execution decoupling for fixed or preprocessable input sizes.
  • Operator optimization: MNN optimizes operators with algorithms and data layouts including Winograd, NC4HW4 SIMD packing, and Strassen multiplication.NC4HW4 places four contiguous elements together for vectorized CPU computation, while Strassen accelerates large matrix multiplication.
  • Operator optimization: Strassen outperforms direct matrix multiplication by 7.5%–13.5% across the reported matrix sizes.
  • Backend abstraction: A uniform Backend class separates resource management, memory allocation, and scheduling from operator implementations across hardware and software backends.This abstraction supports backend scalability, including potential integration of NPU and FPGA platforms.

4 BENCHMARK EXPERIMENTS

MNN is evaluated across mobile inference engines, smartphones, backends, and benchmark networks. It generally delivers faster inference, broad performance across settings, and runtime optimization without TVM’s model-specific deployment overhead.

  • The evaluation covers CoreML, TF-Lite, NCNN, and MACE across iPhone8, iPhoneX, MI6, and Mate20 devices.CPU tests use two or four threads, while GPU tests evaluate Metal, OpenCL, OpenGL, and Vulkan backends.
  • MNN generally outperforms other inference engines by about 20%–40% across smartphones, backends, and networks.
  • On CPU, four-thread MNN inference is about 30% faster than other engines on iOS and about 34% faster on Android platforms such as Mate20.
  • MNN maintains favorable GPU performance across platforms, while competing engines show backend- or network-specific blind spots.On iPhones, MNN is faster than TF-Lite and slightly slower than comparable CoreML; on Android, it obtains favorable results across different hardware and networks.
  • MNN achieves its comprehensive performance advantage through semi-automated search and runtime optimization rather than case-by-case heavy optimization.Its multi-thread CPU inference on high-end devices is also highly competitive with GPU backends.
  • MNN is slightly faster than TVM in some comparisons without model-specific tuning, while TVM’s auto-tuning and compilation add deployment time and resource demands.MNN performs optimizations at runtime, avoiding TVM’s model-specific code-generation process.

5 CONCLUSION AND FUTURE WORK

The conclusion presents MNN as a mobile inference engine designed to combine universality and efficiency. Future work focuses on extending tuning, compression, usability, and language support.

  • MNN combines semi-automated search, pre-inference, kernel optimization, and backend abstraction to target universal and efficient on-device inference.
  • Future work includes backend auto-tuning, on-the-fly model compression, additional user tools, and JavaScript and Python support.

A MLPERF EVALUATION

MNN is additionally evaluated with MLPerf on MobileNet-v2 using four CPU threads on a Pixel 3. The supplied passage identifies the benchmark setting but does not report its results.

  • The MobileNet-v2 benchmark uses MLPerf on four CPU threads of a Pixel 3.
  • The supplied passage refers to results in Table 7 without providing the reported measurements.

B MORE COMPARISON ON PIXEL PHONES

Additional Pixel-phone evaluations compare MNN with TF-Lite on Inception-v3 CPU inference. MNN is consistently faster in both single-thread and multi-thread settings.

  • MNN is consistently faster than TF-Lite on Inception-v3 float models evaluated on Pixel 2 and Pixel 3 CPUs.
  • The comparison covers both single-thread and multi-thread CPU inference settings.

C BACKEND COST EVALUATION

The backend cost evaluation models processor capability with FLOPS and GPU scheduling overhead with tschedule. FLOPS is estimated from CPU frequencies or practical GPU runs, while tschedule depends on the graphical API.

  • FLOPS measures processor capability for both CPUs and GPUs, while tschedule is used only for GPUs.
  • For Linux or Android CPUs, FLOPS sums the largest k core frequencies, where k is the predefined thread count.
  • For other CPU systems, FLOPS is set to 2 × 10^9; GPU FLOPS is estimated by running MobileNet-v1 100 times.
  • Common mobile GPU FLOPS estimates range from 3.19 × 10^9 for Adreno 505 to 42.74 × 10^9 for several Adreno models.
  • tschedule is empirically set to 0.05 ms for OpenCL and OpenGL, and estimated at 0.01 ms for Vulkan.
Loading 2002.12418v1…