Official implementation of "CAVALRY-V: A Large-Scale Generator Framework for Adversarial Attacks on Video MLLMs"
CAVALRY-V is a comprehensive framework for generating adversarial attacks against Video Multimodal Large Language Models (MLLMs). Our approach introduces a novel generator-based method that can efficiently produce adversarial perturbations for both image and video inputs, enabling systematic evaluation of video MLLM robustness.
- π― Universal Generator: Single framework for both image and video adversarial attacks
- β‘ Efficient Generation: Open-source large-scale generator
- π Comprehensive Evaluation: Support for MMBench-Video, MME, and custom datasets
- π οΈ Easy Integration: Compatible with VLMEvalKit for standardized evaluation
- Python 3.8+
- PyTorch 1.12+
- CUDA 11.0+ (recommended)
# Clone the repository
git clone https://github.com/jiamingzhang94/CAVALRY-V.git
cd CAVALRY-V
# Install dependencies
pip install -r requirements.txt
# Install VLMEvalKit for evaluation
git clone https://github.com/open-compass/VLMEvalKit.git
cd VLMEvalKit
pip install -e .| Dataset | Purpose | Download Link |
|---|---|---|
| MMBench-Video | Video evaluation | HuggingFace |
| MME | Image evaluation | Auto-downloaded via HuggingFace |
| Dataset | Purpose | Download Link |
|---|---|---|
| LAION-400M | Generator pre-training | WebDataset |
| LLaVA-Instruct-150K | Visual instruction tuning | Auto-downloaded via HuggingFace |
| Video-MME | Video finetuning | Auto-downloaded via HuggingFace |
Download our pre-trained generator weights:
- Download Link: SharePoint
- Password:
reg&fw12KJ
python generate_video.py \
--generator_checkpoint /path/to/generator/weights \
--video_input_dir /path/to/MMBench-Video \
--video_output_dir /path/to/output/adversarial/videos \
--qa_json dataset/mmbench-video-qa.jsonNote: Generation on MMBench-Video takes several hours on a single GPU. For faster processing:
- You can run multiple instances of the generation command with different GPU assignments
- Each instance will automatically skip already processed videos (supported via lines 157-183 in
generate_video.py) - Remove any
.inprogressfiles after completion
python generate_img.py \
--generator_checkpoint /path/to/generator/weights \
--input_dir /path/to/MME \
--output_dir /path/to/output/adversarial/images \
--raw_tsv /path/to/MME.tsv \
--output_tsv /path/to/output/adversarial/MME.tsvDownload MME.tsv from: OpenCompass
π‘ Tips for Image Generation
- Image generation is much faster than video generation
--output_diris where results are saved - you can easily modify this script to adapt to your own datasets--output_tsvgenerates the TSV file needed for VLMEval evaluation - this is optional if you don't plan to use VLMEval
β οΈ Note: This step can be somewhat complex and requires careful environment management due to dependency conflicts between different models.
-
Configure API Keys: Set up your evaluation model API keys following VLMEvalKit documentation
π‘ Alternative Evaluation Options
- VLMEvalKit also provides free open-source models as scorers, though they may be slightly less effective than GPT-based evaluators
-
Deploy Target Models: Install the MLLMs you want to evaluate:
- Qwen2.5-VL-7B-Instruct
- llava_video_qwen2_7b
- Aria
- InternVL2_5-8B
- MiniCPM-o-2_6
π§ Environment Management Tips
Transformer Version Conflicts: Different models have conflicting transformer library requirements. Based on our experience:
- Qwen and InternVL can share the same conda environment
- Other models (llava_video, Aria, MiniCPM-o) maybe should each have their own separate conda environment
-
Apply Custom Modifications: Copy our custom evaluation files to override original VLMEval folder
-
Update Configuration Paths:
- Edit
VLMEvalKit/vlmeval/dataset/video_dataset_config.py:11β Set your adversarial video output path - Edit
VLMEvalKit/vlmeval/dataset/image_yorn.py:13β Set your adversarial image TSV path
- Edit
cd VLMEvalKit
./run.shβ οΈ Important Evaluation Guidelines
Best Practices:
- One at a time: Evaluate only one dataset and one model per run to avoid conflicts
- Cache management: After each evaluation run, manually delete cache files in:
output_${data}directoryLMUDatadirectory
- Why clean cache: This prevents the evaluator from reading stale cached data that could cause errors in subsequent evaluations
CAVALRY-V/
βββ dataset/ # Dataset configurations
β βββ mmbench-video-qa.json
βββ VLMEvalKit/ # Custom evaluation scripts
β βββ run.sh
β βββ vlmeval/
βββ attack_utils.py # Adversarial attack utilities
βββ config.py # Configuration settings
βββ generate_img.py # Image adversarial generation
βββ generate_video.py # Video adversarial generation
βββ model_utils.py # Model utilities
βββ pretrain.py # Stage 1: Pre-training
βββ visual_finetuning.py # Stage 2: Visual finetuning
βββ video_finetuning.py # Stage 3: Video finetuning
βββ requirements.txt # Dependencies
torchrun --nproc_per_node=8 pretrain.py \
--image_input_dir /path/to/laion400m/tars \
--save_path ./weights/laion/torchrun --nproc_per_node=8 visual_finetuning.py \
--generator_checkpoint ./weights/laion/checkpoint_latest.pth \
--save_path ./weights/visual/torchrun --nproc_per_node=8 video_finetuning.py \
--generator_checkpoint ./weights/visual/checkpoint_latest.pth \
--save_path ./weights/video/If you find this work useful in your research, please consider citing:
@article{zhang2025cavalry,
title={CAVALRY-V: A Large-Scale Generator Framework for Adversarial Attacks on Video MLLMs},
author={Zhang, Jiaming and Hu, Rui and Guo, Qing and Lim, Wei Yang Bryan},
journal={arXiv preprint arXiv:2507.00817},
year={2025}
}This project is licensed under the MIT License - see the LICENSE file for details.
π οΈ Adapting the Generator to Your Own Datasets
For Custom Image Datasets:
- The
generate_img.pyscript can be easily modified to work with your own datasets - Simply adjust the input/output paths and modify the image loading logic if needed
- The TSV output format follows VLMEval standards but can be customized for other evaluation frameworks
For Custom Video Datasets:
- Modify the video loading and processing pipeline in
generate_video.py - Ensure your video format is supported (MP4 recommended)
- Adjust the QA JSON format to match your dataset structure
- VLMEvalKit for evaluation framework
- MMBench-Video for benchmark dataset
- LAION-400M for pre-training data
β If you find this project helpful, please consider giving it a star! β