mirror of
https://github.com/wassname/ray.git
synced 2026-08-09 12:20:09 +08:00
[tune] tf2.0 testing and supporting callables (#5738)
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user