Image-Text-to-Text
Transformers
Safetensors
English
qwen2_5_vl
Pathology
VLM
Reasoning
conversational
text-generation-inference
Instructions to use ChiPhan1110/ScaleReasoner-R1 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use ChiPhan1110/ScaleReasoner-R1 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="ChiPhan1110/ScaleReasoner-R1") 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)# Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("ChiPhan1110/ScaleReasoner-R1") model = AutoModelForMultimodalLM.from_pretrained("ChiPhan1110/ScaleReasoner-R1") 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=40) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use ChiPhan1110/ScaleReasoner-R1 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "ChiPhan1110/ScaleReasoner-R1" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "ChiPhan1110/ScaleReasoner-R1", "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/ChiPhan1110/ScaleReasoner-R1
- SGLang
How to use ChiPhan1110/ScaleReasoner-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 "ChiPhan1110/ScaleReasoner-R1" \ --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": "ChiPhan1110/ScaleReasoner-R1", "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 "ChiPhan1110/ScaleReasoner-R1" \ --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": "ChiPhan1110/ScaleReasoner-R1", "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 ChiPhan1110/ScaleReasoner-R1 with Docker Model Runner:
docker model run hf.co/ChiPhan1110/ScaleReasoner-R1
Create README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,305 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<h1 align="center">[MICCAI 2026] Enhancing Pathological VLMs with Cross-scale Reasoning</h1>
|
| 2 |
+
|
| 3 |
+
<p align="center"> Chi Phan*, Tianyi Zhang*, Qiaochu Xue, Yufeng Wu, Dan Hu, Zeyu Liu, Sudong Wang, Yueming Jin </p>
|
| 4 |
+
|
| 5 |
+
<p align="center">
|
| 6 |
+
<a href="https://conferences.miccai.org/2026/en/default.asp">
|
| 7 |
+
<img src="https://img.shields.io/badge/MICCAI-2026-blue" alt="MICCAI 2026" />
|
| 8 |
+
</a>
|
| 9 |
+
<a href="https://arxiv.org/abs/2606.17412">
|
| 10 |
+
<img src="https://img.shields.io/badge/Paper-arXiv-red" alt="Paper arXiv" />
|
| 11 |
+
</a>
|
| 12 |
+
<a href="https://huggingface.co/ChiPhan1110/ScaleReasoner-R1">
|
| 13 |
+
<img src="https://img.shields.io/badge/%F0%9F%A4%97%20Model-ScaleReasoner--R1-green" alt="Model ScaleReasoner-R1" />
|
| 14 |
+
</a>
|
| 15 |
+
<a href="https://huggingface.co/ChiPhan1110/ScaleReasoner-R1">
|
| 16 |
+
<img src="https://img.shields.io/badge/%F0%9F%A4%97%20Data-Scale--VQA-yellow" alt="Data Scale-VQA" />
|
| 17 |
+
</a>
|
| 18 |
+
</p>
|
| 19 |
+
|
| 20 |
+
## 🔬 Overview
|
| 21 |
+
Pathological diagnosis is inherently multi-scale: pathologists reason from global tissue architecture at low magnification down to cellular morphology at high magnification, integrating evidence across views before reaching a conclusion. While existing pathological datasets for vision-language models (VLMs) include various scales, they often lack explicit cross-scale reasoning objectives. This limitation prevents VLMs from capturing essential cross-scale representations and learning evidence-based reasoning.
|
| 22 |
+
|
| 23 |
+
We introduce the **first cross-scale training and evaluation paradigm** for pathological VLMs, along with:
|
| 24 |
+
|
| 25 |
+
- **Scale-VQA** - a high-quality benchmark of 4,685 leakage-aware multiple-choice questions grounded in multi-magnification pathology images across 15 organs and 5 clinically-aligned reasoning dimensions.
|
| 26 |
+
- **ScaleReasoner-R1** - a pathology VLM trained with Group Relative Policy Optimization (GRPO) that achieves state-of-the-art performance on cross-scale multi-image VQA and transfers strongly to established single-image benchmarks.
|
| 27 |
+
|
| 28 |
+
## 🧩 Method
|
| 29 |
+
|
| 30 |
+
<div align="center">
|
| 31 |
+
<img src="assets/method_fig.png" alt="Method Overview" width="95%">
|
| 32 |
+
|
| 33 |
+
**(a)** Leakage-aware curation pipeline for Scale-VQA. **(b)** Dataset overview across organs and magnifications. **(c)** GRPO-based reinforcement learning framework for ScaleReasoner-R1.
|
| 34 |
+
</div>
|
| 35 |
+
|
| 36 |
+
### Scale-VQA: Leakage-Aware Cross-Scale Benchmark
|
| 37 |
+
|
| 38 |
+
Naively constructed cross-scale VQA benchmarks suffer from **text-only shortcut solutions** — models can infer the correct answer from linguistic or biomedical priors without ever examining the images. Our curation pipeline eliminates these via three steps:
|
| 39 |
+
|
| 40 |
+
| Step | Description |
|
| 41 |
+
|------|-------------|
|
| 42 |
+
| **Scale-specific Feature Decomposition** | Expert annotations are decomposed into per-scale evidence sets; initial visual-grounding and scale-dependency constraints are imposed. |
|
| 43 |
+
| **Text-only Adversarial Screening** | Gemini 3 Pro and Qwen3-Max act as text-only adversaries. If either model answers correctly without images, constraints are tightened and questions are regenerated. |
|
| 44 |
+
| **Cross-scale MCQ Construction & Clinical Validation** | Final MCQs are reviewed by senior pathologists to confirm that correct answers are visually grounded and distractors are clinically plausible. |
|
| 45 |
+
|
| 46 |
+
### ScaleReasoner-R1: Cross-scale Reasoning via RL
|
| 47 |
+
ScaleReasoner-R1 is initialized from **Patho-R1-7B** and fine-tuned with **GRPO** on Scale-VQA. Given a multi-scale image set $I = \{I^{10\times}, I^{40\times}, I^{200\times}\}$, a question, and options, the model generates a structured response with a reasoning trace (`<think>`) followed by a final answer (`<answer>`).
|
| 48 |
+
|
| 49 |
+
**Training Dynamics:**
|
| 50 |
+
|
| 51 |
+
<div align="center">
|
| 52 |
+
|
| 53 |
+
| Training Reward | Validation Accuracy |
|
| 54 |
+
|:-------------------:|:---------------:|
|
| 55 |
+
| <img src="assets/rl_curve_critic.png" width="420"> | <img src="assets/rl_curve_val.png" width="500"> |
|
| 56 |
+
</div>
|
| 57 |
+
|
| 58 |
+
## 🏆 Results
|
| 59 |
+
<div align="center">
|
| 60 |
+
<img src="assets/eval.png" alt="Evaluation Results" width="80%">
|
| 61 |
+
</div>
|
| 62 |
+
|
| 63 |
+
### Cross-scale Multi-image VQA
|
| 64 |
+
|
| 65 |
+
| Model | Corresp. | Confirm. | Localiz. | Explan. | Diagno. | **AVG** |
|
| 66 |
+
|-------|:--------:|:--------:|:--------:|:-------:|:-------:|:-------:|
|
| 67 |
+
| Qwen2.5-VL-7B | 41.79 | 47.26 | 71.14 | 44.28 | 63.68 | 53.63 |
|
| 68 |
+
| Gemini 3 Flash | 48.26 | 58.71 | 71.64 | 53.73 | 72.14 | 60.90 |
|
| 69 |
+
| GPT-5.2 | 47.76 | 59.70 | 74.13 | 45.77 | 65.17 | 58.51 |
|
| 70 |
+
| LLaVA-Med-7B | 25.87 | 16.92 | 28.36 | 20.90 | 24.88 | 23.38 |
|
| 71 |
+
| Quilt-LLaVA | 32.34 | 14.43 | 45.27 | 30.35 | 29.35 | 30.35 |
|
| 72 |
+
| CLOVER | 37.31 | 61.69 | 73.13 | 46.27 | 65.77 | 56.82 |
|
| 73 |
+
| Patho-R1 | 31.84 | 40.30 | 59.70 | 56.22 | 68.66 | 51.34 |
|
| 74 |
+
| **ScaleReasoner-R1** | **80.60** | **89.05** | **84.58** | **76.12** | **84.08** | **82.89** |
|
| 75 |
+
|
| 76 |
+
### Single-image VQA (PathMMU)
|
| 77 |
+
|
| 78 |
+
| Model | Overall | PubMed | SocialPath | EduContent | Atlas | PathCLS |
|
| 79 |
+
|-------|:------------:|:------:|:----------:|:----------:|:-----:|:-------:|
|
| 80 |
+
| Patho-R1 | 64.8 | 68.7 | 63.9 | 65.7 | 73.5 | 41.8 |
|
| 81 |
+
| **ScaleReasoner-R1** | **66.2** | **71.2** | **67.6** | **67.6** | **79.3** | 37.9 |
|
| 82 |
+
|
| 83 |
+
---
|
| 84 |
+
|
| 85 |
+
## 📁 Repository Structure
|
| 86 |
+
```text
|
| 87 |
+
ScaleReasoner-R1/
|
| 88 |
+
├── assets/
|
| 89 |
+
├── data/ # Cross-scale VQA json by split
|
| 90 |
+
├── preprocess/
|
| 91 |
+
│ ├── generate_vqa_data/ # Feature extraction, VQA generation, split creation
|
| 92 |
+
│ └── prompts/ # Leakage-aware prompt templates and constraints
|
| 93 |
+
├── script/
|
| 94 |
+
│ ├── preprocess/ # End-to-end preprocessing entrypoints
|
| 95 |
+
│ ├── train/ # SFT and GRPO launch scripts
|
| 96 |
+
│ └── postprocess/ # Postprocess after training
|
| 97 |
+
├── LLaMA-Factory/ # SFT training framework
|
| 98 |
+
└── verl/ # RL training framework
|
| 99 |
+
```
|
| 100 |
+
## 🚀 Getting Started
|
| 101 |
+
|
| 102 |
+
### Environment Setup
|
| 103 |
+
|
| 104 |
+
```bash
|
| 105 |
+
# Clone the repository
|
| 106 |
+
git clone https://github.com/iMVR-PL/ScaleReasoner-R1.git
|
| 107 |
+
cd ScaleReasoner-R1
|
| 108 |
+
|
| 109 |
+
# Set up environment variables
|
| 110 |
+
cp script/.env.example script/.env
|
| 111 |
+
# Edit script/.env with your paths and API keys
|
| 112 |
+
```
|
| 113 |
+
|
| 114 |
+
Configure `script/.env`:
|
| 115 |
+
|
| 116 |
+
```bash
|
| 117 |
+
# Data paths
|
| 118 |
+
DATA_DIR=/path/to/triplet_raw_data
|
| 119 |
+
ROOT=/path/to/ScaleReasoner-R1
|
| 120 |
+
PROCESSED_DIR=/path/to/processed_data
|
| 121 |
+
|
| 122 |
+
# Model paths
|
| 123 |
+
ACTOR_MODEL_DIR=/path/to/patho-r1-7b # base model (Patho-R1-7B)
|
| 124 |
+
RESULTS_DIR=/path/to/results
|
| 125 |
+
|
| 126 |
+
# Logging
|
| 127 |
+
LOG_DIR=/path/to/logs
|
| 128 |
+
WANDB_DIR=/path/to/wandb
|
| 129 |
+
|
| 130 |
+
# API keys (for VQA generation pipeline)
|
| 131 |
+
GEMINI_API_KEY=...
|
| 132 |
+
OPENAI_API_KEY=...
|
| 133 |
+
DASHSCOPE_API_KEY=...
|
| 134 |
+
HF_TOKEN=...
|
| 135 |
+
```
|
| 136 |
+
|
| 137 |
+
**RL environment (verl).** ScaleReasoner-R1 is trained with [verl](https://github.com/volcengine/verl). Please follow the [verl installation guide](https://verl.readthedocs.io/en/latest/start/install.html) to set up the environment, then install the local copy:
|
| 138 |
+
|
| 139 |
+
```bash
|
| 140 |
+
conda create -n verl python=3.10 -y && conda activate verl
|
| 141 |
+
pip install -e verl/
|
| 142 |
+
```
|
| 143 |
+
|
| 144 |
+
**SFT environment (LLaMA-Factory).** The SFT baseline uses [LLaMA-Factory](https://github.com/hiyouga/LLaMA-Factory):
|
| 145 |
+
|
| 146 |
+
```bash
|
| 147 |
+
conda create -n sft python=3.10 -y && conda activate sft
|
| 148 |
+
pip install -e LLaMA-Factory/
|
| 149 |
+
```
|
| 150 |
+
|
| 151 |
+
> Both environments require CUDA 12.1+ and PyTorch 2.3+. We recommend using separate conda environments for RL and SFT to avoid dependency conflicts.
|
| 152 |
+
|
| 153 |
+
## 🗂️ Dataset
|
| 154 |
+
|
| 155 |
+
Download **Scale-VQA** from [HuggingFace](https://huggingface.co/datasets/iMVR-PL/Scale-VQA). The `data/` directory contains the train/val/test splits in JSON format. Each sample includes:
|
| 156 |
+
|
| 157 |
+
```json
|
| 158 |
+
{
|
| 159 |
+
"question": "...",
|
| 160 |
+
"options": { "A": "...", "B": "...", "C": "...", "D": "..." },
|
| 161 |
+
"answer": "D",
|
| 162 |
+
"rationale": "...",
|
| 163 |
+
"image_path": {
|
| 164 |
+
"low_mag": "wsi_id/rois/10_....jpg",
|
| 165 |
+
"mid_mag": "wsi_id/rois/40_....jpg",
|
| 166 |
+
"high_mag": "wsi_id/rois/200_....jpg"
|
| 167 |
+
}
|
| 168 |
+
}
|
| 169 |
+
```
|
| 170 |
+
|
| 171 |
+
## 🤖 Training & Inference
|
| 172 |
+
|
| 173 |
+
### RL Training (ScaleReasoner-R1)
|
| 174 |
+
|
| 175 |
+
We use [**verl**](https://github.com/volcengine/verl) for GRPO-based RL training:
|
| 176 |
+
|
| 177 |
+
```bash
|
| 178 |
+
conda create -n verl python=3.10 -y && conda activate verl
|
| 179 |
+
pip install -e verl/
|
| 180 |
+
|
| 181 |
+
bash script/train/run_grpo_cross_scale_vqa.sh
|
| 182 |
+
```
|
| 183 |
+
|
| 184 |
+
Key hyperparameters: `n=5` rollouts per question, `total_epochs=5`, `train_batch_size=32`. The custom reward function is at `verl/verl/utils/reward_score/cross_scale_vqa.py`.
|
| 185 |
+
|
| 186 |
+
### SFT Baseline
|
| 187 |
+
|
| 188 |
+
We use [**LLaMA-Factory**](https://github.com/hiyouga/LLaMA-Factory) for supervised fine-tuning:
|
| 189 |
+
|
| 190 |
+
```bash
|
| 191 |
+
conda create -n sft python=3.10 -y && conda activate sft
|
| 192 |
+
pip install -e LLaMA-Factory/
|
| 193 |
+
|
| 194 |
+
bash script/train/run_sft_pathor1_new_triplet_mcq_think_only.sh
|
| 195 |
+
```
|
| 196 |
+
|
| 197 |
+
### Inference
|
| 198 |
+
|
| 199 |
+
Download **ScaleReasoner-R1** from [HuggingFace](https://huggingface.co/ChiPhan1110/ScaleReasoner-R1). ScaleReasoner-R1 was trained to produce structured outputs using `<think>` and `<answer>` tags. To ensure reproducible results, pass the system prompt below:
|
| 200 |
+
|
| 201 |
+
```python
|
| 202 |
+
SYSTEM_PROMPT = (
|
| 203 |
+
"You are a pathology expert. Read the question and options about the image carefully. "
|
| 204 |
+
"Think step by step inside <think> </think>. Then output ONLY the SINGLE best option letter "
|
| 205 |
+
"inside <answer> </answer>.\n"
|
| 206 |
+
"Example: <think>Your reasoning</think> <answer>A</answer>. "
|
| 207 |
+
"Do not include the option text or any extra words inside <answer> </answer> tags."
|
| 208 |
+
)
|
| 209 |
+
```
|
| 210 |
+
|
| 211 |
+
**Option 1 — vLLM server (recommended for batched evaluation)**
|
| 212 |
+
|
| 213 |
+
```bash
|
| 214 |
+
vllm serve <path/to/ScaleReasoner-R1> \
|
| 215 |
+
--host 0.0.0.0 \
|
| 216 |
+
--port 8000 \
|
| 217 |
+
--tensor-parallel-size 1 \
|
| 218 |
+
--max-model-len 8192 \
|
| 219 |
+
--limit-mm-per-prompt.image 5
|
| 220 |
+
|
| 221 |
+
```
|
| 222 |
+
|
| 223 |
+
Then query via the OpenAI-compatible client:
|
| 224 |
+
|
| 225 |
+
```python
|
| 226 |
+
from openai import OpenAI
|
| 227 |
+
import base64
|
| 228 |
+
|
| 229 |
+
def encode_image(path):
|
| 230 |
+
with open(path, "rb") as f:
|
| 231 |
+
return base64.b64encode(f.read()).decode("utf-8")
|
| 232 |
+
|
| 233 |
+
client = OpenAI(base_url="http://localhost:8000/v1", api_key="token")
|
| 234 |
+
|
| 235 |
+
response = client.chat.completions.create(
|
| 236 |
+
model="ChiPhan1110/ScaleReasoner-R1",
|
| 237 |
+
messages=[{
|
| 238 |
+
"role": "user",
|
| 239 |
+
"content": [
|
| 240 |
+
{"type": "image_url", "image_url": {"url": f"data:image/jpeg;base64,{encode_image('low_mag.jpg')}"}},
|
| 241 |
+
{"type": "image_url", "image_url": {"url": f"data:image/jpeg;base64,{encode_image('mid_mag.jpg')}"}},
|
| 242 |
+
{"type": "image_url", "image_url": {"url": f"data:image/jpeg;base64,{encode_image('high_mag.jpg')}"}},
|
| 243 |
+
{"type": "text", "text": "<question>\n(A) ...\n(B) ...\n(C) ...\n(D) ..."},
|
| 244 |
+
]
|
| 245 |
+
}],
|
| 246 |
+
max_tokens=4096,
|
| 247 |
+
)
|
| 248 |
+
print(response.choices[0].message.content)
|
| 249 |
+
```
|
| 250 |
+
|
| 251 |
+
**Option 2 — Hugging Face Transformers**
|
| 252 |
+
|
| 253 |
+
```python
|
| 254 |
+
from transformers import Qwen2_5_VLForConditionalGeneration, AutoProcessor
|
| 255 |
+
from qwen_vl_utils import process_vision_info
|
| 256 |
+
|
| 257 |
+
model = Qwen2_5_VLForConditionalGeneration.from_pretrained(
|
| 258 |
+
"ChiPhan1110/ScaleReasoner-R1", torch_dtype="auto", device_map="auto"
|
| 259 |
+
)
|
| 260 |
+
processor = AutoProcessor.from_pretrained("ChiPhan1110/ScaleReasoner-R1")
|
| 261 |
+
|
| 262 |
+
messages = [{
|
| 263 |
+
"role": "user",
|
| 264 |
+
"content": [
|
| 265 |
+
{"type": "image", "image": "low_mag.jpg"},
|
| 266 |
+
{"type": "image", "image": "mid_mag.jpg"},
|
| 267 |
+
{"type": "image", "image": "high_mag.jpg"},
|
| 268 |
+
{"type": "text", "text": "<question>\n(A) ...\n(B) ...\n(C) ...\n(D) ..."},
|
| 269 |
+
]
|
| 270 |
+
}]
|
| 271 |
+
|
| 272 |
+
text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
| 273 |
+
image_inputs, _ = process_vision_info(messages)
|
| 274 |
+
inputs = processor(text=[text], images=image_inputs, return_tensors="pt").to(model.device)
|
| 275 |
+
|
| 276 |
+
output = model.generate(**inputs, max_new_tokens=4096)
|
| 277 |
+
print(processor.decode(output[0][len(inputs.input_ids[0]):], skip_special_tokens=True))
|
| 278 |
+
```
|
| 279 |
+
|
| 280 |
+
|
| 281 |
+
## 🙏 Acknowledgements
|
| 282 |
+
|
| 283 |
+
This work was supported by the Ministry of Education, Singapore, under the Tier 1 grant (24-1250-P0001) and Tier 2 grant (T2EP20224-0028), and by PuzzleLogic Pte Ltd, Singapore.
|
| 284 |
+
|
| 285 |
+
We gratefully acknowledge the open-source projects that made the development of **ScaleReasoner-R1** possible:
|
| 286 |
+
- [**verl**](https://github.com/volcengine/verl), for the reinforcement learning training framework.
|
| 287 |
+
- [**LLaMA-Factory**](https://github.com/hiyouga/LLaMA-Factory), for the unified fine-tuning pipelines.
|
| 288 |
+
- [**vLLM**](https://github.com/vllm-project/vllm), for efficient large language model inference and serving.
|
| 289 |
+
|
| 290 |
+
We also acknowledge the following open-source models used for comparison in our experiments: [Qwen2.5-VL-7B](https://huggingface.co/Qwen/Qwen2.5-VL-7B-Instruct), [LLaVA-Med-7B](https://github.com/microsoft/LLaVA-Med), [HuaTuoGPT-7B](https://github.com/FreedomIntelligence/HuatuoGPT-Vision), [Lingshu-7B](https://huggingface.co/lingshu-medical-mllm/Lingshu-7B), [Quilt-LLaVA](https://github.com/aldraus/quilt-llava), [CLOVER](https://huggingface.co/jline/CLOVER-Qwen2.5-VL), and [Patho-R1](https://github.com/wenchuan-zhang/patho-r1).
|
| 291 |
+
|
| 292 |
+
We sincerely thank the developers and contributors of these projects for their excellent work and for making their code and models publicly available to the research community.
|
| 293 |
+
|
| 294 |
+
## ❤️ Citation
|
| 295 |
+
|
| 296 |
+
If you find our work helpful, please consider citing our paper and the frameworks we build upon:
|
| 297 |
+
```bibtex
|
| 298 |
+
@article{phan2026enhancing,
|
| 299 |
+
title={Enhancing Pathological VLMs with Cross-scale Reasoning},
|
| 300 |
+
author={Phan, Chi and Zhang, Tianyi and Xue, Qiaochu and Wu, Yufeng and Hu, Dan and Liu, Zeyu and Wang, Sudong and Jin, Yueming},
|
| 301 |
+
journal={arXiv preprint arXiv:2606.17412},
|
| 302 |
+
year={2026}
|
| 303 |
+
}
|
| 304 |
+
|
| 305 |
+
```
|