Skip to content

Commit

Permalink
[rllib] support local mode (#2795)
Browse files Browse the repository at this point in the history
  • Loading branch information
ericl authored and robertnishihara committed Sep 3, 2018
1 parent 0ac855e commit b37a283
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
11 changes: 11 additions & 0 deletions python/ray/experimental/internal_kv.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import ray

_local = {} # dict for local mode


def _internal_kv_initialized():
worker = ray.worker.get_global_worker()
Expand All @@ -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")


Expand All @@ -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:
Expand Down
20 changes: 20 additions & 0 deletions python/ray/rllib/test/test_local.py
Original file line number Diff line number Diff line change
@@ -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)
3 changes: 3 additions & 0 deletions test/jenkins_tests/run_multi_node_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ docker run -e "RAY_USE_XRAY=1" --rm --shm-size=10G --memory=10G $DOCKER_SHA \
docker run -e "RAY_USE_XRAY=1" --rm --shm-size=10G --memory=10G $DOCKER_SHA \
sh /ray/test/jenkins_tests/multi_node_tests/test_rllib_eval.sh

docker run -e "RAY_USE_XRAY=1" --rm --shm-size=10G --memory=10G $DOCKER_SHA \
python /ray/python/ray/rllib/test/test_local.py

docker run -e "RAY_USE_XRAY=1" --rm --shm-size=10G --memory=10G $DOCKER_SHA \
python /ray/python/ray/rllib/test/test_checkpoint_restore.py

Expand Down

0 comments on commit b37a283

Please sign in to comment.