模型概述
模型特點
模型能力
使用案例
🚀 MiniCPM-V 2.6
MiniCPM-V 2.6 是 MiniCPM-V 系列中最新且功能最強大的模型。該模型基於 SigLip - 400M 和 Qwen2 - 7B 構建,總參數達 80 億。相較於 MiniCPM - Llama3 - V 2.5,它在性能上有顯著提升,並引入了多圖像和視頻理解的新特性。
🚀 快速開始
你可以點擊 這裡 嘗試 MiniCPM-V 2.6 的演示。
環境要求
在 NVIDIA GPU 上使用 Huggingface transformers 進行推理。以下是在 Python 3.10 上測試通過的依賴:
Pillow==10.1.0
torch==2.1.2
torchvision==0.16.2
transformers==4.40.0
sentencepiece==0.1.99
decord
代碼示例
# test.py
import torch
from PIL import Image
from transformers import AutoModel, AutoTokenizer
model = AutoModel.from_pretrained('openbmb/MiniCPM-V-2_6', trust_remote_code=True,
attn_implementation='sdpa', torch_dtype=torch.bfloat16) # sdpa or flash_attention_2, no eager
model = model.eval().cuda()
tokenizer = AutoTokenizer.from_pretrained('openbmb/MiniCPM-V-2_6', trust_remote_code=True)
image = 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 generator
res = model.chat(
image=None,
msgs=msgs,
tokenizer=tokenizer,
sampling=True,
stream=True
)
generated_text = ""
for new_text in res:
generated_text += new_text
print(new_text, flush=True, end='')
更多使用細節請查看 GitHub。
✨ 主要特性
🔥 領先的性能
MiniCPM-V 2.6 在最新版本的 OpenCompass 上,通過對 8 個流行基準的綜合評估,平均得分達到 65.2。僅 80 億參數的它,在單圖像理解方面超越了廣泛使用的專有模型,如 GPT - 4o mini、GPT - 4V、Gemini 1.5 Pro 和 Claude 3.5 Sonnet。
🖼️ 多圖像理解和上下文學習
MiniCPM-V 2.6 還能進行多圖像對話和推理。它在 Mantis - Eval、BLINK、Mathverse mv 和 Sciverse mv 等流行的多圖像基準測試中取得了最先進的性能,並展現出了良好的上下文學習能力。
🎬 視頻理解
MiniCPM-V 2.6 可以接受視頻輸入,進行對話併為時空信息提供密集字幕。在有/無字幕的 Video - MME 測試中,它的表現優於 GPT - 4V、Claude 3.5 Sonnet 和 LLaVA - NeXT - Video - 34B。
💪 強大的 OCR 能力及其他
MiniCPM-V 2.6 可以處理任意寬高比、像素高達 180 萬(如 1344x1344)的圖像。它在 OCRBench 上取得了最先進的性能,超越了 GPT - 4o、GPT - 4V 和 Gemini 1.5 Pro 等專有模型。基於最新的 RLAIF - V 和 VisCPM 技術,它具有可靠的行為,在 Object HalBench 上的幻覺率顯著低於 GPT - 4o 和 GPT - 4V,並支持英語、中文、德語、法語、意大利語、韓語等多語言能力。
🚀 卓越的效率
除了模型規模友好外,MiniCPM-V 2.6 還展現出了最先進的令牌密度(即每個視覺令牌編碼的像素數)。處理 180 萬像素的圖像時,它僅生成 640 個令牌,比大多數模型少 75%。這直接提高了推理速度、首令牌延遲、內存使用和功耗。因此,MiniCPM-V 2.6 可以在 iPad 等終端設備上高效支持即時視頻理解。
💫 易於使用
MiniCPM-V 2.6 可以通過多種方式輕鬆使用:
- llama.cpp 和 ollama 支持在本地設備上進行高效的 CPU 推理。
- int4 和 GGUF 格式的 16 種量化模型。
- vLLM 支持高吞吐量和內存高效的推理。
- 在新領域和任務上進行微調。
- 使用 Gradio 快速設置本地 WebUI 演示。
- 在線 Web 演示。
📚 詳細文檔
評估

OpenCompass、MME、MMVet、OCRBench、MMMU、MathVista、MMB、AI2D、TextVQA、DocVQA、HallusionBench、Object HalBench 上的單圖像結果:
* 我們使用思維鏈提示來評估此基準。
+ 令牌密度:最大分辨率下每個視覺令牌編碼的像素數,即最大分辨率下的像素數 / 視覺令牌數。
注意:對於專有模型,我們根據官方 API 文檔中定義的圖像編碼收費策略計算令牌密度,這提供了一個上限估計。
點擊查看 Mantis Eval、BLINK Val、Mathverse mv、Sciverse mv、MIRB 上的多圖像結果。
點擊查看 Video - MME 和 Video - ChatGPT 上的視頻結果。
點擊查看 TextVQA、VizWiz、VQAv2、OK - VQA 上的少樣本結果。
+ 我們評估未進行 SFT 的預訓練檢查點。
示例





點擊查看更多案例。


我們在終端設備上部署了 MiniCPM-V 2.6。演示視頻是在 iPad Pro 上的原始屏幕錄製,未經過編輯。




多圖像對話
點擊查看使用多圖像輸入運行 MiniCPM-V 2.6 的 Python 代碼。
import torch
from PIL import Image
from transformers import AutoModel, AutoTokenizer
model = AutoModel.from_pretrained('openbmb/MiniCPM-V-2_6', trust_remote_code=True,
attn_implementation='sdpa', torch_dtype=torch.bfloat16) # sdpa or flash_attention_2, no eager
model = model.eval().cuda()
tokenizer = AutoTokenizer.from_pretrained('openbmb/MiniCPM-V-2_6', trust_remote_code=True)
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(
image=None,
msgs=msgs,
tokenizer=tokenizer
)
print(answer)
上下文少樣本學習
點擊查看使用少樣本輸入運行 MiniCPM-V 2.6 的 Python 代碼。
import torch
from PIL import Image
from transformers import AutoModel, AutoTokenizer
model = AutoModel.from_pretrained('openbmb/MiniCPM-V-2_6', trust_remote_code=True,
attn_implementation='sdpa', torch_dtype=torch.bfloat16) # sdpa or flash_attention_2, no eager
model = model.eval().cuda()
tokenizer = AutoTokenizer.from_pretrained('openbmb/MiniCPM-V-2_6', trust_remote_code=True)
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(
image=None,
msgs=msgs,
tokenizer=tokenizer
)
print(answer)
視頻對話
點擊查看使用視頻輸入運行 MiniCPM-V 2.6 的 Python 代碼。
import torch
from PIL import Image
from transformers import AutoModel, AutoTokenizer
from decord import VideoReader, cpu # pip install decord
model = AutoModel.from_pretrained('openbmb/MiniCPM-V-2_6', trust_remote_code=True,
attn_implementation='sdpa', torch_dtype=torch.bfloat16) # sdpa or flash_attention_2, no eager
model = model.eval().cuda()
tokenizer = AutoTokenizer.from_pretrained('openbmb/MiniCPM-V-2_6', trust_remote_code=True)
MAX_NUM_FRAMES=64 # if cuda OOM set a smaller number
def encode_video(video_path):
def uniform_sample(l, n):
gap = len(l) / n
idxs = [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) # FPS
frame_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 frames
video_path ="video_test.mp4"
frames = encode_video(video_path)
question = "Describe the video"
msgs = [
{'role': 'user', 'content': frames + [question]},
]
# Set decode params for video
params={}
params["use_image_id"] = False
params["max_slice_nums"] = 2 # use 1 if cuda OOM and video resolution > 448*448
answer = model.chat(
image=None,
msgs=msgs,
tokenizer=tokenizer,
**params
)
print(answer)
🔧 技術細節
llama.cpp 推理
MiniCPM-V 2.6 可以使用 llama.cpp 運行。更多細節請查看我們的 llama.cpp 分支。
Int4 量化版本
下載 Int4 量化版本以降低 GPU 內存(7GB)使用:MiniCPM-V-2_6-int4。
📄 許可證
模型許可證
- 本倉庫中的代碼根據 Apache - 2.0 許可證發佈。
- MiniCPM-V 系列模型權重的使用必須嚴格遵循 MiniCPM 模型許可證。
- MiniCPM 的模型和權重完全免費用於學術研究。填寫 "問卷" 進行註冊後,MiniCPM-V 2.6 權重也可免費用於商業用途。
聲明
- 作為一個大語言模型,MiniCPM-V 2.6 通過學習大量的多模態語料生成內容,但它無法理解、表達個人觀點或進行價值判斷。MiniCPM-V 2.6 生成的任何內容均不代表模型開發者的觀點和立場。
- 我們不對使用 MinCPM-V 模型產生的任何問題負責,包括但不限於數據安全問題、輿論風險,或因模型的誤導、誤用、傳播或濫用而產生的任何風險和問題。
關鍵技術和其他多模態項目
👏 歡迎探索 MiniCPM-V 2.6 的關鍵技術和我們團隊的其他多模態項目: VisCPM | RLHF-V | LLaVA-UHD | RLAIF-V
引用
如果您認為我們的工作有幫助,請考慮引用我們的論文 📝 並給這個項目點贊 ❤️!
@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}
}








