Downloads · 30 days
86
35% of all-time downloads
shahedm2001/qwen3-vl-2b-cataract-grpo
qwen3-vl-2b-cataract-grpo is a image-text-to-text model from shahedm2001. Use it for the image-text-to-text task on the model card, and read the license before you ship it in a product. It is set up for transformers. The card lists the license as apache-2.0.
[](https://opensource.org/licenses/Apache-2.0) [](https://huggingface.co/datasets/shahedm2001/qwen3-vl-2b-cataract-grpo-runs)
Downloads · 30 days
86
35% of all-time downloads
All-time downloads
244
Public
Parameters
2.1B
14.6 GB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors6.3 GB · 60%
From the Hugging Face model README
Qwen3-VL-2B Cataract Surgery GRPO is a multimodal vision-language model trained via a novel Two-Stage Group Relative Policy Optimization (GRPO) curriculum for autonomous clinical surgical video analysis. The model specializes in real-time understanding of cataract surgical procedures (phacoemulsification), multi-choice clinical reasoning, temporal localization, surgical phase transition boundary detection, and instrument identification.
The final model weights are provided as fully merged 16-bit BFloat16 weights (model.safetensors), ready for direct inference with Hugging Face transformers and qwen-vl-utils.
Qwen3-VL-2B-Instructshahedm2001/qwen3-vl-2b-cataract-grpo-runs.Fine-tuning vision-language models on surgical video presents a severe task-space asymmetry across the clinical dataset:
In standard single-stage GRPO, this asymmetry causes an Exploration Bottleneck & Zero-Advantage Trap for high-cardinality tasks. To resolve this, training was structured into two specialized stages:
┌─────────────────────────────────────────────────────────────────────────────┐
│ SFT Checkpoint (Stage 1 & 2) │
│ shahedm2001/qwen3-vl-2b-cataract-sft-stage2 │
└──────────────────────────────────────┬──────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────────────────┐
│ STAGE 1: Foundation Multi-Task GRPO (Steps 1–532) │
│ • Dataset: 4,252 clips (80.5% MCQs, 10.0% Continuous, 9.5% Phase) │
│ • Exploration: G = 4 rollouts per prompt, micro-prompt batching │
│ • Outcome: MCQs reached ~100%; Continuous tIoU grew from 0.49 to 0.76; │
│ Phase Recognition plateaued at ~36–42% (62.6% zero-std rate). │
└──────────────────────────────────────┬──────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────────────────┐
│ STAGE 2: Phase Specialization & Anti-Forgetting Replay (Steps 533–596) │
│ • Dataset: 506 clips (80% Phase Tasks, 10% MCQs Replay, 10% Continuous) │
│ • Algorithmic Innovation: G = 8 rollouts per prompt (boosted exploration) │
│ • Theoretical Gain: Zero-gradient rate dropped from ~63% down to <15% │
│ • Outcome: Phase Accuracy jumped to 65%–75% while MCQs remained at ~100% │
└──────────────────────────────────────┬──────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────────────────┐
│ Final Merged Standalone Model (16-bit BF16) │
│ shahedm2001/qwen3-vl-2b-cataract-grpo │
└─────────────────────────────────────────────────────────────────────────────┘
learning_rate = 5e-5, (\beta = 0.04).$$ 1 - (1 - 0.0769)^4 \approx 27.2% $$
$$ \hat{A}_i = \frac{R_i - \text{mean}(R)}{\text{std}(R) + \epsilon} $$
timestamp_to_phase + 201 contextual_phase_recognition).num_generations = 8).$$ 1 - (1 - 0.35)^8 = 96.8% $$
learning_rate = 4e-5, beta = 0.05 (elevated KL penalty to preserve general representations), 1 full epoch across 506 clips (64 optimizer steps).APPEND_LOGS=1 preserved the continuous log history, and TensorBoard event streams were dynamically stitched with a (+532) global step offset.| Hyperparameter | Stage 1 (Foundation GRPO) | Stage 2 (Phase Specialization) | Rationale |
|---|---|---|---|
| Base Model Initialization | SFT Stage 2 Checkpoint | Stage 1 Merged 16-bit Weights | Progressive policy refinement |
| Training Samples | 4,252 video clips | 506 curated clips | 80% Phase focus + 20% Replay anchors |
| Optimizer Steps | 532 steps (1 epoch) | 64 steps (1 epoch) | Short targeted specialization |
| Rollouts per Prompt ((G)) | 4 rollouts | 8 rollouts | Boost exploration in 13-class phase space |
| Zero-Gradient Prompt Rate | 62.6% on Phase | < 15% on Phase | Dense non-zero advantage signals |
| Prompts per Step | 8 prompts (32 rollouts) | 8 prompts (64 rollouts) | Maintained effective batch size |
| Micro-Prompt Batching | GRPO_MICRO_PROMPTS = 1 | GRPO_MICRO_PROMPTS = 1 | Keeps peak VRAM (\approx 19.2,\text{GB}) on 24GB GPUs |
| Learning Rate (LLM LoRA) | 5e-5 | 4e-5 | Controlled fine-tuning rate |
| Vision Tower LR | 1e-6 | 1e-6 | Protect visual feature extractor |
| Multimodal Projector LR | 5e-6 | 5e-6 | Maintain cross-modal alignment |
| KL Penalty ((\beta)) | 0.04 | 0.05 | Elevated KL penalty to prevent drift |
| Video Frames ((N)) | 50 uniform frames | 50 uniform frames | Consistent temporal receptive field |
| Frame Resolution Range | ([131072, 196608]) pixels | ([131072, 131072]) pixels | Memory stabilization under (G = 8) |
Training utilizes multi-objective deterministic rule-based reward formulations:
$$ R_{\text{total}} = R_{\text{task}} + 0.05 \times R_{\text{format}} $$
Within each slice, group relative advantage normalization is computed across (G) rollouts:
$$ \hat{A}_i = \frac{R_i - \text{mean}({R_1, \dots, R_G})}{\text{std}({R_1, \dots, R_G}) + \epsilon} $$
4-Choice Surgical Video MCQs (Discrete (R_{\text{task}} \in {0.0, 1.0})):
13-Class Surgical Phase Recognition (Discrete (R_{\text{task}} \in {0.0, 1.0})):
Temporal Localization (Continuous (R_{\text{task}} \in [0.0, 1.0])):
$$ R_{\text{task}} = \frac{|[\hat{t}_1, \hat{t}_2] \cap [t^_1, t^_2]|}{|[\hat{t}_1, \hat{t}_2] \cup [t^_1, t^_2]|} $$
$$ R_{\text{task}} = \exp\left(-\frac{|\hat{t} - t^*|}{1.5}\right) $$
{"explanation": "...", "answer": "..."}.

timestamp_to_phase surged from 42.9% (\to) 73.5% (+30.6% absolute gain), and contextual_phase_recognition climbed from 36.7% (\to) 65.2% (+28.5% absolute gain).
0.488 (Early) (\to) 0.650 (Mid) (\to) 0.758 (Late) (\to) 0.781 (Stage 2), with individual prompt rollouts exceeding (t\text{IoU} > 0.85).4.38 seconds (Early) down to 1.15 seconds (Late) and reached sub-second precision ((< 0.9,\text{s})) during Stage 2.

0.00, gradient norms remained bounded between 0.10 and 0.40, and trust-region KL divergence ((D_{\text{KL}})) stayed tightly contained within [0.015, 0.035].37.4% up to >85%, unlocking sustained policy updates across clinical surgical video episodes.pip install torch transformers accelerate qwen-vl-utils decord
import json
import torch
from transformers import AutoProcessor, AutoModelForImageTextToText
from qwen_vl_utils import process_vision_info
model_id = "shahedm2001/qwen3-vl-2b-cataract-grpo"
# 1. Load model and processor
model = AutoModelForImageTextToText.from_pretrained(
model_id,
torch_dtype=torch.bfloat16,
device_map="auto"
)
processor = AutoProcessor.from_pretrained(model_id)
# 2. Formulate video analysis query
messages = [
{
"role": "user",
"content": [
{
"type": "video",
"video": "path/to/cataract_phacoemulsification_clip.mp4",
"nframes": 50,
"video_min_pixels": 131072,
"video_max_pixels": 196608,
},
{
"type": "text",
"text": "Identify the active surgical phase occurring at timestamp 14.5s in this video. Provide clinical explanation and output strictly in JSON format matching {\"explanation\": \"...\", \"phase_id\": \"...\", \"phase_name\": \"...\"}."
}
]
}
]
# 3. Preprocess inputs
prompt = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
image_inputs, video_inputs = process_vision_info(messages)
inputs = processor(
text=[prompt],
images=image_inputs,
videos=video_inputs,
padding=True,
return_tensors="pt"
).to("cuda")
# 4. Generate structured prediction
with torch.no_grad():
generated_ids = model.generate(
**inputs,
max_new_tokens=256,
temperature=0.2,
do_sample=False
)
generated_ids_trimmed = [
out_ids[len(in_ids):] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
]
response = processor.batch_decode(
generated_ids_trimmed,
skip_special_tokens=True,
clean_up_tokenization_spaces=False
)[0]
print("Model Output:")
print(response)
All training code, instrumentation scripts, TensorBoard event runs, and every intermediate 20-step adapter checkpoint are permanently archived:
shahedm2001/qwen3-vl-2b-cataract-grpo-runstraining_logs/logs.zip and tensorboard_data/.This model and its associated code are released under the Apache 2.0 License.