Views
No views yet
1from transformers import Qwen3VLForConditionalGeneration, AutoProcessor
2from PIL import Image
3import torch
4
5# Load the model (MRPO Qwen3-VL checkpoint; or a local trained checkpoint path)
6model_path = "dmis-lab/Qwen3-VL-8B-Instruct-MRPO"
7model = Qwen3VLForConditionalGeneration.from_pretrained(
8 model_path,
9 torch_dtype=torch.bfloat16,
10 device_map="auto",
11)
12processor = AutoProcessor.from_pretrained(model_path)
13
14# Example usage (no system prompt; Qwen3 uses <thinking> tags for reasoning)
15image_path = "path/to/medical/image.jpg"
16question = "What can you see in this medical image?"
17
18question_text = (
19 f"{question} Think step-by-step and enclose your reasoning in "
20 "<thinking>...</thinking> tags. Then provide your answer in <answer>...</answer> tags."
21)
22messages = [
23 {
24 "role": "user",
25 "content": [
26 {"type": "image", "image": image_path},
27 {"type": "text", "text": question_text},
28 ],
29 }
30]
31
32# Preparation for inference
33text = processor.apply_chat_template(
34 messages, tokenize=False, add_generation_prompt=True
35)
36inputs = processor(
37 text=[text],
38 images=[Image.open(image_path)],
39 padding=True,
40 padding_side="left",
41 return_tensors="pt",
42)
43inputs = inputs.to(model.device)
44
45# Inference (greedy decoding, matching inference.py)
46generated_ids = model.generate(**inputs, use_cache=True, max_new_tokens=512, do_sample=False)
47generated_ids_trimmed = [
48 out_ids[len(in_ids):] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
49]
50output_text = processor.batch_decode(
51 generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
52)
53print(output_text)1@misc{jung2026breakingfailurecascadesstepaware,
2 title={Breaking Failure Cascades: Step-Aware Reinforcement Learning for Medical Multimodal Reasoning},
3 author={Junha Jung and Minbyul Jeong and Suhyeon Lim and Sungwook Jung and Jaehoon Yun and Taeyun Roh and Mujeen Sung and Jaewoo Kang},
4 year={2026},
5 eprint={2606.31825},
6 archivePrefix={arXiv},
7 primaryClass={cs.CV},
8 url={https://arxiv.org/abs/2606.31825},
9}