Run this model inference on single tenant GPU with unmatched speed and reliability at scale.
Get help setting up a custom Dedicated Endpoints.
Talk with our engineer to get a quote for reserved GPU instances with discounts.
README
License: apache-2.0MiniCPM-o 2.6
MiniCPM-o 2.6 is the latest and most capable model in the MiniCPM-o series. The model is built in an end-to-end fashion based on SigLip-400M, Whisper-medium-300M, ChatTTS-200M, and Qwen2.5-7B with a total of 8B parameters. It exhibits a significant performance improvement over MiniCPM-V 2.6, and introduces new features for real-time speech conversation and multimodal live streaming. Notable features of MiniCPM-o 2.6 include:
-
🔥 Leading Visual Capability. MiniCPM-o 2.6 achieves an average score of 70.2 on OpenCompass, a comprehensive evaluation over 8 popular benchmarks. With only 8B parameters, it surpasses widely used proprietary models like GPT-4o-202405, Gemini 1.5 Pro, and Claude 3.5 Sonnet for single image understanding. It also outperforms GPT-4V and Claude 3.5 Sonnet in mutli-image and video understanding, and shows promising in-context learning capability.
-
🎙 State-of-the-art Speech Capability. MiniCPM-o 2.6 supports bilingual real-time speech conversation with configurable voices in English and Chinese. It outperforms GPT-4o-realtime on audio understanding tasks such as ASR and STT translation, and shows state-of-the-art performance on speech conversation in both semantic and acoustic evaluations in the open-source community. It also allows for fun features such as emotion/speed/style control, end-to-end voice cloning, role play, etc.
-
🎬 Strong Multimodal Live Streaming Capability. As a new feature, MiniCPM-o 2.6 can accept continous video and audio streams independent of user queries, and support real-time speech interaction. It outperforms GPT-4o-202408 and Claude 3.5 Sonnet and shows state-of-art performance in open-source community on StreamingBench, a comprehensive benchmark for real-time video understanding, omni-source (video & audio) understanding, and multimodal contextual understanding.
-
💪 Strong OCR Capability and Others. Advancing popular visual capabilites from MiniCPM-V series, MiniCPM-o 2.6 can process images with any aspect ratio and up to 1.8 million pixels (e.g., 1344x1344). It achieves state-of-the-art performance on OCRBench for models under 25B, surpassing proprietary models such as GPT-4o-202405. Based on the the latest RLAIF-V and VisCPM techniques, it features trustworthy behaviors, outperforming GPT-4o and Claude 3.5 Sonnet on MMHal-Bench, and supports multilingual capabilities on more than 30 languages.
-
🚀 Superior Efficiency. In addition to its friendly size, MiniCPM-o 2.6 also shows state-of-the-art token density (i.e., number of pixels encoded into each visual token). It produces only 640 tokens when processing a 1.8M pixel image, which is 75% fewer than most models. This directly improves the inference speed, first-token latency, memory usage, and power consumption. As a result, MiniCPM-o 2.6 can efficiently support multimodal live streaming on end-side devices such as iPad.
-
💫 Easy Usage. MiniCPM-o 2.6 can be easily used in various ways: (1) llama.cpp support for efficient CPU inference on local devices, (2) int4 and GGUF format quantized models in 16 sizes, (3) vLLM support for high-throughput and memory-efficient inference, (4) fine-tuning on new domains and tasks with LLaMA-Factory, (5) quick local WebUI demo setup with Gradio, and (6) online web demo on server.
Model Architecture.
- End-to-end Omni-modal Architecture. Different modality encoder/decoders are connected and trained in an end-to-end fashion to fully exploit rich multimodal knowledge.
- Omni-modal Live Streaming Mechanism. (1) We change the offline modality encoder/decoders into online ones for streaminig inputs/outputs. (2) We devise a time-division multiplexing (TDM) mechanism for omni-modality streaminig processing in the LLM backbone. It divides parallel omni-modality streams into sequential info within small periodic time slices.
- Configurable Speech Modeling Design. We devise a multimodal system prompt, including traditional text system prompt, and a new audio system prompt to determine the assistant voice. This enables flexible voice configurations in inference time, and also facilitates end-to-end voice cloning and description-based voice creation.
Evaluation
Visual understanding results
Image Understanding:
+ Token Density: number of pixels encoded into each visual token at maximum resolution, i.e., # pixels at maximum resolution / # visual tokens.
Note: For proprietary models, we calculate token density based on the image encoding charging strategy defined in the official API documentation, which provides an upper-bound estimation.
Multi-image and Video Understanding:
Audio understanding and speech conversation results.
Audio Understanding:
Speech Generation:
End-to-end Voice Cloning
Multimodal live streaming results.
Multimodal Live Streaming: results on StreamingBench
Examples
We deploy MiniCPM-o 2.6 on end devices. The demo video is the raw-speed recording on an iPad Pro and a Web demo.
Online Demo
Click here to try the online demo of MiniCPM-o 2.6.
Usage
Inference using Huggingface transformers on NVIDIA GPUs. Please ensure that transformers==4.44.2 is installed, as other versions may have compatibility issues. We are investigating this issue. Requirements tested on python 3.10:
markdown
Pillow==10.1.0torch==2.3.1torchaudio==2.3.1torchvision==0.18.1transformers==4.44.2librosa==0.9.0soundfile==0.12.1vector-quantize-pytorch==1.18.5vocos==0.1.0decordmoviepy
Model initialization
python
import torchfrom PIL import Imagefrom transformers import AutoModel, AutoTokenizer# load omni model default, the default init_vision/init_audio/init_tts is True# if load vision-only model, please set init_audio=False and init_tts=False# if load audio-only model, please set init_vision=Falsemodel = AutoModel.from_pretrained('openbmb/MiniCPM-o-2_6',trust_remote_code=True,attn_implementation='sdpa', # sdpa or flash_attention_2torch_dtype=torch.bfloat16,init_vision=True,init_audio=True,init_tts=True)model = model.eval().cuda()tokenizer = AutoTokenizer.from_pretrained('openbmb/MiniCPM-o-2_6', trust_remote_code=True)# In addition to vision-only mode, tts processor and vocos also needs to be initializedmodel.init_tts()
If you are using an older version of PyTorch, you might encounter this issue "weight_norm_fwd_first_dim_kernel" not implemented for 'BFloat16', Please convert the TTS to float32 type.
python
model.tts.float()
Omni mode
We provide two inference modes: chat and streaming
Chat inference
python
import mathimport numpy as npfrom PIL import Imagefrom moviepy.editor import VideoFileClipimport tempfileimport librosaimport soundfile as sfdef get_video_chunk_content(video_path, flatten=True):video = VideoFileClip(video_path)print('video_duration:', video.duration)with tempfile.NamedTemporaryFile(suffix=".wav", delete=True) as temp_audio_file:temp_audio_file_path = temp_audio_file.namevideo.audio.write_audiofile(temp_audio_file_path, codec="pcm_s16le", fps=16000)audio_np, sr = librosa.load(temp_audio_file_path, sr=16000, mono=True)num_units = math.ceil(video.duration)# 1 frame + 1s audio chunkcontents= []for i in range(num_units):frame = video.get_frame(i+1)image = Image.fromarray((frame).astype(np.uint8))audio = audio_np[sr*i:sr*(i+1)]if flatten:contents.extend(["<unit>", image, audio])else:contents.append(["<unit>", image, audio])return contentsvideo_path="assets/Skiing.mp4"# if use voice clone prompt, please set ref_audioref_audio_path = 'assets/demo.wav'ref_audio, _ = librosa.load(ref_audio_path, sr=16000, mono=True)sys_msg = model.get_sys_prompt(ref_audio=ref_audio, mode='omni', language='en')# or use default prompt# sys_msg = model.get_sys_prompt(mode='omni', language='en')contents = get_video_chunk_content(video_path)msg = {"role":"user", "content": contents}msgs = [sys_msg, msg]# please set generate_audio=True and output_audio_path to save the tts resultgenerate_audio = Trueoutput_audio_path = 'output.wav'res = model.chat(msgs=msgs,tokenizer=tokenizer,sampling=True,temperature=0.5,max_new_tokens=4096,omni_input=True, # please set omni_input=True when omni inferenceuse_tts_template=True,generate_audio=generate_audio,output_audio_path=output_audio_path,max_slice_nums=1,use_image_id=False,return_dict=True)print(res)## You will get the answer: The person in the picture is skiing down a snowy slope.# import IPython# IPython.display.Audio('output.wav')
Streaming inference
python
# a new conversation need reset session first, it will reset the kv-cachemodel.reset_session()contents = get_video_chunk_content(video_path, flatten=False)session_id = '123'generate_audio = True# 1. prefill system promptres = model.streaming_prefill(session_id=session_id,msgs=[sys_msg],tokenizer=tokenizer)# 2. prefill video/audio chunksfor content in contents:msgs = [{"role":"user", "content": content}]res = model.streaming_prefill(session_id=session_id,msgs=msgs,tokenizer=tokenizer)# 3. generateres = model.streaming_generate(session_id=session_id,tokenizer=tokenizer,temperature=0.5,generate_audio=generate_audio)audios = []text = ""if generate_audio:for r in res:audio_wav = r.audio_wavsampling_rate = r.sampling_ratetxt = r.textaudios.append(audio_wav)text += txtres = np.concatenate(audios)sf.write("output.wav", res, samplerate=sampling_rate)print("text:", text)print("audio saved to output.wav")else:for r in res:text += r['text']print("text:", text)
Speech and Audio Mode
Model initialization
python
import torchimport librosafrom transformers import AutoModel, AutoTokenizermodel = AutoModel.from_pretrained('openbmb/MiniCPM-o-2_6', trust_remote_code=True,attn_implementation='sdpa', torch_dtype=torch.bfloat16) # sdpa or flash_attention_2, no eagermodel = model.eval().cuda()tokenizer = AutoTokenizer.from_pretrained('openbmb/MiniCPM-o-2_6', trust_remote_code=True)model.init_tts()model.tts.float()
Mimick
Mimick task reflects a model's end-to-end speech modeling capability. The model takes audio input, and outputs an ASR transcription and subsequently reconstructs the original audio with high similarity. The higher the similarity between the reconstructed audio and the original audio, the stronger the model's foundational capability in end-to-end speech modeling.
python
mimick_prompt = "Please repeat each user's speech, including voice style and speech content."audio_input, _ = librosa.load('./assets/input_examples/Trump_WEF_2018_10s.mp3', sr=16000, mono=True) # load the audio to be mimicked# can also try `./assets/input_examples/cxk_original.wav`,# `./assets/input_examples/fast-pace.wav`,# `./assets/input_examples/chi-english-1.wav`# `./assets/input_examples/exciting-emotion.wav`# for different aspects of speech-centric features.msgs = [{'role': 'user', 'content': [mimick_prompt, audio_input]}]res = model.chat(msgs=msgs,tokenizer=tokenizer,sampling=True,max_new_tokens=128,use_tts_template=True,temperature=0.3,generate_audio=True,output_audio_path='output_mimick.wav', # save the tts result to output_audio_path)
General Speech Conversation with Configurable Voices
A general usage scenario of MiniCPM-o-2.6 is role-playing a specific character based on the audio prompt. It will mimic the voice of the character to some extent and act like the character in text, including language style. In this mode, MiniCPM-o-2.6 sounds more natural and human-like. Self-defined audio prompts can be used to customize the voice of the character in an end-to-end manner.
python
ref_audio, _ = librosa.load('./assets/input_examples/icl_20.wav', sr=16000, mono=True) # load the reference audiosys_prompt = model.get_sys_prompt(ref_audio=ref_audio, mode='audio_roleplay', language='en')# round oneuser_question = {'role': 'user', 'content': [librosa.load('xxx.wav', sr=16000, mono=True)[0]]}msgs = [sys_prompt, user_question]res = model.chat(msgs=msgs,tokenizer=tokenizer,sampling=True,max_new_tokens=128,use_tts_template=True,generate_audio=True,temperature=0.3,output_audio_path='result_roleplay_round_1.wav',)# round twohistory = msgs.append({'role': 'assistant', 'content': res})user_question = {'role': 'user', 'content': [librosa.load('xxx.wav', sr=16000, mono=True)[0]]}msgs = history.append(user_question)res = model.chat(msgs=msgs,tokenizer=tokenizer,sampling=True,max_new_tokens=128,use_tts_template=True,generate_audio=True,temperature=0.3,output_audio_path='result_roleplay_round_2.wav',)print(res)
Speech Conversation as an AI Assistant
An enhanced feature of MiniCPM-o-2.6 is to act as an AI assistant, but only with limited choice of voices. In this mode, MiniCPM-o-2.6 is less human-like and more like a voice assistant. In this mode, the model is more instruction-following. For demo, you are suggested to use assistant_female_voice, assistant_male_voice, and assistant_default_female_voice. Other voices may work but not as stable as the default voices.
Please note that, assistant_female_voice and assistant_male_voice are more stable but sounds like robots, while assistant_default_female_voice is more human-alike but not stable, its voice often changes in multiple turns. We suggest you to try stable voices assistant_female_voice and assistant_male_voice.
python
ref_audio, _ = librosa.load('./assets/input_examples/assistant_female_voice.wav', sr=16000, mono=True) # or use `./assets/input_examples/assistant_male_voice.wav`sys_prompt = model.get_sys_prompt(ref_audio=ref_audio, mode='audio_assistant', language='en')user_question = {'role': 'user', 'content': [librosa.load('xxx.wav', sr=16000, mono=True)[0]]} # load the user's audio question# round onemsgs = [sys_prompt, user_question]res = model.chat(msgs=msgs,tokenizer=tokenizer,sampling=True,max_new_tokens=128,use_tts_template=True,generate_audio=True,temperature=0.3,output_audio_path='result_assistant_round_1.wav',)# round twohistory = msgs.append({'role': 'assistant', 'content': res})user_question = {'role': 'user', 'content': [librosa.load('xxx.wav', sr=16000, mono=True)[0]]}msgs = history.append(user_question)res = model.chat(msgs=msgs,tokenizer=tokenizer,sampling=True,max_new_tokens=128,use_tts_template=True,generate_audio=True,temperature=0.3,output_audio_path='result_assistant_round_2.wav',)print(res)
Instruction-to-Speech
MiniCPM-o-2.6 can also do Instruction-to-Speech, aka Voice Creation. You can describe a voice in detail, and the model will generate a voice that matches the description. For more Instruction-to-Speech sample instructions, you can refer to https://voxinstruct.github.io/VoxInstruct/.
python
instruction = 'Speak like a male charming superstar, radiating confidence and style in every word.'msgs = [{'role': 'user', 'content': [instruction]}]res = model.chat(msgs=msgs,tokenizer=tokenizer,sampling=True,max_new_tokens=128,use_tts_template=True,generate_audio=True,temperature=0.3,output_audio_path='result_voice_creation.wav',)
Voice Cloning
MiniCPM-o-2.6 can also do zero-shot text-to-speech, aka Voice Cloning. With this mode, model will act like a TTS model.
python
ref_audio, _ = librosa.load('./assets/input_examples/icl_20.wav', sr=16000, mono=True) # load the reference audiosys_prompt = model.get_sys_prompt(ref_audio=ref_audio, mode='voice_cloning', language='en')text_prompt = f"Please read the text below."user_question = {'role': 'user', 'content': [text_prompt, "content that you want to read"]}msgs = [sys_prompt, user_question]res = model.chat(msgs=msgs,tokenizer=tokenizer,sampling=True,max_new_tokens=128,use_tts_template=True,generate_audio=True,temperature=0.3,output_audio_path='result_voice_cloning.wav',)
Addressing Various Audio Understanding Tasks
MiniCPM-o-2.6 can also be used to address various audio understanding tasks, such as ASR, speaker analysis, general audio captioning, and sound scene tagging.
For audio-to-text tasks, you can use the following prompts:
- ASR with ZH(same as AST en2zh):
请仔细听这段音频片段,并将其内容逐字记录。 - ASR with EN(same as AST zh2en):
Please listen to the audio snippet carefully and transcribe the content. - Speaker Analysis:
Based on the speaker's content, speculate on their gender, condition, age range, and health status. - General Audio Caption:
Summarize the main content of the audio. - General Sound Scene Tagging:
Utilize one keyword to convey the audio's content or the associated scene.
python
task_prompt = "Please listen to the audio snippet carefully and transcribe the content." + "\n" # can change to other prompts.audio_input, _ = librosa.load('./assets/input_examples/audio_understanding.mp3', sr=16000, mono=True) # load the audio to be captionedmsgs = [{'role': 'user', 'content': [task_prompt, audio_input]}]res = model.chat(msgs=msgs,tokenizer=tokenizer,sampling=True,max_new_tokens=128,use_tts_template=True,generate_audio=True,temperature=0.3,output_audio_path='result_audio_understanding.wav',)print(res)
Vision-Only mode
MiniCPM-o-2_6 has the same inference methods as MiniCPM-V-2_6
Chat with single image
python
# test.pyimage = Image.open('xx.jpg').convert('RGB')question = 'What is in the image?'msgs = [{'role': 'user', 'content': [image, question]}]res = model.chat(image=None,msgs=msgs,tokenizer=tokenizer)print(res)## if you want to use streaming, please make sure sampling=True and stream=True## the model.chat will return a generatorres = model.chat(msgs=msgs,tokenizer=tokenizer,sampling=True,stream=True)generated_text = ""for new_text in res:generated_text += new_textprint(new_text, flush=True, end='')
Chat with multiple images
python
image1 = Image.open('image1.jpg').convert('RGB')image2 = Image.open('image2.jpg').convert('RGB')question = 'Compare image 1 and image 2, tell me about the differences between image 1 and image 2.'msgs = [{'role': 'user', 'content': [image1, image2, question]}]answer = model.chat(msgs=msgs,tokenizer=tokenizer)print(answer)
In-context few-shot learning
python
question = "production date"image1 = Image.open('example1.jpg').convert('RGB')answer1 = "2023.08.04"image2 = Image.open('example2.jpg').convert('RGB')answer2 = "2007.04.24"image_test = Image.open('test.jpg').convert('RGB')msgs = [{'role': 'user', 'content': [image1, question]}, {'role': 'assistant', 'content': [answer1]},{'role': 'user', 'content': [image2, question]}, {'role': 'assistant', 'content': [answer2]},{'role': 'user', 'content': [image_test, question]}]answer = model.chat(msgs=msgs,tokenizer=tokenizer)print(answer)
Chat with video
python
MAX_NUM_FRAMES=64 # if cuda OOM set a smaller numberdef encode_video(video_path):def uniform_sample(l, n):gap = len(l) / nidxs = [int(i * gap + gap / 2) for i in range(n)]return [l[i] for i in idxs]vr = VideoReader(video_path, ctx=cpu(0))sample_fps = round(vr.get_avg_fps() / 1) # FPSframe_idx = [i for i in range(0, len(vr), sample_fps)]if len(frame_idx) > MAX_NUM_FRAMES:frame_idx = uniform_sample(frame_idx, MAX_NUM_FRAMES)frames = vr.get_batch(frame_idx).asnumpy()frames = [Image.fromarray(v.astype('uint8')) for v in frames]print('num frames:', len(frames))return framesvideo_path ="video_test.mp4"frames = encode_video(video_path)question = "Describe the video"msgs = [{'role': 'user', 'content': frames + [question]},]# Set decode params for videoparams={}params["use_image_id"] = Falseparams["max_slice_nums"] = 2 # use 1 if cuda OOM and video resolution > 448*448answer = model.chat(msgs=msgs,tokenizer=tokenizer,**params)print(answer)
Please look at GitHub for more detail about usage.
Inference with llama.cpp
MiniCPM-o 2.6 (vision-only mode) can run with llama.cpp. See our fork of llama.cpp and readme for more detail.
Int4 quantized version
Download the int4 quantized version for lower GPU memory (7GB) usage: MiniCPM-o-2_6-int4.
License
Model License
- The MiniCPM-o/V model weights and code are open-sourced under the Apache-2.0 license.
- To help us better understand and support our users, we would deeply appreciate it if you could consider optionally filling out a brief registration "questionnaire".
Statement
- As an LMM, MiniCPM-o 2.6 generates contents by learning a large mount of multimodal corpora, but it cannot comprehend, express personal opinions or make value judgement. Anything generated by MiniCPM-o 2.6 does not represent the views and positions of the model developers
- We will not be liable for any problems arising from the use of the MinCPM-V models, including but not limited to data security issues, risk of public opinion, or any risks and problems arising from the misdirection, misuse, dissemination or misuse of the model.
Key Techniques and Other Multimodal Projects
👏 Welcome to explore key techniques of MiniCPM-o 2.6 and other multimodal projects of our team:
VisCPM | RLHF-V | LLaVA-UHD | RLAIF-V
Citation
If you find our work helpful, please consider citing our papers 📝 and liking this project ❤️!
bib
@article{yao2024minicpm,title={MiniCPM-V: A GPT-4V Level MLLM on Your Phone},author={Yao, Yuan and Yu, Tianyu and Zhang, Ao and Wang, Chongyi and Cui, Junbo and Zhu, Hongji and Cai, Tianchi and Li, Haoyu and Zhao, Weilin and He, Zhihui and others},journal={arXiv preprint arXiv:2408.01800},year={2024}}
Model provider
openbmb
Model tree
Base
openbmb/MiniCPM-o-2_6
Quantized
this model
Modalities
Input
Video, Audio, Text, Image
Output
Text
Pricing
Dedicated Endpoints
View detailsSupported Functionality
Model APIs
Dedicated Endpoints
Container
More information