forked from kuangliu/pytorch-cifar
-
Notifications
You must be signed in to change notification settings - Fork 2
/
run_utils.py
166 lines (135 loc) · 4.88 KB
/
run_utils.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
import os, numpy as np, yaml
from pathlib import Path
from itertools import count
dumpdir = "runs/"
if not os.path.isdir(dumpdir):
os.mkdir(dumpdir)
fixed_text = "#!/bin/bash\n"\
"#SBATCH --nodes=1\n"\
"#SBATCH --cpus-per-task=16 \n"\
"#SBATCH --time=2:00:00\n"\
"#SBATCH --mem=40GB\n"\
"#SBATCH --gres=gpu:1\n"
config_file = "resnet_configs/se_fulldrop_good_ResNet4.yaml"
with open(config_file, "r") as stream:
try: config = yaml.safe_load(stream)
except yaml.YAMLError as exc: print(exc)
# print(config.keys())
for key in config:
exp = key
command = fixed_text + "#SBATCH --job-name="+key+"\n#SBATCH --output="+key+".out\n"
command += "\nmodule load python/intel/3.8.6\n"\
"module load openmpi/intel/4.0.5\n"\
"\nsource ../venvs/dl/bin/activate\n"\
"time python3 main.py "
command = ' '.join([
command,
'--config', config_file,
"--resnet_architecture", key
])
# print(command)
log_dir = Path(dumpdir)
for i in count(1):
temp = log_dir/('run{}.sh'.format(i))
if temp.exists():
pass
else:
with open(temp, "w") as f:
f.write(command)
log_dir = temp
break
# """
# resnets
# """
# with open("resnet_configs/nikResNets.yaml", "r") as stream:
# try: config = yaml.safe_load(stream)
# except yaml.YAMLError as exc: print(exc)
# for key in config:
# exp = key
# command = fixed_text + "#SBATCH --job-name="+key+"\n#SBATCH --output="+key+".out\n"
# command += "\nmodule load python/intel/3.8.6\n"\
# "module load openmpi/intel/4.0.5\n"\
# "\nsource ../venvs/dl/bin/activate\n"\
# "time python3 main.py "
# command = ' '.join([
# command,
# "--exp", exp,
# "--resnet_architecture", key,
# '--data_augmentation', '--data_normalize',
# ])
# # print(command)
# log_dir = Path(dumpdir)
# for i in count(1):
# temp = log_dir/('run{}.sh'.format(i))
# if temp.exists():
# pass
# else:
# with open(temp, "w") as f:
# f.write(command)
# log_dir = temp
# break
"""
batch size + lr
"""
"""
for batch_size in range(128, 1024+256, 256):
for lr in np.arange(0.1,0.5,0.1):
exp = os.path.join('batch_size_lr', '_'.join(['batch_size'+str(batch_size), 'lr'+str(lr)]))
command = fixed_text + "#SBATCH --job-name="+'_'.join(['batch_size'+str(batch_size), 'lr'+str(lr)])+"\n" + "#SBATCH --output="+'_'.join(['batch_size'+str(batch_size), 'lr'+str(lr)])+".out\n"
command += "\nmodule load python/intel/3.8.6\n"\
"module load openmpi/intel/4.0.5\n"\
"\nsource ../venvs/dl/bin/activate\n"\
"time python3 main.py "
command = ' '.join([
command,
"--exp", exp,
'--batch_size', str(batch_size),
'--lr', str(lr),
'--data_augmentation', '--data_normalize', "--grad_clip", str(0.1),
])
# print(command)
log_dir = Path(dumpdir)
for i in count(1):
temp = log_dir/('run{}.sh'.format(i))
if temp.exists():
pass
else:
with open(temp, "w") as f:
f.write(command)
log_dir = temp
break
"""
"""
Optimizers
"""
"""
for opt in ['sgd','adam']:
for lr_sched in ['CosineAnnealingLR','LambdaLR', 'MultiplicativeLR',
'StepLR', 'MultiStepLR', 'ExponentialLR',
'CyclicLR', 'CyclicLR2', 'CyclicLR3',
'OneCycleLR', 'OneCycleLR2', 'CosineAnnealingWarmRestarts']:
exp = os.path.join('optimizers', '_'.join([opt, lr_sched]))
command = fixed_text + "#SBATCH --job-name="+'_'.join([opt, lr_sched])+"\n" + "#SBATCH --output="+'_'.join([opt, lr_sched])+".out\n"
command += "\nmodule load python/intel/3.8.6\n"\
"module load openmpi/intel/4.0.5\n"\
"\nsource ../venvs/dl/bin/activate\n"\
"time python3 main.py "
command = ' '.join([
command,
"--exp", exp,
"--opt", opt,
"--lr_sched", lr_sched,
'--data_augmentation', '--data_normalize', "--grad_clip", str(0.1),
])
# print(command)
log_dir = Path(dumpdir)
for i in count(1):
temp = log_dir/('run{}.sh'.format(i))
if temp.exists():
pass
else:
with open(temp, "w") as f:
f.write(command)
log_dir = temp
break
"""