Views
No views yet


| Ovis MLLMs | ViT | LLM | Model Weights | Demo |
|---|---|---|---|---|
| Ovis2-1B | aimv2-large-patch14-448 | Qwen2.5-0.5B-Instruct | Huggingface | Space |
| Ovis2-2B | aimv2-large-patch14-448 | Qwen2.5-1.5B-Instruct | Huggingface | Space |
| Ovis2-4B | aimv2-huge-patch14-448 | Qwen2.5-3B-Instruct | Huggingface | Space |
| Ovis2-8B | aimv2-huge-patch14-448 | Qwen2.5-7B-Instruct | Huggingface | Space |
| Ovis2-16B | aimv2-huge-patch14-448 | Qwen2.5-14B-Instruct | Huggingface | Space |
| Ovis2-34B | aimv2-1B-patch14-448 | Qwen2.5-32B-Instruct | Huggingface | - |

| Benchmark | Qwen2.5-VL-72B | InternVL2.5-38B-MPO | InternVL2.5-26B-MPO | Ovis1.6-27B | LLaVA-OV-72B | Ovis2-16B | Ovis2-34B |
|---|---|---|---|---|---|---|---|
| MMBench-V1.1test | 87.8 | 85.4 | 84.2 | 82.2 | 84.4 | 85.6 | 86.6 |
| MMStar | 71.1 | 70.1 | 67.7 | 63.5 | 65.8 | 67.2 | 69.2 |
| MMMUval | 67.9 | 63.8 | 56.4 | 60.3 | 56.6 | 60.7 | 66.7 |
| MathVistatestmini | 70.8 | 73.6 | 71.5 | 70.2 | 68.4 | 73.7 | 76.1 |
| HallusionBench | 58.8 | 59.7 | 52.4 | 54.1 | 47.9 | 56.8 | 58.8 |
| AI2D | 88.2 | 87.9 | 86.2 | 86.6 | 86.2 | 86.3 | 88.3 |
| OCRBench | 88.1 | 89.4 | 90.5 | 85.6 | 74.1 | 87.9 | 89.4 |
| MMVet | 76.7 | 72.6 | 68.1 | 68 | 60.6 | 68.4 | 77.1 |
| MMBenchtest | 88.2 | 86.4 | 85.4 | 84.6 | 85.6 | 87.1 | 87.8 |
| MMT-Benchval | 69.1 | 69.1 | 65.7 | 68.2 | - | 69.2 | 71.2 |
| RealWorldQA | 75.9 | 74.4 | 73.7 | 72.7 | 73.9 | 74.1 | 75.6 |
| BLINK | 62.3 | 63.2 | 62.6 | 48 | - | 59.0 | 60.1 |
| QBench | - | 76.1 | 76.0 | 77.7 | - | 79.5 | 79.8 |
| ABench | - | 78.6 | 79.4 | 76.5 | - | 79.4 | 78.7 |
| MTVQA | - | 31.2 | 28.7 | 26.5 | - | 30.3 | 30.6 |
| Benchmark | Qwen2.5-VL-72B | InternVL2.5-38B | InternVL2.5-26B | LLaVA-OneVision-72B | Ovis2-16B | Ovis2-34B |
|---|---|---|---|---|---|---|
| VideoMME(wo/w-subs) | 73.3/79.1 | 70.7 / 73.1 | 66.9 / 69.2 | 66.2/69.5 | 70.0/74.4 | 71.2/75.6 |
| MVBench | 70.4 | 74.4 | 75.2 | 59.4 | 68.6 | 70.3 |
| MLVU(M-Avg/G-Avg) | 74.6/- | 75.3/- | 72.3/- | 68.0/- | 77.7/4.44 | 77.8/4.59 |
| MMBench-Video | 2.02 | 1.82 | 1.86 | - | 1.92 | 1.98 |
| TempCompass | 74.8 | - | - | - | 74.16 | 75.97 |

1pip install torch==2.4.0 transformers==4.46.2 numpy==1.25.0 pillow==10.3.0
2pip install flash-attn==2.7.0.post2 --no-build-isolation1import torch
2from PIL import Image
3from transformers import AutoModelForCausalLM
4
5# load model
6model = AutoModelForCausalLM.from_pretrained("AIDC-AI/Ovis2-34B",
7 torch_dtype=torch.bfloat16,
8 multimodal_max_length=32768,
9 trust_remote_code=True).cuda()
10text_tokenizer = model.get_text_tokenizer()
11visual_tokenizer = model.get_visual_tokenizer()
12
13# single-image input
14image_path = '/data/images/example_1.jpg'
15images = [Image.open(image_path)]
16max_partition = 9
17text = 'Describe the image.'
18query = f'<image>\n{text}'
19
20## cot-style input
21# cot_suffix = "Provide a step-by-step solution to the problem, and conclude with 'the answer is' followed by the final solution."
22# image_path = '/data/images/example_1.jpg'
23# images = [Image.open(image_path)]
24# max_partition = 9
25# text = "What's the area of the shape?"
26# query = f'<image>\n{text}\n{cot_suffix}'
27
28## multiple-images input
29# image_paths = [
30# '/data/images/example_1.jpg',
31# '/data/images/example_2.jpg',
32# '/data/images/example_3.jpg'
33# ]
34# images = [Image.open(image_path) for image_path in image_paths]
35# max_partition = 4
36# text = 'Describe each image.'
37# query = '\n'.join([f'Image {i+1}: <image>' for i in range(len(images))]) + '\n' + text
38
39## video input (require `pip install moviepy==1.0.3`)
40# from moviepy.editor import VideoFileClip
41# video_path = '/data/videos/example_1.mp4'
42# num_frames = 12
43# max_partition = 1
44# text = 'Describe the video.'
45# with VideoFileClip(video_path) as clip:
46# total_frames = int(clip.fps * clip.duration)
47# if total_frames <= num_frames:
48# sampled_indices = range(total_frames)
49# else:
50# stride = total_frames / num_frames
51# sampled_indices = [min(total_frames - 1, int((stride * i + stride * (i + 1)) / 2)) for i in range(num_frames)]
52# frames = [clip.get_frame(index / clip.fps) for index in sampled_indices]
53# frames = [Image.fromarray(frame, mode='RGB') for frame in frames]
54# images = frames
55# query = '\n'.join(['<image>'] * len(images)) + '\n' + text
56
57## text-only input
58# images = []
59# max_partition = None
60# text = 'Hello'
61# query = text
62
63# format conversation
64prompt, input_ids, pixel_values = model.preprocess_inputs(query, images, max_partition=max_partition)
65attention_mask = torch.ne(input_ids, text_tokenizer.pad_token_id)
66input_ids = input_ids.unsqueeze(0).to(device=model.device)
67attention_mask = attention_mask.unsqueeze(0).to(device=model.device)
68if pixel_values is not None:
69 pixel_values = pixel_values.to(dtype=visual_tokenizer.dtype, device=visual_tokenizer.device)
70pixel_values = [pixel_values]
71
72# generate output
73with torch.inference_mode():
74 gen_kwargs = dict(
75 max_new_tokens=1024,
76 do_sample=False,
77 top_p=None,
78 top_k=None,
79 temperature=None,
80 repetition_penalty=None,
81 eos_token_id=model.generation_config.eos_token_id,
82 pad_token_id=text_tokenizer.pad_token_id,
83 use_cache=True
84 )
85 output_ids = model.generate(input_ids, pixel_values=pixel_values, attention_mask=attention_mask, **gen_kwargs)[0]
86 output = text_tokenizer.decode(output_ids, skip_special_tokens=True)
87 print(f'Output:\n{output}')1import torch
2from PIL import Image
3from transformers import AutoModelForCausalLM
4
5# load model
6model = AutoModelForCausalLM.from_pretrained("AIDC-AI/Ovis2-34B",
7 torch_dtype=torch.bfloat16,
8 multimodal_max_length=32768,
9 trust_remote_code=True).cuda()
10text_tokenizer = model.get_text_tokenizer()
11visual_tokenizer = model.get_visual_tokenizer()
12
13# preprocess inputs
14batch_inputs = [
15 ('/data/images/example_1.jpg', 'What colors dominate the image?'),
16 ('/data/images/example_2.jpg', 'What objects are depicted in this image?'),
17 ('/data/images/example_3.jpg', 'Is there any text in the image?')
18]
19
20batch_input_ids = []
21batch_attention_mask = []
22batch_pixel_values = []
23
24for image_path, text in batch_inputs:
25 image = Image.open(image_path)
26 query = f'<image>\n{text}'
27 prompt, input_ids, pixel_values = model.preprocess_inputs(query, [image], max_partition=9)
28 attention_mask = torch.ne(input_ids, text_tokenizer.pad_token_id)
29 batch_input_ids.append(input_ids.to(device=model.device))
30 batch_attention_mask.append(attention_mask.to(device=model.device))
31 batch_pixel_values.append(pixel_values.to(dtype=visual_tokenizer.dtype, device=visual_tokenizer.device))
32
33batch_input_ids = torch.nn.utils.rnn.pad_sequence([i.flip(dims=[0]) for i in batch_input_ids], batch_first=True,
34 padding_value=0.0).flip(dims=[1])
35batch_input_ids = batch_input_ids[:, -model.config.multimodal_max_length:]
36batch_attention_mask = torch.nn.utils.rnn.pad_sequence([i.flip(dims=[0]) for i in batch_attention_mask],
37 batch_first=True, padding_value=False).flip(dims=[1])
38batch_attention_mask = batch_attention_mask[:, -model.config.multimodal_max_length:]
39
40# generate outputs
41with torch.inference_mode():
42 gen_kwargs = dict(
43 max_new_tokens=1024,
44 do_sample=False,
45 top_p=None,
46 top_k=None,
47 temperature=None,
48 repetition_penalty=None,
49 eos_token_id=model.generation_config.eos_token_id,
50 pad_token_id=text_tokenizer.pad_token_id,
51 use_cache=True
52 )
53 output_ids = model.generate(batch_input_ids, pixel_values=batch_pixel_values, attention_mask=batch_attention_mask,
54 **gen_kwargs)
55
56for i in range(len(batch_inputs)):
57 output = text_tokenizer.decode(output_ids[i], skip_special_tokens=True)
58 print(f'Output {i + 1}:\n{output}\n')@article{lu2024ovis,
title={Ovis: Structural Embedding Alignment for Multimodal Large Language Model},
author={Shiyin Lu and Yang Li and Qing-Guo Chen and Zhao Xu and Weihua Luo and Kaifu Zhang and Han-Jia Ye},
year={2024},
journal={arXiv:2405.20797}
}