Instructions to use openbmb/MiniCPM-o-2_6 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use openbmb/MiniCPM-o-2_6 with Transformers:
# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("openbmb/MiniCPM-o-2_6", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Add native Transformers support (config and processor files only)
This PR adds native Transformers support for MiniCPM-o 2.6 (image and audio in, text out) while keeping the existing remote code working. It goes with https://github.com/huggingface/transformers/pull/51319, which adds the model to Transformers as minicpmo2_6, on top of MiniCPM-V 2.6 and 4.0 (https://github.com/huggingface/transformers/pull/51299).
The weights are not changed. Transformers maps the original weight names at load time. The speech decoder (tts.*) isn't loaded by the native model.
It can be merged now: the remote code keeps loading as before (trust_remote_code=True, auto_map unchanged), and Transformers versions that include the model load it natively. The native chat template is in chat_template.json, which only the processor reads, not in chat_template.jinja: the remote tokenizer would pick up a .jinja file too, and vLLM's MiniCPM-O, which ends up with the tokenizer's template because the remote processor has none, would then fail on image and audio chat requests (it looks for (<image>./</image>) and (<audio>./</audio>) in the prompt).
| File | Change |
|---|---|
config.json |
All original keys kept, incl. auto_map. model_type changes from minicpmo to minicpmo2_6. Added: text_config, resampler_n_latents, resampler_n_heads, image_token_id, audio_token_id. vision_config gets model_type: "minicpmv2_6_vision" and the activation and norm epsilon the remote code assumes, audio_config gets model_type: "minicpmo2_6_audio" and chunk_size (the remote code only reads their 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). With remote code, Transformers now warns that a minicpmo2_6 config instantiates a minicpmo model; the remote code doesn't read model_type. |
configuration_minicpm.py |
1 line: MiniCPMOConfig accepts and ignores text_config, so get_text_config() keeps returning the config itself. |
processing_minicpmo.py |
1 line: MiniCPMOProcessor accepts and ignores chat_template, which Transformers 4.49 to 4.52 pass to it from chat_template.json. |
preprocessor_config.json |
Original keys and auto_map kept; the native image processor settings and feature_extractor_type 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: only processor_class and an auto_map, so the remote processor is still found. The remote MiniCPMOProcessor takes no other arguments, and on Transformers 4.44.2 extra keys here would be passed to it. |
chat_template.json |
New: chat template for the native processor (the tokenizer's template with images and audio in the content, and the TTS prompt of the remote chat() when the conversation has audio). The tokenizer keeps its own template. |
generation_config.json |
New: the end-of-turn and end-of-text tokens the remote chat() stops on (151645, 151643), with end-of-text as BOS and pad. |
tokenizer_config.json |
padding_side: "left". |
I used Claude Code for parts of this change.
How it was checked
- Remote code (
trust_remote_code=True), on 12 image and audio conversations: the remote processor gives the sameinput_idsand features from this revision as from the current one, on Transformers 4.44.2 (the model card's version) and 4.57.3, and it loads on 4.45.1, 4.48.3, 4.49.0, 4.51.3, 4.52.4 and 4.53.0 as well. On 4.44.2 the remote model still builds and runschat()(tiny random weights). - vLLM's MiniCPM-O (bf16 on CUDA, prompts as strings): the same greedy output with this PR's config, tokenizer and generation files as with the current ones, 12 of 12.
- vLLM's chat path (vLLM main and a87e3a6554 with Transformers 5.23.0 and 5.24.1, an image and an audio chat request, up to the model's prompt processing): the same prompt ids from this revision as from the current one. With the template as
chat_template.jinja, both requests fail there. - Native (the Transformers PR branch, no remote code): the same
input_idsas the remote processor apart from the audio placeholder token, and fp32 greedy generation identical to the remote code in 12 of 12 conversations (details in the Transformers PR).