forked from paulfchristiano/amplification
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexperiment.py
378 lines (329 loc) · 11.5 KB
/
experiment.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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
from amplification.run import run, main, parse_args
import argparse
import logging
import multiprocessing
# Credits: https://github.com/tensorflow/tensorflow/issues/27045#issue-424396145
logging.getLogger("tensorflow").setLevel(logging.ERROR)
# The following description is incomplete.
#
# An experiment consists of a list of configurations.
#
# A configuration is a tuple of triples. A triple consists of
# (configuration key, configuration value, descriptor). The descriptors are
# appended to the name of the experiment. This then in turn used to create a
# path in the log directory.
#
# ``combos`` generates an experiment. It returns configurations based on the
# cartesian product of all the ``options`` among its arguments and adds to each
# of the cartesian product's elements the triples returned by the ``bind``s
# among its arguments.
#
# Ie. within ``combos``, ``bind`` adds one configuration triple to all
# configurations so far. ``options`` generates one configuration for each entry
# in ``opts``.
#
# Is it a monad?
def combos(*xs):
if xs:
return [x + combo for x in xs[0] for combo in combos(*xs[1:])]
else:
return [()]
def each(*xs):
return [y for x in xs for y in x]
def bind(var, val, descriptor=''):
return [((var, val, descriptor),)]
def label(descriptor):
return bind(None, None, str(descriptor))
def options(var, opts):
return each(*[bind(var, val, descriptor) for val, descriptor in opts])
def repeat(n):
return each(*[label(i) for i in range(n)])
def dict_of_dicts_assign(d, ks, v):
if len(ks) == 0:
return v
k = ks[0]
d[k] = dict_of_dicts_assign(d.get(k, {}), ks[1:], v)
return d
# If you have time, don't add conditions to the if-elif. Rather, make a dispatch
# dictionary.
def run_experiment(trials, name, mode='kube'):
for trial in trials:
descriptors = []
raw_kwargs = {}
for k, v, s in trial:
if k is not None: raw_kwargs[k] = v
if s is not '': descriptors.append(s)
exp_name = "-".join([name] + descriptors)
kwargs = parse_args(raw_kwargs)
if mode == 'dry':
kwargs["train"]["stub"] = True
for k in ["num_cpu", "num_gpu"]:
if k in kwargs:
del kwargs[k]
main(**kwargs)
elif mode == 'kube':
raise NotImplementedError("this code path has been removed")
elif mode == 'local' and len(trials) == 1:
run(exp_name, **kwargs)
elif mode == 'local' and len(trials) > 1:
# Run each trial in a new process, so it doesn't get confused with
# global state from the previous trial.
p = multiprocessing.Process(target=run, args=(exp_name,), kwargs=kwargs)
p.start()
p.join()
else:
raise AssertionError("Didn't expect to reach this.")
def cpus(n): return bind("num_cpu", n)
def gpus(n): return bind("num_gpu", n)
# Train an X using amplification and another one from ground truth data only.
# amplification.train.train doesn't have an argument ``amplify``, though.
# Let's hope that the argument ``supervised`` has the opposite effect.
amplify_opts = options("train.amplify", [(True, "amp"), (False, "sup")])
curriculum_opts = options("train.curriculum", [(True, "cy"), (False, "cn")])
def sizes(*xs): return options("task.size", [(x, str(x)) for x in xs])
def tasks(*xs): return options("task.name", [(x, x) for x in xs])
all_tasks = tasks('graph', 'sum', 'iter', 'eval', 'equals')
test = combos(cpus(4), gpus(2), bind("task.name", "evalsum", "evalmod"))
may16 = combos(
each(
combos(cpus(4), gpus(2), bind("train.supervised", False, "amp")),
combos(cpus(2), gpus(1), bind("train.supervised", True, "sup"))
),
all_tasks
)
jan30 = combos(
cpus(4), gpus(2),
each(
all_tasks,
bind("task.name", "evalsum", "evalmod"),
combos(
bind("task.name", "evalsum", "evalsum"),
bind("task.modulus", None),
),
combos(
bind("task.name", "sum", "sumraw"),
bind("task.modulus", None),
)
)
)
jan30_sup = combos(bind("train.supervised", True, "sup"), jan30)
jan29_sum = combos(cpus(4), gpus(2), bind("task.name", "sum", "sum"), bind("task.modulus", None))
jan25_sup = combos(cpus(4), gpus(2), bind("train.supervised", True), bind("task.name", "sum", "sum"), bind("task.modulus", None))
jan25_odds = combos(cpus(4), gpus(2),
each(
bind("task.name", "evalsum", "evalmod"),
combos(
bind("task.name", "evalsum", "evalsum"),
bind("task.modulus", None),
),
combos(
bind("task.name", "sum", "sumraw"),
bind("task.modulus", None),
),
),
)
jan25 = combos(all_tasks, cpus(4), gpus(2))
jan22_fast = combos(all_tasks, bind("train.generation_frequency", 20))
jan22 = combos(
each(
combos(
bind("task.name", "iter", "iter"),
options("task.log_iters", [(6, "l6"), (7, "l7")]),
options("model.answerer.depth", [(6, "d6"), (10, "d10")])
),
combos(
bind("train.supervised", True, "supervised"),
all_tasks,
)
)
)
jan21_eval = combos(
bind("task.name", "eval"),
options("model.answerer.depth", [(6, "d6"), (10, "d10")])
)
jan21 = combos(
all_tasks, options("model.answerer.depth", [(6, "d6"), (10, "d10")])
)
standard = combos(
all_tasks, sizes(64),
)
jan15_final = combos(
each(
combos(tasks('iter', 'sum'), sizes(16, 32, 64)),
combos(tasks('eval'), sizes(64)),
combos(tasks('graph'), sizes(32, 64)),
),
each(
label("prefix"),
bind("train.random_subset", True, "random"),
bind("train.curriculum", False, "none")
),
)
jan15_variants = combos(
tasks('iter', 'sum', 'graph'),
sizes(64),
each(
bind('train.loss_threshold', 0.1, "cautious"),
bind("train.buffer_size", 1000, 'small'),
)
)
jan15_encodings = combos(
each(
label("prefix"),
bind("train.random_subset", True, "random"),
bind("train.curriculum", False, "none")
),
bind("model.answerer.encoder", "concat", "concat"),
tasks('iter', 'graph', 'sum'), sizes(64),
)
jan15_fast_curriculum = combos(
each(
label("prefix"),
bind("train.random_subset", True, "random"),
bind("train.curriculum", False, "none")
),
all_tasks, sizes(64),
)
jan15_curriculum = combos(
each(
label("prefix"),
bind("train.random_subset", True, "random"),
bind("train.curriculum", False, "none")
),
tasks("iter", "sum", "graph", "eval", "equals"),
sizes(32, 64),
)
jan15_eval = combos(
bind("train.num_steps", 200000),
tasks("eval"),
sizes(16, 32, 64),
)
jan15_equals = combos(
bind("train.num_steps", 200000),
tasks("equals"),
sizes(32, 64),
)
jan14 = combos(
bind("train.num_steps", 200000),
each(
combos(tasks('iter', 'sum'), sizes(16, 32, 64)),
combos(tasks('eval'), sizes(64)),
combos(tasks('graph'), sizes(32, 64)),
)
)
harder_tasks = each(
bind("task.name", 'iter', 'iter'),
bind("task.name", 'equals', 'equals'),
combos(
bind("task.name", 'graph', 'graph'),
bind("task.size", 20, "20")
),
combos(
bind("task.name", "sum", "sum"),
bind("task.length", 6, "6"),
),
combos(
bind("task.name", "eval", "eval"),
bind("task.size", 36, "36"),
)
)
jan11_final = combos(harder_tasks, bind("train.num_steps", 200000))
jan11_answerer = combos(harder_tasks, each(bind("train.learn_human_model", False, "noasker"), bind("train.supervised", True, "sup")))
jan11_catchup = combos(bind("task.name", 'equals', 'equals'), each(bind("train.learn_human_model", False, "noasker"), bind("train.supervised", True, "sup")))
dropout = combos(
options("task.name", [("iter", "iter"), ("sum", "sum"), ("graph", "graph")]),
options("model.asker.p_drop", [(0.0, "00"), (0.15, "15")]),
options("train.asker_data_limit", [(300, "300"), (900, "900")]),
bind("train.adjust_drift_epsilon", False),
options("train.initial_drift_epsilon", [(1e-2, "e2"), (1e-3, "e3"), (1e-4, "e4")]),
bind("train.num_steps", 20000),
bind("train.just_asker", True),
)
supervised = combos(all_tasks, bind("train.just_asker", True))
jan9 = combos(all_tasks, repeat(2))
jan10 = combos(all_tasks, options("train.learn_human_model", [(False, "noasker"), (True, "full")]))
jan10_iter = combos(bind("task.name", "iter", "iter"), options("train.learn_human_model", [(False, "noasker"), (True, "full")]))
jan10_sup = combos(all_tasks, bind("train.supervised", True, "sup"))
iterate = combos(bind("task.name", "iterate"),
sizes(8, 40), options("task.bit_length", [(3, "3"), (5, "5")]),
amplify_opts, repeat(2), bind("train.curriculum", False))
evals = combos(
bind("task.name", "eval"),
sizes(20, 100),
bind("train.curriculum", True),
repeat(2)
)
graph = combos(
bind("task.name", "graph"),
bind("train.curriculum", True),
options("task.size", [(20, "100"), (8, "8")]),
bind("train.amplify", True),
bind("train.nbatch", 50),
bind("train.num_steps", 400000),
repeat(2),
)
sums = combos(
bind("task.name", "sum"),
bind("train.curriculum", False),
options("task.size", [(3, "3"), (4, "4"), (5, "5")]),
options("train.amplify", [(True, "amp"), (False, "sup")]),
bind("train.nbatch", 50),
bind("train.num_steps", 300000),
)
search = combos(
bind("task.name", "search"),
bind("train.curriculum", False),
options("task.size", [(10, "10"), (100, "100")]),
options("train.amplify", [(True, "amp"), (False, "sup")]),
bind("train.nbatch", 50),
bind("train.num_steps", 100000),
)
equality = combos(
bind("task.name", "equals100"),
bind("train.curriculum", True, "cy"),
options("train.amplify", [(True, "amp"), (False, "sup")]),
bind("train.nbatch", 50),
bind("train.num_steps", 300000),
repeat(2),
)
iterate_rm = combos(
bind("task.name", "iterate"),
bind("task.nchars", 4),
bind("task.length", 1),
bind("task.log_iters", 3),
bind("train.supervised", False),
bind("train.num_steps", 10),
bind("model.tiny", True),
)
iterate_fail = combos(
iterate_rm,
bind("train.error_probability", 0.1),
)
iterate_v1_proto = combos(
bind("task.name", "iterate"),
bind("task.nchars", 4),
bind("task.length", 1),
bind("task.log_iters", 3),
bind("train.supervised", False),
bind("train.num_steps", 4000),
bind("model.tiny", True),
repeat(3),
)
iterate_v1 = combos(
iterate_v1_proto,
repeat(3),
)
iterate_fail_v1 = combos(
iterate_v1_proto,
options("train.error_probability", [(p, str(p)) for p in [0.01, 0.1, 0.3, 1.0]]),
repeat(3),
)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="run an experiment")
parser.add_argument("-e", "--experiment")
parser.add_argument("--dry", default=False, action='store_const', const=True)
parser.add_argument("--mode", default="kube", choices=['kube', 'dry', 'local'])
parser.add_argument("-n", "--name")
n = parser.parse_args()
trials = globals()[n.experiment]
run_experiment(trials, n.name, mode='dry' if n.dry else n.mode)