forked from wzmsltw/BSN-boundary-sensitive-network.pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_cifar_jobs.py
169 lines (139 loc) · 6.23 KB
/
run_cifar_jobs.py
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import os
import sys
def do_jobarray(counter, job, time, find_counter, do_job=False, do_pretrain=True):
# code_directory = '/home/resnick/Code/BSN-boundary-sensitive-network.pytorch'
code_directory = '/private/home/cinjon/Code/BSN-boundary-sensitive-network.pytorch'
num_gpus = 1
num_cpus = num_gpus * 10
# gb = num_gpus * 16
gb = num_gpus * 64
directory = '/checkpoint/cinjon/spaceofmotion/bsn'
slurm_logs = os.path.join(directory, 'slurm_logs')
slurm_scripts = os.path.join(directory, 'slurm_scripts')
comet_dir = os.path.join(directory, 'comet', 'cifar-%d' % job['num_classes'], job['model'].lower())
if not os.path.exists(comet_dir):
os.makedirs(comet_dir)
job['local_comet_dir'] = comet_dir
job['time'] = time
job['num_workers'] = min(int(2.5 * num_gpus), num_cpus - num_gpus)
jobarray = []
model = job['model']
if model == 'resnet':
batch_sizes = [256]
else:
batch_sizes = [64]
lrs = [0.6, 0.3, 0.1]
min_lrs = [0.0003, 0.00003]
weight_decays = [0.0, 0.0005, 0.00005]
lr_intervals = [20, 50]
for bs in batch_sizes:
for lr in lrs:
for min_lr in min_lrs:
for wd in weight_decays:
for lr_int in lr_intervals:
for not_pretrain in [True, False]:
if not do_pretrain and not not_pretrain:
continue
counter += 1
_job = {k: v for k, v in job.items()}
_job['counter'] = counter
_job['batch_size'] = bs
_job['lr'] = lr
_job['lr_interval'] = lr_int
_job['weight_decay'] = wd
_job['min_lr'] = min_lr
_job['not_pretrain'] = not_pretrain
_job['name'] = '%s.%s-%05d' % (_job['name'], model, counter)
if find_counter == counter:
return counter, _job
jobarray.append(counter)
if not find_counter and do_job:
jobname = 'cifar.%s.%dhr.cnt%d' % (model, time, counter)
jobcommand = "python cifar.py --mode array"
print("Size: ", len(jobarray), jobcommand, " /.../ ", jobname)
slurmfile = os.path.join(slurm_scripts, jobname + '.slurm')
hours = int(time)
minutes = int((time - hours) * 60)
with open(slurmfile, 'w') as f:
f.write("#!/bin/bash\n")
f.write("#SBATCH --job-name=%s\n" % jobname)
f.write("#SBATCH --array=%s\n" % ','.join([str(c) for c in jobarray]))
f.write("#SBATCH --mail-type=END,FAIL\n")
f.write("#SBATCH [email protected]\n")
f.write("#SBATCH --cpus-per-task=%d\n" % num_cpus)
f.write("#SBATCH --time=%d:%d:00\n" % (hours, minutes))
f.write("#SBATCH --gres=ntasks-per-node=1\n")
f.write("#SBATCH --gres=gpu:%d\n" % num_gpus)
f.write("#SBATCH --mem=%dG\n" % gb)
f.write("#SBATCH --nodes=%d\n" % 1)
f.write("#SBATCH --output=%s\n" % os.path.join(
slurm_logs, jobname + ".%A.%a.out"))
f.write("#SBATCH --error=%s\n" % os.path.join(
slurm_logs, jobname + ".%A.%a.err"))
f.write("module purge" + "\n")
f.write("module load cuda/10.0\n")
f.write("source activate onoff\n")
f.write("SRCDIR=%s\n" % code_directory)
f.write("cd ${SRCDIR}\n")
f.write(jobcommand + "\n")
s = "sbatch %s" % os.path.join(slurm_scripts, jobname + ".slurm")
os.system(s)
return counter, None
def do(find_counter=None, do_job=False):
counter = 0
job = {
'name': '2019.11.11', 'num_classes': 10
}
for model in ['ccc', 'resnet', 'amdim', 'corrflow']:
_job = job.copy()
_job['model'] = model
counter, _job = do_jobarray(counter, _job, time=5, find_counter=find_counter, do_job=False)
if find_counter and find_counter == counter:
return counter, _job
job = {
'name': '2019.11.11.c100', 'num_classes': 100
}
for model in ['ccc', 'resnet', 'amdim', 'corrflow']:
_job = job.copy()
_job['model'] = model
counter, _job = do_jobarray(counter, _job, time=3, find_counter=find_counter, do_job=False)
if find_counter and find_counter == counter:
return counter, _job
job = {
'name': '2019.11.12.c100', 'num_classes': 100
}
for model in ['ccc', 'resnet', 'amdim', 'corrflow']:
_job = job.copy()
_job['model'] = model
counter, _job = do_jobarray(counter, _job, time=10, find_counter=find_counter, do_job=False)
if find_counter and find_counter == counter:
return counter, _job
job = {
'name': '2019.11.12.c100', 'num_classes': 100
}
for model in ['ccc', 'resnet', 'corrflow']:
_job = job.copy()
_job['model'] = model
counter, _job = do_jobarray(counter, _job, time=10, find_counter=find_counter, do_job=False)
if find_counter and find_counter == counter:
return counter, _job
job = {
'name': '2019.11.13.c10.np', 'num_classes': 10, 'epochs': 500
}
for model in ['resnet', 'amdim', 'corrflow']:
_job = job.copy()
_job['model'] = model
counter, _job = do_jobarray(counter, _job, time=9, find_counter=find_counter, do_job=False, do_pretrain=False)
if find_counter and find_counter == counter:
return counter, _job
job = {
'name': '2019.11.13.c100', 'num_classes': 100, 'epochs': 500,
}
for model in ['resnet', 'corrflow', 'ccc', 'amdim']:
_job = job.copy()
_job['model'] = model
counter, _job = do_jobarray(counter, _job, time=1, find_counter=find_counter, do_job=model == 'amdim')
if find_counter and find_counter == counter:
return counter, _job
if __name__ == '__main__':
do(do_job=True)