Pillow==10.1.0
torch==2.1.2
torchvision==0.16.2
transformers==4.40.0
sentencepiece==0.1.99
decord1# test.py
2import torch
3from PIL import Image
4from transformers import AutoModel, AutoTokenizer
5
6# Load our fine-tuned model (based on MiniCPM-V-2.6 architecture)
7model = AutoModel.from_pretrained('PengxiangLi/MAT', trust_remote_code=True,
8 attn_implementation='sdpa', torch_dtype=torch.bfloat16) # Maintain original implementation choices
9model = model.eval().cuda()
10tokenizer = AutoTokenizer.from_pretrained('PengxiangLi/MAT', trust_remote_code=True)
11
12image = Image.open('xx.jpg').convert('RGB')
13question = 'What is in the image?'
14msgs = [{'role': 'user', 'content': [image, question]}]
15
16# The chat interface follows MiniCPM's original implementation
17response = model.chat(
18 image=None,
19 msgs=msgs,
20 tokenizer=tokenizer
21)
22print(response)
23
24## Streaming output (inherited from MiniCPM's implementation)
25response_stream = model.chat(
26 image=None,
27 msgs=msgs,
28 tokenizer=tokenizer,
29 sampling=True,
30 stream=True
31)
32
33generated_text = ""
34for new_text in response_stream:
35 generated_text += new_text
36 print(new_text, flush=True, end='')1import torch
2from PIL import Image
3from transformers import AutoModel, AutoTokenizer
4
5model = AutoModel.from_pretrained('PengxiangLi/MAT', trust_remote_code=True,
6 attn_implementation='sdpa', torch_dtype=torch.bfloat16)
7model = model.eval().cuda()
8tokenizer = AutoTokenizer.from_pretrained('PengxiangLi/MAT', trust_remote_code=True)
9
10# The message format follows MiniCPM's original schema
11image1 = Image.open('image1.jpg').convert('RGB')
12image2 = Image.open('image2.jpg').convert('RGB')
13question = 'Compare the two images...'
14
15msgs = [{'role': 'user', 'content': [image1, image2, question]}]
16
17# Using the original chat interface design
18answer = model.chat(
19 image=None,
20 msgs=msgs,
21 tokenizer=tokenizer
22)
23print(answer)1import torch
2from PIL import Image
3from transformers import AutoModel, AutoTokenizer
4
5# Maintain original model loading parameters
6model = AutoModel.from_pretrained('PengxiangLi/MAT', trust_remote_code=True,
7 attn_implementation='sdpa', torch_dtype=torch.bfloat16)
8model = model.eval().cuda()
9tokenizer = AutoTokenizer.from_pretrained('PengxiangLi/MAT', trust_remote_code=True)
10
11# Following MiniCPM's message structure
12question = "production date"
13image1 = Image.open('example1.jpg').convert('RGB')
14answer1 = "2023.08.04"
15image2 = Image.open('example2.jpg').convert('RGB')
16answer2 = "2007.04.24"
17image_test = Image.open('test.jpg').convert('RGB')
18
19msgs = [
20 {'role': 'user', 'content': [image1, question]},
21 {'role': 'assistant', 'content': [answer1]},
22 {'role': 'user', 'content': [image2, question]},
23 {'role': 'assistant', 'content': [answer2]},
24 {'role': 'user', 'content': [image_test, question]}
25]
26
27# Using the unmodified chat interface from original implementation
28answer = model.chat(
29 image=None,
30 msgs=msgs,
31 tokenizer=tokenizer
32)
33print(answer)chat() interface remains unchanged from the original implementation1@article{gao2024multi,
2 title={Multi-modal Agent Tuning: Building a VLM-Driven Agent for Efficient Tool Usage},
3 author={Gao, Zhi and Zhang, Bofei and Li, Pengxiang and Ma, Xiaojian and Yuan, Tao and Fan, Yue and Wu, Yuwei and Jia, Yunde and Zhu, Song-Chun and Li, Qing},
4 journal={arXiv preprint arXiv:2412.15606},
5 year={2024}
6}