Image-Text-to-Text
Transformers
Safetensors
qwen3_5
medical
multimodal
grounding
visual-grounding
multi-image
reasoning
chain-of-thought
radiology
mri
ct
conversational
Run this model with HF Jobs
Run adidukrembzuai/MedChain-R1-9B on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs and TRL to fine-tune https://huggingface.co/adidukrembzuai/MedChain-R1-9B. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/adidukrembzuai/MedChain-R1-9B on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Evaluate on a benchmark
Use HF Jobs to evaluate https://huggingface.co/adidukrembzuai/MedChain-R1-9B. Ask me which benchmark to run, then save the scores and the per-example results to a new dataset repo. Run `hf jobs --help` first to learn the CLI.
Quantize for lower memory use
Use HF Jobs to create a 4-bit version of https://huggingface.co/adidukrembzuai/MedChain-R1-9B. Push it to a new model repo, then reload it from there and report its memory footprint. Run `hf jobs --help` first to learn the CLI.
Instructions to use adidukrembzuai/MedChain-R1-9B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use adidukrembzuai/MedChain-R1-9B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="adidukrembzuai/MedChain-R1-9B") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("adidukrembzuai/MedChain-R1-9B") model = AutoModelForMultimodalLM.from_pretrained("adidukrembzuai/MedChain-R1-9B", device_map="auto") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] inputs = processor.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=256) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use adidukrembzuai/MedChain-R1-9B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "adidukrembzuai/MedChain-R1-9B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "adidukrembzuai/MedChain-R1-9B", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/adidukrembzuai/MedChain-R1-9B
- SGLang
How to use adidukrembzuai/MedChain-R1-9B 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 "adidukrembzuai/MedChain-R1-9B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "adidukrembzuai/MedChain-R1-9B", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'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 "adidukrembzuai/MedChain-R1-9B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "adidukrembzuai/MedChain-R1-9B", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use adidukrembzuai/MedChain-R1-9B with Docker Model Runner:
docker model run hf.co/adidukrembzuai/MedChain-R1-9B
Add model card
Browse filesFiles changed (3)
- .gitattributes+1
- README.mdAdded+146
- overview.pngAdded
33 unmodified lines34353633 unmodified lines*.zst filter=lfs diff=lfs merge=lfs -text*tfevents* filter=lfs diff=lfs merge=lfs -texttokenizer.json filter=lfs diff=lfs merge=lfs -text33 unmodified lines3435363733 unmodified lines*.zst filter=lfs diff=lfs merge=lfs -text*tfevents* filter=lfs diff=lfs merge=lfs -texttokenizer.json filter=lfs diff=lfs merge=lfs -textoverview.png filter=lfs diff=lfs merge=lfs -text
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146---license: apache-2.0library_name: transformerspipeline_tag: image-text-to-textbase_model: Qwen/Qwen3.5-9Btags: - medical - multimodal - grounding - visual-grounding - multi-image - reasoning - radiology - mri - ct---
# MedChain-R1-9B: Reasoning-Driven Sequential Grounding for Medical Images
[](https://github.com/adinathdukre/MedChain-R1)[](https://huggingface.co/adidukrembzuai/MedChain-R1-4B)[](https://huggingface.co/adidukrembzuai/MedChain-R1-9B)[](https://opensource.org/licenses/Apache-2.0)
<p align="center"> <img src="overview.png" alt="MedChain-R1 overview" width="900"/></p>
**MedChain-R1-9B** is a 9B vision-language model for **sequential medical image grounding**: given a short sequence ofmedical images and a question, it writes a short rationale in `<think>β¦</think>` and then returns one bounding box`<answer>(x1,y1),(x2,y2)</answer>` in pixel coordinates of the target image. It is built on[Qwen3.5-9B](https://huggingface.co/Qwen/Qwen3.5-9B) in two stages:
1. **CoT-SFT** on the MedChain rationale corpus: 152,396 MedSG training sequences, each with a box-conditioned rationale (FlemingVL-38B draft, refined by Qwen3.5-397B-A17B with the annotated box as privileged input).2. **GRPO** with an IoU reward on a held-out 30,000-prompt pool (3,750 per task), 8 rollouts per prompt, frozen vision tower.
Training stage of this checkpoint: CoT-SFT (checkpoint-2500) β GRPO on RL30K, two epochs (step 2500 of the second epoch, seed 45).
On MedSG-Bench (8 tasks, 10 modalities, 9,630 test examples), MedChain-R1-9B reaches **77.54 mIoU / 84.87 Acc@0.5**.
---
## π Benchmark Performance
### MedSG-Bench (IoU per task, average IoU / Acc@0.5)
| Model | Size | RDG | NRDG | MV | OT | Concept | Patch | Cross-modal | Referring | **Avg IoU / Acc@0.5** ||---|---|---:|---:|---:|---:|---:|---:|---:|---:|---:|| Qwen2.5-VL | 72B | 4.37 | 3.46 | 7.22 | 13.11 | 10.33 | 26.45 | 16.32 | 20.19 | 13.35 / 6.12 || InternVL3 | 78B | 0.20 | 0.53 | 6.35 | 13.03 | 3.57 | 11.81 | 3.34 | 12.76 | 6.44 / 2.90 || Migician | 7B | 15.26 | 14.49 | 18.16 | 21.38 | 14.23 | 28.87 | 21.41 | 25.30 | 20.29 / 11.39 || HuatuoGPT-Vision | 34B | 1.44 | 2.15 | 9.41 | 13.25 | 6.43 | 14.53 | 10.60 | 8.60 | 8.57 / 2.09 || MedSeq-Grounder | 7B | 83.29 | 83.72 | 55.03 | 62.10 | 74.11 | 85.25 | 78.77 | 60.43 | 72.55 / 79.71 || Qwen3.5 (zero-shot) | 4B / 9B / 27B | 0.0 | 0.0 | 8.3β8.6 | 26.7β28.4 | 0.3β1.5 | 1.6β2.7 | 0.3 | 0.8β1.7 | 4.4β4.5 / 3.0β3.2 || MedChain-R1-9B (CoT-SFT only) | 9B | 84.0 | 83.0 | 55.9 | 67.5 | 74.8 | 91.2 | 84.3 | 70.5 | 76.60 / 83.42 || MedChain-R1-4B | 4B | 83.5 | 82.0 | 56.6 | 66.7 | 71.8 | 90.3 | 84.0 | 70.2 | 75.97 / 83.67 || **MedChain-R1-9B (this model)** | 9B | 84.4 | 83.5 | 58.4 | 68.5 | 75.5 | 91.3 | 84.8 | 72.0 | 77.54 / 84.87 |
> RDG / NRDG = registered / non-registered difference grounding, MV = multi-view, OT = object tracking.> Baselines are the numbers reported for MedSG-Bench (zero-shot general and medical MLLMs; MedSeq-Grounder is trained on MedSG-188K).> MedChain-R1 rows are recomputed from per-example predictions: greedy decoding, batch size 1, bf16, 1,200 new tokens.> Benchmarked on AMD MI210 GPUs.
### Supported tasks
| Task | What the model grounds ||---|---|| Registered / non-registered difference | the region that changed between two scans || Multi-view | the same structure seen from another view || Object tracking | a lesion or structure across slices or time points || Concept | the region matching a described concept across images || Patch | where a given patch lies in the target image || Cross-modal | the same finding in another modality (e.g. FLAIR β DWI) || Referring | the region a text description refers to |
---
## π Quick Start
### Installation
```bashpip install "transformers==5.2.0" torch qwen-vl-utils==0.0.14```
### Basic Usage
```pythonimport torchfrom transformers import AutoModelForImageTextToText, AutoProcessorfrom qwen_vl_utils import process_vision_info
repo = "adidukrembzuai/MedChain-R1-9B"model = AutoModelForImageTextToText.from_pretrained(repo, torch_dtype=torch.bfloat16, device_map="auto").eval()processor = AutoProcessor.from_pretrained(repo)
question = "Locate the region that differs between the first and the second image."messages = [{ "role": "user", "content": [ {"type": "image", "image": "scan_t0.png"}, {"type": "image", "image": "scan_t1.png"}, {"type": "text", "text": question + "\nFirst output the thinking process in <think> </think> tags " "and then output the bounding box in <answer>(x1,y1),(x2,y2)</answer> tags."}, ],}]
text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)image_inputs, video_inputs = process_vision_info(messages)inputs = processor(text=[text], images=image_inputs, videos=video_inputs, return_tensors="pt").to(model.device)
with torch.inference_mode(): out = model.generate(**inputs, max_new_tokens=1200, do_sample=False)print(processor.decode(out[0, inputs["input_ids"].shape[1]:], skip_special_tokens=True))# <think> ... </think><answer>(x1,y1),(x2,y2)</answer>```
**Notes**
* Append the instruction above to every question; it is the prompt the model was trained and evaluated with.* Generate one example at a time: batched generation produced degenerate outputs for some checkpoints.* `eval/eval_bench.py` in the [code repository](https://github.com/adinathdukre/MedChain-R1) is the exact evaluation script.
---
## π¦ Model Family
| Model | Base | MedSG-Bench mIoU / Acc@0.5 | Best for ||---|---|---:|---|| [MedChain-R1-9B](https://huggingface.co/adidukrembzuai/MedChain-R1-9B) | Qwen3.5-9B | 77.54 / 84.87 | highest accuracy β **recommended** || [MedChain-R1-4B](https://huggingface.co/adidukrembzuai/MedChain-R1-4B) | Qwen3.5-4B | 75.97 / 83.67 | resource-constrained environments |
---
## β οΈ Limitations
Research artefact. Trained and evaluated on MedSG data only; **not validated for diagnosis or any clinical use**. Therationales imitate teacher-written, box-conditioned explanations and are not a faithful account of how the box was chosen.
---
## π License
Released under the **Apache License 2.0**. Built on Qwen3.5 (Apache-2.0); the GRPO code derives from open-r1-multimodal andUniVG-R1 (Apache-2.0). MedSG images keep their original licences and are not included..gitattributes+1
README.mdAdded+146
overview.pngAdded

Large File Pointer Details
- SHA256: dde135fc315ad4513badbcca32e75b16f65e65c5ed03f6ecf6e4acc7dc3668a0
- Pointer size: 131 Bytes
- Size of remote file: 798 kB