|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +export MASTER_PORT=$(python -c "import socket; s=socket.socket(); s.bind(('', 0)); print(s.getsockname()[1]); s.close()") |
| 4 | +echo "Master Port: $MASTER_PORT" |
| 5 | + |
| 6 | +######################################################################################################################## |
| 7 | +########################################### Unlearn TOFU models ######################################################## |
| 8 | +######################################################################################################################## |
| 9 | + |
| 10 | +models=( |
| 11 | + "Llama-3.2-1B-Instruct" |
| 12 | +) |
| 13 | +trainers_experiments=( |
| 14 | + "UNDIAL unlearn/tofu/default.yaml" |
| 15 | +) |
| 16 | +forget_retain_splits=( |
| 17 | + "forget10 retain90" |
| 18 | + "forget05 retain95" |
| 19 | + "forget01 retain99" |
| 20 | +) |
| 21 | + |
| 22 | +per_device_train_batch_size=16 |
| 23 | +gradient_accumulation_steps=2 |
| 24 | + |
| 25 | + |
| 26 | +lrs=(1e-5 1e-4 3e-4) |
| 27 | +alphas=(1 2 5) |
| 28 | +betas=(3 10 30) |
| 29 | + |
| 30 | + |
| 31 | +for split in "${forget_retain_splits[@]}"; do |
| 32 | + forget_split=$(echo $split | cut -d' ' -f1) |
| 33 | + retain_split=$(echo $split | cut -d' ' -f2) |
| 34 | + for model in "${models[@]}"; do |
| 35 | + for trainer_experiment in "${trainers_experiments[@]}"; do |
| 36 | + trainer=$(echo $trainer_experiment | cut -d' ' -f1) |
| 37 | + experiment=$(echo $trainer_experiment | cut -d' ' -f2) |
| 38 | + for lr in "${lrs[@]}"; do |
| 39 | + for beta in "${betas[@]}"; do |
| 40 | + for alpha in "${alphas[@]}"; do |
| 41 | + task_name=tofu_${model}_${forget_split}_${trainer}_lr${lr}_beta${beta}_alpha${alpha} |
| 42 | + model_path=open-unlearning/tofu_${model}_full |
| 43 | + echo ${task_name}: Unlearning ${model_path} using ${trainer} |
| 44 | + |
| 45 | + # Unlearn |
| 46 | + CUDA_VISIBLE_DEVICES=0 \ |
| 47 | + python src/train.py --config-name=unlearn.yaml \ |
| 48 | + experiment=${experiment} \ |
| 49 | + trainer=${trainer} \ |
| 50 | + task_name=${task_name} \ |
| 51 | + model=${model} \ |
| 52 | + forget_split=${forget_split} \ |
| 53 | + retain_split=${retain_split} \ |
| 54 | + model.model_args.pretrained_model_name_or_path=${model_path} \ |
| 55 | + retain_logs_path=saves/eval/tofu_${model}_${retain_split}/TOFU_EVAL.json \ |
| 56 | + trainer.args.per_device_train_batch_size=$per_device_train_batch_size \ |
| 57 | + trainer.args.gradient_accumulation_steps=$gradient_accumulation_steps \ |
| 58 | + trainer.args.eval_strategy=no \ |
| 59 | + trainer.args.eval_on_start=False \ |
| 60 | + trainer.args.learning_rate=$lr \ |
| 61 | + trainer.method_args.beta=$beta \ |
| 62 | + trainer.method_args.alpha=$alpha |
| 63 | + |
| 64 | + # Eval |
| 65 | + CUDA_VISIBLE_DEVICES=0 python src/eval.py \ |
| 66 | + experiment=eval/tofu/default.yaml \ |
| 67 | + forget_split=${forget_split} \ |
| 68 | + model=${model} \ |
| 69 | + task_name=${task_name} \ |
| 70 | + model.model_args.pretrained_model_name_or_path=saves/unlearn/${task_name} \ |
| 71 | + paths.output_dir=saves/unlearn/${task_name}/evals \ |
| 72 | + retain_logs_path=saves/eval/tofu_${model}_${retain_split}/TOFU_EVAL.json |
| 73 | + done |
| 74 | + done |
| 75 | + done |
| 76 | + done |
| 77 | + done |
| 78 | +done |
0 commit comments