File size: 4,109 Bytes
6007165
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
---
license: apache-2.0
base_model: Qwen/Qwen3-VL-8B-Instruct
library_name: transformers
pipeline_tag: image-text-to-text
tags:
- medical
- vision-language
- reinforcement-learning
- qwen3-vl
datasets:
- MBZUAI/medix-rl-data
---

# MediX-R1-8B (reproduction)

[Qwen3-VL-8B-Instruct](https://huggingface.co/Qwen/Qwen3-VL-8B-Instruct) trained with reinforcement learning
following the MediX-R1 recipe. This checkpoint is our reproduction of MediX-R1, the "MediX-R1-8B" row of the main
results table in our paper.

## Training

| | |
|---|---|
| Start | Qwen/Qwen3-VL-8B-Instruct, no supervised cold start |
| Data | [MBZUAI/medix-rl-data](https://huggingface.co/datasets/MBZUAI/medix-rl-data), train split |
| Algorithm | GRPO advantages, 5 rollouts per prompt (temperature 1.0) |
| Dynamic sampling | online filter on the overall reward: groups whose mean is outside 0.01 to 0.99 are dropped |
| Reward | format check plus a blend of LLM-judge accuracy, embedding similarity (MedEmbed-large-v0.1) and the modality tag |
| KL | low_var_kl loss, coefficient 0.01 |
| Optimisation | learning rate 1e-6, 512 prompts per rollout batch, 128 per update, clip ratio 0.2 / 0.3 |
| Lengths | prompt up to 4,352 tokens, response up to 4,096 tokens |
| Released step | 200 (2 epochs) |

## Prompt and output format

The model was trained with this user turn: the text below (also in `prompt.txt`), then the image, then the question.

```
You are a Medical AI Assistant with advanced reasoning capabilities
Your task:
1. First output the image modality tag from this set:
   <X_RAY>, <MICROSCOPY>, <CLINICAL_PHOTOGRAPHY>, <CT_SCAN>, <GRAPHICS>,
   <ANGIOGRAPHY>, <PET_SCAN>, <ULTRASOUND>, <MRI_SCAN>, <FUNDUS_PHOTOGRAPHY>,
   <OCT_SCAN>, <ENDOSCOPY>, <MAMMOGRAPHY>, <FLUOROSCOPY>, <OTHER>, <SPECT>
   (Only output the tag, nothing else.)
2. Then output the thinking and medical reasoning process in <thinking>...</thinking>tags.
3. Finally, provide the correct answer inside <answer>...</answer> tags.
4. Do not include any extra information or text outside of these tags.
Question:
<image><your question>
```

It answers with a modality tag, then its reasoning in `<thinking>...</thinking>`, then the final answer in
`<answer>...</answer>`. Read the answer from the `<answer>` tag.

## Usage

```python
import torch
from huggingface_hub import snapshot_download
from transformers import AutoProcessor, Qwen3VLForConditionalGeneration

path = snapshot_download("Shayan0179/Medix-R1", allow_patterns="MediX-R1-8B/*") + "/MediX-R1-8B"
model = Qwen3VLForConditionalGeneration.from_pretrained(path, dtype=torch.bfloat16, device_map="auto")
processor = AutoProcessor.from_pretrained(path)

PROMPT = open(f"{path}/prompt.txt").read()   # the instructions above, ending with "Question: \n"
messages = [{"role": "user", "content": [
    {"type": "text", "text": PROMPT},
    {"type": "image", "image": "chest_xray.png"},
    {"type": "text", "text": "Is there a pleural effusion?"},
]}]
inputs = processor.apply_chat_template(messages, tokenize=True, add_generation_prompt=True,
                                       return_dict=True, return_tensors="pt").to(model.device)
out = model.generate(**inputs, max_new_tokens=2048, do_sample=False)
print(processor.batch_decode(out[:, inputs["input_ids"].shape[1]:], skip_special_tokens=True)[0])
```

## Results

Accuracy (%) on 6 medical VQA and 11 medical text QA benchmarks, greedy decoding, answers scored by a panel of three
LLM judges. VQA and QA are the means over those groups, Macro is the mean over all 17 benchmarks and Micro the accuracy
pooled over all 19,200 items.

| SLAKE | VQA-RAD | PathVQA | PMC-VQA | PMC-VQA-H | MIMIC-Gen | MMLU-Clin | MMLU-Bio | MMLU-Med |
|---|---|---|---|---|---|---|---|---|
| 70.2 | 59.9 | 46.6 | 53.8 | 34.7 | 30.6 | 80.0 | 93.8 | 81.5 |

| MMLU-Gen | MMLU-Prof | MMLU-Anat | MedMCQA | MedQA | USMLE-SA | PubMedQA | MIMIC-Sum | VQA | QA | Macro | Micro |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 89.0 | 83.5 | 77.0 | 62.6 | 75.3 | 79.4 | 43.8 | 52.6 | 49.3 | 74.4 | 65.5 | 56.0 |

## License

Apache 2.0, following the base model.