Instructions to use Shayan0179/Medix-R1 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Shayan0179/Medix-R1 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="Shayan0179/Medix-R1")# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("Shayan0179/Medix-R1", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Shayan0179/Medix-R1 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Shayan0179/Medix-R1" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Shayan0179/Medix-R1", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/Shayan0179/Medix-R1
- SGLang
How to use Shayan0179/Medix-R1 with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "Shayan0179/Medix-R1" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Shayan0179/Medix-R1", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "Shayan0179/Medix-R1" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Shayan0179/Medix-R1", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use Shayan0179/Medix-R1 with Docker Model Runner:
docker model run hf.co/Shayan0179/Medix-R1
|
Download MediX-R1-4B/README.md from Shayan0179/Medix-R1: direct link, hf CLI and curl.
- Browser
- Download file 4.11 kB
-
https://huggingface.co/Shayan0179/Medix-R1/resolve/main/MediX-R1-4B/README.md
- Command line
-
hf download hf://Shayan0179/Medix-R1/MediX-R1-4B/README.md
-
curl -L -o README.md https://huggingface.co/Shayan0179/Medix-R1/resolve/main/MediX-R1-4B/README.md
4.11 kB
| 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](https://huggingface.co/Qwen/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](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-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. | |