Views
No views yet




1from transformers import Qwen2_5_VLForConditionalGeneration, AutoTokenizer, AutoProcessor
2from qwen_vl_utils import process_vision_info
3
4model_path = "internlm/Spatial-SSRL-7B" #You can change it to your own local path if deployed already
5img_path = "examples/eg1.jpg"
6question = "Consider the real-world 3D locations of the objects. Which object has a higher location? A. yellow bear kite B. building"
7#We recommend using the format prompt to make the inference consistent with training
8format_prompt = "\n You FIRST think about the reasoning process as an internal monologue and then provide the final answer. The reasoning process MUST BE enclosed within <think> </think> tags. The final answer MUST BE put in \\boxed{}."
9
10model = Qwen2_5_VLForConditionalGeneration.from_pretrained(
11 model_path, torch_dtype="auto", device_map="auto"
12)
13processor = AutoProcessor.from_pretrained(model_path)
14messages = [
15 {
16 "role": "user",
17 "content": [
18 {
19 "type": "image",
20 "image": img_path,
21 },
22 {"type": "text", "text": question + format_prompt},
23 ],
24 }
25]
26
27text = processor.apply_chat_template(
28 messages, tokenize=False, add_generation_prompt=True
29)
30image_inputs, video_inputs = process_vision_info(messages)
31inputs = processor(
32 text=[text],
33 images=image_inputs,
34 videos=video_inputs,
35 padding=True,
36 return_tensors="pt",
37)
38inputs = inputs.to("cuda")
39
40generated_ids = model.generate(**inputs, max_new_tokens=4096, do_sample=False)
41generated_ids_trimmed = [
42 out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
43]
44output_text = processor.batch_decode(
45 generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
46)
47print("Model Response:", output_text)

@article{liu2025spatial,
title={Spatial-SSRL: Enhancing Spatial Understanding via Self-Supervised Reinforcement Learning},
author={Liu, Yuhong and Zhang, Beichen and Zang, Yuhang and Cao, Yuhang and Xing, Long and Dong, Xiaoyi and Duan, Haodong and Lin, Dahua and Wang, Jiaqi},
journal={arXiv preprint arXiv:2510.27606},
year={2025}
}