Skip to content

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🎬 SOVA: Strict Outcome-Conditioned Virtual Advantages for Video Reasoning

🤗 Qwen2.5-VL Backbone · 🧮 Code

Official implementation of SOVA. SOVA calibrates group-relative advantages for fully successful and all-zero-accuracy response groups using fixed virtual rewards and residual interpolation.

Contents

🎯 Motivation

Fully correct, well-formatted groups have zero original advantages. All-incorrect groups can retain format-based differences but lack correctness contrast.

SOVA motivation

🔄 Method overview

SOVA training workflow

SOVA uses accuracy and format rewards to select two branches:

Branch When it activates Virtual reward Effect
Positive Every response is fully correct and well formatted 1.5 Restores positive advantages
Negative Every response receives zero accuracy credit 2.0 Produces a negative group mean while retaining format ordering

All other groups keep their original advantages exactly. In negative groups with mixed formatting, individual advantages can remain positive; the guarantee concerns the group mean.

📊 Results

The formal experiments were run on H800 servers. The SOVA manuscript reports the following results with Qwen2.5-VL-7B, 1,000 CLEVRER training queries, 500 updates, and group size 8. Scores are accuracy (%); Video-MME excludes subtitles.

Method CLEVRER NExT-GQA MMVU MVBench TempCompass Video-MME
TW-GRPO control 50.4 76.1 65.8 63.3 73.3 55.1
SOVA 52.2 76.7 65.9 64.4 73.3 56.9

The manuscript reports CLEVRER strict accuracy of 52.2 ± 0.36% (mean ± sample standard deviation across five seeds), a gain of 1.8 percentage points over the TW-GRPO control. CLEVRER aggregation weights the 3,945 single-answer and 5,293 multiple-answer questions by their counts; category strict accuracies are 62.2053% and 44.7194%, respectively, giving 52.1866% overall, rounded to 52.2%.

This compact implementation targets the main Qwen2.5-VL-7B protocol and the Qwen2.5-VL-3B backbone. The paper's InternVL3 implementation and unrelated baseline methods are outside this release. The table reports manuscript results, not a rerun of this source release.

🛠️ Setup

Use Linux, Python 3.10/3.11, and two NVIDIA H800 80 GB GPUs for the reference training run. Evaluation uses one GPU; the reference batch size is 16.

git clone https://github.com/just-a-go/SOVA.git
cd SOVA
conda create -n sova python=3.10 -y
conda activate sova
pip install torch==2.5.1 torchvision==0.20.1 --index-url https://download.pytorch.org/whl/cu124
pip install -e ".[train,test]"
pip install flash-attn==2.7.4.post1 --no-build-isolation

Set CUDA_HOME to your CUDA toolkit installation if it is not already configured. CUDA 12.4 and a C++ build toolchain are needed to build the training extensions.

📥 Model backbone

huggingface-cli download Qwen/Qwen2.5-VL-7B-Instruct \
  --local-dir models/Qwen2.5-VL-7B-Instruct

🎥 Datasets

Download the videos and annotations from their original sources:

Dataset Source Subset
CLEVRER Official website Counterfactual
NExT-GQA Official repository Multiple choice
MMVU Hugging Face Multiple choice
MVBench Hugging Face Multiple choice
TempCompass Hugging Face Multiple choice
Video-MME Hugging Face Without subtitles

Each input file is a JSON array. Use absolute video paths. For CLEVRER, place the question and labeled choices in problem; comma-separated solution letters represent all correct choices. For the other benchmarks, provide labeled choices in options.

[
  {
    "video": "/absolute/path/to/video.mp4",
    "problem": "Your question.\nA. First choice\nB. Second choice",
    "solution": "<answer>A,B</answer>"
  }
]

The example illustrates the schema; it is not a benchmark sample. Supply at least 1,000 training queries. The loader selects one fixed 1,000-query subset with seed 42; --seed controls the training shuffle and rollout sampling. Keep the annotation order unchanged when comparing runs.

For CLEVRER, convert the official Questions and Answers file after extracting the videos:

python -m sova.prepare_clevrer \
  --questions /absolute/path/to/questions/train.json \
  --videos /absolute/path/to/train_videos \
  --output data/clevrer_train.json

Repeat for validation. The converter retains counterfactual questions with nonempty correct-answer sets, as assumed in the paper, and resolves nested video directories. For the other benchmarks, adapt their annotations to the schema above with options containing labeled choices.

🏃 Training

CUDA_VISIBLE_DEVICES=0,1 torchrun --standalone --nproc_per_node=2 -m sova.train \
  --model models/Qwen2.5-VL-7B-Instruct \
  --data /absolute/path/to/clevrer_train.json \
  --output outputs/sova

The defaults implement the reference configuration:

Setting Value
Training queries / updates 1,000 / 500
Query batch / processes 1 per device / 2
Group size 8 responses per query
SOVA coefficients lambda_positive=0.0625, lambda_negative=0.03125
Virtual rewards / normalization epsilon 1.5 and 2.0 / 0.0001
TW coefficient / maximum token weight 0.7 / 1.7
KL coefficient / ratio clipping 0 / [0.8, 1.2]
Learning rate / gradient clipping 0.000001 / 20
Prompt / completion limit 4,096 / 4,096 tokens
Training frames / pixel budget per frame 16 uniformly sampled / 128 × 28 × 28
Precision / optimizer sharding BF16 / ZeRO-3 with CPU offloading
Vision encoder Frozen

One fresh response group is used once per update. Token weighting retains the original TW-GRPO rule and its gradient path; SOVA changes only the response advantages. Checkpointed token chunks avoid retaining a second full-vocabulary log-probability tensor. No reward-model, reference-policy, or rollout-reuse branch is needed for the paper's beta=0 setting.

⚙️ Controlled comparisons

Append these options to the training command and choose a separate output directory:

Configuration Options
TW-GRPO control --lambda-positive 0 --lambda-negative 0
Positive-only SOVA --lambda-negative 0
Negative-only SOVA --lambda-positive 0
Group-size study --group-size 2, 4, 8, or 16
Paired seeds --seed 11, 22, 33, 44, or 55

Model and processor files are saved together in the output directory. Existing nonempty output directories are rejected to keep runs separate.

📈 Evaluation

CUDA_VISIBLE_DEVICES=0 python -m sova.evaluate \
  --model outputs/sova \
  --data /absolute/path/to/clevrer_val.json \
  --benchmark clevrer \
  --output outputs/sova/clevrer_results.json

Use nextgqa, mmvu, mvbench, tempcompass, or videomme with the corresponding annotation file. The evaluator uses 16 frames, a 256 × 28 × 28 pixel budget per frame, temperature 0.01, top-p 0.001, and batch size 16. It reports strict answer-set accuracy, partial credit, and format compliance, and saves each response. A lower --batch-size can reduce memory use but differs from the reported evaluation protocol.

✅ Implementation checks

python -m pytest tests -q

The tests cover strict gates, sample statistics, mixed-format failures, exact bypass, group-size changes, reward parsing, EOS masks, data conversion, and TW weight gradients. A tiny randomly initialized Qwen2.5-VL model also reads a synthetic video, generates responses, completes an optimizer update, and runs the evaluator on CPU. This test downloads no dataset or pretrained checkpoint; it does not replace a full H800 benchmark reproduction.

📁 Repository layout

SOVA/
├── docs/figs/              # Paper figures
├── scripts/zero3_offload.json
├── sova/                  # Training and evaluation
├── tests/
├── pyproject.toml
└── README.md
File Purpose
sova/core.py Rewards, SOVA advantages, TW weights, and policy loss
sova/video.py Uniform frame sampling and prompts
sova/trainer.py Group rollouts and policy updates
sova/train.py Reference training entry point
sova/evaluate.py Six-benchmark multiple-choice evaluation
sova/prepare_clevrer.py Official CLEVRER annotation conversion

🙏 Acknowledgements

We thank TW-GRPO, Open-R1-Video, Video-R1, VideoChat-R1, TRL, and Qwen2.5-VL for their open-source contributions.

This implementation builds on TW-GRPO and Hugging Face TRL, licensed under Apache-2.0. The token-weighting rule, format verifier, and single-use policy-ratio convention are adapted from TW-GRPO. Copyright 2025 The HuggingFace Team. All rights reserved. Qwen2.5-VL preprocessing utilities are installed as an external dependency.

Released under the Apache License 2.0.

About

Official implementation of SOVA: Strict Outcome-Conditioned Virtual Advantages for Video Reasoning. Correctness-oriented calibration for TW-GRPO without extra rollouts.

Topics

Resources

Stars

16 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages