-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathslurm_test.py
134 lines (110 loc) · 3.51 KB
/
slurm_test.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
import argparse
import datetime
import itertools
import pprint
import os
import submitit
from test_model import run as runner_main
from test_model import parser as runner_parser
os.environ['OMP_NUM_THREADS'] = '1'
parser = argparse.ArgumentParser()
parser.add_argument('--local', action='store_true')
parser.add_argument('--debug', action='store_true')
parser.add_argument('--partition', type=str, default='devlab',
choices=['learnfair', 'devlab', 'prioritylab'])
# key => k; some_key => sk
def make_prefix(key):
tokens = key.split('_')
return ''.join(w[0] for w in tokens)
def expand_args(params):
sweep_args = {k: v for k, v in params.items() if isinstance(v, list)}
# sweep :: [{arg1: val1, arg2: val1}, {arg1: val2, arg2: val2}, ...]
sweep = [
dict(zip(sweep_args.keys(), vs))
for vs in itertools.product(*sweep_args.values())
]
expanded = []
for swargs in sweep:
new_args = {**params, **swargs} # shallow merge
expanded.append(new_args)
return expanded
args_grid = dict(
from_env=[
# 'HabitatNav-apartment_0',
'MiniGrid-DoorKey-8x8-v0',
'MiniGrid-KeyCorridorS3R3-v0',
'MultiEnv',
],
to_env=[
# 'HabitatNav-apartment_0',
# 'HabitatNav-apartment_1',
# 'HabitatNav-apartment_2',
# 'HabitatNav-room_0',
# 'HabitatNav-room_1',
# 'HabitatNav-room_2',
# 'HabitatNav-frl_apartment_0',
# 'HabitatNav-hotel_0',
# 'HabitatNav-office_3',
'MiniGrid-Unlock-v0',
'MiniGrid-DoorKey-8x8-v0',
'MiniGrid-KeyCorridorS3R3-v0',
'MiniGrid-UnlockPickup-v0',
'MiniGrid-BlockedUnlockPickup-v0',
'MiniGrid-MultiRoom-N6-v0',
'MiniGrid-MultiRoom-N12-S10-v0',
'MiniGrid-ObstructedMaze-1Dlh-v0',
'MiniGrid-ObstructedMaze-2Dlh-v0',
'MiniGrid-ObstructedMaze-2Dlhb-v0'
],
logdir=[
'log/21-10-11/baselines-15-31-34-823340',
],
algs=['cbet','ride','rnd','curiosity','random'],
)
# NOTE params is a shallow merge, so do not reuse values
def make_command(params, unique_id):
# creating cmd-like params
params = itertools.chain(*[('--%s' % k, str(v))
for k, v in params.items()])
return list(params)
args = parser.parse_args()
args_grid = expand_args(args_grid)
print(f"Submitting {len(args_grid)} jobs to Slurm...")
uid = datetime.datetime.now().strftime('%H-%M-%S-%f')
job_index = 0
for run_args in args_grid:
print(run_args)
print()
job_index += 1
flags = runner_parser.parse_args(make_command(run_args, uid))
print('########## Job {:>4}/{} ##########\nFlags: {}'.format(
job_index, len(args_grid), flags))
if args.local:
executor_cls = submitit.LocalExecutor
else:
executor_cls = submitit.SlurmExecutor
executor = executor_cls(folder='./out/')
partition = args.partition
if args.debug:
partition = 'devlab'
executor.update_parameters(
partition=partition,
comment='neurips_oral_video_10_18',
time=1319,
nodes=1,
ntasks_per_node=1,
# job setup
job_name='cbet-testing',
mem="4GB",
cpus_per_task=2,
num_gpus=1,
constraint='pascal',
)
print('Sending to slurm... ', end='')
job = executor.submit(runner_main, flags)
print('Submitted with job id: ', job.job_id)
if args.debug:
print('Only running one job on devfair for debugging...')
print(args)
import sys
sys.exit(0)