[tune] tf2.0 testing and supporting callables (#5738)

This commit is contained in:
Richard Liaw
2019-09-21 17:01:14 -07:00
committed by GitHub
parent c91a37f622
commit e00071721a
6 changed files with 44 additions and 26 deletions
+11 -13
View File
@@ -6,11 +6,11 @@ import copy
import logging
import os
import six
import types
from ray.tune.error import TuneError
from ray.tune.registry import register_trainable
from ray.tune.result import DEFAULT_RESULTS_DIR
from ray.tune.sample import sample_from
logger = logging.getLogger(__name__)
@@ -145,8 +145,7 @@ class Experiment(object):
def _register_if_needed(cls, run_object):
"""Registers Trainable or Function at runtime.
Assumes already registered if run_object is a string. Does not
register lambdas because they could be part of variant generation.
Assumes already registered if run_object is a string.
Also, does not inspect interface of given run_object.
Arguments:
@@ -160,17 +159,16 @@ class Experiment(object):
if isinstance(run_object, six.string_types):
return run_object
elif isinstance(run_object, types.FunctionType):
if run_object.__name__ == "<lambda>":
logger.warning(
"Not auto-registering lambdas - resolving as variant.")
return run_object
else:
elif isinstance(run_object, sample_from):
logger.warning("Not registering trainable. Resolving as variant.")
return run_object
elif isinstance(run_object, type) or callable(run_object):
name = "DEFAULT"
if hasattr(run_object, "__name__"):
name = run_object.__name__
register_trainable(name, run_object)
return name
elif isinstance(run_object, type):
name = run_object.__name__
else:
logger.warning(
"No name detected on trainable. Using {}.".format(name))
register_trainable(name, run_object)
return name
else: