This repository contains code for Red-teaming with GFlowNet, as described in the ICLR 2025 paper.
Note: We are actively working on testing and cleaning up the code for release. If you encounter issues before that please let us know!
Learning Diverse Attacks on Large Language Models for Robust Red-teaming and Safety Tuning
Seanie Lee, Minsu Kim, Lynn Cherif, David Dobre, Juho Lee, Sung Ju Hwang, Kenji Kawaguchi, Gauthier Gidel, Yoshua Bengio, Esmeralda S. Whitammer, Moksh Jain
Paper: https://arxiv.org/abs/2405.18540
@article{
lee2025learning,
title={Learning Diverse Attacks on Large Language Models for Robust Red-Teaming and Safety Tuning},
author={Seanie Lee and Minsu Kim and Lynn Cherif and David Dobre and Juho Lee and Sung Ju Hwang and Kenji Kawaguchi and Gauthier Gidel and Yoshua Bengio and Esmeralda S. Whitammer and Moksh Jain},
journal={International Conference on Learning Representations (ICLR)},
year={2025}
}
conda env create -n redteam python=3.10
conda activate redteam
pip install -r requirements.txt
You can download the checkpoint from link.
and save it under the directory ./save
You can try three different victim models: ["vicgalle/gpt2-alpaca", "meta-llama/Llama-2-7b-chat-hf", "databricks/dolly-v2-7b"].
python eval.py \
--ckpt save/dolly-gfn/latest \
--output_file dolly-gfn \
--victim_model dolly
python eval.py \
--ckpt /save/gemma-gfn/latest \
--output_file gemma-gfn \
--victim_model gemma
python eval.py \
--ckpt save/llama-gfn/latest \
--output_file llama-gfn \
--victim_model llama
For gpt2, dolly target model, we set to train_steps for 2000 and batch_size for 2048. For the other models, we use 1000 and 1024 for train_steps and batch_size, respectively. Note that $\text{target\_model} \in \{\text{gpt2}, \text{dolly}, \text{gemma}, \text{llama} \}$.
Collect offline samples based on reward:
python collect_samples.py --exp_name "{target_model}"_gfn
Run MLE smoothing:
For evaluation:
python eval.py \
--ckpt save/"{target_model}"_gfn/latest \
--output_file "{target_model}"_mle \
--victim_model "{target_model}" \
--no_lora
First train an attacker model with GFlowNet and MLE for Gemma and you can transfer to attack new target models from $\{\text{llama, mistral, gemma, starling} \}$
For safety fine-tuning, train gflownet + MLE to red-team Gemma-2b-it and generate attack prompts.
python main.py \
--model_name google/gemma-2b-it \
--save_dir /network/scratch/s/seanie.lee/redteam/save \
--mode safety \
--lr 5e-5 \
--weight_decay 0.0 \
--batch_size 32 \
--num_warmup_steps 0 \
--epoch 2 \
--prompt_file safety_dataset/gemma_mle.json \
--exp_name gfn-safety-tuned
Python
98.1%
Jupyter Notebook
1.9%
This repository contains code for Red-teaming with GFlowNet, as described in the ICLR 2025 paper.
Note: We are actively working on testing and cleaning up the code for release. If you encounter issues before that please let us know!
Learning Diverse Attacks on Large Language Models for Robust Red-teaming and Safety Tuning
Seanie Lee, Minsu Kim, Lynn Cherif, David Dobre, Juho Lee, Sung Ju Hwang, Kenji Kawaguchi, Gauthier Gidel, Yoshua Bengio, Esmeralda S. Whitammer, Moksh Jain
Paper: https://arxiv.org/abs/2405.18540
@article{
lee2025learning,
title={Learning Diverse Attacks on Large Language Models for Robust Red-Teaming and Safety Tuning},
author={Seanie Lee and Minsu Kim and Lynn Cherif and David Dobre and Juho Lee and Sung Ju Hwang and Kenji Kawaguchi and Gauthier Gidel and Yoshua Bengio and Esmeralda S. Whitammer and Moksh Jain},
journal={International Conference on Learning Representations (ICLR)},
year={2025}
}
conda env create -n redteam python=3.10
conda activate redteam
pip install -r requirements.txt
You can download the checkpoint from link.
and save it under the directory ./save
You can try three different victim models: ["vicgalle/gpt2-alpaca", "meta-llama/Llama-2-7b-chat-hf", "databricks/dolly-v2-7b"].
python eval.py \
--ckpt save/dolly-gfn/latest \
--output_file dolly-gfn \
--victim_model dolly
python eval.py \
--ckpt /save/gemma-gfn/latest \
--output_file gemma-gfn \
--victim_model gemma
python eval.py \
--ckpt save/llama-gfn/latest \
--output_file llama-gfn \
--victim_model llama
For gpt2, dolly target model, we set to train_steps for 2000 and batch_size for 2048. For the other models, we use 1000 and 1024 for train_steps and batch_size, respectively. Note that $\text{target\_model} \in \{\text{gpt2}, \text{dolly}, \text{gemma}, \text{llama} \}$.
Collect offline samples based on reward:
python collect_samples.py --exp_name "{target_model}"_gfn
Run MLE smoothing:
For evaluation:
python eval.py \
--ckpt save/"{target_model}"_gfn/latest \
--output_file "{target_model}"_mle \
--victim_model "{target_model}" \
--no_lora
First train an attacker model with GFlowNet and MLE for Gemma and you can transfer to attack new target models from $\{\text{llama, mistral, gemma, starling} \}$
For safety fine-tuning, train gflownet + MLE to red-team Gemma-2b-it and generate attack prompts.
python main.py \
--model_name google/gemma-2b-it \
--save_dir /network/scratch/s/seanie.lee/redteam/save \
--mode safety \
--lr 5e-5 \
--weight_decay 0.0 \
--batch_size 32 \
--num_warmup_steps 0 \
--epoch 2 \
--prompt_file safety_dataset/gemma_mle.json \
--exp_name gfn-safety-tuned
Python
98.1%
Jupyter Notebook
1.9%