-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_model.py
More file actions
57 lines (46 loc) · 1.4 KB
/
test_model.py
File metadata and controls
57 lines (46 loc) · 1.4 KB
1
2
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
30
31
32
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
"""
Quick test to verify the Qwen2.5-Omni model is working
"""
from transformers import Qwen2_5OmniForConditionalGeneration, Qwen2_5OmniProcessor
import torch
print("="*60)
print("Testing Qwen2.5-Omni-3B Model")
print("="*60)
print("\nLoading model...")
model = Qwen2_5OmniForConditionalGeneration.from_pretrained(
"Qwen/Qwen2.5-Omni-3B",
torch_dtype="auto",
device_map="auto"
)
processor = Qwen2_5OmniProcessor.from_pretrained("Qwen/Qwen2.5-Omni-3B")
print(f"✓ Model loaded on device: {model.device}\n")
# Test question
conversation = [
{"role": "system", "content": "You are a helpful math tutor."},
{"role": "user", "content": "What is 5 + 3?"}
]
print("Test Question: What is 5 + 3?")
print("Generating response...\n")
# Generate response
text_input = processor.apply_chat_template(
conversation,
add_generation_prompt=True,
tokenize=False
)
inputs = processor(text=text_input, return_tensors="pt").to(model.device)
with torch.no_grad():
generated_ids = model.generate(**inputs, max_new_tokens=100)
response = processor.batch_decode(
generated_ids[:, inputs['input_ids'].shape[1]:],
skip_special_tokens=True
)[0]
print("="*60)
print("Model Response:")
print("="*60)
print(response)
print("\n" + "="*60)
print("✓ Model is working correctly!")
print("="*60)
print("\nYou can now run the web app with:")
print(" python app.py")
print("\nThen open: http://localhost:5000")