-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtoy_ablation.py
187 lines (157 loc) · 5.46 KB
/
toy_ablation.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
import copy
from cluster_utils import my_nfs_cluster_job, trial_dirname_creator
import argparse
import os
import sys
from random import seed, shuffle
import numpy as np
import ray
from ray import tune
from config_utils import dict_to_list, get_cfg_defaults, load_from_yaml
from train_utils import max_batch_size, simple_train
def get_parser():
parser = argparse.ArgumentParser(description="Ray Tune")
parser.add_argument(
"-v", "--verbose", action="store_true", help="verbose", default=False
)
parser.add_argument(
"-p", "--progress", action="store_true", help="progress", default=False
)
parser.add_argument(
"--rm", action="store_true", default=False, help="Remove all previous results"
)
parser.add_argument(
"--name", type=str, default="debug", help="Name of the experiment"
)
parser.add_argument(
"--time", type=int, default=-1, help="Time limit of the experiment"
)
return parser
@my_nfs_cluster_job
def job(tune_dict, cfg, progress=False, **kwargs):
if "row" in tune_dict:
global ROW_LIST
row = tune_dict["row"]
tune_dict.pop("row")
print(ROW_LIST[row])
tune_dict.update(ROW_LIST[row])
cfg.merge_from_list(dict_to_list(tune_dict))
cfg = max_batch_size(cfg)
ret = simple_train(
cfg=cfg,
progress=progress,
rm_soup=True,
**kwargs,
)
def run_ray(
name, cfg, tune_config, rm=False, progress=False, verbose=False, num_samples=1, time_budget_s=None
):
cfg = copy.deepcopy(cfg)
if rm:
import shutil
shutil.rmtree(os.path.join(cfg.RESULTS_DIR, name), ignore_errors=True)
try:
ana = tune.run(
tune.with_parameters(job, cfg=cfg, progress=progress),
local_dir=cfg.RESULTS_DIR,
config=tune_config,
resources_per_trial={"cpu": 1, "gpu": 1},
num_samples=num_samples,
name=name,
verbose=verbose,
resume="AUTO+ERRORED",
trial_dirname_creator=trial_dirname_creator,
time_budget_s=time_budget_s
)
except Exception as e:
print(e)
# print traceback
import traceback
traceback.print_exc()
answer = np.concatenate([np.arange(0, 8), np.arange(21, 35)]).tolist()
memory = np.arange(8, 19).tolist()
time = np.arange(19, 21).tolist()
full = np.arange(0, 35).tolist()
no_answer = [i for i in full if i not in answer]
no_memory = [i for i in full if i not in memory]
no_time = [i for i in full if i not in time]
ROW_LIST = [
{
"EXPERIMENTAL.USE_PREV_FRAME": True,
"EXPERIMENTAL.USE_RETINA_MAPPER": True,
"EXPERIMENTAL.USE_LAYER_SELECTOR": True,
"EXPERIMENTAL.USE_BHV": True,
"EXPERIMENTAL.USE_BHV_PASSTHROUGH": True,
"EXPERIMENTAL.BEHV_SELECTION": [-1],
}, # full
{
"EXPERIMENTAL.USE_PREV_FRAME": True,
"EXPERIMENTAL.USE_RETINA_MAPPER": False,
"EXPERIMENTAL.USE_LAYER_SELECTOR": True,
"EXPERIMENTAL.USE_BHV": True,
"EXPERIMENTAL.USE_BHV_PASSTHROUGH": True,
"EXPERIMENTAL.BEHV_SELECTION": [-1],
}, # noretinamapper
{
"EXPERIMENTAL.USE_PREV_FRAME": True,
"EXPERIMENTAL.USE_RETINA_MAPPER": True,
"EXPERIMENTAL.USE_LAYER_SELECTOR": False,
"EXPERIMENTAL.USE_BHV": True,
"EXPERIMENTAL.USE_BHV_PASSTHROUGH": True,
"EXPERIMENTAL.BEHV_SELECTION": [-1],
}, # nolayerselector
{
"EXPERIMENTAL.USE_PREV_FRAME": False,
"EXPERIMENTAL.USE_RETINA_MAPPER": True,
"EXPERIMENTAL.USE_LAYER_SELECTOR": True,
"EXPERIMENTAL.USE_BHV": True,
"EXPERIMENTAL.USE_BHV_PASSTHROUGH": True,
"EXPERIMENTAL.BEHV_SELECTION": [-1],
}, # noprevframe
{
"EXPERIMENTAL.USE_PREV_FRAME": True,
"EXPERIMENTAL.USE_RETINA_MAPPER": True,
"EXPERIMENTAL.USE_LAYER_SELECTOR": True,
"EXPERIMENTAL.USE_BHV": True,
"EXPERIMENTAL.USE_BHV_PASSTHROUGH": True,
"EXPERIMENTAL.BEHV_SELECTION": no_answer,
"MODEL.COND.IN_DIM": 13,
}, # noanswer
{
"EXPERIMENTAL.USE_PREV_FRAME": True,
"EXPERIMENTAL.USE_RETINA_MAPPER": True,
"EXPERIMENTAL.USE_LAYER_SELECTOR": True,
"EXPERIMENTAL.USE_BHV": True,
"EXPERIMENTAL.USE_BHV_PASSTHROUGH": True,
"EXPERIMENTAL.BEHV_SELECTION": no_memory,
"MODEL.COND.IN_DIM": 24,
}, # nomemory
{
"EXPERIMENTAL.USE_PREV_FRAME": True,
"EXPERIMENTAL.USE_RETINA_MAPPER": True,
"EXPERIMENTAL.USE_LAYER_SELECTOR": True,
"EXPERIMENTAL.USE_BHV": True,
"EXPERIMENTAL.USE_BHV_PASSTHROUGH": True,
"EXPERIMENTAL.BEHV_SELECTION": no_time,
"MODEL.COND.IN_DIM": 33,
}, # notime
]
# -
if __name__ == "__main__":
parser = get_parser()
args = parser.parse_args()
t = args.time if args.time > 0 else None
cfg = load_from_yaml("/workspace/configs/dev.yaml")
cfg.DATASET.SUBJECT_LIST = ['subj01']
cfg.DATASET.ROIS = ["all"]
cfg.DATASET.FMRI_SPACE = 'fsaverage'
cfg.TRAINER.LIMIT_TRAIN_BATCHES = 0.5
cfg.TRAINER.LIMIT_VAL_BATCHES = 0.5
cfg.TRAINER.CALLBACKS.EARLY_STOP.PATIENCE = 30
cfg.RESULTS_DIR = "/nfscc/alg23/toy_ablation"
cfg.EXPERIMENTAL.USE_DEV_MODEL = True
tune_config = {
'row': tune.grid_search(list(range(len(ROW_LIST)))),
}
name = f"ablation"
run_ray(name, cfg, tune_config, args.rm, args.progress, args.verbose, 3, t)