Instructions to use openbmb/MiniCPM-V-2_6 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use openbmb/MiniCPM-V-2_6 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="openbmb/MiniCPM-V-2_6", trust_remote_code=True) messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("openbmb/MiniCPM-V-2_6", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use openbmb/MiniCPM-V-2_6 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "openbmb/MiniCPM-V-2_6" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "openbmb/MiniCPM-V-2_6", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/openbmb/MiniCPM-V-2_6
- SGLang
How to use openbmb/MiniCPM-V-2_6 with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "openbmb/MiniCPM-V-2_6" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "openbmb/MiniCPM-V-2_6", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "openbmb/MiniCPM-V-2_6" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "openbmb/MiniCPM-V-2_6", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use openbmb/MiniCPM-V-2_6 with Docker Model Runner:
docker model run hf.co/openbmb/MiniCPM-V-2_6
Add native Transformers support (config and processor files only)
This PR adds native Transformers support for MiniCPM-V 2.6 while keeping the existing remote code working. It goes with https://github.com/huggingface/transformers/pull/51299, which adds the model to Transformers as minicpmv2_6, on top of MiniCPM-Llama3-V 2.5 (https://github.com/huggingface/transformers/pull/50929). MiniCPM-V 4.0's files (openbmb/MiniCPM-V-4#6) and MiniCPM-Llama3-V 2.5's (openbmb/MiniCPM-Llama3-V-2_5#80) have the same layout.
The weights are not changed. Transformers maps the original weight names at load time.
It can be merged now: the remote code keeps loading as before (trust_remote_code=True, auto_map and the tokenizer's chat template unchanged), and Transformers versions that include the model load it natively.
| File | Change |
|---|---|
config.json |
All original keys kept, incl. auto_map. Added: model_type: "minicpmv2_6", text_config, resampler_n_latents, resampler_n_heads, image_token_id. vision_config gets model_type: "minicpmv2_6_vision" and the activation and norm epsilon the remote code assumes (it only reads its sizes), and slice_config no longer has its own model_type (on Transformers 4.57 the remote config was otherwise built from that sub-dict). |
configuration_minicpm.py |
1 line: MiniCPMVConfig accepts and ignores text_config, so get_text_config() keeps returning the config itself. |
processing_minicpmv.py |
1 line: MiniCPMVProcessor.__init__ takes **kwargs, as MiniCPM-V-4's does; Transformers 4.40 to 4.52 pass it the keys of processor_config.json and the chat template. |
preprocessor_config.json |
Original keys and auto_map kept; the native image processor settings are added next to them, and image_processor_type names the native class (the remote code still loads its own through auto_map). |
processor_config.json |
New: native processor settings, plus an auto_map so the remote processor is still found. |
chat_template.json |
New: chat template for the native processor, with the default system prompt of the remote chat(). Only the processor reads this file, so the tokenizer keeps its own template. |
tokenizer_config.json |
padding_side: "left". |
I used Claude Code for parts of this change.
How it was checked
- Remote code on Transformers 4.40.0 (the model card's version), 4.44.2, 4.45.1, 4.48.3, 4.49.0, 4.51.3, 4.52.4, 4.53.0, 4.57.3 and 5.24.1: the processor loads as with the current revision, and
chat()builds the same inputs. - Remote code (
trust_remote_code=True) on Transformers 4.57.3: the sameinput_idsas the current revision in 5 of 5 prompts. - Native (the Transformers PR branch, no remote code): the prompts tokenize to the same
input_idsas the remote processor, with bitwise-equal pixel values, and the vision tower and resampler give the same image features as the remote code in fp32 (details in the Transformers PR).