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)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("openbmb/MiniCPM-V-4", trust_remote_code=True, dtype="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
HF Space?
Hello!
I would like to test the model online to evaluate its quality and if it's suitable for my use case of long video understanding (10+ minute length). Unfortunately, I don't have iOS to use the app.
Will there be an Android app or HF Space coming soon? Thank you!
HF Space should be faster, and you can also use our demo to test it, maybe it can meet your needs.
demo is here, ^_^
@tc-mb
Thank you very much for the demo access! :)
I am currently trying it with this video https://www.youtube.com/watch?v=irAFwHXKCGg downloaded in 720p30, 77.7mb file size, with the prompt "What is the video about?"
Unfortunately, it's returning "Error, please retry".
Got it, let me check.
@JermemyHaschal Ok, we found an error in the boundary conditions and have fixed it. Thank you again for your reminder and feedback. ^_^
@tc-mb It works, and so fast too! While it got the featured character in the video wrong, everything else seems to be correct :)
I know that such a small model isn't perfect, but I'm still really impressed by that size-to-accuracy ratio!
We're happy to hear your feedback.
Smaller models are indeed more difficult to achieve comprehensive accuracy, and we'll continue to optimize them.
@tc-mb One last thing: Is there a way for me to locally use the Space with a UI? I tried git clone but it didn't work with this one. Should I use the official "Usage" script from the repo instead?
@JermemyHaschal We've open-sourced the cookbook. We only linked it to the GitHub repository, not to Huggingface. This was an oversight, and I'll link it later.
Our cookbook includes all of our demos, and we hope to enable users to replicate all of our demos locally.
For the Gradio demo you mentioned, you can refer to this document to replicate it locally. If you encounter any questions, please feel free to ask.
https://github.com/OpenSQZ/MiniCPM-V-CookBook/tree/main/demo/web_demo/gradio