If you are building distributed applications
Ray Core provides a simple, universal API for building distributed applications.
Ray accomplishes this mission by:
- Providing simple primitives for building and running distributed applications.
- Enabling end users to parallelize single machine code, with little to zero code changes.
- Including a large ecosystem of applications, libraries, and tools on top of the core Ray to enable complex applications.
After installing Ray with pip install ray
, here's how you start a local Ray cluster in two lines of code:
$ import ray
$ ray.init()
2021-12-20 12:45:11,656 INFO services.py:1340 -- View the Ray dashboard at http://127.0.0.1:8265
{'node_ip_address': '127.0.0.1', 'raylet_ip_address': '127.0.0.1', 'redis_address': '127.0.0.1:6379', 'object_store_address': '/tmp/ray/session_2021-12-20_12-45-09_357883_95594/sockets/plasma_store', 'raylet_socket_name': '/tmp/ray/session_2021-12-20_12-45-09_357883_95594/sockets/raylet', 'webui_url': '127.0.0.1:8265', 'session_dir': '/tmp/ray/session_2021-12-20_12-45-09_357883_95594', 'metrics_export_port': 57266, 'node_id': '2be6ccc5db99d2748876762216c51cfa7c841e9a8d7c18ec07c7eb9c'}
Ray Core provides simple primitives for building distributed applications.
If you are building machine learning solutions
On top of Ray Core are several libraries for solving problems in machine learning:
- Ray Data (beta): distributed data loading and compute
- Ray Train: distributed deep learning
- Ray Tune: scalable hyperparameter tuning
- Ray RLlib: industry-grade reinforcement learning
As well as libraries for taking ML and distributed apps to production:
- Ray Serve: scalable and programmable serving
- Ray Workflows (alpha): fast, durable application flows
There are also many community integrations with Ray, including Dask, MARS, Modin, Horovod, Hugging Face, Scikit-learn, and others. Check out the full list of Ray distributed libraries here.
If you are deploying Ray on your infrastructure
TODO
Getting Involved
Ray is more than a framework for distributed applications but also an active community of developers, researchers, and folks that love machine learning. Here's a list of tips for getting involved with the Ray community:
- Join our community Slack to discuss Ray!
- Star and follow us on GitHub.
- To post questions or feature requests, check out the Discussion Board.
- Follow us and spread the word on Twitter.
- Join our Meetup Group to connect with others in the community.
- Use the
[ray]
tag on StackOverflow to ask and answer questions about Ray usage.
If you're interested in contributing to Ray, visit our page on Getting Involved to read about the contribution process and see what you can work on!
# First, run `pip install ray`.
import ray
ray.init()
@ray.remote
def f(x):
return x * x
futures = [f.remote(i) for i in range(4)]
print(ray.get(futures)) # [0, 1, 4, 9]
@ray.remote
class Counter(object):
def __init__(self):
self.n = 0
def increment(self):
self.n += 1
def read(self):
return self.n
counters = [Counter.remote() for i in range(4)]
[c.increment.remote() for c in counters]
futures = [c.read.remote() for c in counters]
print(ray.get(futures)) # [1, 1, 1, 1]
First, add the ray-api <https://mvnrepository.com/artifact/io.ray/ray-api>
and ray-runtime <https://mvnrepository.com/artifact/io.ray/ray-runtime>
dependencies in your project.
import io.ray.api.ActorHandle;
import io.ray.api.ObjectRef;
import io.ray.api.Ray;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
public class RayDemo {
public static int square(int x) {
return x * x;
}
public static class Counter {
private int value = 0;
public void increment() {
this.value += 1;
}
public int read() {
return this.value;
}
}
public static void main(String[] args) {
// Intialize Ray runtime.
Ray.init();
{
List<ObjectRef<Integer>> objectRefList = new ArrayList<>();
// Invoke the `square` method 4 times remotely as Ray tasks.
// The tasks will run in parallel in the background.
for (int i = 0; i < 4; i++) {
objectRefList.add(Ray.task(RayDemo::square, i).remote());
}
// Get the actual results of the tasks with `get`.
System.out.println(Ray.get(objectRefList)); // [0, 1, 4, 9]
}
{
List<ActorHandle<Counter>> counters = new ArrayList<>();
// Create 4 actors from the `Counter` class.
// They will run in remote worker processes.
for (int i = 0; i < 4; i++) {
counters.add(Ray.actor(Counter::new).remote());
}
// Invoke the `increment` method on each actor.
// This will send an actor task to each remote actor.
for (ActorHandle<Counter> counter : counters) {
counter.task(Counter::increment).remote();
}
// Invoke the `read` method on each actor, and print the results.
List<ObjectRef<Integer>> objectRefList = counters.stream()
.map(counter -> counter.task(Counter::read).remote())
.collect(Collectors.toList());
System.out.println(Ray.get(objectRefList)); // [1, 1, 1, 1]
}
}
}
| The C++ Ray API is currently experimental with limited support. You can track its development here <https://github.com/ray-project/ray/milestone/17>
__ and report issues on GitHub.
| Run the following commands to get started:
| - Install ray with C++ API support and generate a bazel project with the ray command.
pip install "ray[cpp]"
mkdir ray-template && ray cpp --generate-bazel-project-template-to ray-template
| - The project template comes with a simple example application. You can try this example out in 2 ways: | - 1. Run the example application directly, which will start a Ray cluster locally.
| - 2. Connect the example application to an existing Ray cluster by specifying the RAY_ADDRESS env var.
| - Now you can build your own Ray C++ application based on this project template.