Views
No views yet
1conda create -n avatar python=3.10
2conda activate avatar
3
4# Install PyTorch with CUDA 12.6
5pip install torch==2.7.1 torchvision==0.22.1 torchaudio==2.7.1 --index-url https://download.pytorch.org/whl/cu126
6
7# Install flash attention (if facing issues, use the command below)
8pip install flash-attn==2.7.4.post1
9
10# If flash-attn installation fails, try:
11pip install flash-attn==2.7.4.post1 --no-build-isolation
12
13pip install transformers==4.54.1
14
15# Install other dependencies
16pip install decord opencv-python pillow numpy
17pip install qwen-omni-utils[decord] -U1import os
2import torch
3from transformers import (
4 Qwen2_5OmniThinkerForConditionalGeneration,
5 Qwen2_5OmniProcessor,
6)
7from qwen_omni_utils import process_mm_info
8
9
10def run_inference():
11 MODEL_PATH = ""
12 VIDEO_PATH = ""
13 QUESTION = "Use available audio and video to answer: Why the person is doing what they are doing? Give reasoning between <think> and </think> tags."
14
15 device = "cuda:0"
16 use_audio_flag = True
17
18 print("Loading model...")
19 model = Qwen2_5OmniThinkerForConditionalGeneration.from_pretrained(
20 MODEL_PATH,
21 device_map=device,
22 torch_dtype=torch.bfloat16,
23 attn_implementation="flash_attention_2",
24 ).eval()
25 processor = Qwen2_5OmniProcessor.from_pretrained(MODEL_PATH)
26 print("Model loaded.")
27
28 content_items = [
29 {"type": "video", "video": VIDEO_PATH},
30 {"type": "text", "text": QUESTION},
31 ]
32
33 conv = [{"role": "user", "content": content_items}]
34
35 prompt_text = processor.apply_chat_template(
36 conv, add_generation_prompt=True, tokenize=False
37 )
38
39 try:
40 audios, images, videos = process_mm_info(
41 conv, use_audio_in_video=use_audio_flag
42 )
43 except Exception as e:
44 print(f"Failed to process with audio, retrying without: {e}")
45 use_audio_flag = False
46 audios, images, videos = process_mm_info(conv, use_audio_in_video=False)
47
48 inputs = processor(
49 text=prompt_text,
50 audio=audios,
51 images=images,
52 videos=videos,
53 return_tensors="pt",
54 padding=True,
55 use_audio_in_video=use_audio_flag,
56 ).to(device)
57
58 print("Generating response...")
59 with torch.no_grad():
60 out_ids = model.generate(
61 **inputs,
62 use_audio_in_video=use_audio_flag,
63 do_sample=False,
64 max_new_tokens=512,
65 )
66
67 reply = processor.batch_decode(out_ids, skip_special_tokens=True)[0]
68
69 print("\n" + "=" * 20 + " MODEL OUTPUT " + "=" * 20)
70 print(reply)
71 print("=" * 54 + "\n")
72
73
74if __name__ == "__main__":
75 run_inference()
761@article{kulkarni2025avatar,
2 title={AVATAR: Reinforcement Learning to See, Hear, and Reason Over Video},
3 author={Kulkarni, Yogesh and Fazli, Pooyan},
4 journal={arXiv preprint arXiv:2508.03100},
5 year={2025}
6}ykulka10@asu.edu. You can also open an issue in this GitHub repository for bugs or specific questions related to the code.