forked from facebookresearch/EGG
-
Notifications
You must be signed in to change notification settings - Fork 1
/
example.py
50 lines (42 loc) · 1.39 KB
/
example.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
# Copyright (c) Facebook, Inc. and its affiliates.
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
# not necessary, but could be useful
def dict2string(d):
s = []
for k, v in d.items():
if type(v) in (int, float):
s.append(f"--{k}={v}")
elif type(v) is bool and v:
s.append(f"--{k}")
elif type(v) is str:
assert (
'"' not in v
), f"Key {k} has string value {v} which contains forbidden quotes."
s.append(f"--{k}={v}")
else:
raise Exception(f"Key {k} has value {v} of unsupported type {type(v)}.")
return s
# only grid() is called from nest
def grid():
"""
Should return an iterable of the parameter strings, e.g.
`--param1=value1 --param2`
"""
for random_seed in range(4):
for vocab_size in [10, 15]:
params = dict(
vocab_size=vocab_size,
random_seed=random_seed,
n_epoch=15,
batch_size=256,
)
yield dict2string(params)
for vocab_size in [16, 32]:
params = dict(
vocab_size=vocab_size,
random_seed=random_seed,
n_epoch=150,
batch_size=128,
)
yield dict2string(params)