MiniCPM-V-4.6-gguf
MiniCPM-V-4.6-gguf
该仓库托管 MiniCPM-V 4.6 的 GGUF 量化版本,原始 BF16 权重见 openbmb/MiniCPM-V-4.6。模型基于 SigLIP2-400M 和 Qwen3.5-0.8B LLM 构建,引入混合 4x/16x 视觉 token 压缩,在 Artificial Analysis Intelligence Index 基准测试得分为 13,优于 Qwen3.5-0.8B 的 10 分。支持 iOS、Android 和 HarmonyOS 平台部署,已适配 vLLM、SGLang、llama.cpp、Ollama 等推理框架及 SWIFT、LLaMA-Factory 微调生态系统。
此仓库托管 MiniCPM-V 4.6 的 GGUF (llama.cpp) 量化版本。 原始 BF16 权重及完整模型卡请参阅 openbmb/MiniCPM-V-4.6。
一款口袋大小的 MLLM,用于在手机上实现超高效图像与视频理解
MiniCPM-V 4.6
MiniCPM-V 4.6 是我们迄今为止最适配边缘部署的模型。该模型基于 SigLIP2-400M 和 Qwen3.5-0.8B LLM 构建。它继承了 MiniCPM-V 系列强大的单图、多图及视频理解能力,同时显著提升了计算效率。此外,它还引入了混合 4x/16x 视觉 token 压缩。MiniCPM-V 4.6 的显著特性包括:
🔥 领先的基础能力。 MiniCPM-V 4.6 在 Artificial Analysis Intelligence Index 基准测试中得分为 13,优于 Qwen3.5-0.8B 的 10 分(token 成本降低 19 倍)和 Qwen3.5-0.8B-Thinking 的 11 分(token 成本降低 43 倍)。它还超越了更大的 Ministral 3 3B(得分 11)。
💪 强大的多模态能力。 MiniCPM-V 4.6 在大多数视觉-语言理解任务上优于 Qwen3.5-0.8B,并在 OpenCompass、RefCOCO、HallusionBench、MUIRBench 和 OCRBench 等多个基准测试中达到 Qwen3.5 2B 级别的能力。
🚀 超高效架构。 基于 LLaVA-UHD v4 的最新技术,MiniCPM-V 4.6 将视觉编码计算 FLOPs 降低了 50% 以上。这使得 MiniCPM-V 4.6 相比更小的模型也能实现更高的效率,token 吞吐量约为 Qwen3.5-0.8B 的 1.5 倍。 它还支持混合 4x/16x 视觉 token 压缩率,可在精度和速度之间灵活切换。
📱 广泛的移动平台覆盖。 MiniCPM-V 4.6 可部署在所有三大主流移动平台——iOS、Android 和 HarmonyOS 上。所有边缘适配代码均已开源,开发者只需几个步骤即可复现设备端体验。
🛠️ 开发者友好。 MiniCPM-V 4.6 已适配 vLLM、SGLang、llama.cpp、Ollama 等推理框架,并支持 SWIFT、LLaMA-Factory 等微调生态系统。开发者可以在消费级 GPU 上快速为新领域和任务定制模型。我们提供 GGUF、BNB、AWQ 和 GPTQ 格式的多种量化变体。
评估
整体性能(Instruct)
高并发吞吐量
单请求 TTFT(毫秒)
示例
整体
MiniCPM-V 4.6 可部署在三大主流端侧平台——iOS、Android 和 HarmonyOS 上。以下片段为手机设备上的原始屏幕录制,未经编辑。
使用方法
使用 Transformers 进行推理
安装
pip install "transformers[torch]>=5.7.0" torchvision torchcodec
关于 CUDA 兼容性的说明:
torchcodec(用于视频解码)可能与某些 CUDA 版本存在兼容性问题。例如,torch>=2.11默认捆绑 CUDA 13.1,而使用 CUDA 12.x 的环境可能会遇到类似RuntimeError: Could not load libtorchcodec的错误。两种解决方法:
- 将
torchcodec替换为PyAV——支持图像和视频推理,无 CUDA 版本限制:pip install "transformers[torch]>=5.7.0" torchvision av- 固定 CUDA 版本 安装 torch 以匹配你的环境(例如 CUDA 12.8):
pip install "transformers>=5.7.0" torchvision torchcodec --index-url https://download.pytorch.org/whl/cu128
加载模型
from transformers import AutoModelForImageTextToText, AutoProcessor
model_id = "openbmb/MiniCPM-V-4.6"
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,
).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,
).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])
高级参数
你可以通过向 apply_chat_template 传递额外参数来自定义图像/视频处理:
| 参数 | 默认值 | 适用范围 | 描述 |
|---|---|---|---|
downsample_mode |
"16x" |
图像与视频 | 视觉 token 下采样。"16x" 合并 token 以提高效率;"4x" 保留 4 倍 token 以获取更精细的细节。也必须传递给 generate()。 |
max_slice_nums |
9 |
图像与视频 | 分割高分辨率图像时的最大切片数。较高的值可为大图像保留更多细节。建议:图像为 36,视频为 1。 |
max_num_frames |
128 |
仅视频 | 从视频中采样的最大主帧数。 |
stack_frames |
1 |
仅视频 | 每秒的总采样点数。1 = 仅主帧(无堆叠)。N (N>1) = 每秒 1 个主帧 + N−1 个子帧;子帧被合成为网格图像并与主帧交错。建议:3 或 5。 |
use_image_id |
True |
图像与视频 | 是否在每个图像/帧占位符前添加 <image_id>N</image_id> 标签。建议:图像为 True,视频为 False。 |
注意:
downsample_mode必须同时传递给apply_chat_template(用于正确的占位符计数)和generate(用于视觉编码器)。所有其他参数只需传递给apply_chat_template。
使用 transformers serve 提供服务
Hugging Face Transformers 包含一个轻量级的 OpenAI 兼容服务器,用于快速测试和中负载部署。
pip install "transformers[serving]>=5.7.0"
启动服务器:
transformers serve openbmb/MiniCPM-V-4.6 --port 8000 --host 0.0.0.0 --continuous-batching
发送请求:
curl -s http://localhost:8000/v1/chat/completions \
-H 'Content-Type: application/json' \
-d '{
"model": "openbmb/MiniCPM-V-4.6",
"messages": [{
"role": "user",
"content": [
{"type": "image_url", "image_url": {"url": "https://huggingface.co/datasets/openbmb/DemoCase/resolve/main/refract.png"}},
{"type": "text", "text": "What causes this phenomenon?"}
]
}]
}'
处理模型输出中的转义换行符
在某些情况下,模型可能会将转义换行符 \n 输出为字符串字面量,而不是实际的换行符。为了正确渲染文本(尤其是在 UI 层),你可以使用以下工具函数。该函数会小心地将字面量 \n 替换为实际换行符,同时保护 \n 具有特定语义的场景。
工具函数:
import re
_PATTERN = re.compile(
r'(```[\s\S]*?```' # 围栏代码块
r'|`[^`]+`' # 行内代码
r'|\$\$[\s\S]*?\$\$' # 显示数学
r'|\$[^$]+\$' # 行内数学
r'|\\\([\s\S]*?\\\)' # \(...\)
r'|\\\[[\s\S]*?\\\]' # \[...\]
r')'
r'|(?<!\\)(?:\\r\\n|\\[nr])'
)
def normalize_response_text(text: str) -> str:
"""
轻量级后处理:将字面量 '\\n' 转换为实际换行符,
同时保护代码块、行内代码和 LaTeX 命令。
"""
if not isinstance(text, str) or "\\" not in text:
return text
return _PATTERN.sub(lambda m: m.group(1) or '\n', text)
在 iOS、Android 和 HarmonyOS 平台上部署 MiniCPM-V 4.6
我们已将 MiniCPM-V 4.6 适配部署到 iOS、Android 和 HarmonyOS 平台,所有边缘适配代码均已完全开源。开发者只需几个步骤即可复现设备端体验。请访问我们的边缘部署仓库获取各平台构建指南,或前往下载页面直接试用预构建应用。
在其他推理和训练框架中使用 MiniCPM-V 4.6
MiniCPM-V 4.6 支持多种推理和训练框架。以下是每个框架的快速入门命令。完整详情请参阅我们的 Cookbook。
vllm serve openbmb/MiniCPM-V-4.6 \
--port 8000 \
--enable-auto-tool-choice \
--tool-call-parser qwen3_coder \
--default-chat-template-kwargs '{"enable_thinking": false}'
注意:
--enable-auto-tool-choice和--tool-call-parser qwen3_coder启用工具/函数调用支持。如果你不需要工具使用,可以省略这些标志,直接运行vllm serve openbmb/MiniCPM-V-4.6。
curl -s http://localhost:8000/v1/chat/completions -H 'Content-Type: application/json' -d '{
"model": "openbmb/MiniCPM-V-4.6",
"messages": [{"role": "user", "content": [
{"type": "image_url", "image_url": {"url": "https://huggingface.co/datasets/openbmb/DemoCase/resolve/main/refract.png"}},
{"type": "text", "text": "What causes this phenomenon?"}
]}]
}'
工具调用示例:
curl -s http://localhost:8000/v1/chat/completions -H 'Content-Type: application/json' -d '{
"model": "openbmb/MiniCPM-V-4.6",
"messages": [{"role": "user", "content": [
{"type": "text", "text": "北京的天气"}
]}],
"tools": [{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the current weather for a given location",
"parameters": {
"type": "object",
"properties": {
"location": {"type": "string", "description": "City name"}
},
"required": ["location"]
}
}
}]
}'
python -m sglang.launch_server --model openbmb/MiniCPM-V-4.6 --port 30000
curl -s http://localhost:30000/v1/chat/completions -H 'Content-Type: application/json' -d '{
"model": "openbmb/MiniCPM-V-4.6",
"messages": [{"role": "user", "content": [
{"type": "image_url", "image_url": {"url": "https://huggingface.co/datasets/openbmb/DemoCase/resolve/main/refract.png"}},
{"type": "text", "text": "What causes this phenomenon?"}
]}]
}'
llama-server -m MiniCPM-V-4.6-Q4_K_M.gguf --port 8080
curl -s http://localhost:8080/v1/chat/completions -H 'Content-Type: application/json' -d '{
"model": "MiniCPM-V-4.6",
"messages": [{"role": "user", "content": [
{"type": "image_url", "image_url": {"url": "https://huggingface.co/datasets/openbmb/DemoCase/resolve/main/refract.png"}},
{"type": "text", "text": "What causes this phenomenon?"}
]}]
}'
ollama run minicpm-v-4.6
在交互式会话中,直接粘贴图像路径或 URL 即可与模型对话。
llamafactory-cli train examples/train_lora/minicpmv4_6_lora_sft.yaml
swift sft --model_type minicpm-v-4_6 --dataset <your-dataset>
许可证
模型许可证
- MiniCPM-o/V 模型权重和代码根据 Apache-2.0 许可证开源。
声明
- 作为 MLLM,MiniCPM-o/V 模型通过学习大量多模态语料库生成内容,但无法理解、表达个人观点或做出价值判断。MiniCPM-o/V 模型生成的任何内容均不代表模型开发者的观点和立场。
- 对于因使用 MiniCPM-o/V 模型而产生的任何问题,包括但不限于数据安全问题、舆论风险,或因模型误导、滥用、传播或误用而产生的任何风险和问题,我们概不负责。
技术报告与关键技术论文
👏 欢迎探索 MiniCPM-o/V 的关键技术以及我们团队的其他多模态项目:
技术报告: MiniCPM-o 4.5 | MiniCPM-V 4.5 | MiniCPM-o 2.6 | MiniCPM-Llama3-V 2.5 | MiniCPM-V 2.0
其他多模态项目: VisCPM | RLPR | RLHF-V | LLaVA-UHD | RLAIF-V
引用
如果你觉得我们的模型/代码/论文有帮助,请考虑引用我们的论文 📝 并给我们加星 ⭐️!
@misc{cui2026minicpmo45realtimefullduplex,
title={MiniCPM-o 4.5: Towards Real-Time Full-Duplex Omni-Modal Interaction},
author={Junbo Cui and Bokai Xu and Chongyi Wang and Tianyu Yu and Weiyue Sun and Yingjing Xu and Tianran Wang and Zhihui He and Wenshuo Ma and Tianchi Cai and others},
year={2026},
url={https://arxiv.org/abs/2604.27393},
}
@proceedings{yu2025minicpmv45cookingefficient,
title={MiniCPM-V 4.5: Cooking Efficient MLLMs via Architecture, Data, and Training Recipe},
author={Tianyu Yu and Zefan Wang and Chongyi Wang and Fuwei Huang and Wenshuo Ma and Zhihui He and Tianchi Cai and Weize Chen and Yuxiang Huang and Yuanqian Zhao and others},
year={2025},
url={https://arxiv.org/abs/2509.18154},
}
@article{yao2024minicpm,
title={MiniCPM-V: A GPT-4V Level MLLM on Your Phone},
author={Yao, Yuan and Yu, Tianyu and Zhang, Ao and Wang, Chongyi and Cui, Junbo and Zhu, Hongji and Cai, Tianchi and Li, Haoyu and Zhao, Weilin and He, Zhihui and others},
journal={arXiv preprint arXiv:2408.01800},
year={2024}
}