Image-Text-to-Text
Transformers
Safetensors
English
qwen2_5_vl
multimodal
Pathology
conversational
text-generation-inference
Instructions to use WenchuanZhang/Patho-R1-7B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use WenchuanZhang/Patho-R1-7B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="WenchuanZhang/Patho-R1-7B") 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("WenchuanZhang/Patho-R1-7B") model = AutoModelForMultimodalLM.from_pretrained("WenchuanZhang/Patho-R1-7B", 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 WenchuanZhang/Patho-R1-7B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "WenchuanZhang/Patho-R1-7B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "WenchuanZhang/Patho-R1-7B", "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/WenchuanZhang/Patho-R1-7B
- SGLang
How to use WenchuanZhang/Patho-R1-7B 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 "WenchuanZhang/Patho-R1-7B" \ --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": "WenchuanZhang/Patho-R1-7B", "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 "WenchuanZhang/Patho-R1-7B" \ --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": "WenchuanZhang/Patho-R1-7B", "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 WenchuanZhang/Patho-R1-7B with Docker Model Runner:
docker model run hf.co/WenchuanZhang/Patho-R1-7B
Update README.md
Browse files
README.md
CHANGED
|
@@ -1,3 +1,136 @@
|
|
| 1 |
-
---
|
| 2 |
-
license: cc-by-nc-nd-4.0
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: cc-by-nc-nd-4.0
|
| 3 |
+
language:
|
| 4 |
+
- en
|
| 5 |
+
pipeline_tag: image-text-to-text
|
| 6 |
+
library_name: transformers
|
| 7 |
+
tags:
|
| 8 |
+
- multimodal
|
| 9 |
+
- Pathology
|
| 10 |
+
- arxiv:2505.11404
|
| 11 |
+
extra_gated_prompt: >-
|
| 12 |
+
The Patho-R1-7B model and its associated materials are released under the CC-BY-NC-ND 4.0 license.
|
| 13 |
+
Access is restricted to non-commercial, academic research purposes only, with proper citation required.
|
| 14 |
+
Any commercial usage, redistribution, or derivative work (including training models based on this model or generating datasets from its outputs)
|
| 15 |
+
is strictly prohibited without prior written approval.
|
| 16 |
+
|
| 17 |
+
Users must register with an official institutional email address (generic domains such as @gmail, @qq, @hotmail, etc. will not be accepted).
|
| 18 |
+
By requesting access, you confirm that your information is accurate and current, and that you agree to comply with all terms listed herein.
|
| 19 |
+
If other members of your organization wish to use the model, they must register independently and agree to the same terms.
|
| 20 |
+
|
| 21 |
+
extra_gated_fields:
|
| 22 |
+
Full name (first and last): text
|
| 23 |
+
Institutional affiliation (no abbreviations): text
|
| 24 |
+
Role/Position:
|
| 25 |
+
type: select
|
| 26 |
+
options:
|
| 27 |
+
- Faculty/Principal Investigator
|
| 28 |
+
- PhD Student
|
| 29 |
+
- Postdoctoral Researcher
|
| 30 |
+
- Research Staff
|
| 31 |
+
- Other
|
| 32 |
+
Official institutional email (**must match your Hugging Face primary email; generic domains will be denied**): text
|
| 33 |
+
Intended research use (be specific): text
|
| 34 |
+
I agree to use this model only for non-commercial academic purposes: checkbox
|
| 35 |
+
I agree not to redistribute this model or share it outside of my individual usage: checkbox
|
| 36 |
+
I confirm that all submitted information is accurate and up to date: checkbox
|
| 37 |
+
---
|
| 38 |
+
## Introduction📝
|
| 39 |
+
While vision-language models have shown impressive progress in general medical domains, pathology remains a challenging subfield due to its high-resolution image requirements and complex diagnostic reasoning.
|
| 40 |
+
|
| 41 |
+
To address this gap, we introduce **Patho-R1-7B**, a multimodal pathology reasoner designed to enhance diagnostic understanding through structured reasoning. **Patho-R1-7B** is trained using a three-stage pipeline:
|
| 42 |
+
1. *Continued pretraining* on **3.5M pathology figure-caption pairs** for domain knowledge acquisition
|
| 43 |
+
2. *Supervised fine-tuning* on **500k expert-annotated Chain-of-Thought samples** to encourage reasoning
|
| 44 |
+
3. *Reinforcement learning* with **Group Relative Policy Optimization** to refine response quality
|
| 45 |
+
|
| 46 |
+
Experimental results show that **Patho-R1-7B** achieves strong performance across key pathology tasks, including **multiple choice questions** and **visual question answering**, highlighting its potential for real-world pathology AI applications.
|
| 47 |
+

|
| 48 |
+
|
| 49 |
+
### Quickstart🏃
|
| 50 |
+
Here we show a code snippet to show you how to use the chat model with `transformers` and `qwen_vl_utils`:
|
| 51 |
+
|
| 52 |
+
```python
|
| 53 |
+
from transformers import Qwen2_5_VLForConditionalGeneration, AutoProcessor
|
| 54 |
+
from qwen_vl_utils import process_vision_info
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
model = Qwen2_5_VLForConditionalGeneration.from_pretrained(
|
| 58 |
+
"WenchuanZhang/Patho-R1-7B",
|
| 59 |
+
torch_dtype="auto", device_map="auto"
|
| 60 |
+
)
|
| 61 |
+
processor = AutoProcessor.from_pretrained("WenchuanZhang/Patho-R1-7B")
|
| 62 |
+
|
| 63 |
+
# example question from Pathmmu-test-dataset
|
| 64 |
+
# ground truth: D
|
| 65 |
+
|
| 66 |
+
messages = [
|
| 67 |
+
{ "role": "system",
|
| 68 |
+
"content": [
|
| 69 |
+
{
|
| 70 |
+
"type": "image",
|
| 71 |
+
"image": "./images/241.jpg",
|
| 72 |
+
},
|
| 73 |
+
{"type": "text", "text": "You are a pathology expert, your task is to answer question step by step. Use the following format:<think> Your step-by-step reasoning </think><answer> Your final answer </answer>"},
|
| 74 |
+
],
|
| 75 |
+
|
| 76 |
+
},
|
| 77 |
+
{
|
| 78 |
+
"role": "user",
|
| 79 |
+
"content": [
|
| 80 |
+
{
|
| 81 |
+
"type": "image",
|
| 82 |
+
"image": "./images/241.jpg",
|
| 83 |
+
},
|
| 84 |
+
{"type": "text", "text": "What feature in the provided micrograph is indicative of chronic inflammation? /n A. Granuloma formation /n B. Multinucleated giant cells /n C. Neutrophilic infiltration /n D. Plasma cells with eccentrically placed nuclei"},
|
| 85 |
+
],
|
| 86 |
+
}
|
| 87 |
+
]
|
| 88 |
+
# Preparation for inference
|
| 89 |
+
text = processor.apply_chat_template(
|
| 90 |
+
messages, tokenize=False, add_generation_prompt=True
|
| 91 |
+
)
|
| 92 |
+
image_inputs, video_inputs = process_vision_info(messages)
|
| 93 |
+
inputs = processor(
|
| 94 |
+
text=[text],
|
| 95 |
+
images=image_inputs,
|
| 96 |
+
videos=video_inputs,
|
| 97 |
+
padding=True,
|
| 98 |
+
return_tensors="pt",
|
| 99 |
+
)
|
| 100 |
+
inputs = inputs.to(model.device)
|
| 101 |
+
|
| 102 |
+
# Inference: Generation of the output
|
| 103 |
+
generated_ids = model.generate(**inputs, max_new_tokens=2048)
|
| 104 |
+
generated_ids_trimmed = [
|
| 105 |
+
out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
|
| 106 |
+
]
|
| 107 |
+
output_text = processor.batch_decode(
|
| 108 |
+
generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
|
| 109 |
+
)
|
| 110 |
+
print(output_text)
|
| 111 |
+
```
|
| 112 |
+
## Acknowledgements🎖
|
| 113 |
+
|
| 114 |
+
We gratefully acknowledge the contributions of the open-source community, particularly the following projects which laid the foundation for various components of this work:
|
| 115 |
+
|
| 116 |
+
- [Qwen](https://github.com/QwenLM) for providing powerful vision language models that significantly advanced our multimodal understanding and generation capabilities.
|
| 117 |
+
- [DocLayout-YOLO](https://github.com/opendatalab/DocLayout-YOLO) for document layout detection.
|
| 118 |
+
- [PaddleOCR](https://github.com/PaddlePaddle/PaddleOCR) for comprehensive optical character recognition.
|
| 119 |
+
- [ModelScope Swift](https://github.com/modelscope/ms-swift) for efficient model serving and deployment tools.
|
| 120 |
+
- [LLaMA-Factory](https://github.com/hiyouga/LLaMA-Factory) for robust LLM training and fine-tuning pipelines.
|
| 121 |
+
- [VERL](https://github.com/volcengine/verl) for valuable visual-language pretraining resources.
|
| 122 |
+
- [DeepSeek](https://github.com/deepseek-ai) for high-quality models and infrastructure supporting text understanding.
|
| 123 |
+
|
| 124 |
+
We thank the authors and contributors of these repositories for their dedication and impactful work, which made our development of Patho-R1-3B possible.
|
| 125 |
+
|
| 126 |
+
## Citation❤️
|
| 127 |
+
If you find our work helpful, a citation would be greatly appreciated:
|
| 128 |
+
|
| 129 |
+
```
|
| 130 |
+
@article{zhang2025patho,
|
| 131 |
+
title={Patho-R1: A Multimodal Reinforcement Learning-Based Pathology Expert Reasoner},
|
| 132 |
+
author={Zhang, Wenchuan and Zhang, Penghao and Guo, Jingru and Cheng, Tao and Chen, Jie and Zhang, Shuwan and Zhang, Zhang and Yi, Yuhao and Bu, Hong},
|
| 133 |
+
journal={arXiv preprint arXiv:2505.11404},
|
| 134 |
+
year={2025}
|
| 135 |
+
}
|
| 136 |
+
```
|