[tune] clean up population based training prototype (#1478)

* patch up pbt

* Sat Jan 27 01:00:03 PST 2018

* Sat Jan 27 01:04:14 PST 2018

* Sat Jan 27 01:04:21 PST 2018

* Sat Jan 27 01:15:15 PST 2018

* Sat Jan 27 01:15:42 PST 2018

* Sat Jan 27 01:16:14 PST 2018

* Sat Jan 27 01:38:42 PST 2018

* Sat Jan 27 01:39:21 PST 2018

* add pbt

* Sat Jan 27 01:41:19 PST 2018

* Sat Jan 27 01:44:21 PST 2018

* Sat Jan 27 01:45:46 PST 2018

* Sat Jan 27 16:54:42 PST 2018

* Sat Jan 27 16:57:53 PST 2018

* clean up test

* Sat Jan 27 18:01:15 PST 2018

* Sat Jan 27 18:02:54 PST 2018

* Sat Jan 27 18:11:18 PST 2018

* Sat Jan 27 18:11:55 PST 2018

* Sat Jan 27 18:14:09 PST 2018

* review

* try out a ppo example

* some tweaks to ppo example

* add postprocess hook

* Sun Jan 28 15:00:40 PST 2018

* clean up custom explore fn

* Sun Jan 28 15:10:21 PST 2018

* Sun Jan 28 15:14:53 PST 2018

* Sun Jan 28 15:17:04 PST 2018

* Sun Jan 28 15:33:13 PST 2018

* Sun Jan 28 15:56:40 PST 2018

* Sun Jan 28 15:57:36 PST 2018

* Sun Jan 28 16:00:35 PST 2018

* Sun Jan 28 16:02:58 PST 2018

* Sun Jan 28 16:29:50 PST 2018

* Sun Jan 28 16:30:36 PST 2018

* Sun Jan 28 16:31:44 PST 2018

* improve tune doc

* concepts

* update humanoid

* Fri Feb  2 18:03:33 PST 2018

* fix example

* show error file
This commit is contained in:
Eric Liang
2018-02-02 23:03:12 -08:00
committed by GitHub
parent a936468f99
commit b948405532
22 changed files with 697 additions and 287 deletions
+35 -16
View File
@@ -96,7 +96,7 @@ class Trial(object):
"Stopping condition key `{}` must be one of {}".format(
k, TrainingResult._fields))
# Immutable config
# Trial config
self.trainable_name = trainable_name
self.config = config or {}
self.local_dir = local_dir
@@ -105,6 +105,7 @@ class Trial(object):
self.stopping_criterion = stopping_criterion or {}
self.checkpoint_freq = checkpoint_freq
self.upload_dir = upload_dir
self.verbose = True
# Local trial state that is updated during the run
self.last_result = None
@@ -117,16 +118,22 @@ class Trial(object):
self.result_logger = None
self.last_debug = 0
self.trial_id = binary_to_hex(random_string())[:8]
self.error_file = None
def start(self):
def start(self, checkpoint_obj=None):
"""Starts this trial.
If an error is encountered when starting the trial, an exception will
be thrown.
Args:
checkpoint_obj (obj): Optional checkpoint to resume from.
"""
self._setup_runner()
if self._checkpoint_path:
if checkpoint_obj:
self.restore_from_obj(checkpoint_obj)
elif self._checkpoint_path:
self.restore_from_path(self._checkpoint_path)
elif self._checkpoint_obj:
self.restore_from_obj(self._checkpoint_obj)
@@ -155,6 +162,7 @@ class Trial(object):
self.logdir, "error_{}.txt".format(date_str()))
with open(error_file, "w") as f:
f.write(error_msg)
self.error_file = error_file
if self.runner:
stop_tasks = []
stop_tasks.append(self.runner.stop.remote())
@@ -163,9 +171,6 @@ class Trial(object):
# TODO(ekl) seems like wait hangs when killing actors
_, unfinished = ray.wait(
stop_tasks, num_returns=2, timeout=250)
if unfinished:
print(("Stopping %s Actor timed out, "
"but moving on...") % self)
except Exception:
print("Error stopping runner:", traceback.format_exc())
self.status = Trial.ERROR
@@ -230,7 +235,7 @@ class Trial(object):
"""Returns a progress message for printing out to the console."""
if self.last_result is None:
return self.status
return self._status_string()
def location_string(hostname, pid):
if hostname == os.uname()[1]:
@@ -240,7 +245,8 @@ class Trial(object):
pieces = [
'{} [{}]'.format(
self.status, location_string(
self._status_string(),
location_string(
self.last_result.hostname, self.last_result.pid)),
'{} s'.format(int(self.last_result.time_total_s)),
'{} ts'.format(int(self.last_result.timesteps_total))]
@@ -259,6 +265,11 @@ class Trial(object):
return ', '.join(pieces)
def _status_string(self):
return "{}{}".format(
self.status,
" => {}".format(self.error_file) if self.error_file else "")
def checkpoint(self, to_object_store=False):
"""Checkpoints the state of this trial.
@@ -276,7 +287,8 @@ class Trial(object):
self._checkpoint_path = path
self._checkpoint_obj = obj
print("Saved checkpoint to:", path or obj)
if self.verbose:
print("Saved checkpoint for {} to {}".format(self, path or obj))
return path or obj
def restore_from_path(self, path):
@@ -310,7 +322,9 @@ class Trial(object):
def update_last_result(self, result, terminate=False):
if terminate:
result = result._replace(done=True)
if terminate or time.time() - self.last_debug > DEBUG_PRINT_INTERVAL:
if terminate or (
self.verbose and
time.time() - self.last_debug > DEBUG_PRINT_INTERVAL):
print("TrainingResult for {}:".format(self))
print(" {}".format(pretty_print(result).replace("\n", "\n ")))
self.last_debug = time.time()
@@ -348,12 +362,17 @@ class Trial(object):
config=self.config, registry=get_registry(),
logger_creator=logger_creator)
def __str__(self):
"""Combines ``env`` with ``trainable_name`` and ``experiment_tag``.
def set_verbose(self, verbose):
self.verbose = verbose
Truncates to MAX_LEN_IDENTIFIER (default is 130) to avoid problems
when creating logging directories.
"""
def is_finished(self):
return self.status in [Trial.TERMINATED, Trial.ERROR]
def __repr__(self):
return str(self)
def __str__(self):
"""Combines ``env`` with ``trainable_name`` and ``experiment_tag``."""
if "env" in self.config:
identifier = "{}_{}".format(
self.trainable_name, self.config["env"])
@@ -361,4 +380,4 @@ class Trial(object):
identifier = self.trainable_name
if self.experiment_tag:
identifier += "_" + self.experiment_tag
return identifier[:MAX_LEN_IDENTIFIER]
return identifier