Views
No views yet

[!WARNING] Note: This model contains artifacts and may perform poorly in some cases.
| Example | Image |
|---|---|
| Example 1 | ![]() |
| Example 2 | ![]() |
| Example 3 | ![]() |
| Example 4 | ![]() |
| Example 5 | ![]() |
1
2instruction = "Analyze the provided image and the associated problem statement. Carefully consider the geometric relationships and mathematical principles involved. Provide a step-by-step solution to the problem, ensuring that each step is logically derived from the previous one. Conclude with the correct answer, clearly labeled."
31from transformers import Qwen2VLForConditionalGeneration, AutoTokenizer, AutoProcessor
2from qwen_vl_utils import process_vision_info
3
4# Load the model with automatic device placement
5model = Qwen2VLForConditionalGeneration.from_pretrained(
6 "prithivMLmods/Open-R1-Mini-Experimental", torch_dtype="auto", device_map="auto"
7)
8
9# Recommended: Enable flash_attention_2 for better performance in multi-image and video tasks
10# model = Qwen2VLForConditionalGeneration.from_pretrained(
11# "prithivMLmods/Open-R1-Mini-Experimental",
12# torch_dtype=torch.bfloat16,
13# attn_implementation="flash_attention_2",
14# device_map="auto",
15# )
16
17# Load processor
18processor = AutoProcessor.from_pretrained("prithivMLmods/Open-R1-Mini-Experimental")
19
20# Adjust visual token range for optimized memory usage
21# min_pixels = 256*28*28
22# max_pixels = 1280*28*28
23# processor = AutoProcessor.from_pretrained("Qwen/Qwen2-VL-2B-Instruct", min_pixels=min_pixels, max_pixels=max_pixels)
24
25messages = [
26 {
27 "role": "user",
28 "content": [
29 {
30 "type": "image",
31 "image": "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen-VL/assets/demo.jpeg",
32 },
33 {"type": "text", "text": "Analyze the context of this image."},
34 ],
35 }
36]
37
38# Prepare input
39text = processor.apply_chat_template(
40 messages, tokenize=False, add_generation_prompt=True
41)
42image_inputs, video_inputs = process_vision_info(messages)
43inputs = processor(
44 text=[text],
45 images=image_inputs,
46 videos=video_inputs,
47 padding=True,
48 return_tensors="pt",
49)
50inputs = inputs.to("cuda")
51
52# Inference
53generated_ids = model.generate(**inputs, max_new_tokens=128)
54generated_ids_trimmed = [
55 out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
56]
57output_text = processor.batch_decode(
58 generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
59)
60print(output_text)1 buffer = ""
2 for new_text in streamer:
3 buffer += new_text
4 buffer = buffer.replace("<|im_end|>", "")
5 yield buffer