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]>
README.md
CHANGED
@@ -1,80 +1,103 @@
|
|
1 |
-
---
|
2 |
-
license: mit
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
from
|
30 |
-
|
31 |
-
|
32 |
-
import
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
#
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+

|
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).
|