Use AIUnderstand AIBuild with AI
Build with AI·Model deep dive·· 5 min read

Run MiniCPM-V 4.7 35B-A3B for Image, Video and Tool Calls

MiniCPM-V 4.7 35B-A3B is OpenBMB's first MoE vision-language model, Apache-2.0, with a 16x/4x visual token switch. Load it with Transformers and serve it.

The code in this post comes from the model's docs and hasn't been run in our CI yet. If something breaks, let us know.

MiniCPM-V 4.7 35B-A3B is a multimodal model from OpenBMB that takes single images, multiple images or video plus text and returns text. It is released under Apache-2.0 and is the first mixture-of-experts (MoE) model in the MiniCPM-V series. The card’s headline claim is on-device use: with a technique called Lookahead Expert Scheduling (LES), fine-grained layer-wise quantization and DSpark speculative sampling, it reports decoding at 13+ tokens/s with 3 GB of memory on an iPhone 17 Pro Max. This post covers the plain Transformers route, which is what the card shows for servers and workstations.

Key specs

Variant 35B-A3B (the card does not give an exact parameter count)
Task image-text-to-text, library transformers
License Apache-2.0
Inputs Single image, multiple images, video
Visual token compression Mixed 4x/16x, chosen with downsample_mode
Language backbone Credited to Qwen3.5 and Qwen3.6; vision module credited to SigLIP2
Inference frameworks SGLang, vLLM, llama.cpp, Ollama
Other builds FP8, int4, AWQ (W4A16), GPTQ (W4A16), GGUF, plus a DSpark draft model; the card also links a BNB quantization guide

On quality, the card says that in Instruct mode the model “achieves a higher overall score in less inference time than Qwen3.6 35B-A3B”. That claim rests on charts in the card, so check the figures there before relying on it for your own task. The card doesn’t state a minimum GPU for the full-precision weights.

Install

The card requires Transformers 5.18.0 or newer:

Terminal window
pip install "transformers[torch]>=5.18.0" torchvision torchcodec

torchcodec handles video decoding and can fail on some CUDA setups. The card’s example error is RuntimeError: Could not load libtorchcodec on CUDA 12.x with torch>=2.11. Its two workarounds are to swap in PyAV, or to pin a matching CUDA build of torch:

Terminal window
pip install "transformers[torch]>=5.18.0" torchvision av

Run it

This is the card’s loading code, with the image example folded in.

image_qa.py
import torch
from transformers import AutoModelForImageTextToText, AutoProcessor
model_id = "openbmb/MiniCPM-V-4.7-35B-A3B"
processor = AutoProcessor.from_pretrained(model_id)
model = AutoModelForImageTextToText.from_pretrained(
model_id, torch_dtype="auto", device_map="auto"
)
messages = [
{
"role": "user",
"content": [
{"type": "image", "url": "https://huggingface.co/datasets/openbmb/DemoCase/resolve/main/refract.png"},
{"type": "text", "text": "What causes this phenomenon?"},
],
}
]
downsample_mode = "16x" # use "4x" for finer detail
inputs = processor.apply_chat_template(
messages, tokenize=True, add_generation_prompt=True,
return_dict=True, return_tensors="pt",
downsample_mode=downsample_mode,
max_slice_nums=36,
enable_thinking=False,
).to(model.device)
generated_ids = model.generate(
**inputs,
downsample_mode=downsample_mode,
max_new_tokens=512,
do_sample=True,
temperature=0.7,
top_p=0.95,
top_k=100,
min_p=0.0,
presence_penalty=0,
repetition_penalty=1.03,
)
generated_ids_trimmed = [
out_ids[len(in_ids):] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
]
output_text = processor.batch_decode(
generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
)
print(output_text[0])

The card says Flash Attention 2 is recommended for faster inference and lower GPU memory use, especially with multiple images and video. To enable it, load with torch_dtype=torch.bfloat16 and attn_implementation="flash_attention_2".

The sampling values above are the card’s recommended settings for instruct mode.

Trade detail for cost with downsample_mode

"16x" (the default) merges visual tokens for efficiency. "4x" keeps four times as many tokens for finer detail, at the cost of more visual tokens and compute. The card is explicit that downsample_mode must be passed to both apply_chat_template and generate.

Video

The video example uses the same pipeline with a video content item and different processing arguments.

video_qa.py
import torch
from transformers import AutoModelForImageTextToText, AutoProcessor
model_id = "openbmb/MiniCPM-V-4.7-35B-A3B"
processor = AutoProcessor.from_pretrained(model_id)
model = AutoModelForImageTextToText.from_pretrained(
model_id, torch_dtype="auto", device_map="auto"
)
messages = [
{
"role": "user",
"content": [
{"type": "video", "url": "https://huggingface.co/datasets/openbmb/DemoCase/resolve/main/football.mp4"},
{"type": "text", "text": "Describe this video in detail. Follow the timeline and focus on on-screen text, interface changes, main actions, and scene changes."},
],
}
]
downsample_mode = "16x"
inputs = processor.apply_chat_template(
messages, tokenize=True, add_generation_prompt=True,
return_dict=True, return_tensors="pt",
downsample_mode=downsample_mode,
max_num_frames=128,
stack_frames=1,
max_slice_nums=1,
use_image_id=False,
enable_thinking=False,
).to(model.device)
generated_ids = model.generate(
**inputs,
downsample_mode=downsample_mode,
max_new_tokens=2048,
do_sample=True,
temperature=0.7,
top_p=0.95,
top_k=100,
min_p=0.0,
presence_penalty=0,
repetition_penalty=1.03,
)
generated_ids_trimmed = [
out_ids[len(in_ids):] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
]
output_text = processor.batch_decode(
generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
)
print(output_text[0])

Processing parameters from the card’s table:

Parameter Default Notes
max_slice_nums 9 Recommended 36 for images, 1 for video
max_num_frames 128 Video only: maximum main frames sampled
stack_frames 1 Video only: 1 is main frame only; the card recommends 3 or 5 if you want sub-frames stacked into grid images
use_image_id True Recommended True for images, False for video

Serve it and call tools

Transformers ships a lightweight OpenAI-compatible server, which the card describes as suited to quick testing and moderate-load deployment.

Terminal window
pip install "transformers[serving]>=5.18.0"
transformers serve openbmb/MiniCPM-V-4.7-35B-A3B --port 8000 --host 0.0.0.0

An image request, as in the card:

Terminal window
curl -s http://localhost:8000/v1/chat/completions \
-H 'Content-Type: application/json' \
-d '{
"model": "openbmb/MiniCPM-V-4.7-35B-A3B",
"messages": [{
"role": "user",
"content": [
{"type": "image_url", "image_url": {"url": "https://huggingface.co/datasets/openbmb/DemoCase/resolve/main/refract.png"}},
{"type": "text", "text": "What causes this phenomenon?"}
]
}]
}'

Tool calling uses the standard tools field with a function schema:

Terminal window
curl -s http://localhost:8000/v1/chat/completions -H 'Content-Type: application/json' -d '{
"model": "openbmb/MiniCPM-V-4.7-35B-A3B",
"messages": [{"role": "user", "content": [
{"type": "text", "text": "the weather of Beijing"}
]}],
"tools": [{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the current weather for a given location",
"parameters": {
"type": "object",
"properties": {
"location": {"type": "string", "description": "City name"}
},
"required": ["location"]
}
}
}]
}'

The card shows only the request. It doesn’t show the response format or how to feed a tool result back, so check the Transformers serving docs before building a loop around it.

Gotchas

  • Transformers version. The card requires >=5.18.0, for both the install and the server.
  • Pass downsample_mode twice. It goes to both apply_chat_template and generate. The card says the first call needs it for the correct placeholder count and generate needs it for the vision encoder.
  • Video decoding. torchcodec and CUDA version mismatches are a known problem; use PyAV if you hit it.
  • Memory. MoE models activate only some experts per token, but the card notes that on-device storage requirements are not limited to the active parameters. Plan for the full 35B-parameter model, not just the roughly 3B active part.
  • The phone result depends on extras. The 13+ tokens/s figure combines LES, layer-wise quantization and DSpark. It is not what you get from the Transformers snippets above.
  • Quantized builds are separate repos. The card lists FP8, int4, AWQ, GPTQ and GGUF versions, plus a DSpark draft model, but the examples above are for the main repo.

When to pick it

Pick it if you want one open, Apache-2.0 model for single-image, multi-image and video understanding, with a built-in way to trade visual detail for cost, and a route to phones and edge chips. The card also lists task guides for OCR, PDF parsing and visual grounding, which are worth reading before you commit.

Skip it if you need a published GPU requirement before you start. The card doesn’t give one, so you will have to measure. Also don’t treat the Qwen3.6 35B-A3B comparison as proof for your workload; it comes from the card’s own charts. This post’s code is taken from the card and has not been run.

Related