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-3B | SAIL-VL-2B | InternVL2.5-2B-MPO | Ovis1.6-3B | InternVL2.5-1B-MPO | Ovis2-1B | Ovis2-2B |
|---|---|---|---|---|---|---|---|
| MMBench-V1.1test | 77.1 | 73.6 | 70.7 | 74.1 | 65.8 | 68.4 | 76.9 |
| MMStar | 56.5 | 56.5 | 54.9 | 52.0 | 49.5 | 52.1 | 56.7 |
| MMMUval | 51.4 | 44.1 | 44.6 | 46.7 | 40.3 | 36.1 | 45.6 |
| MathVistatestmini | 60.1 | 62.8 | 53.4 | 58.9 | 47.7 | 59.4 | 64.1 |
| HallusionBench | 48.7 | 45.9 | 40.7 | 43.8 | 34.8 | 45.2 | 50.2 |
| AI2D | 81.4 | 77.4 | 75.1 | 77.8 | 68.5 | 76.4 | 82.7 |
| OCRBench | 83.1 | 83.1 | 83.8 | 80.1 | 84.3 | 89.0 | 87.3 |
| MMVet | 63.2 | 44.2 | 64.2 | 57.6 | 47.2 | 50.0 | 58.3 |
| MMBenchtest | 78.6 | 77 | 72.8 | 76.6 | 67.9 | 70.2 | 78.9 |
| MMT-Benchval | 60.8 | 57.1 | 54.4 | 59.2 | 50.8 | 55.5 | 61.7 |
| RealWorldQA | 66.5 | 62 | 61.3 | 66.7 | 57 | 63.9 | 66.0 |
| BLINK | 48.4 | 46.4 | 43.8 | 43.8 | 41 | 44.0 | 47.9 |
| QBench | 74.4 | 72.8 | 69.8 | 75.8 | 63.3 | 71.3 | 76.2 |
| ABench | 75.5 | 74.5 | 71.1 | 75.2 | 67.5 | 71.3 | 76.6 |
| MTVQA | 24.9 | 20.2 | 22.6 | 21.1 | 21.7 | 23.7 | 25.6 |
| Benchmark | Qwen2.5-VL-3B | InternVL2.5-2B | InternVL2.5-1B | Ovis2-1B | Ovis2-2B |
|---|---|---|---|---|---|
| VideoMME(wo/w-subs) | 61.5/67.6 | 51.9 / 54.1 | 50.3 / 52.3 | 48.6/49.5 | 57.2/60.8 |
| MVBench | 67.0 | 68.8 | 64.3 | 60.32 | 64.9 |
| MLVU(M-Avg/G-Avg) | 68.2/- | 61.4/- | 57.3/- | 58.5/3.66 | 68.6/3.86 |
| MMBench-Video | 1.63 | 1.44 | 1.36 | 1.26 | 1.57 |
| TempCompass | 64.4 | - | - | 51.43 | 62.64 |
1pip install numpy==1.26.4 pandas=2.2.3
2pip install torch==2.8.0 transformers==4.51.3
3pip install peft==0.16.0 deepspeed==0.16.5 hjson==3.1.0
4pip 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("Tnt3o5/Ovis2-2B-v2",
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 = '/kaggle/input/vlsp2025/train_images/train_images/train_1_3.jpg'
15images = [Image.open(image_path)]
16max_partition = 9
17text = "Những loại phương tiện nào bị cấm trên đoạn đường này"
18query = f'<image>
19{text}'
20
21## cot-style input
22# cot_suffix = "Provide a step-by-step solution to the problem, and conclude with 'the answer is' followed by the final solution."
23# image_path = '/data/images/example_1.jpg'
24# images = [Image.open(image_path)]
25# max_partition = 9
26# text = "What's the area of the shape?"
27# query = f'<image>
28{text}
29{cot_suffix}'
30
31## multiple-images input
32# image_paths = [
33# '/data/images/example_1.jpg',
34# '/data/images/example_2.jpg',
35# '/data/images/example_3.jpg'
36# ]
37# images = [Image.open(image_path) for image_path in image_paths]
38# max_partition = 4
39# text = 'Describe each image.'
40# query = '
41'.join([f'Image {i+1}: <image>' for i in range(len(images))]) + '
42' + text
43
44## video input (require `pip install moviepy==1.0.3`)
45# from moviepy.editor import VideoFileClip
46# video_path = '/data/videos/example_1.mp4'
47# num_frames = 12
48# max_partition = 1
49# text = 'Describe the video.'
50# with VideoFileClip(video_path) as clip:
51# total_frames = int(clip.fps * clip.duration)
52# if total_frames <= num_frames:
53# sampled_indices = range(total_frames)
54# else:
55# stride = total_frames / num_frames
56# sampled_indices = [min(total_frames - 1, int((stride * i + stride * (i + 1)) / 2)) for i in range(num_frames)]
57# frames = [clip.get_frame(index / clip.fps) for index in sampled_indices]
58# frames = [Image.fromarray(frame, mode='RGB') for frame in frames]
59# images = frames
60# query = '
61'.join(['<image>'] * len(images)) + '
62' + text
63
64## text-only input
65# images = []
66# max_partition = None
67# text = 'Hello'
68# query = text
69
70# format conversation
71prompt, input_ids, pixel_values = model.preprocess_inputs(query, images, max_partition=max_partition)
72attention_mask = torch.ne(input_ids, text_tokenizer.pad_token_id)
73input_ids = input_ids.unsqueeze(0).to(device=model.device)
74attention_mask = attention_mask.unsqueeze(0).to(device=model.device)
75if pixel_values is not None:
76 pixel_values = pixel_values.to(dtype=visual_tokenizer.dtype, device=visual_tokenizer.device)
77pixel_values = [pixel_values]
78
79# generate output
80with torch.inference_mode():
81 gen_kwargs = dict(
82 max_new_tokens=1024,
83 do_sample=False,
84 top_p=None,
85 top_k=None,
86 temperature=None,
87 repetition_penalty=None,
88 eos_token_id=model.generation_config.eos_token_id,
89 pad_token_id=text_tokenizer.pad_token_id,
90 use_cache=True
91 )
92 output_ids = model.generate(input_ids, pixel_values=pixel_values, attention_mask=attention_mask, **gen_kwargs)[0]
93 output = text_tokenizer.decode(output_ids, skip_special_tokens=True)
94 print(f'Output:
95{output}')1import torch
2from PIL import Image
3from transformers import AutoModelForCausalLM
4
5# load model
6model = AutoModelForCausalLM.from_pretrained("AIDC-AI/Ovis2-1B",
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>
27{text}'
28 prompt, input_ids, pixel_values = model.preprocess_inputs(query, [image], max_partition=9)
29 attention_mask = torch.ne(input_ids, text_tokenizer.pad_token_id)
30 batch_input_ids.append(input_ids.to(device=model.device))
31 batch_attention_mask.append(attention_mask.to(device=model.device))
32 batch_pixel_values.append(pixel_values.to(dtype=visual_tokenizer.dtype, device=visual_tokenizer.device))
33
34batch_input_ids = torch.nn.utils.rnn.pad_sequence([i.flip(dims=[0]) for i in batch_input_ids], batch_first=True,
35 padding_value=0.0).flip(dims=[1])
36batch_input_ids = batch_input_ids[:, -model.config.multimodal_max_length:]
37batch_attention_mask = torch.nn.utils.rnn.pad_sequence([i.flip(dims=[0]) for i in batch_attention_mask],
38 batch_first=True, padding_value=False).flip(dims=[1])
39batch_attention_mask = batch_attention_mask[:, -model.config.multimodal_max_length:]
40
41# generate outputs
42with torch.inference_mode():
43 gen_kwargs = dict(
44 max_new_tokens=1024,
45 do_sample=False,
46 top_p=None,
47 top_k=None,
48 temperature=None,
49 repetition_penalty=None,
50 eos_token_id=model.generation_config.eos_token_id,
51 pad_token_id=text_tokenizer.pad_token_id,
52 use_cache=True
53 )
54 output_ids = model.generate(batch_input_ids, pixel_values=batch_pixel_values, attention_mask=batch_attention_mask,
55 **gen_kwargs)
56
57for i in range(len(batch_inputs)):
58 output = text_tokenizer.decode(output_ids[i], skip_special_tokens=True)
59 print(f'Output {i + 1}:
60{output}
61')@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}
}