Instructions to use openbmb/MiniCPM-V-4 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use openbmb/MiniCPM-V-4 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="openbmb/MiniCPM-V-4", 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-4", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use openbmb/MiniCPM-V-4 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "openbmb/MiniCPM-V-4" # 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-4", "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-4
- SGLang
How to use openbmb/MiniCPM-V-4 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-4" \ --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-4", "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-4" \ --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-4", "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-4 with Docker Model Runner:
docker model run hf.co/openbmb/MiniCPM-V-4
Add native Transformers support (config and processor files only)
This PR adds native Transformers support for MiniCPM-V 4.0 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, whose Hub files are openbmb/MiniCPM-Llama3-V-2_5#80, with 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" (the remote code 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. |
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. Only the processor reads this file, so the tokenizer keeps its own template. |
tokenizer_config.json |
pad_token: "</s>" (it had none, and <unk> is the image token) and padding_side: "left". |
I used Claude Code for parts of this change.
How it was checked
- Remote code (
trust_remote_code=True) on Transformers 4.57.3: the sameinput_idsas the current revision, and the same greedy output (bf16 on CUDA). vLLM's MiniCPM-V, which loads the remote processor on Transformers 5, loads this revision as before. - Native (the Transformers PR branch, no remote code): the prompt tokenizes to the same
input_idsas the remote processor, and fp32 greedy generation matches the remote code (details in the Transformers PR).