qwen3-vl-2b-cataract-grpo API & Inference Endpoint | FriendliAI
README
License: apache-2.0
📋 Model Summary
Model Architecture:Qwen3-VL-2B-Instruct
Training Methodology:Two-Stage Group Relative Policy Optimization (GRPO) with deterministic rule-based multi-objective reward functions.
Stage 1 (Foundation Multi-Task GRPO): 532 global optimizer steps (4,252 video clips) across all 7 surgical video tasks with G=4 rollouts per prompt.
Stage 2 (Targeted Phase Specialization & Continuous Alignment): 64 global optimizer steps (506 video clips) focused on 13-class surgical phase recognition and temporal alignment with boosted exploration (G=8 rollouts per prompt) and an anchor replay buffer to prevent catastrophic forgetting.
Modality: Surgical Video (50 frames) & Text Prompt → Structured JSON Clinical Output.
The Motivation for Two-Stage RL in Multi-Objective Surgical Video Tasks
Fine-tuning vision-language models on surgical video presents a severe task-space asymmetry across the clinical dataset:
Low-Cardinality Categorical Tasks: 4-choice Multiple Choice Questions (MCQs) have a random-chance baseline of 25.0%.
Dense Continuous Tasks: Temporal Localization (tIoU) and Transition Boundary Detection (∣Δt∣) offer smooth, continuous reward gradients in [0.05,1.05].
High-Cardinality Categorical Tasks: 13-class surgical phase recognition (P01 to P) has a random-chance baseline of only .
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:
text
┌─────────────────────────────────────────────────────────────────────────────┐│ 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 │└─────────────────────────────────────────────────────────────────────────────┘
Stage 1: Foundation Multi-Task GRPO (Steps 1–532)
Objective: Establish foundational visual reasoning across all surgical domains.
9.5% Phase Classification (Timestamp to Phase: 203, Contextual Phase: 201).
Rollout Configuration:G=4 generations per prompt, learning_rate = 5e-5, β=0.04.
Empirical Diagnostic & The Zero-Advantage Trap:
1−(1−0.0769)4≈27.2%
of generating at least one correct completion by exploration. In empirical logs, 62.6% of phase prompt groups had all 4 completions incorrect (R=0.05).
Because GRPO computes relative group advantage as:
A^i=std(R)+ϵRi−mean(R)
when all rollouts receive identical rewards, std(R)=0⟹A^i=0. The policy received zero gradient updates on nearly two-thirds of phase samples, limiting further improvement.
Objective: Overcome the exploration bottleneck on the 13-class phase recognition task while anchoring existing representations to prevent catastrophic forgetting.
Curated Dataset Architecture (506 samples):
Target Phase Focus (80% / 404 clips): 100% of all available phase data (203 timestamp_to_phase + 201 contextual_phase_recognition).
Surgical MCQ Replay Buffer (10% / 51 clips): Exactly 17 samples each of Visual Observation, Step ID, and Instrument ID.
📊 Empirical Evaluation & Learning Dynamics by Data Group
1. Group 1: 4-Choice Surgical Video MCQs
Visual Observation, Step Identification, and Instrument Identification (3,475 prompt slices):
All three tasks rapidly reached 100.0% accuracy during Stage 1.
Stage 2 Replay Retention: Evaluated across the Stage 2 anchor replay buffer (Steps 533–596), the model preserved 100.0% accuracy on Visual Observation and Step ID, and 94.1% on Instrument ID, proving zero catastrophic forgetting during phase specialization.
2. Group 2: 13-Class Surgical Phase Recognition Specialization
Timestamp to Phase & Contextual Phase Recognition (808 prompt slices):
The G=4 Exploration Bottleneck: In Stage 1, sampling only 4 rollouts in a 13-class categorical action space yielded identical zero rewards (R=0.05) on 62.6% of prompt slices, producing std(R)=0⟹A and zero policy gradients.
3. Group 3: Continuous Fine-Grained Temporal Tasks
Optimization Stability: Optimizer loss converged smoothly around 0.00, gradient norms remained bounded between 0.10 and 0.40, and trust-region KL divergence (DKL) stayed tightly contained within [0.015, 0.035].
Exploration Coverage: Active gradient groups (σ>0) rose from the Stage 1 baseline of 37.4% up to >85%, unlocking sustained policy updates across clinical surgical video episodes.
Milestone Checkpoints Included: Steps 20 through 520 (Stage 1) and Steps 20, 40, 60 (Stage 2).
Logs & TensorBoard: Complete continuous logs available in training_logs/logs.zip and tensorboard_data/.
📜 License
This model and its associated code are released under the Apache 2.0 License.
13
1/13≈7.69%
While surgical MCQs converged rapidly to >98–100% accuracy and continuous temporal localization increased from tIoU=0.488 to 0.758, 13-class phase recognition plateaued at 36.7% – 42.9%.
Mathematical Root Cause: In a 13-class action phase space, sampling only G=4 rollouts with baseline accuracy ∼10% has a probability of:
G
=
4
G=8
num_generations = 8
With the model's Stage 1 competency at ∼35%, generating 8 rollouts per prompt increased the probability of generating at least one correct rollout to:
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 ≈19.2GB 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 (β)
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
+
ϵ
Ri−mean({R1,…,RG})
Rtask
∈
{0.0,1.0}
Standardized phase categorization from P01 through P13 given frame timestamps or surrounding clinical context.
Evaluates the predicted time interval [t^1,t^2] against ground truth [t1∗,t2∗] using temporal Intersection over Union (tIoU):
2
]
∪
[
t1∗
,
t2∗
]
∣
∣[t^1,t^2]∩[t1∗,t2∗]∣
τ=1.5s
^
i
=
0
The G=8 Specialization Breakthrough: Increasing rollouts to G=8 boosted exploration discovery to 1−(1−0.35)8=96.8%, slashing zero-advantage prompt groups to < 15%.
Performance Jump: Accuracy on timestamp_to_phase surged from 42.9% → 73.5% (+30.6% absolute gain), and contextual_phase_recognition climbed from 36.7% → 65.2% (+28.5% absolute gain).
Phase Boundary Transition Detection (∣Δt∣):
4.38 seconds
1.15 seconds
<0.9s
The empirical CDF confirms that over 75% of predictions land well within the clinical scale window of τ=1.5s.