业界首个端侧MoE多模态模型MiniCPM-V4.7开源,iPhone仅3GB跑35B

近日,开源大模型团队推出了MiniCPM-V 4.7系列多模态大模型,其中35B-A3B版本是该系列首款MoE架构模型,实现了突破性的端侧部署能力——在iPhone 17 Pro Max设备上仅占用3GB内存,即可达到每秒13+个token的解码速度,刷新了端侧大模型推理效率的行业标杆。该系列同时提供1B参数量的轻量版本,兼顾不同端侧设备的资源约束。
MiniCPM-V 4.7的两个规格版本都优化了性能与效率的平衡:在Instruct模式下,35B-A3B以更短的推理时间超过了同参数量的Qwen3.6 35B-A3B;1B版本则在综合得分和推理效率上,均显著领先Qwen3.5 0.8B模型。
全维度性能测试覆盖
团队针对35B-A3B版本开展了全面的性能测试,涵盖视觉语言综合理解与通用语言任务两大维度,全方位验证模型的实际表现。
对于1B轻量版本,其开发目标是适配更严苛的端侧资源限制,相较上一代MiniCPM-V 4.6版本,该版本进一步提升了基础能力,在性能与推理耗时之间实现了更高的能力密度,让低配置端侧设备也能获得流畅的多模态交互体验。
端侧MoE推理的核心技术方案
MoE架构的总参数量远大于单个token实际激活的参数量,但端侧设备面临内存不足与调度延迟的双重挑战:不同token在不同网络层会选择不同的专家模块,设备内存通常无法同时存储所有专家权重;如果将权重存储在固态硬盘中按需加载,频繁的读写操作又会带来明显的等待延迟,难以满足实时交互的需求。
固定整段prompt的专家子集虽然可以降低加载频率,但会限制后续token的动态路由选择,可能错过模型原本最优的专家路径。MiniCPM-V 4.7的35B-A3B版本针对性解决了这两个问题:既不改变模型原有的路由逻辑,又减少了有限内存与带宽下的加载等待时间。
该方案由三项核心技术协同实现:
- LES前瞻专家调度:通过跨层路由预测,提前加载下一层可能用到的专家模块。预测仅负责预取和调度,实际计算仍遵循模型原有的token级路由规则,未命中的专家也会正常加载并参与计算,确保模型效果不受影响。
- 精细的层级量化:降低专家权重的存储占用和访存开销,让专家加载流程更适配端侧设备的内存与带宽条件,同时完整保留模型的核心能力。
- DSpark投机采样适配:将投机采样技术与端侧推理流程深度结合,与专家调度和量化方案协同提升解码效率,进一步优化端侧交互的流畅度。
这套技术组合让35B-A3B版本在iPhone 17 Pro Max上仅需3GB内存,就能达到每秒13+个token的解码速度,实现了流畅的实时交互。
该模型可部署在手机和平板等端侧设备上,官方提供了多段设备端运行演示,分别展示了35B-A3B在iPhone 17 Pro Max、iPad M4上的运行效果,以及1B版本在iPhone 17 Pro Max上的运行表现。
模型获取与部署
本地下载模型
可以通过官方工具下载指定版本的模型,若需要获取35B-A3B版本,使用以下命令:
modelscope download --model OpenBMB/MiniCPM-V-4.7-35B-A3B --local_dir ./MiniCPM-V-4.7-35B-A3B
如果需要获取1B版本,只需将模型ID替换为OpenBMB/MiniCPM-V-4.7-1B即可。
使用Transformers进行推理
首先安装必要的依赖环境:
pip install "transformers[torch]>=5.18.0" torchvision torchcodec
基础推理脚本示例如下:
import torch from transformers import AutoModelForImageTextToText, AutoProcessormodel_id = “openbmb/MiniCPM-V-4.7-35B-A3B”
processor = AutoProcessor.from_pretrained(model_id)
model = AutoModelForImageTextToText.from_pretrained(
model_id, torch_dtype=“auto”, device_map=“auto”
)推荐使用Flash Attention 2以获得更好的加速与显存节省,尤其在多图和视频场景下效果显著
model = AutoModelForImageTextToText.from_pretrained(
model_id,
torch_dtype=torch.bfloat16,
attn_implementation=“flash_attention_2”,
device_map=“auto”,
)
图片推理的完整示例:
messages = [
{
"role": "user",
"content": [
{"type": "image", "url": "https://huggingface.co/datasets/openbmb/DemoCase/resolve/main/refract.png"},
{"type": "text", "text": "What causes this phenomenon?"},
],
}
]
downsample_mode = "16x" # 使用`downsample_mode="4x"`可获得更精细的细节
inputs = processor.apply_chat_template(
messages, tokenize=True, add_generation_prompt=True,
return_dict=True, return_tensors="pt",
downsample_mode=downsample_mode,
max_slice_nums=36,
enable_thinking=False,
).to(model.device)
generated_ids = model.generate(**inputs, downsample_mode=downsample_mode, max_new_tokens=512)
generated_ids_trimmed = [
out_ids[len(in_ids):] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
]
output_text = processor.batch_decode(
generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
)
print(output_text[0])
视频推理的示例代码:
messages = [
{
"role": "user",
"content": [
{"type": "video", "url": "https://huggingface.co/datasets/openbmb/DemoCase/resolve/main/football.mp4"},
{"type": "text", "text": "Describe this video in detail. Follow the timeline and focus on on-screen text, interface changes, main actions, and scene changes."},
],
}
]
downsample_mode = "16x" # 使用`downsample_mode="4x"`可获得更精细的细节
inputs = processor.apply_chat_template(
messages, tokenize=True, add_generation_prompt=True,
return_dict=True, return_tensors="pt",
downsample_mode=downsample_mode,
max_num_frames=128,
stack_frames=1,
max_slice_nums=1,
use_image_id=False,
enable_thinking=False,
).to(model.device)
generated_ids = model.generate(**inputs, downsample_mode=downsample_mode, max_new_tokens=2048)
generated_ids_trimmed = [
out_ids[len(in_ids):] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
]
output_text = processor.batch_decode(
generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
)
print(output_text[0])
模型微调
ms-swift框架支持对MiniCPM-V-4.7-1B和35B-A3B版本进行微调,该框架是国内开源模型社区推出的官方大模型训练工具,开源仓库地址为https://github.com/modelscope/ms-swift。
首先准备环境:
pip install git+https://github.com/modelscope/ms-swift.git pip install "transformers>=5.18.0" -U # 更多依赖安装参考: https://swift.readthedocs.io/zh-cn/latest/Instruction/安装.html
多模态SFT训练脚本示例:
# 16GiB CUDA_VISIBLE_DEVICES=0 \ swift sft \ --model OpenBMB/MiniCPM-V-4.7-1B \ --dataset 'AI-ModelScope/LaTeX_OCR:human_handwrite#2000' \ --load_from_cache_file true \ --tuner_type full \ --torch_dtype bfloat16 \ --attn_impl sdpa \ --max_length 2048 \ --num_train_epochs 2 \ --per_device_train_batch_size 8 \ --gradient_accumulation_steps 1 \ --learning_rate 1e-5 \ --lr_scheduler_type cosine \ --split_dataset_ratio 0 \ --logging_steps 1 \ --save_steps 100 \ --dataset_num_proc 4 \ --dataloader_num_workers 4 \ --output_dir output
训练完成后,对验证集进行推理的命令:
CUDA_VISIBLE_DEVICES=0 swift infer \ --model output/vx-xxx/checkpoint-xxx \ --val_dataset latex_test3.jsonl \ --max_new_tokens 256 \ --temperature 0 \ --attn_impl sdpa \ --stream false
将微调后的模型推送到开源社区平台的命令:
swift export \ --adapters output/vx-xxx/checkpoint-xxx \ --push_to_hub true \ --hub_model_id '<your-model-id>' \ --hub_token '<your-sdk-token>'

