|
| 1 | +<!--Copyright 2026 OpenBMB and the HuggingFace Inc. team. All rights reserved. |
| 2 | +
|
| 3 | +Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
| 4 | +the License. You may obtain a copy of the License at |
| 5 | +
|
| 6 | +http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | +
|
| 8 | +Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
| 9 | +an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
| 10 | +specific language governing permissions and limitations under the License. |
| 11 | +
|
| 12 | +⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be |
| 13 | +rendered properly in your Markdown viewer. |
| 14 | +
|
| 15 | +--> |
| 16 | +*This model was released on 2025-09-16 and added to Hugging Face Transformers on 2026-04-28.* |
| 17 | + |
| 18 | +<div style="float: right;"> |
| 19 | + <div class="flex flex-wrap space-x-1"> |
| 20 | + <img alt="PyTorch" src="https://img.shields.io/badge/PyTorch-DE3412?style=flat&logo=pytorch&logoColor=white"> |
| 21 | + <img alt="SDPA" src="https://img.shields.io/badge/SDPA-DE3412?style=flat&logo=pytorch&logoColor=white"> |
| 22 | + <img alt="FlashAttention" src="https://img.shields.io/badge/%E2%9A%A1%EF%B8%8E%20FlashAttention-eae0c8?style=flat"> |
| 23 | + </div> |
| 24 | +</div> |
| 25 | + |
| 26 | +# MiniCPM-V |
| 27 | + |
| 28 | +[MiniCPM-V](https://huggingface.co/papers/2509.18154) is a series of efficient multimodal large language models developed by [OpenBMB](https://github.com/OpenBMB). The MiniCPM-V 4.6 architecture uses a [SigLIP](siglip) vision encoder with a window-attention merger and a [Qwen3.5](qwen3_5) language model backbone, supporting both 4x and 16x visual downsampling modes. |
| 29 | + |
| 30 | +This model was contributed by [OpenBMB](https://huggingface.co/openbmb). |
| 31 | +The original code can be found [here](https://github.com/OpenBMB/MiniCPM-V). |
| 32 | + |
| 33 | +## Usage example |
| 34 | + |
| 35 | +### Inference with Pipeline |
| 36 | + |
| 37 | +```python |
| 38 | +from transformers import pipeline |
| 39 | + |
| 40 | +messages = [ |
| 41 | + { |
| 42 | + "role": "user", |
| 43 | + "content": [ |
| 44 | + { |
| 45 | + "type": "image", |
| 46 | + "image": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/bee.jpg", |
| 47 | + }, |
| 48 | + {"type": "text", "text": "Describe this image."}, |
| 49 | + ], |
| 50 | + }, |
| 51 | +] |
| 52 | + |
| 53 | +pipe = pipeline("image-text-to-text", model="openbmb/MiniCPM-V-4_6") |
| 54 | +outputs = pipe(text=messages, max_new_tokens=50, return_full_text=False) |
| 55 | +outputs[0]["generated_text"] |
| 56 | +``` |
| 57 | + |
| 58 | +### Inference on a single image |
| 59 | + |
| 60 | +> [!NOTE] |
| 61 | +> The model has been trained with a specific prompt format for chatting. Use `processor.apply_chat_template(my_conversation_dict)` to correctly format your prompts. |
| 62 | +
|
| 63 | +```python |
| 64 | +from transformers import AutoProcessor, AutoModelForImageTextToText |
| 65 | + |
| 66 | +model_checkpoint = "openbmb/MiniCPM-V-4_6" |
| 67 | +processor = AutoProcessor.from_pretrained(model_checkpoint) |
| 68 | +model = AutoModelForImageTextToText.from_pretrained(model_checkpoint, device_map="auto") |
| 69 | + |
| 70 | +messages = [ |
| 71 | + { |
| 72 | + "role": "user", |
| 73 | + "content": [ |
| 74 | + {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/pipeline-cat-chonk.jpeg"}, |
| 75 | + {"type": "text", "text": "Describe this image."}, |
| 76 | + ], |
| 77 | + } |
| 78 | +] |
| 79 | + |
| 80 | +inputs = processor.apply_chat_template( |
| 81 | + messages, add_generation_prompt=True, tokenize=True, |
| 82 | + return_dict=True, return_tensors="pt", |
| 83 | +).to(model.device, dtype=model.dtype) |
| 84 | + |
| 85 | +output = model.generate(**inputs, max_new_tokens=100) |
| 86 | +decoded_output = processor.decode(output[0, inputs["input_ids"].shape[1]:], skip_special_tokens=True) |
| 87 | +print(decoded_output) |
| 88 | +``` |
| 89 | + |
| 90 | +### Downsampling mode |
| 91 | + |
| 92 | +MiniCPM-V 4.6 supports two visual downsampling modes: |
| 93 | + |
| 94 | +- **16x** (default): More aggressive downsampling, fewer visual tokens, faster inference. |
| 95 | +- **4x**: Less downsampling, more visual tokens, better for detail-rich tasks. |
| 96 | + |
| 97 | +You can change the downsampling mode at runtime by passing `downsample_mode` via `processor_kwargs` and to `model.generate`: |
| 98 | + |
| 99 | +```python |
| 100 | +inputs = processor.apply_chat_template( |
| 101 | + messages, add_generation_prompt=True, tokenize=True, |
| 102 | + return_dict=True, return_tensors="pt", |
| 103 | + processor_kwargs={"downsample_mode": "4x"}, |
| 104 | +).to(model.device, dtype=model.dtype) |
| 105 | + |
| 106 | +output = model.generate(**inputs, max_new_tokens=100, downsample_mode="4x") |
| 107 | +``` |
| 108 | + |
| 109 | +### Thinking mode |
| 110 | + |
| 111 | +The model supports a thinking mode controlled by `enable_thinking` in the chat template. When enabled, the model generates internal reasoning before providing the final answer: |
| 112 | + |
| 113 | +```python |
| 114 | +inputs = processor.apply_chat_template( |
| 115 | + messages, add_generation_prompt=True, tokenize=True, |
| 116 | + return_dict=True, return_tensors="pt", |
| 117 | + enable_thinking=True, |
| 118 | +).to(model.device, dtype=model.dtype) |
| 119 | + |
| 120 | +output = model.generate(**inputs, max_new_tokens=1024) |
| 121 | +``` |
| 122 | + |
| 123 | +To disable thinking (default for evaluation): |
| 124 | + |
| 125 | +```python |
| 126 | +inputs = processor.apply_chat_template( |
| 127 | + messages, add_generation_prompt=True, tokenize=True, |
| 128 | + return_dict=True, return_tensors="pt", |
| 129 | + enable_thinking=False, |
| 130 | +).to(model.device, dtype=model.dtype) |
| 131 | +``` |
| 132 | + |
| 133 | +### Image processing backend |
| 134 | + |
| 135 | +MiniCPM-V 4.6 provides two image processing backends: |
| 136 | + |
| 137 | +- **torchvision** (default): Uses `torchvision.transforms` for image resizing. |
| 138 | +- **pil**: Uses `PIL.Image.resize`, matching the original implementation. |
| 139 | + |
| 140 | +To use the PIL backend: |
| 141 | + |
| 142 | +```python |
| 143 | +from transformers import AutoProcessor, AutoImageProcessor |
| 144 | + |
| 145 | +processor = AutoProcessor.from_pretrained(model_checkpoint) |
| 146 | +processor.image_processor = AutoImageProcessor.from_pretrained(model_checkpoint, backend="pil") |
| 147 | +``` |
| 148 | + |
| 149 | +### Video inference |
| 150 | + |
| 151 | +MiniCPM-V 4.6 supports video understanding. |
| 152 | + |
| 153 | +```python |
| 154 | +messages = [ |
| 155 | + { |
| 156 | + "role": "user", |
| 157 | + "content": [ |
| 158 | + {"type": "video", "video": "path/to/video.mp4"}, |
| 159 | + {"type": "text", "text": "Describe what happens in this video."}, |
| 160 | + ], |
| 161 | + } |
| 162 | +] |
| 163 | + |
| 164 | +inputs = processor.apply_chat_template( |
| 165 | + messages, add_generation_prompt=True, tokenize=True, |
| 166 | + return_dict=True, return_tensors="pt", |
| 167 | +).to(model.device, dtype=model.dtype) |
| 168 | + |
| 169 | +output = model.generate(**inputs, max_new_tokens=200) |
| 170 | +decoded_output = processor.decode(output[0, inputs["input_ids"].shape[1]:], skip_special_tokens=True) |
| 171 | +print(decoded_output) |
| 172 | +``` |
| 173 | + |
| 174 | +If you already have the rendered prompt string, you can call `processor(text=..., videos=[...])` directly instead. |
| 175 | + |
| 176 | +## MiniCPMV4_6Config |
| 177 | + |
| 178 | +[[autodoc]] MiniCPMV4_6Config |
| 179 | + |
| 180 | +## MiniCPMV4_6VisionConfig |
| 181 | + |
| 182 | +[[autodoc]] MiniCPMV4_6VisionConfig |
| 183 | + |
| 184 | +## MiniCPMV4_6Model |
| 185 | + |
| 186 | +[[autodoc]] MiniCPMV4_6Model |
| 187 | + - forward |
| 188 | + - get_image_features |
| 189 | + |
| 190 | +## MiniCPMV4_6ForConditionalGeneration |
| 191 | + |
| 192 | +[[autodoc]] MiniCPMV4_6ForConditionalGeneration |
| 193 | + - forward |
| 194 | + - get_image_features |
| 195 | + |
| 196 | +## MiniCPMV4_6Processor |
| 197 | + |
| 198 | +[[autodoc]] MiniCPMV4_6Processor |
| 199 | + - __call__ |
| 200 | + |
| 201 | +## MiniCPMV4_6ImageProcessor |
| 202 | + |
| 203 | +[[autodoc]] MiniCPMV4_6ImageProcessor |
| 204 | + - preprocess |
| 205 | + |
| 206 | +## MiniCPMV4_6ImageProcessorPil |
| 207 | + |
| 208 | +[[autodoc]] MiniCPMV4_6ImageProcessorPil |
| 209 | + - preprocess |
| 210 | + |
| 211 | +## MiniCPMV4_6VideoProcessor |
| 212 | + |
| 213 | +[[autodoc]] MiniCPMV4_6VideoProcessor |
| 214 | + - preprocess |
0 commit comments