Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rllib] support local mode #2795

Merged
merged 6 commits into from
Sep 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't Jenkins run in 2.7...?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's wrong?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh the print() statement should fail, but you got the fix.



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