2017-10-13 16:18:16 -07:00
|
|
|
from __future__ import absolute_import
|
|
|
|
from __future__ import division
|
|
|
|
from __future__ import print_function
|
|
|
|
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
import json
|
|
|
|
|
2017-11-06 23:41:17 -08:00
|
|
|
from ray.tune.trial import Resources
|
2017-10-13 16:18:16 -07:00
|
|
|
|
|
|
|
|
2017-11-06 23:41:17 -08:00
|
|
|
def json_to_resources(data):
|
|
|
|
if type(data) is str:
|
|
|
|
data = json.loads(data)
|
2017-10-28 22:16:05 -07:00
|
|
|
return Resources(
|
2017-11-06 23:41:17 -08:00
|
|
|
data.get("cpu", 0), data.get("gpu", 0),
|
|
|
|
data.get("driver_cpu_limit"), data.get("driver_gpu_limit"))
|
2017-10-13 16:18:16 -07:00
|
|
|
|
|
|
|
|
2017-11-06 23:41:17 -08:00
|
|
|
def resources_to_json(resources):
|
|
|
|
return {
|
|
|
|
"cpu": resources.cpu,
|
|
|
|
"gpu": resources.gpu,
|
|
|
|
"driver_cpu_limit": resources.driver_cpu_limit,
|
|
|
|
"driver_gpu_limit": resources.driver_gpu_limit,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
def make_parser(**kwargs):
|
2017-10-13 16:18:16 -07:00
|
|
|
"""Returns a base argument parser for the ray.tune tool."""
|
|
|
|
|
2017-11-06 23:41:17 -08:00
|
|
|
parser = argparse.ArgumentParser(**kwargs)
|
2017-10-13 16:18:16 -07:00
|
|
|
|
2017-11-12 12:05:18 -08:00
|
|
|
# Note: keep this in sync with rllib/train.py
|
2017-11-06 23:41:17 -08:00
|
|
|
parser.add_argument("--alg", default=None, type=str,
|
2017-10-13 16:18:16 -07:00
|
|
|
help="The learning algorithm to train.")
|
|
|
|
parser.add_argument("--stop", default="{}", type=json.loads,
|
|
|
|
help="The stopping criteria, specified in JSON.")
|
|
|
|
parser.add_argument("--config", default="{}", type=json.loads,
|
|
|
|
help="The config of the algorithm, specified in JSON.")
|
|
|
|
parser.add_argument("--resources", default='{"cpu": 1}',
|
2017-11-06 23:41:17 -08:00
|
|
|
type=json_to_resources,
|
2017-10-13 16:18:16 -07:00
|
|
|
help="Amount of resources to allocate per trial.")
|
2017-11-06 23:41:17 -08:00
|
|
|
parser.add_argument("--repeat", default=1, type=int,
|
|
|
|
help="Number of times to repeat each trial.")
|
2017-10-18 11:49:28 -07:00
|
|
|
parser.add_argument("--local-dir", default="/tmp/ray", type=str,
|
2017-10-13 16:18:16 -07:00
|
|
|
help="Local dir to save training results to.")
|
2017-11-12 12:05:18 -08:00
|
|
|
parser.add_argument("--upload-dir", default="", type=str,
|
2017-10-13 16:18:16 -07:00
|
|
|
help="URI to upload training results to.")
|
2017-11-12 12:05:18 -08:00
|
|
|
parser.add_argument("--checkpoint-freq", default=0, type=int,
|
2017-10-13 16:18:16 -07:00
|
|
|
help="How many iterations between checkpoints.")
|
2017-11-12 12:05:18 -08:00
|
|
|
parser.add_argument("--scheduler", default="FIFO", type=str,
|
|
|
|
help="FIFO, MedianStopping, or HyperBand")
|
|
|
|
parser.add_argument("--scheduler-config", default="{}", type=json.loads,
|
|
|
|
help="Config options to pass to the scheduler.")
|
2017-10-13 16:18:16 -07:00
|
|
|
|
2017-11-06 23:41:17 -08:00
|
|
|
# Note: this currently only makes sense when running a single trial
|
|
|
|
parser.add_argument("--restore", default=None, type=str,
|
|
|
|
help="If specified, restore from this checkpoint.")
|
|
|
|
|
2017-10-13 16:18:16 -07:00
|
|
|
# TODO(ekl) environments are RL specific
|
|
|
|
parser.add_argument("--env", default=None, type=str,
|
|
|
|
help="The gym environment to use.")
|
|
|
|
|
|
|
|
return parser
|