Skip to content
Projects

About

ZoomLynx is a 4B visual reasoning agent for high-resolution images. With a single zoom tool, it learns when to inspect, where to zoom, and when to stop. Aperture-580 evaluates these decisions on 580 questions with annotated task categories and evidence regions.

Design & Media

How these counts are measured

What you can do

  • Preserving real failures and repairing them. When the first crop misses its target, we keep the model’s tool call and the image it saw. A teacher continues from that history. On repaired trajectories, only the corrected continuation is supervised.
  • Training a budgeted observation policy. With a single zoom tool and up to three calls, ZoomLynx learns when to inspect, where to zoom, and when to stop. We train the policy with Selective Zoom Training (M2), then compare two branches trained independently from M2, DPO (M3) and GSPO (M4).
  • Building a diagnostic benchmark. Aperture-580 annotates task categories and evidence regions so we can evaluate the model’s observation decisions alongside its final answers.

Measured star growth

in 24h
Collecting history
in 7 days
Collecting history
in 15 days
Collecting history
in 1 month
Collecting history

Net star changes over overlapping periods, not daily totals. Missing measurements are left blank. Stars measure attention, not software quality.

README.md

Original

ZoomLynx

English · 简体中文

Learning to Zoom In on What Matters

Active Visual Reasoning Selective Zoom Training vLLM

Paper PDF HF Model ModelScope Project Page GitHub Benchmark@HF Benchmark@MS

Aperture-580 · Downloads · Deployment · Quick Start · Evaluation · Training

ZoomLynx compares positions, reads fine details, counts objects and recovers from a missed crop.

📰 News

🧭 Contents

News · Highlights · Aperture-580 · Installation · Downloads · Deployment Options · Quick Start · Tool Protocol · Training & RL · Evaluation · Multi-View Examples · Documentation · License · Citation

✨ Research Highlights

  • Preserving real failures and repairing them. When the first crop misses its target, we keep the model’s tool call and the image it saw. A teacher continues from that history. On repaired trajectories, only the corrected continuation is supervised.
  • Training a budgeted observation policy. With a single zoom tool and up to three calls, ZoomLynx learns when to inspect, where to zoom, and when to stop. We train the policy with Selective Zoom Training (M2), then compare two branches trained independently from M2, DPO (M3) and GSPO (M4).
  • Building a diagnostic benchmark. Aperture-580 annotates task categories and evidence regions so we can evaluate the model’s observation decisions alongside its final answers.

🔎 Aperture-580

Aperture-580 contains 580 questions in four categories. The over-call rate is the fraction of Direct questions on which the model still zooms. Necessary-observation recall is the fraction of Necessary questions on which it zooms at least once. The annotated regions show whether the first crop contains the evidence. In a separate recovery test, every model starts from the same faulty first crop on each selected question.

Category Questions Expected behavior
Direct 162 Answer from the original image.
Necessary 243 Zoom in to inspect a local detail.
Multi-region 101 Combine evidence from several regions.
Stop 74 Abstain when the image cannot support an answer.

Download the bilingual annotations and run the dataset’s image tool to fetch all 580 evaluation images directly from Objects365 (216.1 MB of archive data). Prepare Aperture-580 images and evaluation input

Benchmark@HF · Benchmark@MS · Evaluation input format

🛠️ Installation

Use Linux and a CUDA-enabled PyTorch environment for vLLM serving. Run the examples from the repository root.

git clone https://github.com/Skywalker-yqz/ZoomLynx.git
cd ZoomLynx
python -m venv .venv
source .venv/bin/activate
python -m pip install -r requirements.txt
python scripts/check_env.py

Training on H800. The reference training stack records CUDA 12.9, PyTorch 2.8.0 and ms-swift 4.6.1. Install these pins in a separate training environment. SFT and DPO use FlashAttention-2 and DeepSpeed ZeRO-2. GSPO uses a separate verl installation. H800 environment notes

python -m venv .venv-h800
source .venv-h800/bin/activate
python -m pip install -r requirements-h800.txt
python -m pip install flash-attn --no-build-isolation

📥 Model and Benchmark Downloads

Artifact Contents Hugging Face ModelScope (coming soon)
ZoomLynx 4B M2 (SFT) checkpoint, based on Qwen3-VL-4B-Instruct HF Model MS Model
Aperture-580 580 questions, task labels and evidence regions Benchmark@HF Benchmark@MS

Use the Hugging Face links above to download the model weights and Aperture-580 annotations. Save the weights in weights/ZoomLynx/. The evaluation runner reads one JSON object per line. This record is from the original benchmark format guide.

{"sample_id":"sample_001","image":"sample_001.jpg","question":"...","reference_answer":"...","question_type":"blank","bucket":"necessary","oracle_region_0_1000":[100,200,400,500]}

🧩 Deployment Options

What you have How to serve it
Full ZoomLynx checkpoint Set MODEL to the directory containing config.json and the weight shards. The launcher exposes a vLLM chat endpoint.
LoRA adapter from local training Merge the selected adapter with training/merge_lora.sh and serve the merged directory with the same launcher.
Running model and SR services Point the demo or batch runner at --base-url (including /v1), --model and --sr-url (including /v1/sr/upscale). The model service must accept images and return structured tool calls. The demo and batch runner make unauthenticated Chat Completions requests to the configured model service.

⚡ Serve the model with vLLM

Activate the serving environment in each service and client terminal (for the environment above, run source .venv/bin/activate). Start the model server in its own terminal. It uses BF16 and the Hermes parser for automatic tool selection. SERVED_NAME sets the model ID that the inference and evaluation clients send in each request.

MODEL=weights/ZoomLynx SERVED_NAME=zoomlynx PORT=8000 \
  CUDA_VISIBLE_DEVICES=0 TP=1 bash inference/serve_vllm.sh

For tensor parallel serving, set CUDA_VISIBLE_DEVICES=0,1 TP=2 on a two-GPU allocation. MAX_LEN (49,152), MAX_NUM_SEQS (64) and GPU_MEM (0.90) control context, concurrency and GPU allocation. For a trained adapter, export a full checkpoint first.

bash training/merge_lora.sh /path/to/adapter outputs/merged
MODEL=outputs/merged bash inference/serve_vllm.sh

🔬 Start the super-resolution service

In another terminal, download the Real-ESRGAN x2, x4 and x8 weights and start the service. The tool executor sends small crops to this service. For a single-GPU machine with limited free memory, the SR service also accepts --device cpu --dtype fp32.

bash scripts/download_sr_weights.sh
bash tool_servers/sr/start.sh --device cuda --dtype fp16 --port 9049

From the client terminal, check the advertised model name and SR service status.

curl -fsS http://127.0.0.1:8000/v1/models
curl -fsS http://127.0.0.1:9049/health

vLLM settings · SR configuration and smoke test

🚀 Quick Start

🎯 Ask a question about one image

With both services running, the client sends the image and question, executes each requested zoom, and returns the new views to the model until it answers or stops.

python inference/run_demo.py --image /path/to/image.jpg \
  --question "What is written on the sign?" \
  --base-url http://127.0.0.1:8000/v1 --model zoomlynx \
  --sr-url http://127.0.0.1:9049/v1/sr/upscale --output-dir outputs/demo

The terminal prints the extracted answer. On an answer or stop response, outputs/demo/trace.json contains the conversation and terminal action. Each successful crop also produces a raw PNG and, when applied, an SR PNG. --max-turns defaults to 8 and --max-new-tokens to 1,024 per model turn.

🧰 Call the crop executor directly

To inspect a chosen region without the model loop, pass the index of a visible image and an integer [x1, y1, x2, y2] box on a 0–1000 grid. Index 0 is the original image. In a model episode, returned crops are assigned new indices for nested calls.

python inference/zoom_sr_executor.py --image /path/to/image.jpg \
  --arguments '{"image_idx":0,"bbox_2d":[200,200,700,700]}' \
  --output-dir outputs/crop

🎯 Tool Calls and Output Format

Each episode has a budget of three zoom attempts. The executor saves the raw crop and its bounding box in original-image coordinates. It requests 4× SR for crops with a short side below 112 pixels, or 2× below 224 pixels, when the enlarged long side fits within 2,048 pixels. Other crops retain their native resolution.

The terminal action is answer or stop. A stop adds a reason such as insufficient_visual_evidence. Scoring extracts the text inside the answer tags. The protocol defines the complete schema.

{"action":"answer","answer":"<reasoning>The letter is visible.</reasoning><answer>A</answer>"}

🏋️ Training

Selective Zoom Training uses more than 237,000 supervised examples. The trajectories teach five behaviors that can overlap. Direct answers from the original image. Necessary-Zoom inspects one local detail. Recovery returns to the original image after a missed crop. Multi-region combines evidence from distinct regions. Stop/Abstain gives a reason when the evidence cannot support an answer.

Construction of model-in-the-loop training trajectories for the five observation behaviors.

🧩 M2 · Supervised fine-tuning

Run the examples from the repository root in a CUDA environment with ms-swift, DeepSpeed, and FlashAttention-2. Supply your own UTF-8 JSONL trajectories and images. Each row starts with a system message and ends with an assistant JSON action of answer or stop. List the original images and crops in the order of their <image> placeholders. The preparer checks the protocol and image paths and writes the accepted rows and a validation report. Record examples · H800 environment

export WORK="$PWD/outputs/zoomlynx"
export IMAGE_ROOT=/path/to/images
python data/prepare_sft.py --input /path/to/trajectories.jsonl \
  --image-root "$IMAGE_ROOT" --output "$WORK/sft.jsonl"

MODEL=Qwen/Qwen3-VL-4B-Instruct DATASET="$WORK/sft.jsonl" OUTPUT="$WORK/m2" \
  TUNER=lora NPROC=8 bash training/run_sft.sh

The launcher defaults to one epoch of LoRA with rank 16 and a learning rate of 1e-4. Both tuning modes freeze the vision encoder and aligner. For full language-model tuning on eight GPUs, set TUNER=full EPOCHS=3 LR=5e-6 BATCH=1 GRAD_ACC=4. The paper used 16 H800 GPUs across two nodes, a global batch of 32, and a context of 16,384 tokens.

For a LoRA run, select the saved adapter checkpoint and merge it before starting either branch below. For a full run, point M2 directly at the saved full checkpoint.

export M2="$WORK/m2_merged"
bash training/merge_lora.sh /path/to/m2/adapter-checkpoint "$M2"

DPO and GSPO branch from the same SFT policy. A missed first crop is followed by a successful second observation.

🔀 M3 · Direct preference optimization

The paper uses two kinds of pairs. Answer-level pairs favor the teacher’s correct answer over an incorrect M2 answer. Decision-level pairs favor zooming when observation is necessary and answering directly otherwise. Supply each pair as a shared conversation prefix, images, and distinct chosen and rejected strings. The converter appends the chosen assistant turn and writes the other completion to rejected_response.

python data/prepare_dpo.py --input /path/to/preference-pairs.jsonl \
  --image-root "$IMAGE_ROOT" --output "$WORK/dpo.jsonl"
MODEL="$M2" DATASET="$WORK/dpo.jsonl" OUTPUT="$WORK/m3" REF_MODEL= \
  NPROC=8 bash training/run_dpo.sh
bash training/merge_lora.sh /path/to/m3/adapter-checkpoint "$WORK/m3_merged"

DPO uses one epoch of LoRA with rank 16, alpha 32, dropout 0.05, and an 8,192-token context. With ms-swift 4.6.1, leave REF_MODEL empty to use the base as the reference. The final command exports a standalone M3 checkpoint for evaluation. SFT and DPO settings

🎛️ M4 · Group sequence policy optimization

In the paper, M4 starts from the same M2 checkpoint as DPO. This repository provides a verl launcher, its GSPO configuration and an offline reward scorer. The launcher calls verl.trainer.main_ppo in the environment selected by PYTHON_BIN. Set MODEL to the merged M2 checkpoint to override the template’s M3 default. The template reads question and image from the training and validation records.

MODEL="$M2" TRAIN_FILES=/path/to/train.jsonl VAL_FILES=/path/to/val.jsonl \
  OUTPUT="$WORK/m4" PYTHON_BIN=/path/to/verl-env/bin/python \
  NNODES=1 NPROC=8 bash training/rl/run_gspo.sh

To score already labelled rollouts offline, provide answer_correct, requires_call, n_calls, should_stop, and stopped. The scorer adds a reward field to each row.

python training/rl/zoom_reward.py --input /path/to/labelled-rollouts.jsonl \
  --output "$WORK/scored.jsonl"

📈 Evaluation

🗂️ Run a benchmark

Start the model and SR services under Deployment Options. Point BENCH at a local Aperture-580 JSONL in the format above. Each row needs a unique sample_id, image, question, reference_answer and question_type (mcq or blank) per row. For relative image paths, pass --image-root /path/to/images. Benchmark format

BENCH=/path/to/Aperture-580/aperture580_zh.eval.jsonl
RUN=outputs/aperture-m2

python eval/run_agent_eval.py --benchmark "$BENCH" \
  --base-url http://127.0.0.1:8000/v1 --model zoomlynx \
  --output-dir "$RUN" --workers 8 --max-new-tokens 2048 --resume
python eval/summarize.py --rollout "$RUN/rollout.jsonl" \
  --benchmark "$BENCH" --out "$RUN/summary.json"

Each row in rollout.jsonl records the answer, terminal status, tool-call count and path to the sample trace. With --resume, the runner skips every ID already present in the output directory’s rollout.jsonl. The summary reports rule-based accuracy, the share of questions with a tool call and the mean number of calls. The rule scorer checks whether the normalized prediction equals or contains the reference.

🎯 Score Aperture-580

The paper used GPT-5.5 to grade open-ended Chinese answers as equivalent, partial or different. Only equivalent answers earned credit. The bundled judge asks for a binary equivalence decision and reports failed requests separately. Point the example at a running judge and set JUDGE_MODEL to its served name. For a remote endpoint, export OPENAI_API_KEY.

OPENAI_API_BASE=http://127.0.0.1:8001/v1 JUDGE_MODEL=my-judge \
  python eval/judge_gpt.py --bench "$BENCH" --run "$RUN/rollout.jsonl" \
  --out "$RUN/judge.json"
python eval/behavior_metrics.py --benchmark "$BENCH" --rollout "$RUN/rollout.jsonl" \
  --trace-root "$RUN" --iou 0.3 --out "$RUN/behavior.json"

The behavior report reads bucket and the recorded crop boxes. For direct it measures over-calling. For necessary it measures call recall and compares the requested boxes directly with oracle_region_0_1000 at the chosen IoU threshold. For nested zooms the requested box is relative to its parent view. For multi it counts items with at least two calls and a rule-matched answer. For stop it counts items ending with the stop action.

📊 Paper results

The released M2 (SFT) checkpoint scores 71.55% on Aperture-580. M3 (DPO) scores 62.60% on ZoomBench and 94.76% on V*Bench. M4 (GSPO) scores 61.18% and 94.24% on those two benchmarks, above GPT-5.5 and Gemini-3.1-pro in their direct-answer settings. Results for all seven benchmarks

Accuracy of ZoomLynx M2, M4 and the three highest-scoring baselines on each benchmark.

ZoomBench · HR-Bench-4K · HR-Bench-8K · V*Bench · ActiView · MME-RealWorld-Lite · Aperture-580

🔍 Multi-View Examples from the Paper

The paper shows four zero-shot examples with a policy trained on single images. In the MMSI-Bench example, the second crop lands on a doorframe. The model switches views, locates the table, and correctly judges it longer than the piano. The demo and batch runner here each take one original image per question. Later calls can select crops returned earlier in the episode.

Zero-shot examples of selecting evidence across images and views.

📚 Code and Documentation

Entry point Guide
inference/ Model serving, LoRA and single-image inference
tool_servers/sr/ SR weights, endpoints and devices
training/ SFT, DPO and adapter export
training/rl/ verl configuration and offline reward scoring
eval/ Batch generation, traces and scoring
eval/prompt_robustness/ Prompt variants and robustness evaluation
protocols/ Zoom budget, image indices and terminal actions

📜 License

ZoomLynx code is licensed under Apache 2.0. The authors dedicate their original Aperture-580 annotations to the public domain under CC0 1.0. See the third-party notices for upstream code, checkpoints, and image terms.

📖 Citation

Explore related projects

Loading…