🚀 MiniCPM-V 2.6 int4
MiniCPM-V 2.6 int4 是 MiniCPM-V 2.6 的 int4 量化版本,使用該版本進行推理時,GPU 內存佔用更低(約 7GB)。
🚀 快速開始
環境依賴
在 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
accelerate==0.30.1
bitsandbytes==0.43.1
代碼示例
import torch
from PIL import Image
from transformers import AutoModel, AutoTokenizer
model = AutoModel.from_pretrained('openbmb/MiniCPM-V-2_6-int4', trust_remote_code=True)
tokenizer = AutoTokenizer.from_pretrained('openbmb/MiniCPM-V-2_6-int4', trust_remote_code=True)
model.eval()
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)
res = model.chat(
image=None,
msgs=msgs,
tokenizer=tokenizer,
sampling=True,
temperature=0.7,
stream=True
)
generated_text = ""
for new_text in res:
generated_text += new_text
print(new_text, flush=True, end='')
✨ 主要特性
- 多語言支持:支持多種語言的處理。
- 多模態能力:支持圖像、文本輸入,可處理圖像識別、OCR 等任務。
- 低內存佔用:int4 量化版本顯著降低 GPU 內存使用。
📦 安裝指南
按照上述依賴列表,使用以下命令安裝所需庫:
pip install Pillow==10.1.0 torch==2.1.2 torchvision==0.16.2 transformers==4.40.0 sentencepiece==0.1.99 accelerate==0.30.1 bitsandbytes==0.43.1
💻 使用示例
基礎用法
import torch
from PIL import Image
from transformers import AutoModel, AutoTokenizer
model = AutoModel.from_pretrained('openbmb/MiniCPM-V-2_6-int4', trust_remote_code=True)
tokenizer = AutoTokenizer.from_pretrained('openbmb/MiniCPM-V-2_6-int4', trust_remote_code=True)
model.eval()
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)
高級用法
res = model.chat(
image=None,
msgs=msgs,
tokenizer=tokenizer,
sampling=True,
temperature=0.7,
stream=True
)
generated_text = ""
for new_text in res:
generated_text += new_text
print(new_text, flush=True, end='')
📚 詳細文檔
模型信息
屬性 |
詳情 |
模型類型 |
圖像文本到文本模型 |
訓練數據 |
openbmb/RLAIF-V-Dataset |
基礎模型 |
openbmb/MiniCPM-V-2_6 |
最新消息
- [2025.01.14] 🔥🔥 我們開源了 MiniCPM-o 2.6,相較於 MiniCPM-V 2.6 有顯著的性能提升,並且支持即時語音到語音對話和多模態直播。快來試試吧。