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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
pipeline_tag: image-text-to-text
|
| 4 |
+
tags:
|
| 5 |
+
- minicpm-v
|
| 6 |
+
- multimodal
|
| 7 |
+
---
|
| 8 |
+
|
| 9 |
+
> **This repository hosts the AWQ (W4A16, AutoAWQ) quantized version of [MiniCPM-V 4.6](https://huggingface.co/openbmb/MiniCPM-V-4.6).** For the original BF16 weights and the full model card, please refer to [openbmb/MiniCPM-V-4.6](https://huggingface.co/openbmb/MiniCPM-V-4.6).
|
| 10 |
+
|
| 11 |
+
A Pocket-Sized MLLM for Ultra-Efficient Image and Video Understanding on Your Phone
|
| 12 |
+
|
| 13 |
+
[GitHub](https://github.com/OpenBMB/MiniCPM-o) | [CookBook](https://github.com/OpenSQZ/MiniCPM-V-CookBook) | [Demo](https://huggingface.co/spaces/openbmb/MiniCPM-V-4.6-AWQ-Demo) |
|
| 14 |
+
[Feishu (Lark)](https://raw.githubusercontent.com/openbmb/MiniCPM-V/main/assets/feishu_qrcode.png)
|
| 15 |
+
|
| 16 |
+
## MiniCPM-V 4.6
|
| 17 |
+
|
| 18 |
+
**MiniCPM-V 4.6** is our most edge-deployment-friendly model to date. The model is built based on SigLIP2-400M and the Qwen3.5-0.8B LLM. It inherits the strong single-image, multi-image, and video understanding capabilities of MiniCPM-V family, while significantly improving computation efficiency. It also introduces mixed 4x/16x visual token compression. Notable features of MiniCPM-V 4.6 include:
|
| 19 |
+
|
| 20 |
+
- 🔥 **Leading Foundation Capability.**
|
| 21 |
+
MiniCPM-V 4.6 scores 13 on the Artificial Analysis Intelligence Index benchmark, outperforming Qwen3.5-0.8B's score of 10 with 19x fewer token cost, and Qwen3.5-0.8B-Thinking's score of 11 with 43x fewer token cost. It also surpasses the larger Ministral 3 3B (score of 11).
|
| 22 |
+
|
| 23 |
+
- 💪 **Strong Multimodal Capability.**
|
| 24 |
+
MiniCPM-V 4.6 outperforms Qwen3.5-0.8B on most vision-language understanding tasks, and reaches Qwen3.5 2B-level capability on many benchmarks including OpenCompass, RefCOCO, HallusionBench, MUIRBench, and OCRBench.
|
| 25 |
+
- 🚀 **Ultra-Efficient Architecture.**
|
| 26 |
+
Based on the latest technique in [LLaVA-UHD v4](https://github.com/THUMAI-Lab/LLaVA-UHD-v4), MiniCPM-V 4.6 reduces the visual encoding computation FLOPs by more than 50%. It enables MiniCPM-V 4.6 to achieve better efficiency to even smaller models, achieving ~1.5x token throughput compared to Qwen3.5-0.8B.
|
| 27 |
+
It also supports mixed 4x/16x visual token compression rate, allowing flexible switching between accuracy and speed.
|
| 28 |
+
- 📱 **Broad Mobile Platform Coverage.**
|
| 29 |
+
MiniCPM-V 4.6 can be deployed across all three mainstream mobile platforms — iOS, Android, and HarmonyOS. With every edge adaptation code open-sourced, developers can reproduce the on-device experience in [just a few steps](#deploy-minicpm-v-46-on-ios-android-and-harmonyos-platforms).
|
| 30 |
+
- 🛠️ **Developer Friendly.**
|
| 31 |
+
MiniCPM-V 4.6 is adapted to [inference frameworks](#use-minicpm-v-46-in-other-inference-and-training-frameworks) such as vLLM, SGLang, llama.cpp, Ollama, and supports [fine-tuning ecosystems](#use-minicpm-v-46-in-other-inference-and-training-frameworks) such as SWIFT and LLaMA-Factory. Developers can quickly customize models for new domains and tasks on consumer-grade GPUs. We provide multiple quantized variants across GGUF, BNB, AWQ, and GPTQ formats.
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
### Evaluation <!-- omit in toc -->
|
| 35 |
+
|
| 36 |
+
**Overall Performance (Instruct)**
|
| 37 |
+
|
| 38 |
+
<p align="center">
|
| 39 |
+
<img src="https://raw.githubusercontent.com/openbmb/MiniCPM-V/main/assets/minicpmv4.6/instruct.png" width="90%"></img>
|
| 40 |
+
</p>
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
<details>
|
| 44 |
+
<summary>Click to view MiniCPM-V 4.6-Thinking performance.</summary>
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
<p align="center">
|
| 48 |
+
<img src="https://raw.githubusercontent.com/openbmb/MiniCPM-V/main/assets/minicpmv4.6/thinking.png" width="90%"></img>
|
| 49 |
+
</p>
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
</details>
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
<details>
|
| 56 |
+
<summary>Click to view MiniCPM-V 4.6 inference efficiency results.</summary>
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
**High-Concurrency Throughput**
|
| 60 |
+
|
| 61 |
+
<p align="center">
|
| 62 |
+
<img src="https://raw.githubusercontent.com/openbmb/MiniCPM-V/main/assets/minicpmv4.6/throughput.png" width="60%"></img>
|
| 63 |
+
</p>
|
| 64 |
+
|
| 65 |
+
**Single Request TTFT (ms)**
|
| 66 |
+
|
| 67 |
+
<p align="center">
|
| 68 |
+
<img src="https://raw.githubusercontent.com/openbmb/MiniCPM-V/main/assets/minicpmv4.6/ttft.png" width="60%"></img>
|
| 69 |
+
</p>
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
</details>
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
### Examples <!-- omit in toc -->
|
| 76 |
+
|
| 77 |
+
#### Overall
|
| 78 |
+
|
| 79 |
+
<div align="center">
|
| 80 |
+
<a href="https://www.youtube.com/watch?v=Ch5UG1FoysM"><img src="https://raw.githubusercontent.com/openbmb/MiniCPM-V/main/assets/minicpmv4.6/video_play.png" width="70%"></a>
|
| 81 |
+
</div>
|
| 82 |
+
|
| 83 |
+
MiniCPM-V 4.6 can be deployed across three mainstream end-side platforms — **iOS, Android and HarmonyOS**. The clips below are raw screen recordings on phone devices without edition.
|
| 84 |
+
|
| 85 |
+
<table align="center">
|
| 86 |
+
<tr>
|
| 87 |
+
<td align="center"><b>iPhone</b><br><sub>iPhone 17 Pro Max</sub></td>
|
| 88 |
+
<td align="center"><b>Android</b><br><sub>Redmi K70</sub></td>
|
| 89 |
+
<td align="center"><b>HarmonyOS</b><br><sub>HUAWEI nova 14</sub></td>
|
| 90 |
+
</tr>
|
| 91 |
+
<tr>
|
| 92 |
+
<td align="center"><img src="https://raw.githubusercontent.com/openbmb/MiniCPM-V/main/assets/minicpmv4.6/v46_iphone_en_handwriting.gif" width="100%"/></td>
|
| 93 |
+
<td align="center"><img src="https://raw.githubusercontent.com/openbmb/MiniCPM-V/main/assets/minicpmv4.6/v46_android_en_refraction.gif" width="100%"/></td>
|
| 94 |
+
<td align="center"><img src="https://raw.githubusercontent.com/openbmb/MiniCPM-V/main/assets/minicpmv4.6/v46_harmonyos_en_ticket.gif" width="100%"/></td>
|
| 95 |
+
</tr>
|
| 96 |
+
</table>
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
### Usages
|
| 100 |
+
|
| 101 |
+
#### Inference with Transformers <!-- omit in toc -->
|
| 102 |
+
##### Installation <!-- omit in toc -->
|
| 103 |
+
|
| 104 |
+
```bash
|
| 105 |
+
pip install "transformers[torch]>=5.7.0" torchvision torchcodec
|
| 106 |
+
```
|
| 107 |
+
|
| 108 |
+
> **Note on CUDA compatibility:** `torchcodec` (used for video decoding) may have compatibility issues with certain CUDA versions. For example, `torch>=2.11` bundles CUDA 13.1 by default, while environments with CUDA 12.x may encounter errors such as `RuntimeError: Could not load libtorchcodec`. Two workarounds:
|
| 109 |
+
>
|
| 110 |
+
> 1. **Replace `torchcodec` with `PyAV`** — supports both image and video inference without CUDA version constraints:
|
| 111 |
+
> ```bash
|
| 112 |
+
> pip install "transformers[torch]>=5.7.0" torchvision av
|
| 113 |
+
> ```
|
| 114 |
+
> 2. **Pin the CUDA version** when installing torch to match your environment (e.g. CUDA 12.8):
|
| 115 |
+
> ```bash
|
| 116 |
+
> pip install "transformers>=5.7.0" torchvision torchcodec --index-url https://download.pytorch.org/whl/cu128
|
| 117 |
+
> ```
|
| 118 |
+
|
| 119 |
+
##### Load Model <!-- omit in toc -->
|
| 120 |
+
|
| 121 |
+
```python
|
| 122 |
+
from transformers import AutoModelForImageTextToText, AutoProcessor
|
| 123 |
+
|
| 124 |
+
model_id = "openbmb/MiniCPM-V-4.6-AWQ"
|
| 125 |
+
|
| 126 |
+
processor = AutoProcessor.from_pretrained(model_id)
|
| 127 |
+
model = AutoModelForImageTextToText.from_pretrained(
|
| 128 |
+
model_id, torch_dtype="auto", device_map="auto"
|
| 129 |
+
)
|
| 130 |
+
|
| 131 |
+
# Flash Attention 2 is recommended for better acceleration and memory saving,
|
| 132 |
+
# especially in multi-image and video scenarios.
|
| 133 |
+
# model = AutoModelForImageTextToText.from_pretrained(
|
| 134 |
+
# model_id,
|
| 135 |
+
# torch_dtype=torch.bfloat16,
|
| 136 |
+
# attn_implementation="flash_attention_2",
|
| 137 |
+
# device_map="auto",
|
| 138 |
+
# )
|
| 139 |
+
```
|
| 140 |
+
|
| 141 |
+
##### Image Inference <!-- omit in toc -->
|
| 142 |
+
|
| 143 |
+
```python
|
| 144 |
+
messages = [
|
| 145 |
+
{
|
| 146 |
+
"role": "user",
|
| 147 |
+
"content": [
|
| 148 |
+
{"type": "image", "url": "https://huggingface.co/datasets/openbmb/DemoCase/resolve/main/refract.png"},
|
| 149 |
+
{"type": "text", "text": "What causes this phenomenon?"},
|
| 150 |
+
],
|
| 151 |
+
}
|
| 152 |
+
]
|
| 153 |
+
|
| 154 |
+
downsample_mode = "16x" # Using `downsample_mode="4x"` for Finer Detail
|
| 155 |
+
|
| 156 |
+
inputs = processor.apply_chat_template(
|
| 157 |
+
messages, tokenize=True, add_generation_prompt=True,
|
| 158 |
+
return_dict=True, return_tensors="pt",
|
| 159 |
+
downsample_mode=downsample_mode,
|
| 160 |
+
max_slice_nums=36,
|
| 161 |
+
).to(model.device)
|
| 162 |
+
|
| 163 |
+
generated_ids = model.generate(**inputs, downsample_mode=downsample_mode, max_new_tokens=512)
|
| 164 |
+
generated_ids_trimmed = [
|
| 165 |
+
out_ids[len(in_ids):] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
|
| 166 |
+
]
|
| 167 |
+
output_text = processor.batch_decode(
|
| 168 |
+
generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
|
| 169 |
+
)
|
| 170 |
+
print(output_text[0])
|
| 171 |
+
```
|
| 172 |
+
|
| 173 |
+
##### Video Inference <!-- omit in toc -->
|
| 174 |
+
|
| 175 |
+
```python
|
| 176 |
+
messages = [
|
| 177 |
+
{
|
| 178 |
+
"role": "user",
|
| 179 |
+
"content": [
|
| 180 |
+
{"type": "video", "url": "https://huggingface.co/datasets/openbmb/DemoCase/resolve/main/football.mp4"},
|
| 181 |
+
{"type": "text", "text": "Describe this video in detail. Follow the timeline and focus on on-screen text, interface changes, main actions, and scene changes."},
|
| 182 |
+
],
|
| 183 |
+
}
|
| 184 |
+
]
|
| 185 |
+
|
| 186 |
+
downsample_mode = "16x" # Using `downsample_mode="4x"` for Finer Detail
|
| 187 |
+
|
| 188 |
+
inputs = processor.apply_chat_template(
|
| 189 |
+
messages, tokenize=True, add_generation_prompt=True,
|
| 190 |
+
return_dict=True, return_tensors="pt",
|
| 191 |
+
downsample_mode=downsample_mode,
|
| 192 |
+
max_num_frames=128,
|
| 193 |
+
stack_frames=1,
|
| 194 |
+
max_slice_nums=1,
|
| 195 |
+
use_image_id=False,
|
| 196 |
+
).to(model.device)
|
| 197 |
+
|
| 198 |
+
generated_ids = model.generate(**inputs, downsample_mode=downsample_mode, max_new_tokens=2048)
|
| 199 |
+
generated_ids_trimmed = [
|
| 200 |
+
out_ids[len(in_ids):] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
|
| 201 |
+
]
|
| 202 |
+
output_text = processor.batch_decode(
|
| 203 |
+
generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
|
| 204 |
+
)
|
| 205 |
+
print(output_text[0])
|
| 206 |
+
```
|
| 207 |
+
|
| 208 |
+
##### Advanced Parameters <!-- omit in toc -->
|
| 209 |
+
|
| 210 |
+
You can customize image/video processing by passing additional parameters to `apply_chat_template`:
|
| 211 |
+
|
| 212 |
+
| Parameter | Default | Applies to | Description |
|
| 213 |
+
|-----------|---------|------------|-------------|
|
| 214 |
+
| `downsample_mode` | `"16x"` | Image & Video | Visual token downsampling. `"16x"` merges tokens for efficiency; `"4x"` keeps 4× more tokens for finer detail. Must also be passed to `generate()`. |
|
| 215 |
+
| `max_slice_nums` | `9` | Image & Video | Maximum number of slices when splitting a high-resolution image. Higher values preserve more detail for large images. Recommended: `36` for image, `1` for video. |
|
| 216 |
+
| `max_num_frames` | `128` | Video only | Maximum number of main frames sampled from the video. |
|
| 217 |
+
| `stack_frames` | `1` | Video only | Total sample points per second. `1` = main frame only (no stacking). `N` (N>1) = 1 main frame + N−1 sub-frames per second; the sub-frames are composited into a grid image and interleaved with main frames. Recommended: `3` or `5`. |
|
| 218 |
+
| `use_image_id` | `True` | Image & Video | Whether to prepend `<image_id>N</image_id>` tags before each image/frame placeholder. Recommended: `True` for image, `False` for video. |
|
| 219 |
+
|
| 220 |
+
> **Note:** `downsample_mode` must be passed to **both** `apply_chat_template` (for correct placeholder count) and `generate` (for the vision encoder). All other parameters only need to be passed to `apply_chat_template`.
|
| 221 |
+
|
| 222 |
+
##### Serving with `transformers serve` <!-- omit in toc -->
|
| 223 |
+
|
| 224 |
+
Hugging Face Transformers includes a lightweight OpenAI-compatible server for quick testing and moderate-load deployment.
|
| 225 |
+
|
| 226 |
+
```bash
|
| 227 |
+
pip install "transformers[serving]>=5.7.0"
|
| 228 |
+
```
|
| 229 |
+
|
| 230 |
+
Start the server:
|
| 231 |
+
|
| 232 |
+
```bash
|
| 233 |
+
transformers serve openbmb/MiniCPM-V-4.6-AWQ --port 8000 --host 0.0.0.0 --continuous-batching
|
| 234 |
+
```
|
| 235 |
+
|
| 236 |
+
Send a request:
|
| 237 |
+
|
| 238 |
+
```bash
|
| 239 |
+
curl -s http://localhost:8000/v1/chat/completions \
|
| 240 |
+
-H 'Content-Type: application/json' \
|
| 241 |
+
-d '{
|
| 242 |
+
"model": "openbmb/MiniCPM-V-4.6-AWQ",
|
| 243 |
+
"messages": [{
|
| 244 |
+
"role": "user",
|
| 245 |
+
"content": [
|
| 246 |
+
{"type": "image_url", "image_url": {"url": "https://huggingface.co/datasets/openbmb/DemoCase/resolve/main/refract.png"}},
|
| 247 |
+
{"type": "text", "text": "What causes this phenomenon?"}
|
| 248 |
+
]
|
| 249 |
+
}]
|
| 250 |
+
}'
|
| 251 |
+
```
|
| 252 |
+
|
| 253 |
+
#### Handling Escaped Newlines in Model Outputs <!-- omit in toc -->
|
| 254 |
+
|
| 255 |
+
In some cases, the model might output escaped newline characters `\n` as string literals instead of actual newlines. To render the text correctly, especially in UI layers, you can use the following utility function. This function carefully replaces literal `\n` with real newlines while protecting scenarios where `\n` has specific semantic meaning.
|
| 256 |
+
|
| 257 |
+
**Utility Function:**
|
| 258 |
+
|
| 259 |
+
```python
|
| 260 |
+
import re
|
| 261 |
+
|
| 262 |
+
_PATTERN = re.compile(
|
| 263 |
+
r'(```[\s\S]*?```' # fenced code blocks
|
| 264 |
+
r'|`[^`]+`' # inline code
|
| 265 |
+
r'|\$\$[\s\S]*?\$\$' # display math
|
| 266 |
+
r'|\$[^$]+\$' # inline math
|
| 267 |
+
r'|\\\([\s\S]*?\\\)' # \(...\)
|
| 268 |
+
r'|\\\[[\s\S]*?\\\]' # \[...\]
|
| 269 |
+
r')'
|
| 270 |
+
r'|(?<!\\)(?:\\r\\n|\\[nr])'
|
| 271 |
+
)
|
| 272 |
+
|
| 273 |
+
def normalize_response_text(text: str) -> str:
|
| 274 |
+
"""
|
| 275 |
+
Lightweight post-processing: Converts literal '\\n' to actual newlines,
|
| 276 |
+
while protecting code blocks, inline code, and LaTeX commands.
|
| 277 |
+
"""
|
| 278 |
+
if not isinstance(text, str) or "\\" not in text:
|
| 279 |
+
return text
|
| 280 |
+
return _PATTERN.sub(lambda m: m.group(1) or '\n', text)
|
| 281 |
+
```
|
| 282 |
+
|
| 283 |
+
#### Deploy MiniCPM-V 4.6 on iOS, Android, and HarmonyOS Platforms <!-- omit in toc -->
|
| 284 |
+
|
| 285 |
+
We have adapted MiniCPM-V 4.6 for deployment on **iOS, Android, and HarmonyOS** platforms, with **all edge adaptation code fully open-sourced**. Developers can reproduce the on-device experience in just a few steps. Visit our [edge deployment repository](https://github.com/OpenBMB/MiniCPM-V-edge-demo) for platform-specific build guides, or go to the [download page](https://github.com/OpenBMB/MiniCPM-V-edge-demo/blob/main/DOWNLOAD.md) to try pre-built apps directly.
|
| 286 |
+
|
| 287 |
+
#### Use MiniCPM-V 4.6 in Other Inference and Training Frameworks <!-- omit in toc -->
|
| 288 |
+
|
| 289 |
+
MiniCPM-V 4.6 supports multiple inference and training frameworks. Below are quick-start commands for each. For full details, see our [Cookbook](https://github.com/OpenSQZ/MiniCPM-V-CookBook).
|
| 290 |
+
|
| 291 |
+
<details>
|
| 292 |
+
<summary><b>vLLM</b> — <a href="https://github.com/OpenSQZ/MiniCPM-V-CookBook/blob/main/deployment/vllm/minicpm-v4_6_vllm.md">Full Guide</a></summary>
|
| 293 |
+
|
| 294 |
+
```bash
|
| 295 |
+
vllm serve openbmb/MiniCPM-V-4.6-AWQ \
|
| 296 |
+
--port 8000 \
|
| 297 |
+
--enable-auto-tool-choice \
|
| 298 |
+
--tool-call-parser qwen3_coder \
|
| 299 |
+
--default-chat-template-kwargs '{"enable_thinking": false}'
|
| 300 |
+
```
|
| 301 |
+
|
| 302 |
+
> **Note:** `--enable-auto-tool-choice` and `--tool-call-parser qwen3_coder` enable tool/function calling support. If you don't need tool use, you can omit these flags and simply run `vllm serve openbmb/MiniCPM-V-4.6-AWQ`.
|
| 303 |
+
|
| 304 |
+
```bash
|
| 305 |
+
curl -s http://localhost:8000/v1/chat/completions -H 'Content-Type: application/json' -d '{
|
| 306 |
+
"model": "openbmb/MiniCPM-V-4.6-AWQ",
|
| 307 |
+
"messages": [{"role": "user", "content": [
|
| 308 |
+
{"type": "image_url", "image_url": {"url": "https://huggingface.co/datasets/openbmb/DemoCase/resolve/main/refract.png"}},
|
| 309 |
+
{"type": "text", "text": "What causes this phenomenon?"}
|
| 310 |
+
]}]
|
| 311 |
+
}'
|
| 312 |
+
```
|
| 313 |
+
|
| 314 |
+
|
| 315 |
+
Tool calling example:
|
| 316 |
+
|
| 317 |
+
```bash
|
| 318 |
+
curl -s http://localhost:8000/v1/chat/completions -H 'Content-Type: application/json' -d '{
|
| 319 |
+
"model": "openbmb/MiniCPM-V-4.6-AWQ",
|
| 320 |
+
"messages": [{"role": "user", "content": [
|
| 321 |
+
{"type": "text", "text": "北京的天气"}
|
| 322 |
+
]}],
|
| 323 |
+
"tools": [{
|
| 324 |
+
"type": "function",
|
| 325 |
+
"function": {
|
| 326 |
+
"name": "get_weather",
|
| 327 |
+
"description": "Get the current weather for a given location",
|
| 328 |
+
"parameters": {
|
| 329 |
+
"type": "object",
|
| 330 |
+
"properties": {
|
| 331 |
+
"location": {"type": "string", "description": "City name"}
|
| 332 |
+
},
|
| 333 |
+
"required": ["location"]
|
| 334 |
+
}
|
| 335 |
+
}
|
| 336 |
+
}]
|
| 337 |
+
}'
|
| 338 |
+
```
|
| 339 |
+
|
| 340 |
+
</details>
|
| 341 |
+
|
| 342 |
+
<details>
|
| 343 |
+
<summary><b>SGLang</b> — <a href="https://github.com/OpenSQZ/MiniCPM-V-CookBook/blob/main/deployment/sglang/minicpm-v4_6_sglang.md">Full Guide</a></summary>
|
| 344 |
+
|
| 345 |
+
```bash
|
| 346 |
+
python -m sglang.launch_server --model openbmb/MiniCPM-V-4.6-AWQ --port 30000
|
| 347 |
+
```
|
| 348 |
+
|
| 349 |
+
```bash
|
| 350 |
+
curl -s http://localhost:30000/v1/chat/completions -H 'Content-Type: application/json' -d '{
|
| 351 |
+
"model": "openbmb/MiniCPM-V-4.6-AWQ",
|
| 352 |
+
"messages": [{"role": "user", "content": [
|
| 353 |
+
{"type": "image_url", "image_url": {"url": "https://huggingface.co/datasets/openbmb/DemoCase/resolve/main/refract.png"}},
|
| 354 |
+
{"type": "text", "text": "What causes this phenomenon?"}
|
| 355 |
+
]}]
|
| 356 |
+
}'
|
| 357 |
+
```
|
| 358 |
+
|
| 359 |
+
</details>
|
| 360 |
+
|
| 361 |
+
<details>
|
| 362 |
+
<summary><b>llama.cpp</b> — <a href="https://github.com/OpenSQZ/MiniCPM-V-CookBook/blob/main/deployment/llama.cpp/minicpm-v4_6_llamacpp.md">Full Guide</a></summary>
|
| 363 |
+
|
| 364 |
+
```bash
|
| 365 |
+
llama-server -m MiniCPM-V-4.6-Q4_K_M.gguf --port 8080
|
| 366 |
+
```
|
| 367 |
+
|
| 368 |
+
```bash
|
| 369 |
+
curl -s http://localhost:8080/v1/chat/completions -H 'Content-Type: application/json' -d '{
|
| 370 |
+
"model": "MiniCPM-V-4.6",
|
| 371 |
+
"messages": [{"role": "user", "content": [
|
| 372 |
+
{"type": "image_url", "image_url": {"url": "https://huggingface.co/datasets/openbmb/DemoCase/resolve/main/refract.png"}},
|
| 373 |
+
{"type": "text", "text": "What causes this phenomenon?"}
|
| 374 |
+
]}]
|
| 375 |
+
}'
|
| 376 |
+
```
|
| 377 |
+
|
| 378 |
+
</details>
|
| 379 |
+
|
| 380 |
+
<details>
|
| 381 |
+
<summary><b>Ollama</b> — <a href="https://github.com/OpenSQZ/MiniCPM-V-CookBook/blob/main/deployment/ollama/minicpm-v4_6_ollama.md">Full Guide</a></summary>
|
| 382 |
+
|
| 383 |
+
```bash
|
| 384 |
+
ollama run minicpm-v-4.6
|
| 385 |
+
```
|
| 386 |
+
|
| 387 |
+
In the interactive session, paste an image path or URL directly to chat with the model.
|
| 388 |
+
|
| 389 |
+
</details>
|
| 390 |
+
|
| 391 |
+
<details>
|
| 392 |
+
<summary><b>LLaMA-Factory</b> (Fine-tuning) — <a href="https://github.com/OpenSQZ/MiniCPM-V-CookBook/blob/main/finetune/llamafactory_minicpmv46.md">Full Guide</a></summary>
|
| 393 |
+
|
| 394 |
+
```bash
|
| 395 |
+
llamafactory-cli train examples/train_lora/minicpmv4_6_lora_sft.yaml
|
| 396 |
+
```
|
| 397 |
+
|
| 398 |
+
</details>
|
| 399 |
+
|
| 400 |
+
<details>
|
| 401 |
+
<summary><b>ms-swift</b> (Fine-tuning) — <a href="https://github.com/OpenSQZ/MiniCPM-V-CookBook/blob/main/finetune/swift_minicpmv46.md">Full Guide</a></summary>
|
| 402 |
+
|
| 403 |
+
```bash
|
| 404 |
+
swift sft --model_type minicpm-v-4_6 --dataset <your-dataset>
|
| 405 |
+
```
|
| 406 |
+
|
| 407 |
+
</details>
|
| 408 |
+
|
| 409 |
+
## License
|
| 410 |
+
|
| 411 |
+
#### Model License
|
| 412 |
+
* The MiniCPM-o/V model weights and code are open-sourced under the [Apache-2.0](https://github.com/OpenBMB/MiniCPM-V/blob/main/LICENSE) license.
|
| 413 |
+
|
| 414 |
+
#### Statement
|
| 415 |
+
* As MLLMs, MiniCPM-o/V models generate content by learning a large number of multimodal corpora, but they cannot comprehend, express personal opinions, or make value judgements. Anything generated by MiniCPM-o/V models does not represent the views and positions of the model developers
|
| 416 |
+
* We will not be liable for any problems arising from the use of MiniCPM-o/V models, including but not limited to data security issues, risk of public opinion, or any risks and problems arising from the misdirection, misuse, dissemination, or misuse of the model.
|
| 417 |
+
|
| 418 |
+
|
| 419 |
+
## Technical Reports and Key Techniques Papers
|
| 420 |
+
|
| 421 |
+
👏 Welcome to explore key techniques of MiniCPM-o/V and other multimodal projects of our team:
|
| 422 |
+
|
| 423 |
+
**Technical Reports:** [MiniCPM-o 4.5](https://huggingface.co/papers/2604.27393) | [MiniCPM-V 4.5](https://arxiv.org/abs/2509.18154) | [MiniCPM-o 2.6](https://openbmb.notion.site/MiniCPM-o-2-6-A-GPT-4o-Level-MLLM-for-Vision-Speech-and-Multimodal-Live-Streaming-on-Your-Phone-185ede1b7a558042b5d5e45e6b237da9) | [MiniCPM-Llama3-V 2.5](https://arxiv.org/abs/2408.01800) | [MiniCPM-V 2.0](https://openbmb.vercel.app/minicpm-v-2)
|
| 424 |
+
|
| 425 |
+
**Other Multimodal Projects:** [VisCPM](https://github.com/OpenBMB/VisCPM/tree/main) | [RLPR](https://github.com/OpenBMB/RLPR) | [RLHF-V](https://github.com/RLHF-V/RLHF-V) | [LLaVA-UHD](https://github.com/thunlp/LLaVA-UHD) | [RLAIF-V](https://github.com/RLHF-V/RLAIF-V)
|
| 426 |
+
|
| 427 |
+
|
| 428 |
+
## Citation <!-- omit in toc -->
|
| 429 |
+
|
| 430 |
+
If you find our model/code/paper helpful, please consider citing our papers 📝 and staring us ⭐️!
|
| 431 |
+
|
| 432 |
+
```bib
|
| 433 |
+
@misc{cui2026minicpmo45realtimefullduplex,
|
| 434 |
+
title={MiniCPM-o 4.5: Towards Real-Time Full-Duplex Omni-Modal Interaction},
|
| 435 |
+
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},
|
| 436 |
+
year={2026},
|
| 437 |
+
url={https://arxiv.org/abs/2604.27393},
|
| 438 |
+
}
|
| 439 |
+
|
| 440 |
+
@proceedings{yu2025minicpmv45cookingefficient,
|
| 441 |
+
title={MiniCPM-V 4.5: Cooking Efficient MLLMs via Architecture, Data, and Training Recipe},
|
| 442 |
+
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},
|
| 443 |
+
year={2025},
|
| 444 |
+
url={https://arxiv.org/abs/2509.18154},
|
| 445 |
+
}
|
| 446 |
+
|
| 447 |
+
@article{yao2024minicpm,
|
| 448 |
+
title={MiniCPM-V: A GPT-4V Level MLLM on Your Phone},
|
| 449 |
+
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},
|
| 450 |
+
journal={arXiv preprint arXiv:2408.01800},
|
| 451 |
+
year={2024}
|
| 452 |
+
}
|
| 453 |
+
```
|