-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnew_reseed_gen.py
More file actions
67 lines (56 loc) · 1.98 KB
/
Copy pathnew_reseed_gen.py
File metadata and controls
67 lines (56 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import os
datasets = ['cifar10', 'cinic10', 'cifar100', 'purchase' ]
unlearn_types = ['class_percentage']
class_ratio = [0.1]
# SLURM template
slurm_template = """#!/bin/bash
#SBATCH --nodes=1
#SBATCH --time=0:59:00
#SBATCH --gpus=1
#SBATCH --constraint="a100|v100"
#SBATCH --cpus-per-gpu=5
#SBATCH --mem=256GB
#SBATCH --job-name={job_name}
#SBATCH --mail-type=ALL
#SBATCH --output=logs/new_records/slurm/reseed-{output_name}-%x-%j-slurm.out
#SBATCH --error=logs/new_records/slurm/reseed-{output_name}-%x-%j-slurm.err
# specificy project dir
# source conda env
source $HOME/miniforge/bin/activate base
echo "activation conda"
conda activate IAM
echo "activation env"
#run the application:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$HOME/miniforge/envs/IAM/lib/
cd $HOME/projs/Evaluate-Unlearning
{python_commands}
"""
# Directory to save SLURM scripts
slurm_dir = "records_scripts/reseed"
os.makedirs(slurm_dir, exist_ok=True)
def generate_python_command(count):
return f"python new_reseed.py --SEED_init={42+count} --LOOP=1 --unlearn_type=set_random"
# Function to create and submit SLURM scripts with 10 tasks per SLURM file
def create_and_submit_slurm_job(job_name, output_name, python_commands):
slurm_script_content = slurm_template.format(
job_name=job_name,
output_name=output_name,
python_commands="\n".join(python_commands)
)
# Save the SLURM script
script_name = f"{slurm_dir}/slurm_{job_name}.sh"
with open(script_name, 'w') as f:
f.write(slurm_script_content)
# Submit the SLURM script
os.system(f"sbatch {script_name}")
# Main process to generate and submit jobs
current_batch = []
batch_counter = 0
# 2. One Class unlearning
for class_index in range(10):
command = generate_python_command(class_index)
job_name = f'reseed_{batch_counter}_remaining'
output_name = f'reseed_{class_index}_{job_name}'
create_and_submit_slurm_job(job_name, output_name, [command])
batch_counter +=1
current_batch.append(command)