alibaba/MNN

GitHub: alibaba/MNN

阿里巴巴开源的高效轻量深度学习推理框架,支持在移动端和边缘设备上本地运行大语言模型、Stable Diffusion 等多模态 AI 能力。

Stars: 14347 | Forks: 2215

## ![MNN](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/93de8e01f4144754.png) [![License](https://img.shields.io/github/license/alibaba/MNN)](LICENSE.txt) [![Documentation](https://img.shields.io/badge/Documentation-Read-green)](https://mnn-docs.readthedocs.io/en/latest/) [![中文版本](https://img.shields.io/badge/Language-%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87-green)](README_CN.md) [![日本語バージョン](https://img.shields.io/badge/Language-%E6%97%A5%E6%9C%AC%E8%AA%9E-green)](README_JP.md) [![MNN 主页](https://img.shields.io/badge/Homepage-Visit-green)](http://www.mnn.zone) [![MNN Chat App](https://img.shields.io/badge/Apps-MNN_Chat-blue)](./apps/Android/MnnLlmChat/README.md) [![TaoAvatar](https://img.shields.io/badge/Apps-MNN_TaoAvatar-blue)](./apps/Android/Mnn3dAvatar/README.md) [![Sana](https://img.shields.io/badge/Apps-Sana_Image_Edit-blue)](./apps/sana/README.md) ## 新闻 🔥 - [2026/02/13] MNN-Sana-Edit-V2 现已登陆 [apps](./apps/sana/README.md),提供基于 Sana 的卡通风格照片编辑功能。

Icon

- [2025/10/16] 支持 Qwen3-VL 系列。 - [2025/06/11] 新应用 MNN TaoAvatar 发布,你可以在本地离线与 3DAvatar 对话,LLM、ASR、TTS、A2BS 和 NNR 模型全部在本地设备上运行!![MNN TaoAvatar](./apps/Android/Mnn3dAvatar/README.md)

Icon

- [2025/05/12] Android 应用支持 qwen2.5 omni 3b 和 7b [MNN Chat App](./apps/Android/MnnLlmChat/README.md#releases)。

Icon Icon Icon

历史新闻 - [2025/04/30] Android 应用支持 qwen3 和暗黑模式 [MNN Chat App](./apps/Android/MnnLlmChat/README.md#releases)。

Icon

- [2025/02/18] iOS 多模态 LLM App 发布 [MNN LLM iOS](./apps/iOS/MNNLLMChat/README.md)。

Icon

- [2025/02/11] Android 应用支持 [deepseek r1 1.5b](./project/android/apps/MnnLlmApp/README.md#version-021)。

Icon

- [2025/01/23] 我们发布了完整的多模态 LLM Android App:[MNN-LLM-Android](./apps/Android/MnnLlmChat/README.md)。包括 text-to-text、image-to-text、audio-to-text 和 text-to-image 生成。

Icon Icon Icon Icon

## 简介 MNN 是一个高效、轻量的深度学习框架。它支持深度学习模型的推理和训练,在设备端推理和训练方面拥有行业领先的性能。目前,MNN 已集成到阿里巴巴旗下的 30 多个 App 中,如淘宝、天猫、优酷、钉钉、闲鱼等,覆盖了直播、短视频捕获、搜索推荐、拍立淘、互动营销、权益分发、安全风控等 70 多个使用场景。此外,MNN 也被用于嵌入式设备,如物联网。 [MNN-LLM](./transformers/README.md) 是基于 MNN 引擎开发的大语言模型运行时解决方案。该项目的使命是在每个人的平台(手机/PC/IOT)上本地部署 LLM 模型。它支持通义千问、百川、智谱、LLAMA 等主流大语言模型。[MNN-LLM 用户指南](https://mnn-docs.readthedocs.io/en/latest/transformers/llm.html) [MNN-Diffusion](https://github.com/alibaba/MNN/tree/master/transformers/diffusion) 是基于 MNN 引擎开发的 Stable Diffusion 模型运行时解决方案。该项目的使命是在每个人的平台上本地部署 Stable Diffusion 模型。[MNN-Diffusion 用户指南](https://mnn-docs.readthedocs.io/en/latest/transformers/diffusion.html) ![architecture](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/edcacbd1f8144755.png) 在阿里巴巴内部,[MNN](https://mp.weixin.qq.com/s/5I1ISpx8lQqvCS8tGd6EJw) 作为 [Walle](https://mp.weixin.qq.com/s/qpeCETty0BqqNJV9CMJafA) 系统中计算容器的基础模块,Walle 是首个端到端、通用且大规模生产的端云协同机器学习系统,已在顶级系统会议 OSDI’22 上发表。MNN 的关键设计原则以及广泛的基准测试结果(对比 TensorFlow、TensorFlow Lite、PyTorch、PyTorch Mobile、TVM)可以在 OSDI 论文中找到。用于基准测试的脚本和说明放在路径“/benchmark”中。如果 MNN 或 Walle 的设计对您的研究或生产使用有帮助,请引用我们的 OSDI 论文,如下所示: ``` @inproceedings {proc:osdi22:walle, author = {Chengfei Lv and Chaoyue Niu and Renjie Gu and Xiaotang Jiang and Zhaode Wang and Bin Liu and Ziqi Wu and Qiulin Yao and Congyu Huang and Panos Huang and Tao Huang and Hui Shu and Jinde Song and Bin Zou and Peng Lan and Guohuan Xu and Fei Wu and Shaojie Tang and Fan Wu and Guihai Chen}, title = {Walle: An {End-to-End}, {General-Purpose}, and {Large-Scale} Production System for {Device-Cloud} Collaborative Machine Learning}, booktitle = {16th USENIX Symposium on Operating Systems Design and Implementation (OSDI 22)}, year = {2022}, isbn = {978-1-939133-28-1}, address = {Carlsbad, CA}, pages = {249--265}, url = {https://www.usenix.org/conference/osdi22/presentation/lv}, publisher = {USENIX Association}, month = jul, } ``` ## 文档与 Workbench MNN 的文档发布在 [Read the docs](https://mnn-docs.readthedocs.io/en/latest)。 你也可以阅读 docs/README 来构建文档的 HTML。 MNN Workbench 可从 [MNN 主页](http://www.mnn.zone) 下载,它提供预训练模型、可视化训练工具以及模型到设备的一键部署功能。 ## 关键特性 ### 轻量 - 针对设备优化,无依赖,可轻松部署到移动设备和各种嵌入式设备。 - iOS 平台:armv7+arm64 平台全量静态库大小约为 12MB,链接可执行文件增大约 2M。 - Android 平台:核心 so 大小约为 800KB (armv7a - c++_shared)。 - 使用 MNN_BUILD_MINI 可减少约 25% 的包大小,仅限固定模型输入大小。 - 支持 FP16 / Int8 量化,可减少模型大小 50%-70%。 ### 通用性 - 支持 `Tensorflow`、`Caffe`、`ONNX`、`Torchscripts`,并支持常见的神经网络,如 `CNN`、`RNN`、`GAN`、`Transformer`。 - 支持多输入多输出的 AI 模型、各种维度格式、动态输入、控制流。 - MNN 支持 AI 模型中几乎所有的算子。转换器支持 178 个 `Tensorflow` 算子,52 个 `Caffe` 算子,163 个 `Torchscripts` 算子,158 个 `ONNX` 算子。 - 支持 iOS 8.0+、Android 4.3+ 以及具有 POSIX 接口的嵌入式设备。 - 支持多设备混合计算。目前支持 CPU 和 GPU。 ### 高性能 - 核心计算采用大量优化过的汇编代码实现,以充分利用 ARM / x64 CPU。 - 使用 Metal / OpenCL / Vulkan 支持移动端 GPU 推理。 - 使用 CUDA 和 Tensor Core 支持 NVIDIA GPU 以获得更好的性能。 - 卷积和转置卷积算法高效且稳定。Winograd 卷积算法被广泛用于更好的对称卷积,如 3x3、4x4、5x5、6x6、7x7。 - 新架构 ARM v8.2 支持 FP16 半精度计算,速度提升两倍。ARM v8.2 使用 sdot 以及 VNNI 速度提升 2.5 倍。 ### 易用性 - 支持使用 MNN 的算子进行类似 numpy 的数值计算。 - 支持类似 OpenCV 的轻量级图像处理模块,大小仅 100k。 - 支持在 PC / 移动端构建模型并进行训练。 - MNN Python API 帮助 ML 工程师轻松使用 MNN 进行推理、训练和图像处理,无需涉及 C++ 代码。 MNN 支持的架构 / 精度如下所示: - S:支持且运行良好,深度优化,推荐使用 - A:支持且运行良好,可以使用 - B:支持但有 bug 或未优化,不推荐使用 - C:不支持 | Architecture / Precision | | Normal | FP16 | BF16 | Int8 | | --- | --- | --- | --- | --- | --- | | CPU | Native | B | C | B | B | | | x86/x64-SSE4.1 | A | C | C | A | | | x86/x64-AVX2 | S | C | C | A | | | x86/x64-AVX512 | S | C | C | S | | | ARMv7a | S | S (ARMv8.2) | S | S | | | ARMv8 | S | S (ARMv8.2) | S(ARMv8.6) | S | | GPU | OpenCL | A | S | C | S | | | Vulkan | A | A | C | A | | | Metal | A | S | C | S | | | CUDA | A | S | C | A | | NPU | CoreML | A | C | C | C | | | HIAI | A | C | C | C | | | NNAPI | B | B | C | B | | | QNN | C | B | C | C | ## 工具 基于 MNN(张量计算引擎),我们提供了一系列用于推理、训练和通用计算的工具。 - MNN-Converter:将其他模型转换为 MNN 模型以进行推理,例如 Tensorflow(lite)、Caffe、ONNX、Torchscripts。并进行图优化以减少计算量。 - MNN-Compress:压缩模型以减小体积并提高性能 / 速度。 - MNN-Express:支持带控制流的模型,使用 MNN 的算子进行通用计算。 - MNN-CV:一个类似 OpenCV 的库,但基于 MNN,因此更加轻量。 - MNN-Train:支持训练 MNN 模型。 ## 如何参与讨论并向 MNN 社区求助 群讨论以中文为主。但我们欢迎并帮助讲英语的朋友。 钉钉讨论群: 4群 (可加入): 160170007549 3群 (已满) 2群 (已满): 23350225 1群 (已满): 23329087 ## 历史论文 MNN 的早期版本作为移动推理引擎并专注于手动优化,也已发表在 MLSys 2020 上。如果 MNN 以前对您的研究有帮助,请引用该论文: ``` @inproceedings{alibaba2020mnn, author = {Jiang, Xiaotang and Wang, Huan and Chen, Yiliu and Wu, Ziqi and Wang, Lichuan and Zou, Bin and Yang, Yafeng and Cui, Zongyang and Cai, Yu and Yu, Tianhang and Lv, Chengfei and Wu, Zhihua}, title = {MNN: A Universal and Efficient Inference Engine}, booktitle = {MLSys}, year = {2020} } ``` ## 许可证 Apache 2.0 ## 致谢 MNN 参与者:淘宝技术部、搜索工程团队、DAMO 团队、优酷以及其他阿里巴巴集团员工。 MNN 参考了以下项目: - [Caffe](https://github.com/BVLC/caffe) - [flatbuffer](https://github.com/google/flatbuffers) - [gemmlowp](https://github.com/google/gemmlowp) - [Google Vulkan demo](http://www.github.com/googlesamples/android-vulkan-tutorials) - [Halide](https://github.com/halide/Halide) - [Mace](https://github.com/XiaoMi/mace) - [ONNX](https://github.com/onnx/onnx) - [protobuffer](https://github.com/protocolbuffers/protobuf) - [skia](https://github.com/google/skia) - [Tensorflow](https://github.com/tensorflow/tensorflow) - [ncnn](https://github.com/Tencent/ncnn) - [paddle-mobile](https://github.com/PaddlePaddle/paddle-mobile) - [stb](https://github.com/nothings/stb) - [rapidjson](https://github.com/Tencent/rapidjson) - [pybind11](https://github.com/pybind/pybind11) - [pytorch](https://github.com/pytorch/pytorch) - [bolt](https://github.com/huawei-noah/bolt) - [libyuv](https://chromium.googlesource.com/libyuv/libyuv) - [libjpeg](https://github.com/libjpeg-turbo/libjpeg-turbo) - [opencv](https://github.com/opencv/opencv) - [onnxruntime](https://github.com/microsoft/onnxruntime)
标签:3D数字人, Android应用开发, CNCF毕业项目, LLM, MNN, Qwen, TaoAvatar, UML, Unmanaged PE, Vectored Exception Handling, Veh, 凭据扫描, 图像编辑, 多模态大模型, 本地推理, 模型部署, 深度学习框架, 神经网络, 离线人工智能, 移动端机器学习, 端侧AI, 计算机视觉, 语音合成, 语音识别, 轻量级推理, 逆向工具, 阿里巴巴, 高性能计算