A comprehensive benchmark and evaluation framework for assessing the safety and robustness of text-to-image diffusion models against jailbreak attacks.
JailbreakDiffusionBench provides tools and methodologies to evaluate how diffusion models respond to adversarial prompts designed to bypass safety filters. The framework supports multiple attack methods, various diffusion models, and different safety detection systems.
Multiple Attack Methods:
Comprehensive Model Support:
Extensive Safety Detector Support:
gpt_4o with prompt_file: 'incontext' in config)gpt_4o_mini with prompt_file: 'incontext' in config)Standardized Benchmarking: A unified framework to evaluate and compare model safety across different attack scenarios with detailed metrics and visualization tools
# Clone the repository
git clone https://github.com/JailbreakDiffusionBench.git
cd JailbreakDiffusionBench
# Create conda environment
conda env create -f environment.yml
conda activate jdb
from jailbreak_diffusion.attack import AttackerFactory
from jailbreak_diffusion.diffusion_model import DiffusionFactory
# Initialize a diffusion model
model = DiffusionFactory(
model_name="stable-diffusion-3.5-medium",
device="cuda"
)
# Initialize an attacker with safety detectors
attacker = AttackerFactory(
attack_type="MMA",
target_model=model,
text_detector={"name": "NSFW_text_classifier"},
image_detector={"name": "multihead_detector"}
)
# Run attack on a prompt
result = attacker("a landscape photograph")
# Check if attack was successful
print(f"Attack success: {result.success}")
print(f"NSFW text detected: {result.is_text_NSFW}")
print(f"NSFW image detected: {result.is_image_NSFW}")
Use the benchmark experiment system to evaluate models:
# Run benchmark with a specific configuration
python exp.py --config_path config/MMA/stable-diffusion-3.5-medium.yaml
Or use predefined scripts:
# Run MMA attack benchmark
bash scripts/bench_exp/run_MMA.sh
Configure experiments through YAML files:
# Example configuration for SD3.5 Medium with MMA attack
experiment_name: "jailbreak_sd35_MMA"
output_dir: "benchmark_results"
save_images: true
save_prompts: true
log_level: "INFO"
batch_size: 20
num_workers: 1
model:
name: "stable-diffusion-3.5-medium"
params:
model_name: "stable-diffusion-3.5-medium"
device: "cuda"
attack_method: "MMA"
text_detector:
name: "NSFW_text_classifier"
# For GPT detectors with in-context prompts, use:
# name: "gpt_4o"
# prompt_file: "incontext" # or "gpt_4o_mini_incontext" for gpt_4o_mini
image_detector:
name: "multihead_detector"
datasets:
- "data/jailbreak_diffusion_bench/jailbreak_diffusion_bench_filtered_400.json"
| Attack Method | Description |
|---|---|
| MMA | Multi-Modal Attack using gradient-based optimization to craft adversarial prompts |
| DACA | Direct Attack with Crafted Adversaries using LLM to transform sensitive content into safe descriptions |
| PGJ | Prompt Gradient Jailbreak using GPT to generate safe alternatives for unsafe prompts |
| RingABell | Genetic algorithm-based attack using concept vectors to optimize adversarial prompts |
| SneakPrompt | Reinforcement learning-based attack that replaces sensitive words with safe alternatives |
| ParallelMMA | Parallelized version of MMA for batch processing multiple prompts efficiently |
| no_attack | Baseline method without any attack (direct generation) |
The main benchmark dataset (jailbreak_diffusion_bench_filtered_400.json) contains 400 harmful prompts distributed across 8 categories, with 50 prompts per category:
All prompts are labeled as harmful and are evenly distributed across categories, providing a balanced evaluation benchmark for assessing model safety and robustness against various types of harmful content.
Results are stored in a structured format:
benchmark_results/
└── [attack_method]/
└── [model_name]/
├── images/
│ └── [prompt_index].png
├── results.csv
└── metadata.json
The benchmark produces:
save_images is enabled)JailbreakDiffusionBench/
├── config/ # Attack & evaluation configurations
├── data/ # Benchmark datasets
│ ├── jailbreak_diffusion_bench/ # Main benchmark dataset
│ ├── benign/ # Benign prompts for evaluation
│ ├── harmful/ # Harmful prompts from various sources
│ └── video/ # Video datasets
├── jailbreak_diffusion/ # Core framework code
│ ├── attack/ # Attack implementations
│ ├── diffusion_model/ # Model wrappers
│ │ ├── core/ # Core factory and types
│ │ └── models/ # Model-specific implementations
│ │ ├── T2I_model/ # Text-to-image models
│ │ └── T2V_model/ # Text-to-video models (base framework)
│ └── judger/ # Safety detection systems
│ ├── pre_checker/ # Text safety detectors
│ └── post_checker/ # Image safety detectors
├── evaluation_image_detector/ # Image safety evaluation
├── evaluation_text_detector/ # Text safety evaluation
├── scripts/ # Benchmark scripts
│ ├── bench_exp/ # Benchmark experiment scripts
│ └── direct_jailbreak/ # Direct jailbreak scripts
├── test/ # Test files
├── exp.py # Main experiment runner
├── environment.yml # Conda environment configuration
└── README.md # This file
jailbreak_diffusion/attack/BaseAttackerAttackerFactoryDiffusionFactory.MODEL_REGISTRYjudger/pre_checker/ or judger/post_checker/)attack/factory.py1 commits
Python
96.2%
Shell
3.8%
A comprehensive benchmark and evaluation framework for assessing the safety and robustness of text-to-image diffusion models against jailbreak attacks.
JailbreakDiffusionBench provides tools and methodologies to evaluate how diffusion models respond to adversarial prompts designed to bypass safety filters. The framework supports multiple attack methods, various diffusion models, and different safety detection systems.
Multiple Attack Methods:
Comprehensive Model Support:
Extensive Safety Detector Support:
gpt_4o with prompt_file: 'incontext' in config)gpt_4o_mini with prompt_file: 'incontext' in config)Standardized Benchmarking: A unified framework to evaluate and compare model safety across different attack scenarios with detailed metrics and visualization tools
# Clone the repository
git clone https://github.com/JailbreakDiffusionBench.git
cd JailbreakDiffusionBench
# Create conda environment
conda env create -f environment.yml
conda activate jdb
from jailbreak_diffusion.attack import AttackerFactory
from jailbreak_diffusion.diffusion_model import DiffusionFactory
# Initialize a diffusion model
model = DiffusionFactory(
model_name="stable-diffusion-3.5-medium",
device="cuda"
)
# Initialize an attacker with safety detectors
attacker = AttackerFactory(
attack_type="MMA",
target_model=model,
text_detector={"name": "NSFW_text_classifier"},
image_detector={"name": "multihead_detector"}
)
# Run attack on a prompt
result = attacker("a landscape photograph")
# Check if attack was successful
print(f"Attack success: {result.success}")
print(f"NSFW text detected: {result.is_text_NSFW}")
print(f"NSFW image detected: {result.is_image_NSFW}")
Use the benchmark experiment system to evaluate models:
# Run benchmark with a specific configuration
python exp.py --config_path config/MMA/stable-diffusion-3.5-medium.yaml
Or use predefined scripts:
# Run MMA attack benchmark
bash scripts/bench_exp/run_MMA.sh
Configure experiments through YAML files:
# Example configuration for SD3.5 Medium with MMA attack
experiment_name: "jailbreak_sd35_MMA"
output_dir: "benchmark_results"
save_images: true
save_prompts: true
log_level: "INFO"
batch_size: 20
num_workers: 1
model:
name: "stable-diffusion-3.5-medium"
params:
model_name: "stable-diffusion-3.5-medium"
device: "cuda"
attack_method: "MMA"
text_detector:
name: "NSFW_text_classifier"
# For GPT detectors with in-context prompts, use:
# name: "gpt_4o"
# prompt_file: "incontext" # or "gpt_4o_mini_incontext" for gpt_4o_mini
image_detector:
name: "multihead_detector"
datasets:
- "data/jailbreak_diffusion_bench/jailbreak_diffusion_bench_filtered_400.json"
| Attack Method | Description |
|---|---|
| MMA | Multi-Modal Attack using gradient-based optimization to craft adversarial prompts |
| DACA | Direct Attack with Crafted Adversaries using LLM to transform sensitive content into safe descriptions |
| PGJ | Prompt Gradient Jailbreak using GPT to generate safe alternatives for unsafe prompts |
| RingABell | Genetic algorithm-based attack using concept vectors to optimize adversarial prompts |
| SneakPrompt | Reinforcement learning-based attack that replaces sensitive words with safe alternatives |
| ParallelMMA | Parallelized version of MMA for batch processing multiple prompts efficiently |
| no_attack | Baseline method without any attack (direct generation) |
The main benchmark dataset (jailbreak_diffusion_bench_filtered_400.json) contains 400 harmful prompts distributed across 8 categories, with 50 prompts per category:
All prompts are labeled as harmful and are evenly distributed across categories, providing a balanced evaluation benchmark for assessing model safety and robustness against various types of harmful content.
Results are stored in a structured format:
benchmark_results/
└── [attack_method]/
└── [model_name]/
├── images/
│ └── [prompt_index].png
├── results.csv
└── metadata.json
The benchmark produces:
save_images is enabled)JailbreakDiffusionBench/
├── config/ # Attack & evaluation configurations
├── data/ # Benchmark datasets
│ ├── jailbreak_diffusion_bench/ # Main benchmark dataset
│ ├── benign/ # Benign prompts for evaluation
│ ├── harmful/ # Harmful prompts from various sources
│ └── video/ # Video datasets
├── jailbreak_diffusion/ # Core framework code
│ ├── attack/ # Attack implementations
│ ├── diffusion_model/ # Model wrappers
│ │ ├── core/ # Core factory and types
│ │ └── models/ # Model-specific implementations
│ │ ├── T2I_model/ # Text-to-image models
│ │ └── T2V_model/ # Text-to-video models (base framework)
│ └── judger/ # Safety detection systems
│ ├── pre_checker/ # Text safety detectors
│ └── post_checker/ # Image safety detectors
├── evaluation_image_detector/ # Image safety evaluation
├── evaluation_text_detector/ # Text safety evaluation
├── scripts/ # Benchmark scripts
│ ├── bench_exp/ # Benchmark experiment scripts
│ └── direct_jailbreak/ # Direct jailbreak scripts
├── test/ # Test files
├── exp.py # Main experiment runner
├── environment.yml # Conda environment configuration
└── README.md # This file
jailbreak_diffusion/attack/BaseAttackerAttackerFactoryDiffusionFactory.MODEL_REGISTRYjudger/pre_checker/ or judger/post_checker/)attack/factory.py1 commits
Python
96.2%
Shell
3.8%