[rllib] support local mode (#2795)

This commit is contained in:
Eric Liang
2018-09-02 23:02:19 -07:00
committed by Robert Nishihara
parent 0ac855e061
commit b37a283053
3 changed files with 34 additions and 0 deletions
+11
View File
@@ -4,6 +4,8 @@ from __future__ import print_function
import ray
_local = {} # dict for local mode
def _internal_kv_initialized():
worker = ray.worker.get_global_worker()
@@ -14,6 +16,9 @@ def _internal_kv_get(key):
"""Fetch the value of a binary key."""
worker = ray.worker.get_global_worker()
if worker.mode == ray.worker.LOCAL_MODE:
return _local.get(key)
return worker.redis_client.hget(key, "value")
@@ -27,6 +32,12 @@ def _internal_kv_put(key, value, overwrite=False):
"""
worker = ray.worker.get_global_worker()
if worker.mode == ray.worker.LOCAL_MODE:
exists = key in _local
if not exists or overwrite:
_local[key] = value
return exists
if overwrite:
updated = worker.redis_client.hset(key, "value", value)
else:
+20
View File
@@ -0,0 +1,20 @@
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import unittest
from ray.rllib.agents.ppo import PPOAgent, DEFAULT_CONFIG
import ray
class LocalModeTest(unittest.TestCase):
def testLocal(self):
ray.init(local_mode=True)
cf = DEFAULT_CONFIG.copy()
agent = PPOAgent(cf, "CartPole-v0")
print(agent.train())
if __name__ == "__main__":
unittest.main(verbosity=2)