-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsluggish_runs.py
261 lines (223 loc) · 8.13 KB
/
sluggish_runs.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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
import torch
from pathlib import Path
import numpy as np
from utils.data import make_blobs_dataset, make_trees_dataset
from utils.nnet import get_device
from hebbcl.logger import MetricLogger1Hidden, LoggerFactory
from hebbcl.model import Nnet, ModelFactory
from hebbcl.trainer import Optimiser, train_on_blobs, train_on_trees
from hebbcl.parameters import parser
from joblib import Parallel, delayed
args = parser.parse_args()
# overwrite cuda argument depending on GPU availability
args.cuda = args.cuda and torch.cuda.is_available()
def execute_run_trees(i_run):
print("run {} / {}".format(str(i_run), str(args.n_runs)))
# create checkpoint dir
run_name = "run_" + str(i_run)
save_dir = Path("checkpoints") / args.save_dir / run_name
# get (cuda) device
args.device, _ = get_device(args.cuda)
# trees settings
args.n_episodes = 100
args.n_layers = 2
args.n_hidden = 100
args.n_features = 974
# get dataset
dataset = make_trees_dataset(args, filepath="./datasets/")
# instantiate logger, model and optimiser
logger = LoggerFactory.create(args, save_dir)
model = ModelFactory.create(args)
optim = Optimiser(args)
# send model to GPU
model = model.to(args.device)
# train model
train_on_trees(args, model, optim, dataset, logger)
# save results
if args.save_results:
save_dir.mkdir(parents=True, exist_ok=True)
logger.save(model)
def execute_run(i_run):
print("run {} / {}".format(str(i_run), str(args.n_runs)))
# create checkpoint dir
run_name = "run_" + str(i_run)
save_dir = Path("checkpoints") / args.save_dir / run_name
# get (cuda) device
args.device, _ = get_device(args.cuda)
# get dataset
dataset = make_blobs_dataset(args)
# instantiate logger, model and optimiser
logger = MetricLogger1Hidden(save_dir)
model = Nnet(args)
optim = Optimiser(args)
# send model to GPU
model = model.to(args.device)
# train model
train_on_blobs(args, model, optim, dataset, logger)
# save results
if args.save_results:
save_dir.mkdir(parents=True, exist_ok=True)
logger.save(model)
if __name__ == "__main__":
# # BASELINE NETWORK -------------------------------------------------
# args.cuda = False
# args.ctx_scaling = 5
# args.lrate_sgd = 0.2
# args.lrate_hebb = 0.0093
# args.weight_init = 1e-2
# args.save_results = True
# args.gating = "None"
# args.perform_hebb = False
# args.centering = False
# args.verbose = False
# args.ctx_avg = True
# args.ctx_avg_type = "ema"
# args.training_schedule = "interleaved"
# args.n_runs = 50
# sluggish_vals = np.linspace(0.05, 1, 20)
# for ii, sv in enumerate(sluggish_vals):
# args.ctx_avg_alpha = sv
# args.save_dir = "sluggish_baseline_int_select_sv" + str(ii)
# Parallel(n_jobs=-1, verbose=10)(
# delayed(execute_run)(i_run) for i_run in range(args.n_runs)
# )
# # OJA CTX NETWORK BLOCKED ---------------------------------------------
# # overwrite standard parameters
# args.cuda = False
# args.ctx_scaling = 1
# args.lrate_sgd = 0.03
# args.lrate_hebb = 0.05
# args.weight_init = 1e-2
# args.save_results = True
# args.gating = "oja_ctx"
# args.centering = True
# args.verbose = False
# args.ctx_avg = True
# args.ctx_avg_type = "ema"
# args.training_schedule = "blocked"
# args.n_runs = 20
# sluggish_vals = np.linspace(0.05, 1, 20)
# for ii, sv in enumerate(sluggish_vals):
# args.ctx_avg_alpha = sv
# args.save_dir = "sluggish_oja_blocked_select_sv" + str(ii)
# Parallel(n_jobs=6, verbose=10)(
# delayed(execute_run)(i_run) for i_run in range(args.n_runs)
# )
# # OJA CTX NETWORK INTERLEAVED -----------------------------------------
# # overwrite standard parameters
# args.cuda = False
# args.ctx_scaling = 1
# args.lrate_sgd = 0.03
# args.lrate_hebb = 0.05
# args.weight_init = 1e-2
# args.save_results = True
# args.gating = "oja_ctx"
# args.centering = True
# args.verbose = False
# args.ctx_avg = True
# args.ctx_avg_type = "ema"
# args.training_schedule = "interleaved"
# args.n_runs = 20
# sluggish_vals = np.linspace(0.05, 1, 20)
# for ii, sv in enumerate(sluggish_vals):
# args.ctx_avg_alpha = sv
# args.save_dir = "sluggish_oja_int_select_sv" + str(ii)
# Parallel(n_jobs=6, verbose=10)(
# delayed(execute_run)(i_run) for i_run in range(args.n_runs)
# )
# REVISION: OJA NETWORK BLOCKED ---------------------------------------------
# # overwrite standard parameters
# args.cuda = False
# args.n_episodes = 8
# args.ctx_scaling = 3
# args.lrate_sgd = 0.09056499086887726
# args.lrate_hebb = 0.002583861043525858
# args.weight_init = 1e-2
# args.save_results = True
# args.perform_hebb = True
# args.gating = "oja"
# args.centering = True
# args.verbose = False
# args.ctx_avg = True
# args.ctx_avg_type = "ema"
# args.training_schedule = "blocked"
# args.n_runs = 50
# sluggish_vals = np.linspace(0.05, 1, 30)
# for ii, sv in enumerate(sluggish_vals):
# args.ctx_avg_alpha = sv
# args.save_dir = "blobs_revision_8episodes_sluggish_blocked_oja_sv" + str(ii)
# Parallel(n_jobs=-1, verbose=10)(
# delayed(execute_run)(i_run) for i_run in range(args.n_runs)
# )
# # REVISION: OJA NETWORK INTERLEAVED -----------------------------------------
# # overwrite standard parameters
# args.cuda = False
# args.n_episodes = 8
# args.ctx_scaling = 4
# args.lrate_sgd = 0.09263634569936459
# args.lrate_hebb = 0.0003276905554752727
# args.weight_init = 1e-2
# args.save_results = True
# args.perform_hebb = True
# args.gating = "oja"
# args.centering = True
# args.verbose = False
# args.ctx_avg = True
# args.ctx_avg_type = "ema"
# args.training_schedule = "interleaved"
# args.n_runs = 50
# sluggish_vals = np.linspace(0.05, 1, 30)
# for ii, sv in enumerate(sluggish_vals):
# args.ctx_avg_alpha = sv
# args.save_dir = "blobs_revision_8episodes_sluggish_interleaved_oja_sv" + str(ii)
# Parallel(n_jobs=-1, verbose=10)(
# delayed(execute_run)(i_run) for i_run in range(args.n_runs)
# )
# REVISION: SLUGGISH TREES BLOCKED --------------------------------------------------
# overwrite standard parameters
args.cuda = False
args.n_episodes = 100
args.ctx_scaling = 4
args.lrate_sgd = 0.00196874872857594
args.lrate_hebb = 0.0008495631690508217
args.weight_init = 1e-2
args.save_results = True
args.perform_hebb = True
args.gating = "oja_ctx"
args.centering = True
args.verbose = False
args.ctx_avg = True
args.ctx_avg_type = "ema"
args.training_schedule = "blocked"
args.n_runs = 50
sluggish_vals = np.linspace(0.05, 1, 30)
for ii, sv in enumerate(sluggish_vals):
args.ctx_avg_alpha = sv
args.save_dir = "trees_revision_sluggish_blocked_oja_sv" + str(ii)
Parallel(n_jobs=25, verbose=10)(
delayed(execute_run_trees)(i_run) for i_run in range(args.n_runs)
)
# REVISION: SLUGGISH TREES INTERLEAVED ----------------------------------------------
# overwrite standard parameters
args.cuda = False
args.n_episodes = 100
args.ctx_scaling = 1
args.lrate_sgd = 0.0018549176154984076
args.lrate_hebb = 0.0066835760364487365
args.weight_init = 1e-2
args.save_results = True
args.perform_hebb = True
args.gating = "oja_ctx"
args.centering = True
args.verbose = False
args.ctx_avg = True
args.ctx_avg_type = "ema"
args.training_schedule = "interleaved"
args.n_runs = 50
sluggish_vals = np.linspace(0.05, 1, 30)
for ii, sv in enumerate(sluggish_vals):
args.ctx_avg_alpha = sv
args.save_dir = "trees_revision_sluggish_interleaved_oja_sv" + str(ii)
Parallel(n_jobs=25, verbose=10)(
delayed(execute_run_trees)(i_run) for i_run in range(args.n_runs)
)