2016-06-10 14:12:15 -07:00
|
|
|
# Ray
|
2016-02-22 17:32:07 -08:00
|
|
|
|
2016-09-17 00:52:05 -07:00
|
|
|
[](https://travis-ci.org/ray-project/ray)
|
2016-06-22 11:28:01 -07:00
|
|
|
|
2016-07-28 20:47:37 -07:00
|
|
|
Ray is an experimental distributed extension of Python. It is under development
|
2016-09-16 23:05:14 -07:00
|
|
|
and not ready to be used.
|
2016-02-22 17:32:07 -08:00
|
|
|
|
2016-07-08 20:03:21 -07:00
|
|
|
The goal of Ray is to make it easy to write machine learning applications that
|
|
|
|
run on a cluster while providing the development and debugging experience of
|
|
|
|
working on a single machine.
|
|
|
|
|
|
|
|
Before jumping into the details, here's a simple Python example for doing a
|
|
|
|
Monte Carlo estimation of pi (using multiple cores or potentially multiple
|
|
|
|
machines).
|
|
|
|
|
|
|
|
```python
|
|
|
|
import ray
|
|
|
|
import numpy as np
|
|
|
|
|
2016-07-28 20:47:37 -07:00
|
|
|
# Start a scheduler, an object store, and some workers.
|
2016-07-31 19:26:35 -07:00
|
|
|
ray.init(start_ray_local=True, num_workers=10)
|
2016-07-28 20:47:37 -07:00
|
|
|
|
|
|
|
# Define a remote function for estimating pi.
|
2016-08-30 15:14:02 -07:00
|
|
|
@ray.remote
|
2016-07-08 20:03:21 -07:00
|
|
|
def estimate_pi(n):
|
|
|
|
x = np.random.uniform(size=n)
|
|
|
|
y = np.random.uniform(size=n)
|
|
|
|
return 4 * np.mean(x ** 2 + y ** 2 < 1)
|
2016-07-28 20:47:37 -07:00
|
|
|
|
|
|
|
# Launch 10 tasks, each of which estimates pi.
|
2016-07-31 19:58:03 -07:00
|
|
|
result_ids = []
|
2016-07-28 20:47:37 -07:00
|
|
|
for _ in range(10):
|
2016-07-31 19:58:03 -07:00
|
|
|
result_ids.append(estimate_pi.remote(100))
|
2016-07-28 20:47:37 -07:00
|
|
|
|
|
|
|
# Fetch the results of the tasks and print their average.
|
2016-09-02 18:02:44 -07:00
|
|
|
estimate = np.mean(ray.get(result_ids))
|
2016-07-28 20:47:37 -07:00
|
|
|
print "Pi is approximately {}.".format(estimate)
|
2016-07-08 20:03:21 -07:00
|
|
|
```
|
|
|
|
|
2016-07-31 15:25:19 -07:00
|
|
|
Within the for loop, each call to `estimate_pi.remote(100)` sends a message to
|
|
|
|
the scheduler asking it to schedule the task of running `estimate_pi` with the
|
2016-07-28 20:47:37 -07:00
|
|
|
argument `100`. This call returns right away without waiting for the actual
|
|
|
|
estimation of pi to take place. Instead of returning a float, it returns an
|
2016-07-31 19:58:03 -07:00
|
|
|
**object ID**, which represents the eventual output of the computation (this is
|
|
|
|
a similar to a Future).
|
2016-07-08 20:03:21 -07:00
|
|
|
|
2016-07-31 19:58:03 -07:00
|
|
|
The call to `ray.get(result_id)` takes an object ID and returns the actual
|
2016-07-08 20:03:21 -07:00
|
|
|
estimate of pi (waiting until the computation has finished if necessary).
|
|
|
|
|
|
|
|
## Next Steps
|
|
|
|
|
2016-11-12 19:34:22 -08:00
|
|
|
- Installation on [Ubuntu](doc/install-on-ubuntu.md), [Mac OS X](doc/install-on-macosx.md)
|
2016-07-08 20:03:21 -07:00
|
|
|
- [Tutorial](doc/tutorial.md)
|
2016-09-16 23:05:14 -07:00
|
|
|
- Documentation
|
2016-09-16 23:49:59 -07:00
|
|
|
- [Serialization in the Object Store](doc/serialization.md)
|
2016-09-16 23:10:34 -07:00
|
|
|
- [Reusable Variables](doc/reusable-variables.md)
|
2016-09-17 00:45:22 -07:00
|
|
|
- [Using Ray with TensorFlow](doc/using-ray-with-tensorflow.md)
|
2016-07-08 20:03:21 -07:00
|
|
|
|
|
|
|
## Example Applications
|
|
|
|
|
|
|
|
- [Hyperparameter Optimization](examples/hyperopt/README.md)
|
|
|
|
- [Batch L-BFGS](examples/lbfgs/README.md)
|
2016-08-01 18:29:04 -07:00
|
|
|
- [Learning to Play Pong](examples/rl_pong/README.md)
|
|
|
|
- [Training AlexNet](examples/alexnet/README.md)
|