Views
No views yet
1@article{zhong2025omnir1reinforcementlearningomnimodal,
2 title={Omni-R1: Reinforcement Learning for Omnimodal Reasoning via Two-System Collaboration},
3 author={Hao Zhong and Muzhi Zhu and Zongze Du and Zheng Huang and Canyu Zhao and Mingyu Liu and Wen Wang and Hao Chen and Chunhua Shen},
4 year={2025},
5 eprint={2505.20256},
6 archivePrefix={arXiv},
7 primaryClass={cs.CV},
8 url={https://arxiv.org/abs/2505.20256},
9}
1git clone https://github.com/aim-uofa/Omni-R1
2cd Omni-R1
3
4# build environment
5conda create -n omni python=3.10
6conda activate omni
7
8# install packages
9pip install -r requirements.txt
10pip install -e src/qwen-omni-utils[decord]
11pip install flash-attn --no-build-isolation
12pip install transformers/transformers_omni.zip
13
14# replace transformers Qwen2.5-Omni .py file
15bash replace_omni.shuv, if preferred,1uv sync --no-build-isolation-package flash-attn
2source .venv/bin/activate
3
4# replace transformers Qwen2.5-Omni .py file
5bash replace_omni.shsrc/r1-v/datasets.json according to src/r1-v/datasets_demo.json.1# for uv, source .venv/bin/activate
2conda activate omni
3
4# start SAM server first. If not training VOS or alpha_g is set to 0.0, then SAM server is not necessary.
5bash src/scripts/run_sam_server.sh
6
7# start training, by default this script does not need a SAM server.
8bash src/scripts/omni_r1_run_training.shSAM_HOST and SAM_PORT as environment variables in src/scripts/omni_r1_run_training.sh.1import torch
2from transformers import (
3 Qwen2_5OmniModel,
4 Qwen2_5OmniProcessor,
5 GenerationConfig,
6 Qwen2_5OmniThinkerForConditionalGeneration,
7)
8from transformers import AutoModelForCausalLM, AutoTokenizer
9from qwen_omni_utils import process_mm_info, process_vision_info
10
11
12omni_path = "/path/to/Omni-R1"
13
14# Omni-R1 is Qwen2_5OmniThinker, not Qwen2_5OmniModel, so inference code is different from that of Qwen offical codes.
15model = Qwen2_5OmniThinkerForConditionalGeneration.from_pretrained(
16 omni_path,
17 device_map="auto",
18 torch_dtype=torch.bfloat16,
19 attn_implementation="flash_attention_2",
20).eval()
21processor = Qwen2_5OmniProcessor.from_pretrained(omni_path)
22
23
24generation_config = GenerationConfig(
25 use_cache=True, max_new_tokens=1024, do_sample=False
26)
27
28def inference(video_path, prompt, sys_prompt):
29 messages = [
30 {"role": "system", "content": [{"type": "text", "text": sys_prompt}]},
31 {
32 "role": "user",
33 "content": [
34 {"type": "video", "video": video_path},
35 {"type": "text", "text": prompt},
36 ],
37 },
38 ]
39 text_input = processor.apply_chat_template(
40 messages, tokenize=False, add_generation_prompt=True
41 )
42
43 audio_input, image_input, video_input, process_args = process_mm_info(
44 messages, use_audio_in_video=False
45 )
46
47 inputs = processor(
48 text=text_input,
49 images=image_input,
50 audios=audio_input,
51 videos=video_input,
52 return_tensors="pt",
53 do_resize=True,
54 )
55
56 # 生成输出
57 with torch.inference_mode():
58 generated_ids = model.generate(**inputs, generation_config=generation_config)
59
60 prompt_length = inputs["input_ids"].size(1)
61 completion_ids = generated_ids[:, prompt_length:]
62 # Decode the generated completions
63 text = processor.batch_decode(completion_ids, skip_special_tokens=True)
64 return text
65
66video_path = "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen2.5-Omni/shopping.mp4"
67prompt = "How many kind of drinks can you see in the video?"
68
69## Use a local model to inference.
70response = inference(
71 video_path, prompt=prompt, sys_prompt="You are a helpful assistant."
72)
73print(response[0])
741@article{zhong2025omnir1reinforcementlearningomnimodal,
2 title={Omni-R1: Reinforcement Learning for Omnimodal Reasoning via Two-System Collaboration},
3 author={Hao Zhong and Muzhi Zhu and Zongze Du and Zheng Huang and Canyu Zhao and Mingyu Liu and Wen Wang and Hao Chen and Chunhua Shen},
4 year={2025},
5 eprint={2505.20256},
6 archivePrefix={arXiv},
7 primaryClass={cs.CV},
8 url={https://arxiv.org/abs/2505.20256},
9}