RLib

November 14, 2019

What is Ray

Ray (Github, Documentation) is a fast and simple framework for building and running distributed applications in Python. Ray is packaged with the following libraries for accelerating machine learning workloads:

1. Tune: Scalable Hyperparameter Tuning
2. RLlib: Scalable Reinforcement Learning
3. Distributed Training

Installing Ray

pip install ray

Doesn’t work on Windows

Stack Overflow

but why? Two key reasons (full thread documented here):

  • Ray depends on RedisĀ (Readable Dictionary Server) to do distributed memory management however Redis doesn’t offer good support for Windows thus the problem of memory leaks.
  • The second is the problem with making automated systems calls. The network I/0 calls are very different for Windows v/s Linux thus causing the crash.

One very limited workaround suggested is to use Windows WSL – I personally used Ubuntu for the same (see instructions) however the reason it’s limited is that you cannot use GPU on WSL thus making distributed training pretty futile. Although, I haven’t personally tried it but someone has suggested using PCI passthrough via OVMF (Open Virtual Machine Firmware).

Anyway, the installation was completed.

Novemeber 15, 2019

I am using WSL Terminal from my local Visual Studio Code (setup instructions) to make it easier to run saved files easily. In the past, I wasted a lot of time to access linux/Ubuntu files from Windows 10 WSL, which can be found on this path-

C:\Users\%USERNAME%\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs\

Next Step, test the installation

python -m pytest -v python/ray/tests/test_mini.py

but the test fails

Let’s see what went wrong-

It’s trying to look for the test_mini file under ray. My first guess is that the path might be wrong (since we are using WSL instead of Linux) so I look for the file and find the path. Run again.

But I don’t know what’s the supposed behaviour of this test file. Was it supposed to print something? Let’s check. Here is the code for test_main.py

```
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import ray

test_values = [1, 1.0, "test", b"test", (0, 1), [0, 1], {0: 1}]


def test_basic_task_api(ray_start_regular):

    # Test a simple function.

    @ray.remote
    def f_simple():
        return 1

    assert ray.get(f_simple.remote()) == 1

    # Test multiple return values.

    @ray.remote(num_return_vals=3)
    def f_multiple_returns():
        return 1, 2, 3

    x_id1, x_id2, x_id3 = f_multiple_returns.remote()
    assert ray.get([x_id1, x_id2, x_id3]) == [1, 2, 3]

    # Test arguments passed by value.

    @ray.remote
    def f_args_by_value(x):
        return x

    for arg in test_values:
        assert ray.get(f_args_by_value.remote(arg)) == arg

    # Test arguments passed by ID.

    # Test keyword arguments.


def test_put_api(ray_start_regular):

    for obj in test_values:
        assert ray.get(ray.put(obj)) == obj

    # Test putting object IDs.
    x_id = ray.put(0)
    for obj in [[x_id], (x_id, ), {x_id: x_id}]:
        assert ray.get(ray.put(obj)) == obj


def test_actor_api(ray_start_regular):
    @ray.remote
    class Foo(object):
        def __init__(self, val):
            self.x = val

        def get(self):
            return self.x

    x = 1
    f = Foo.remote(x)
    assert (ray.get(f.get.remote()) == x)
```

Leave a Comment

Your email address will not be published. Required fields are marked *