
Detects unknown jailbreak attacks in large vision-language models using hidden state analysis and autoencoders, with training and evaluation pipelines for robust safety monitoring.
Official implementation of “Learning to Detect Unknown Jailbreak Attacks in Large Vision-Language Models.”
This repository contains the data-processing, hidden-state extraction, classifier training, safety-pattern auto-encoder, and evaluation code used in the project.
The experiments use the following base models:
Download the model weights separately and place them under:
asset/weights/
.
├── asset/
│ ├── advbench/ # AdvBench images
│ ├── harmbench/ # HarmBench DirectRequest images
│ ├── GQA/ # GQA images
│ ├── HiddenStates/ # Extracted hidden states
│ └── weights/ # Model weights (not included)
├── Benchmarks/ # Evaluation benchmark metadata
├── vicuna/
│ ├── instructions/
│ │ ├── advbench.json
│ │ ├── GQA.json
│ │ └── harmbench.json # HarmBench DirectRequest metadata
│ ├── qa.py
│ ├── qa-baseline.py
│ └── train.py
├── autoencoder.py
├── llama3_guard.py
└── test.py
Some scripts use paths relative to their own working directory. Run the commands from the directories shown below.
Query the model on the unsafe source data (AdvBench) and safe source data (GQA):
cd vicuna
python qa.py --dataset advbench
python qa.py --dataset GQA
cd ..
The HarmBench DirectRequest data can be queried with the same interface:
cd vicuna
python qa.py --dataset harmbench
cd ..
Assess the generated AdvBench responses with Llama Guard 3:
python llama3_guard.py --file vicuna/instructions/advbench.json
Create the AdvBench and GQA training/test splits:
cd vicuna/instructions
python process.py
cd ../..
Extract hidden states for the evaluation benchmarks currently configured in vicuna/qa-baseline.py:
cd vicuna
python qa-baseline.py
cd ..
cd vicuna
python train.py --train
python train.py --test
cd ..
python autoencoder.py
python test.py
The included HarmBench DirectRequest subset contains 320 image–request pairs. Image paths in harmbench.json are repository-relative and follow the same layout convention as AdvBench.
Metadata for the included evaluation sets is stored in Benchmarks/, including HADES, JOOD, MML-m, MOAT, SEED, and SafetyBench variants.
External dataset resources:
Place any separately downloaded dataset assets under asset/ and keep the image paths in the corresponding JSON files consistent with the local directory layout.
| Dataset | Role | Metadata | Images |
|---|
| AdvBench | Unsafe source data | vicuna/instructions/advbench.json | asset/advbench/ |
| GQA | Safe source data | vicuna/instructions/GQA.json | asset/GQA/ |
| HarmBench (DirectRequest) | Unsafe-source experiment reported in the appendix | vicuna/instructions/harmbench.json | asset/harmbench/ |