mirror of
https://github.com/wassname/ray.git
synced 2026-07-13 02:44:01 +08:00
[tune] Remove rllib dep again, and add a test (#1792)
* tune should not depend on rllib * fix dep test * Tue Mar 27 16:55:41 PDT 2018 * f401
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import sys
|
||||
|
||||
import ray
|
||||
from ray.tune import register_trainable, run_experiments
|
||||
|
||||
|
||||
def f(config, reporter):
|
||||
reporter(timesteps_total=1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
ray.init()
|
||||
register_trainable("my_class", f)
|
||||
run_experiments({
|
||||
"test": {
|
||||
"run": "my_class",
|
||||
"stop": {"training_iteration": 1}
|
||||
}
|
||||
})
|
||||
assert 'ray.rllib' not in sys.modules, "RLlib should not be imported"
|
||||
@@ -56,6 +56,11 @@ class Resources(
|
||||
return self.gpu + self.extra_gpu
|
||||
|
||||
|
||||
def has_trainable(trainable_name):
|
||||
return ray.tune.registry._default_registry.contains(
|
||||
ray.tune.registry.TRAINABLE_CLASS, trainable_name)
|
||||
|
||||
|
||||
class Trial(object):
|
||||
"""A trial object holds the state for one model training run.
|
||||
|
||||
@@ -83,9 +88,11 @@ class Trial(object):
|
||||
in ray.tune.config_parser.
|
||||
"""
|
||||
|
||||
if not ray.tune.registry._default_registry.contains(
|
||||
ray.tune.registry.TRAINABLE_CLASS, trainable_name):
|
||||
raise TuneError("Unknown trainable: " + trainable_name)
|
||||
if not has_trainable(trainable_name):
|
||||
# Make sure rllib agents are registered
|
||||
from ray import rllib # noqa: F401
|
||||
if not has_trainable(trainable_name):
|
||||
raise TuneError("Unknown trainable: " + trainable_name)
|
||||
|
||||
if stopping_criterion:
|
||||
for k in stopping_criterion:
|
||||
|
||||
@@ -49,9 +49,6 @@ def run_experiments(experiments, scheduler=None, with_server=False,
|
||||
verbose (bool): How much output should be printed for each trial.
|
||||
"""
|
||||
|
||||
# Make sure rllib agents are registered
|
||||
from ray import rllib # noqa # pylint: disable=unused-import
|
||||
|
||||
if scheduler is None:
|
||||
scheduler = FIFOScheduler()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user