MCPcopy Create free account
hub / github.com/UbiquitousLearning/mllm

github.com/UbiquitousLearning/mllm @2.0.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release 2.0.0 ↗ · + Follow
7,830 symbols 19,862 edges 1,243 files 630 documented · 8% updated 18d ago2.0.0 · 2026-02-16★ 1,55963 open issues

Browse by type

Functions 5,971 Types & classes 1,855 Endpoints 4
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

mllm

适用于移动端和边缘设备的快速、轻量级多模态大语言模型推理引擎

License: MIT Documentation GitHub Stars

📚 文档🚀 快速开始💡 示例🛠️ 安装

最新动态

  • [2026 年 2 月 3 日] 🔥🔥🔥 MLLM Qnn AOT 已支持在 NPU 上全图执行!快速开始, 技术报告
  • [2025 年 11 月 27 日] Android Demo 更新:通过一种全新的 In-App Go 服务架构,在 Android 上实现了 Qwen3 和 DeepSeek-OCR 的稳定流式推理。
  • [2025 年 11 月 23 日] MLLM v2 发布!
  • [2025 年 8 月 28 日] 即将停止对 MLLM V1 的支持。在弃用前,V1 将集成以下功能:GPT-OSS。随后 MLLM 将迁移至 V2(可在 V2 分支查看)。V2 将带来全新的能力:

  • 更加 Pythonic 的模型编写方式,支持即时执行(eager execution)

  • 支持编译,便于 NPU 集成
  • 支持多模型并行执行
  • 更加完善、精细的工程实现
  • [2025 年 7 月 30 日] 为 QNN 后端模型新增旋转量化(Rotation Quantization)方法,并支持 Qwen-2-VL 2B(ViT 性能分析将在 v2 中集成)

Android Demo & Architecture

我们已对 Android 端实现进行了重构,采用了一种稳健的、完全在设备端运行的 Client-Server 架构。

不同于传统的 JNI 集成方式,我们引入了一个基于 Golang 构建的 In-App Server 层(mllm_server.aar)。该设计将 UI 与高负载的推理计算解耦。

image

关键特性

  1. Python 风格的即时执行(eager execution) —— 支持快速模型开发
  2. 统一的硬件支持 —— 支持 Arm CPU、OpenCL GPU、QNN NPU
  3. 高级优化能力 —— 包括量化、剪枝、推测执行
  4. 面向 NPU 的 IR —— 可与 NPU 框架无缝集成
  5. 部署工具链 —— 提供 SDK 与 CLI 推理工具

MLLM 的作用

MLLM 是 AI 推理技术栈的核心枢纽。它向上连接推测解码、剪枝、量化等优化算法,向下对接用于硬件执行的 AI 编译器 / 运行时层(如 CANN、CUDA、MLIR)。图中以红色标注的 MLLM 独特地打通了算法创新与硬件优化,使其成为连接软件生态与硬件加速的关键节点。

mllm 框架可以与主流社区框架的模型检查点无缝集成。通过 mllm-convertor,可直接导入 PyTorch 和 SafeTensors 模型,对其进行量化并转换为 mllm 格式,随后由 mllm Runtime 加载并执行。

支持的模型

mllm v2

| Model(v2) | CPU | Hexagon NPU

INT8 | |-----------------------------------------------------------------------------|------|-----------------------| | Qwen3-0.6B | ✔️ w4a8 | | | Qwen3-1.7B | ✔️ w4a8 | W4A16-SM8650 | | DeepSeek-OCR | ✔️ w4a8 | | | SmolLM3| ✔️ w4a8 | | | Qwen2-VL-2B-Instruct|✔️ w4a8 || | Qwen2-VL-7B-Instruct|✔️ w4a8|| | Qwen2.5-VL-3B-Instruct|✔️ w4a8|| | Qwen2.5-VL-7B-Instruct|✔️ w4a8||

mllm v1

| Model(v1) | CPU

FP32 | CPU

INT4 | Hexagon NPU

INT8 | |-----------------------------------------------------------------------------|------|-----|----------------------------| | LLaMA 2 7B | ✔️ | ✔️ | | | LLaMA 3 1B | ✔️ | ✔️ | | | LLaMA 3 3B | ✔️ | ✔️ | | | Alpaca 7B | ✔️ | ✔️ | | | TinyLLaMA 1.1B | ✔️ | ✔️ | | | LLaVA 7B | ✔️ | ✔️ | | | Gemma 2B | ✔️ | ✔️ | | | Gemma 2 2B | ✔️ | ✔️ | | | Qwen 1.5 0.5B | ✔️ | ✔️ | ✔️ | | Qwen 1.5 1.8B | ✔️ | ✔️ | ✔️ | | Qwen 2.5 1.5B | ✔️ | ✔️ | ✔️ | | Qwen 3 0.6B | ✔️ | ✔️ | | | Mistral 7B | ✔️ | ✔️ | | | Yi 6B | ✔️ | ✔️ | | | StableLM 2 1.6B | ✔️ | ✔️ | | | OPT 1.3B | ✔️ | ✔️ | | | Phi 3 mini 3.8B | ✔️ | ✔️ | | | MiniCPM 2B | ✔️ | ✔️ | | | MiniCPM 3 4B | ✔️ | ✔️ | | | MiniCPM MoE 8x2B | ✔️ | ✔️ | | | SmolLM 1.7B | ✔️ | ✔️ | | | DCLM 1B | ✔️| ✔️| | | OpenELM 1.1B | ✔️| ✔️| | PhoneLM 1.5B | ✔️| ✔️| ✔️| | Fuyu 8B | ✔️ | ✔️ |
| Vision Transformer | ✔️ | ✔️ | | CLIP | ✔️ | ✔️ | | ImageBind (3 modalities) | ✔️ | ✔️ | | LLaVA 7B | ✔️ | ✔️ | | Phi-3-Vision | ✔️ | ✔️ | | Qwen2-VL 2B | ✔️ | ✔️ | ✔️ |

测试设备

Device OS CPU GPU NPU
PC-X86-w/oAVX512 Ubuntu 22.04 build-passing - -
Nvidia A40 Ubuntu 22.04 - build-passing -
Xiaomi14-8Elite Android 15 build-passing - build-pending
OnePlus13-8Elite Android 15 build-passing - build-pending
MacMini-M4 MacOS 15.5 build-passing - -
OrangePi AI Pro(310B) Ubuntu 22.04 - - build-pending
OrangePi AI Studio(310P) Ubuntu 22.04 - - build-pending

快速开始

使用 mllm-cli 提供 LLM 服务

我们为 MLLM C++ SDK 开发了一个 C SDK 包装器,以实现与 Golang 的无缝集成。基于该包装器,我们用 Golang 构建了 mllm-cli 命令行工具,该工具即将发布。

使用 C++ API 对 VLM 进行推理

以下示例展示了如何使用 mllm 框架的 C++ API 对多模态视觉-语言模型(VLM),具体为 Qwen2-VL,进行推理。流程包括加载模型配置、初始化分词器、加载预训练权重、处理图文输入,以及执行流式文本生成。

auto qwen2vl_cfg        = Qwen2VLConfig(config_path);
auto qwen2vl_tokenizer  = Qwen2VLTokenizer(tokenizer_path);
auto qwen2vl            = Qwen2VLForCausalLM(qwen2vl_cfg);

qwen2vl.load(mllm::load(model_path));
auto inputs = qwen2vl_tokenizer.convertMessage({.prompt = prompt_text, .img_file_path = image_path});

for (auto& step : qwen2vl.chat(inputs)) { 
  std::wcout << qwen2vl_tokenizer.detokenize(step.cur_token_id) << std::flush; 
}

更多示例可见 示例

自定义模型

MLLM 提供了高度 Python 风格的 API,以简化用户的模型实现。例如,下面是一个简洁的 VisionMLP 实现示例:

```c++ class VisionMlp final : public nn::Module { int32_t dim_; int32_t hidden_dim_;

nn::QuickGELU act_; nn::Linear fc_1_; nn::Linear fc_2_;

public: VisionMlp() = default;

inline VisionMlp(const std::string& name, const Qwen2VLConfig& cfg) : nn::Module(name) { dim_ = cfg.visual_embed_dim; hidden_dim_ = cfg.visual_embed_dim * cfg.visual_mlp_ratio;

fc_1_ = reg<nn::Linear>("fc1", dim_, hidden_dim_, true, cfg.linear_impl_type);
fc_2_ = reg<nn::Linear>("fc2", hidden_dim_, dim_, true, cfg.linear_impl_type);
act_ = reg<nn::QuickGELU>("act");

}

std::vector forward(const std::vector& inputs, const std::vector& args)

Core symbols most depended-on inside this repo

Shape

Method 4,269
Class 1,772
Function 1,702
Enum 70
Struct 11
Route 4
TypeAlias 2

Languages

C++92%
Python8%
Go1%

Modules by API surface

mllm/backends/opencl/vendors/OpenCL-Headers/CL/opencl.hpp362 symbols
mllm/backends/cpu/kernels/arm/primitives.hpp272 symbols
pymllm/ffi/__init__.py134 symbols
mllm/compile/ir/linalg/Op.hpp80 symbols
mllm/core/Tensor.cpp65 symbols
mllm-kernel/include/mllm_kernel/tensor.hpp62 symbols
mllm/backends/opencl/runtime/OpenCLLoader.cpp58 symbols
mllm/backends/cpu/kernels/arm/elementwise.cpp57 symbols
algorithms/lazy_vlm/models/qwen2_5vl/modeling_qwen2_5vl.hpp57 symbols
mllm/backends/cpu/kernels/common/kernel_dispatch.cpp56 symbols
algorithms/lazy_vlm/models/qwen2vl/modeling_qwen2vl.hpp56 symbols
mllm/compile/symbolic_expr/AST.hpp53 symbols

For agents

$ claude mcp add mllm \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page