mirror of
https://github.com/wassname/ray.git
synced 2026-06-28 14:48:54 +08:00
[rllib] support local mode (#2795)
This commit is contained in:
committed by
Robert Nishihara
parent
0ac855e061
commit
b37a283053
@@ -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:
|
||||
|
||||
@@ -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)
|
||||
Reference in New Issue
Block a user