-
Notifications
You must be signed in to change notification settings - Fork 2
/
experiments.py
205 lines (165 loc) · 7.23 KB
/
experiments.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
from itertools import product
import yaml
from argparse import ArgumentDefaultsHelpFormatter, ArgumentParser
from core import console
from core.jobutils.registry import WandBJobRegistry
from core.jobutils.scheduler import JobScheduler, cluster_resolver
from rich.progress import Progress
def create_train_commands(registry: WandBJobRegistry):
# ### Hyper-parameters
datasets = [
'facebook', 'reddit', 'amazon', 'facebook-100', 'wenet'
]
batch_size = {'facebook': 256, 'reddit': 2048, 'amazon': 4096, 'facebook-100': 4096, 'wenet': 1024}
max_degree = {'facebook': 100, 'reddit': 400, 'amazon': 50, 'facebook-100': 100, 'wenet': 400}
methods = ['progap', 'gap']
levels = ['none', 'edge', 'node']
hparams = {(dataset, method, level): {} for dataset, method, level in product(datasets, methods, levels)}
for dataset in datasets:
# Default for all methods
for method, level in product(methods, levels):
hparams[dataset, method, level]['hidden_dim'] = 16
hparams[dataset, method, level]['activation'] = 'selu'
hparams[dataset, method, level]['optimizer'] = 'adam'
hparams[dataset, method, level]['learning_rate'] = [0.01, 0.05]
hparams[dataset, method, level]['repeats'] = 10
hparams[dataset, method, level]['epochs'] = 100
hparams[dataset, method, level]['batch_size'] = 'full'
hparams[dataset, method, level]['verbose'] = False
# For ProGAP methods
for level in levels:
hparams[dataset, 'progap', level]['base_layers'] = [1, 2]
hparams[dataset, 'progap', level]['head_layers'] = 1
hparams[dataset, 'progap', level]['jk'] = 'cat'
hparams[dataset, 'progap', level]['depth'] = [1, 2, 3, 4, 5]
hparams[dataset, 'progap', level]['layerwise'] = False
# For GAP methods
for level in levels:
hparams[dataset, 'gap', level]['encoder_layers'] = 2
hparams[dataset, 'gap', level]['base_layers'] = 1
hparams[dataset, 'gap', level]['head_layers'] = 1
hparams[dataset, 'gap', level]['combine'] = 'cat'
hparams[dataset, 'gap', level]['hops'] = [1, 2, 3, 4, 5]
# For node-level methods
for method in methods:
hparams[dataset, method, 'node']['max_degree'] = max_degree[dataset]
hparams[dataset, method, 'node']['max_grad_norm'] = 1.0
hparams[dataset, method, 'node']['epochs'] = [5, 10]
hparams[dataset, method, 'node']['batch_size'] = batch_size[dataset]
progress = Progress(
*Progress.get_default_columns(),
"[cyan]{task.fields[registered]}[/cyan] jobs registered",
console=console,
)
task = progress.add_task('generating jobs', total=None, registered=0)
with progress:
for dataset in datasets:
# ### Accuracy/Privacy Trade-off
for method in methods:
for level in levels:
# copy to avoid overwriting
params = {**hparams[dataset, method, level]}
if level == 'node':
params['epsilon'] = [2, 4, 8, 16, 32]
elif level == 'edge':
params['epsilon'] = [0.25, 0.5, 1, 2, 4]
registry.register(
'train.py',
method,
level,
dataset=dataset,
**params,
)
progress.update(task, registered=len(registry.df_job_cmds))
# ### Convergence
for level in levels:
if level == 'none': continue
# copy to avoid overwriting
params = {**hparams[dataset, 'progap', level]}
params['repeats'] = 1
params['depth'] = 5
if level == 'node':
params['epsilon'] = 8
params['epochs'] = 10
elif level == 'edge':
params['epsilon'] = 1
params['epochs'] = 100
params['log_all'] = True
registry.register(
'train.py',
'progap',
level,
dataset=dataset,
**params,
)
progress.update(task, registered=len(registry.df_job_cmds))
# ### Progressive vs. Layer-wise
for level in levels:
# copy to avoid overwriting
params = {**hparams[dataset, 'progap', level]}
if level == 'node':
params['epsilon'] = 8
elif level == 'edge':
params['epsilon'] = 1
params['layerwise'] = True
registry.register(
'train.py',
'progap',
level,
dataset=dataset,
**params,
)
params['layerwise'] = False
registry.register(
'train.py',
'progap',
level,
dataset=dataset,
**params,
)
progress.update(task, registered=len(registry.df_job_cmds))
def generate(path: str):
"""Generate experiment job file.
Args:
path (str): Path to store job file.
"""
with open('config/wandb.yaml') as f:
wandb_config = yaml.safe_load(f)
registry = WandBJobRegistry(**wandb_config)
registry.pull()
create_train_commands(registry)
num_jobs = registry.save(path=path)
console.info(f'[bold cyan]{num_jobs}[/bold cyan] jobs saved to [bold blue]{path}[/bold blue]')
def run(job_file: str, scheduler_name: str) -> None:
"""Run jobs in parallel using a distributed job scheduler.
Args:
job_file (str): Path to the job file.
scheduler_name (str): Name of the scheduler to use.
"""
with open('config/dask.yaml') as f:
config = yaml.safe_load(f)
scheduler = JobScheduler(
job_file=job_file,
scheduler=scheduler_name,
config=config
)
try:
scheduler.submit()
except KeyboardInterrupt:
console.warning('Graceful shutdown')
def main() -> None:
parser = ArgumentParser(formatter_class=ArgumentDefaultsHelpFormatter)
parser.add_argument('--generate', action='store_true', help='Generate jobs')
parser.add_argument('--run', action='store_true', help='Run jobs')
parser.add_argument('--path', type=str, default='jobs/experiments.sh', help='Path to the job file')
parser.add_argument('--scheduler', type=str, default='sge', help='Job scheduler to use',
choices=cluster_resolver.options)
args = parser.parse_args()
if args.generate:
generate(args.path)
if args.run:
run(job_file=args.path, scheduler_name=args.scheduler)
if not args.generate and not args.run:
parser.error('Please specify either --generate or --run')
if __name__ == '__main__':
main()