ColorfulAI nielsr HF Staff commited on
Commit
c859c97
·
verified ·
1 Parent(s): 6fd8baf

Add pipeline tag, library name, link to paper and project page (#1)

Browse files

- Add pipeline tag, library name, link to paper and project page (804910e94826b29c41c642dbb1b609431c85c817)


Co-authored-by: Niels Rogge <[email protected]>

Files changed (1) hide show
  1. README.md +103 -80
README.md CHANGED
@@ -1,80 +1,103 @@
1
- ---
2
- license: mit
3
- ---
4
- # M4-LongVA-7B-Qwen2
5
-
6
- ![images](./assets/framework.png)
7
-
8
- Enhancing Interactive Capabilities in MLLM
9
-
10
- M4-7B is an extension of [LongVA-7B](https://github.com/EvolvingLMMs-Lab/LongVA), further trained using the [M4-IT](https://huggingface.co/datasets/ColorfulAI/M4-IT) dataset, which comprises 9,963 visual instruction tuning instances. This training was conducted without any special modifications to the existing training pipeline.
11
-
12
- ## Usage
13
-
14
- *Please refer to [M4](https://github.com/patrick-tssn/M4) to install relvevant packages*
15
-
16
- ```python
17
- import os
18
- from PIL import Image
19
- import numpy as np
20
- import torchaudio
21
- import torch
22
- from decord import VideoReader, cpu
23
- import whisper
24
- # fix seed
25
- torch.manual_seed(0)
26
-
27
- from intersuit.model.builder import load_pretrained_model
28
- from intersuit.mm_utils import tokenizer_image_speech_tokens, process_images
29
- from intersuit.constants import IMAGE_TOKEN_INDEX, SPEECH_TOKEN_INDEX
30
-
31
-
32
- import warnings
33
- warnings.filterwarnings("ignore")
34
-
35
- model_path = "checkpoints/M4-LongVA-7B-Qwen2"
36
- video_path = "local_demo/assets/water.mp4"
37
- max_frames_num = 16 # you can change this to several thousands so long you GPU memory can handle it :)
38
- gen_kwargs = {"do_sample": True, "temperature": 0.5, "top_p": None, "num_beams": 1, "use_cache": True, "max_new_tokens": 1024}
39
- tokenizer, model, image_processor, _ = load_pretrained_model(model_path, None, "llava_qwen", device_map="cuda:0", attn_implementation="eager")
40
-
41
- # original query
42
- query = "Give a detailed caption of the video as if I am blind."
43
- prompt = f"<|im_start|>system\nYou are a helpful assistant.<|im_end|>\n<|im_start|>user\n<image>{query}\n<|im_end|>\n<|im_start|>assistant\n"
44
- input_ids = tokenizer_image_speech_tokens(prompt, tokenizer, IMAGE_TOKEN_INDEX, SPEECH_TOKEN_INDEX, return_tensors="pt").unsqueeze(0).to(model.device)
45
- pad_token_ids = (tokenizer.pad_token_id if tokenizer.pad_token_id is not None else tokenizer.eos_token_id)
46
- attention_masks = input_ids.ne(pad_token_ids).to(input_ids.device)
47
-
48
- # new query
49
- new_query = "How many people in the video?"
50
- new_query = "Okay, I see."
51
- new_query = "Sorry to interrupt."
52
- new_query_pos = 10 # which token encounter the new query
53
- new_prompt = f"<|im_start|>system\nYou are a helpful assistant.<|im_end|>\n<|im_start|>user\n{new_query}\n<|im_end|>\n<|im_start|>assistant\n"
54
- new_input_ids = tokenizer_image_speech_tokens(new_prompt, tokenizer, IMAGE_TOKEN_INDEX, SPEECH_TOKEN_INDEX, return_tensors="pt").unsqueeze(0).to(model.device)
55
-
56
- #video input
57
- vr = VideoReader(video_path, ctx=cpu(0))
58
- total_frame_num = len(vr)
59
- uniform_sampled_frames = np.linspace(0, total_frame_num - 1, max_frames_num, dtype=int)
60
- frame_idx = uniform_sampled_frames.tolist()
61
- frames = vr.get_batch(frame_idx).asnumpy()
62
- video_tensor = image_processor.preprocess(frames, return_tensors="pt")["pixel_values"].to(model.device, dtype=torch.bfloat16)
63
-
64
-
65
- with torch.inference_mode():
66
- output_ids = model.generate_parallel(input_ids,
67
- attention_mask=attention_masks,
68
- images=[video_tensor],
69
- modalities=["video"],
70
- new_query=new_input_ids,
71
- new_query_pos=new_query_pos,
72
- query_str=query,
73
- new_query_str=new_query,
74
- tokenizer=tokenizer,
75
- **gen_kwargs)
76
- outputs = tokenizer.batch_decode(output_ids, skip_special_tokens=True)[0].strip()
77
-
78
- ```
79
-
80
- For more information about the interaction inference pipeline, please visit the [M4 GitHub repository](https://github.com/patrick-tssn/M4).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ pipeline_tag: video-text-to-text
4
+ library_name: transformers
5
+ ---
6
+
7
+ # M4-LongVA-7B-Qwen2
8
+
9
+ [Project Page](https://omnimmi.github.io/)
10
+
11
+ This is the model described in the paper [OmniMMI: A Comprehensive Multi-modal Interaction Benchmark in Streaming Video Contexts](https://huggingface.co/papers/2503.22952).
12
+
13
+ The abstract of the paper is the following:
14
+
15
+ > The rapid advancement of multi-modal language models (MLLMs) like GPT-4o has propelled the development of Omni language models, designed to process and proactively respond to continuous streams of multi-modal data. Despite their potential, evaluating their real-world interactive capabilities in streaming video contexts remains a formidable challenge. In this work, we introduce OmniMMI, a comprehensive multi-modal interaction benchmark tailored for OmniLLMs in streaming video contexts. OmniMMI encompasses over 1,121 videos and 2,290 questions, addressing two critical yet underexplored challenges in existing video benchmarks: streaming video understanding and proactive reasoning, across six distinct subtasks. Moreover, we propose a novel framework, Multi-modal Multiplexing Modeling (M4), designed to enable an inference-efficient streaming model that can see, listen while generating.
16
+
17
+ ![images](./assets/framework.png)
18
+
19
+ Enhancing Interactive Capabilities in MLLM
20
+
21
+ M4-7B is an extension of [LongVA-7B](https://github.com/EvolvingLMMs-Lab/LongVA), further trained using the [M4-IT](https://huggingface.co/datasets/ColorfulAI/M4-IT) dataset, which comprises 9,963 visual instruction tuning instances. This training was conducted without any special modifications to the existing training pipeline.
22
+
23
+ ## Usage
24
+
25
+ *Please refer to [M4](https://github.com/patrick-tssn/M4) to install relvevant packages*
26
+
27
+ ```python
28
+ import os
29
+ from PIL import Image
30
+ import numpy as np
31
+ import torchaudio
32
+ import torch
33
+ from decord import VideoReader, cpu
34
+ import whisper
35
+ # fix seed
36
+ torch.manual_seed(0)
37
+
38
+ from intersuit.model.builder import load_pretrained_model
39
+ from intersuit.mm_utils import tokenizer_image_speech_tokens, process_images
40
+ from intersuit.constants import IMAGE_TOKEN_INDEX, SPEECH_TOKEN_INDEX
41
+
42
+
43
+ import warnings
44
+ warnings.filterwarnings("ignore")
45
+
46
+ model_path = "checkpoints/M4-LongVA-7B-Qwen2"
47
+ video_path = "local_demo/assets/water.mp4"
48
+ max_frames_num = 16 # you can change this to several thousands so long you GPU memory can handle it :)
49
+ gen_kwargs = {"do_sample": True, "temperature": 0.5, "top_p": None, "num_beams": 1, "use_cache": True, "max_new_tokens": 1024}
50
+ tokenizer, model, image_processor, _ = load_pretrained_model(model_path, None, "llava_qwen", device_map="cuda:0", attn_implementation="eager")
51
+
52
+ # original query
53
+ query = "Give a detailed caption of the video as if I am blind."
54
+ prompt = f"<|im_start|>system
55
+ You are a helpful assistant.<|im_end|>
56
+ <|im_start|>user
57
+ <image>{query}
58
+ <|im_end|>
59
+ <|im_start|>assistant
60
+ "
61
+ input_ids = tokenizer_image_speech_tokens(prompt, tokenizer, IMAGE_TOKEN_INDEX, SPEECH_TOKEN_INDEX, return_tensors="pt").unsqueeze(0).to(model.device)
62
+ pad_token_ids = (tokenizer.pad_token_id if tokenizer.pad_token_id is not None else tokenizer.eos_token_id)
63
+ attention_masks = input_ids.ne(pad_token_ids).to(input_ids.device)
64
+
65
+ # new query
66
+ new_query = "How many people in the video?"
67
+ new_query = "Okay, I see."
68
+ new_query = "Sorry to interrupt."
69
+ new_query_pos = 10 # which token encounter the new query
70
+ new_prompt = f"<|im_start|>system
71
+ You are a helpful assistant.<|im_end|>
72
+ <|im_start|>user
73
+ {new_query}
74
+ <|im_end|>
75
+ <|im_start|>assistant
76
+ "
77
+ new_input_ids = tokenizer_image_speech_tokens(new_prompt, tokenizer, IMAGE_TOKEN_INDEX, SPEECH_TOKEN_INDEX, return_tensors="pt").unsqueeze(0).to(model.device)
78
+
79
+ #video input
80
+ vr = VideoReader(video_path, ctx=cpu(0))
81
+ total_frame_num = len(vr)
82
+ uniform_sampled_frames = np.linspace(0, total_frame_num - 1, max_frames_num, dtype=int)
83
+ frame_idx = uniform_sampled_frames.tolist()
84
+ frames = vr.get_batch(frame_idx).asnumpy()
85
+ video_tensor = image_processor.preprocess(frames, return_tensors="pt")["pixel_values"].to(model.device, dtype=torch.bfloat16)
86
+
87
+
88
+ with torch.inference_mode():
89
+ output_ids = model.generate_parallel(input_ids,
90
+ attention_mask=attention_masks,
91
+ images=[video_tensor],
92
+ modalities=["video"],
93
+ new_query=new_input_ids,
94
+ new_query_pos=new_query_pos,
95
+ query_str=query,
96
+ new_query_str=new_query,
97
+ tokenizer=tokenizer,
98
+ **gen_kwargs)
99
+ outputs = tokenizer.batch_decode(output_ids, skip_special_tokens=True)[0].strip()
100
+
101
+ ```
102
+
103
+ For more information about the interaction inference pipeline, please visit the [M4 GitHub repository](https://github.com/patrick-tssn/M4).