Medix-R1 / MediX-R1-4B /README.md
Shayan0179's picture
Add files using upload-large-folder tool
6007165 verified
|
Raw History Blame Contribute Delete
4.11 kB
metadata
license: apache-2.0
base_model: Qwen/Qwen3-VL-4B-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-4B (reproduction)

Qwen3-VL-4B-Instruct trained with reinforcement learning following the MediX-R1 recipe. This checkpoint is our reproduction of MediX-R1, the "MediX-R1-4B" row of the main results table in our paper.

Training

Start Qwen/Qwen3-VL-4B-Instruct, no supervised cold start
Data 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

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

path = snapshot_download("Shayan0179/Medix-R1", allow_patterns="MediX-R1-4B/*") + "/MediX-R1-4B"
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
73.7 58.3 44.6 54.8 34.3 29.4 76.6 88.2 79.8
MMLU-Gen MMLU-Prof MMLU-Anat MedMCQA MedQA USMLE-SA PubMedQA MIMIC-Sum VQA QA Macro Micro
87.0 77.9 70.4 58.6 67.2 73.2 44.4 52.1 49.2 70.5 63.0 53.8

License

Apache 2.0, following the base model.