Views
No views yet
1from transformers import AutoModelForCausalLM, AutoTokenizer
2
3
4example={
5 'image': your_image_path,
6 'problem': 'You are an assistant trained to navigate the mobile phone. \nGiven a task instruction, a screen observation, and an action history sequence, \noutput the next action and wait for the next observation. \nHere is the action space:\n1. `CLICK`: Click on an element, value is not applicable and the position [x,y] is required. \n2. `TYPE`: Type a string into an element, value is a string to type and the position is not applicable.\n3. `SCROLL UP`: Scroll up for the screen.\n4. `SCROLL DOWN`: Scroll down for the screen.\n5. `SCROLL LEFT`: Scroll left for the screen.\n6. `SCROLL RIGHT`: Scroll right for the screen.\n7. `PRESS BACK`: Press for returning to the previous step, value and position are not applicable.\n8. `PRESS HOME`: Press for returning to the home screen, value and position are not applicable.\n9. `PRESS ENTER`: Press for submitting the input content, value and position are not applicable.\n10. `STATUS TASK COMPLETE`: Indicate the task is completed, value and position are not applicable.\n\nFormat the action as a dictionary with the following keys:\n{'action': 'ACTION_TYPE', 'value': 'element', 'position': [x,y]}\n\nIf value or position is not applicable, set it as `None`.\nPosition represents the relative coordinates on the screenshot and should be scaled to a range of 0-1.\n\n**Please first thinks about the reasoning process in the mind and then provides the user with the action. The reasoning process and answer are enclosed within <think> </think> and <action> </action> tags, respectively, i.e., <think> reasoning process here </think><action> action here </action>**\nTask: Search for hotels in London\n'
7}
8
9def make_conversation_image(example):
10 return {
11 'image': example['image'], # Store path instead of loaded image
12 'prompt': [{
13 'role': 'user',
14 'content': [
15 {'type': 'image', 'text': None},
16 {'type': 'text', 'text': example['problem']}
17 ]
18 }]
19 }
20
21model_name = "kolerk/TON-3B-AITZ"
22
23model = AutoModelForCausalLM.from_pretrained(
24 model_name,
25 torch_dtype="auto",
26 device_map="auto"
27)
28tokenizer = AutoTokenizer.from_pretrained(model_name)
29
30
31text = tokenizer.apply_chat_template(
32 make_conversation_image(example),
33 tokenize=False,
34 add_generation_prompt=True
35)
36model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
37
38generated_ids = model.generate(
39 **model_inputs,
40 max_new_tokens=4096,
41 top_p=0.95,
42 top_k=1,
43 temperature=0.6
44)
45generated_ids = [
46 output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
47]
48
49response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
50print(response)@misc{wang2025think,
title={Think or Not? Selective Reasoning via Reinforcement Learning for Vision-Language Models},
author={Jiaqi Wang and Kevin Qinghong Lin and James Cheng and Mike Zheng Shou},
year={2025},
eprint={2505.16854},
archivePrefix={arXiv},
primaryClass={cs.AI}
}