prithivMLmods/Open-R1-Mini-Experimental
332
1---2license: apache-2.03language:4- en5base_model:6- Qwen/Qwen2-VL-2B-Instruct7pipeline_tag: image-text-to-text8library_name: transformers9tags:10- reasoner11- r112- exp13- diagram14- math15- theorem16- text-generation-inference17---1819 20> [!WARNING]21> **Note:** This model contains artifacts and may perform poorly in some cases.22 23# **Open-R1-Mini-Experimental**24 25The **Open-R1-Mini-Experimental** model is a fine-tuned version of Qwen2-VL-2B-Instruct, specifically designed for reasoning tasks, context reasoning, and multi-modal understanding based on the **R1 reasoning logits data**. This model integrates a conversational approach with deep reasoning capabilities to handle complex multi-modal tasks efficiently.26 27# **Key Enhancements**28 29* **Advanced Contextual Reasoning**: Open-R1-Mini-Experimental achieves state-of-the-art performance in reasoning tasks by leveraging R1 reasoning logits data, enhancing logical inference and decision-making.30 31* **Understanding images of various resolution & ratio**: The model excels at visual understanding benchmarks, including MathVista, DocVQA, RealWorldQA, MTVQA, etc.32 33* **Long-Context Video Understanding**: Capable of processing and reasoning over videos of 20 minutes or more for high-quality video-based question answering, content creation, and dialogue.34 35* **Device Integration**: With strong reasoning and decision-making abilities, the model can be integrated into mobile devices, robots, and automation systems for real-time operation based on both visual and textual input.36 37* **Multilingual Support**: Supports text understanding in various languages within images, including English, Chinese, Japanese, Korean, Arabic, most European languages, and Vietnamese.38 39# **Sample Inference**40 41| Example | Image |42|---------|-------|43| **Example 1** |  |44| **Example 2** |  |45| **Example 3** |  |46| **Example 4** |  |47| **Example 5** |  |48 49**Demo:** https://huggingface.co/prithivMLmods/Open-R1-Mini-Experimental/blob/main/open-r1-reasoner-doc-py/open-r1-exp.ipynb50 51# **How to Use**52 53```python54 55instruction = "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."56 57```58 59```python60from transformers import Qwen2VLForConditionalGeneration, AutoTokenizer, AutoProcessor61from qwen_vl_utils import process_vision_info62 63# Load the model with automatic device placement64model = Qwen2VLForConditionalGeneration.from_pretrained(65 "prithivMLmods/Open-R1-Mini-Experimental", torch_dtype="auto", device_map="auto"66)67 68# Recommended: Enable flash_attention_2 for better performance in multi-image and video tasks69# model = Qwen2VLForConditionalGeneration.from_pretrained(70# "prithivMLmods/Open-R1-Mini-Experimental",71# torch_dtype=torch.bfloat16,72# attn_implementation="flash_attention_2",73# device_map="auto",74# )75 76# Load processor77processor = AutoProcessor.from_pretrained("prithivMLmods/Open-R1-Mini-Experimental")78 79# Adjust visual token range for optimized memory usage80# min_pixels = 256*28*2881# max_pixels = 1280*28*2882# processor = AutoProcessor.from_pretrained("Qwen/Qwen2-VL-2B-Instruct", min_pixels=min_pixels, max_pixels=max_pixels)83 84messages = [85 {86 "role": "user",87 "content": [88 {89 "type": "image",90 "image": "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen-VL/assets/demo.jpeg",91 },92 {"type": "text", "text": "Analyze the context of this image."},93 ],94 }95]96 97# Prepare input98text = processor.apply_chat_template(99 messages, tokenize=False, add_generation_prompt=True100)101image_inputs, video_inputs = process_vision_info(messages)102inputs = processor(103 text=[text],104 images=image_inputs,105 videos=video_inputs,106 padding=True,107 return_tensors="pt",108)109inputs = inputs.to("cuda")110 111# Inference112generated_ids = model.generate(**inputs, max_new_tokens=128)113generated_ids_trimmed = [114 out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)115]116output_text = processor.batch_decode(117 generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False118)119print(output_text)120```121# **Buffer Handling**122```python123 buffer = ""124 for new_text in streamer:125 buffer += new_text126 buffer = buffer.replace("<|im_end|>", "")127 yield buffer128```129# **Key Features**130 1311. **Advanced Contextual Reasoning:** 132 - Optimized for **context-aware problem-solving** and **logical inference** based on R1 reasoning logits.133 1342. **Optical Character Recognition (OCR):** 135 - Extracts and processes text from images with exceptional accuracy.136 1373. **Mathematical and Logical Problem Solving:** 138 - Supports complex reasoning and outputs equations in **LaTeX format**.139 1404. **Conversational and Multi-Turn Interaction:** 141 - Handles **multi-turn dialogue** with enhanced memory retention and response coherence.142 1435. **Multi-Modal Inputs & Outputs:** 144 - Processes images, text, and combined inputs to generate insightful analyses.145 1466. **Secure and Efficient Model Loading:** 147 - Uses **Safetensors** for faster and more secure model weight handling.