-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconsole_scripts.py
More file actions
203 lines (166 loc) · 6.5 KB
/
console_scripts.py
File metadata and controls
203 lines (166 loc) · 6.5 KB
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
"""A command line interface that exposes softlearning examples to user.
This package exposes the functions in examples.instrument module to the user
through a cli, which allows seamless runs of examples in different modes (e.g.
locally, in google compute engine, or ec2).
There are two types of cli commands in this file (each have their corresponding
function in examples.instrument):
1. run_example_* methods, which run the experiments by invoking
`tune.run_experiments` function.
2. launch_example_* methods, which are helpers function to submit an
example to be run in the cloud. In practice, these launch a cluster,
and then run the `run_example_cluster` method with the provided
arguments and options.
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import logging
import click
from utilities.instrument import (
run_example_dry,
run_example_local,
run_example_debug,
run_example_cluster,
launch_example_cluster,
launch_example_gce,
launch_example_ec2)
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
def add_options(options):
def decorator(f):
for option in options[::-1]:
click.decorators._param_memo(f, option)
return f
return decorator
@click.group()
def cli():
pass
@cli.command(
name='run_example_dry',
context_settings={'ignore_unknown_options': True})
@click.argument("example_module_name", required=True, type=str)
@click.argument('example_argv', nargs=-1, type=click.UNPROCESSED)
def run_example_dry_cmd(example_module_name, example_argv):
"""Print the variant spec and related information of an example."""
return run_example_dry(example_module_name, example_argv)
@cli.command(
name='run_local',
context_settings={'ignore_unknown_options': True})
@click.argument("example_module_name", required=True, type=str)
@click.argument('example_argv', nargs=-1, type=click.UNPROCESSED)
def run_example_local_cmd(example_module_name, example_argv):
"""Run example locally, potentially parallelizing across cpus/gpus."""
return run_example_local(example_module_name, example_argv)
@cli.command(
name='run_example_debug',
context_settings={'ignore_unknown_options': True})
@click.argument("example_module_name", required=True, type=str)
@click.argument('example_argv', nargs=-1, type=click.UNPROCESSED)
def run_example_debug_cmd(example_module_name, example_argv):
"""The debug mode limits tune trial runs to enable use of debugger."""
return run_example_debug(example_module_name, example_argv)
@cli.command(
name='run_example_cluster',
context_settings={'ignore_unknown_options': True})
@click.argument("example_module_name", required=True, type=str)
@click.argument('example_argv', nargs=-1, type=click.UNPROCESSED)
def run_example_cluster_cmd(example_module_name, example_argv):
"""Run example on cluster mode.
This functions is very similar to the local mode, except that it
correctly sets the redis address to make ray/tune work on a cluster.
"""
run_example_cluster(example_module_name, example_argv)
@cli.command(
name='launch_example_cluster',
context_settings={
'allow_extra_args': True,
'ignore_unknown_options': True
})
@click.argument("example_module_name", required=True, type=str)
@click.argument('example_argv', nargs=-1, type=click.UNPROCESSED)
@click.option(
"--config_file",
required=False,
type=str)
@click.option(
"--stop/--no-stop",
is_flag=True,
default=True,
help="Stop the cluster after the command finishes running.")
@click.option(
"--start/--no-start",
is_flag=True,
default=True,
help="Start the cluster if needed.")
@click.option(
"--screen/--no-screen",
is_flag=True,
default=False,
help="Run the command in a screen.")
@click.option(
"--tmux/--no-tmux",
is_flag=True,
default=True,
help="Run the command in tmux.")
@click.option(
"--override-cluster-name",
required=False,
type=str,
help="Override the configured cluster name.")
@click.option(
"--port-forward", required=False, type=int, help="Port to forward.")
def launch_example_cluster_cmd(*args, **kwargs):
"""Launches the example on autoscaled ray cluster through ray exec_cmd.
This handles basic validation and sanity checks for the experiment, and
then executes the command on autoscaled ray cluster. If necessary, it will
also fill in more useful defaults for our workflow (i.e. for tmux and
override_cluster_name).
"""
return launch_example_cluster(*args, **kwargs)
@cli.command(
name='launch_example_gce',
context_settings={
'allow_extra_args': True,
'ignore_unknown_options': True
})
@add_options(launch_example_cluster_cmd.params)
def launch_example_gce_cmd(*args, **kwargs):
"""Forwards call to `launch_example_cluster` after adding gce defaults.
This optionally sets the ray autoscaler configuration file to the default
gce configuration file, and then calls `launch_example_cluster` to
execute the original command on autoscaled gce cluster by parsing the args.
See `launch_example_cluster` for further details.
"""
return launch_example_gce(*args, **kwargs)
@cli.command(
name='launch_example_ec2',
context_settings={
'allow_extra_args': True,
'ignore_unknown_options': True
})
@add_options(launch_example_cluster_cmd.params)
def launch_example_ec2_cmd(*args, **kwargs):
"""Forwards call to `launch_example_cluster` after adding ec2 defaults.
This optionally sets the ray autoscaler configuration file to the default
ec2 configuration file, and then calls `launch_example_cluster` to
execute the original command on autoscaled ec2 cluster by parsing the args.
See `launch_example_cluster` for further details.
"""
return launch_example_ec2(*args, **kwargs)
cli.add_command(run_example_local_cmd)
cli.add_command(run_example_dry_cmd)
cli.add_command(run_example_cluster_cmd)
# Alias for run_example_local
cli.add_command(run_example_local_cmd, name='launch_example_local')
# Alias for run_example_dry
cli.add_command(run_example_dry_cmd, name='launch_example_dry')
# Alias for run_example_debug
cli.add_command(run_example_debug_cmd, name='launch_example_debug')
cli.add_command(launch_example_cluster_cmd)
cli.add_command(launch_example_gce_cmd)
cli.add_command(launch_example_ec2_cmd)
def main():
return cli()
if __name__ == "__main__":
main()