Skip to main content

Ray provides a simple, universal API for building distributed applications.

Project description

https://github.com/ray-project/ray/raw/master/doc/source/images/ray_header_logo.png https://readthedocs.org/projects/ray/badge/?version=master https://img.shields.io/badge/Ray-Join%20Slack-blue https://img.shields.io/badge/Discuss-Ask%20Questions-blue

Ray provides a simple, universal API for building distributed applications.

Ray is packaged with the following libraries for accelerating machine learning workloads:

  • Tune: Scalable Hyperparameter Tuning

  • RLlib: Scalable Reinforcement Learning

  • RaySGD: Distributed Training Wrappers

  • Ray Serve: Scalable and Programmable Serving

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.

Install Ray with: pip install ray. For nightly wheels, see the Installation page.

Quick Start

Execute Python functions in parallel.

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))

To use Ray’s actor model:

import ray
ray.init()

@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))

Ray programs can run on a single machine, and can also seamlessly scale to large clusters. To execute the above Ray script in the cloud, just download this configuration file, and run:

ray submit [CLUSTER.YAML] example.py --start

Read more about launching clusters.

Tune Quick Start

https://github.com/ray-project/ray/raw/master/doc/source/images/tune-wide.png

Tune is a library for hyperparameter tuning at any scale.

To run this example, you will need to install the following:

$ pip install "ray[tune]"

This example runs a parallel grid search to optimize an example objective function.

from ray import tune


def objective(step, alpha, beta):
    return (0.1 + alpha * step / 100)**(-1) + beta * 0.1


def training_function(config):
    # Hyperparameters
    alpha, beta = config["alpha"], config["beta"]
    for step in range(10):
        # Iterative training function - can be any arbitrary training procedure.
        intermediate_score = objective(step, alpha, beta)
        # Feed the score back back to Tune.
        tune.report(mean_loss=intermediate_score)


analysis = tune.run(
    training_function,
    config={
        "alpha": tune.grid_search([0.001, 0.01, 0.1]),
        "beta": tune.choice([1, 2, 3])
    })

print("Best config: ", analysis.get_best_config(metric="mean_loss", mode="min"))

# Get a dataframe for analyzing trial results.
df = analysis.results_df

If TensorBoard is installed, automatically visualize all trial results:

tensorboard --logdir ~/ray_results

RLlib Quick Start

https://github.com/ray-project/ray/raw/master/doc/source/images/rllib-wide.jpg

RLlib is an open-source library for reinforcement learning built on top of Ray that offers both high scalability and a unified API for a variety of applications.

pip install tensorflow  # or tensorflow-gpu
pip install "ray[rllib]"
import gym
from gym.spaces import Discrete, Box
from ray import tune

class SimpleCorridor(gym.Env):
    def __init__(self, config):
        self.end_pos = config["corridor_length"]
        self.cur_pos = 0
        self.action_space = Discrete(2)
        self.observation_space = Box(0.0, self.end_pos, shape=(1, ))

    def reset(self):
        self.cur_pos = 0
        return [self.cur_pos]

    def step(self, action):
        if action == 0 and self.cur_pos > 0:
            self.cur_pos -= 1
        elif action == 1:
            self.cur_pos += 1
        done = self.cur_pos >= self.end_pos
        return [self.cur_pos], 1 if done else 0, done, {}

tune.run(
    "PPO",
    config={
        "env": SimpleCorridor,
        "num_workers": 4,
        "env_config": {"corridor_length": 5}})

Ray Serve Quick Start

https://raw.githubusercontent.com/ray-project/ray/master/doc/source/serve/logo.svg

Ray Serve is a scalable model-serving library built on Ray. It is:

  • Framework Agnostic: Use the same toolkit to serve everything from deep learning models built with frameworks like PyTorch or Tensorflow & Keras to Scikit-Learn models or arbitrary business logic.

  • Python First: Configure your model serving declaratively in pure Python, without needing YAMLs or JSON configs.

  • Performance Oriented: Turn on batching, pipelining, and GPU acceleration to increase the throughput of your model.

  • Composition Native: Allow you to create “model pipelines” by composing multiple models together to drive a single prediction.

  • Horizontally Scalable: Serve can linearly scale as you add more machines. Enable your ML-powered service to handle growing traffic.

To run this example, you will need to install the following:

$ pip install scikit-learn
$ pip install "ray[serve]"

This example runs serves a scikit-learn gradient boosting classifier.

from ray import serve
import pickle
import requests
from sklearn.datasets import load_iris
from sklearn.ensemble import GradientBoostingClassifier

# Train model
iris_dataset = load_iris()
model = GradientBoostingClassifier()
model.fit(iris_dataset["data"], iris_dataset["target"])

# Define Ray Serve model,
class BoostingModel:
    def __init__(self):
        self.model = model
        self.label_list = iris_dataset["target_names"].tolist()

    def __call__(self, flask_request):
        payload = flask_request.json["vector"]
        print("Worker: received flask request with data", payload)

        prediction = self.model.predict([payload])[0]
        human_name = self.label_list[prediction]
        return {"result": human_name}


# Deploy model
client = serve.start()
client.create_backend("iris:v1", BoostingModel)
client.create_endpoint("iris_classifier", backend="iris:v1", route="/iris")

# Query it!
sample_request_input = {"vector": [1.2, 1.0, 1.1, 0.9]}
response = requests.get("http://localhost:8000/iris", json=sample_request_input)
print(response.text)
# Result:
# {
#  "result": "versicolor"
# }

More Information

Older documents:

Getting Involved

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

ray-1.5.1-cp39-cp39-win_amd64.whl (15.9 MB view details)

Uploaded CPython 3.9Windows x86-64

ray-1.5.1-cp39-cp39-manylinux2014_x86_64.whl (51.3 MB view details)

Uploaded CPython 3.9

ray-1.5.1-cp39-cp39-macosx_10_13_x86_64.whl (53.4 MB view details)

Uploaded CPython 3.9macOS 10.13+ x86-64

ray-1.5.1-cp38-cp38-win_amd64.whl (15.9 MB view details)

Uploaded CPython 3.8Windows x86-64

ray-1.5.1-cp38-cp38-manylinux2014_x86_64.whl (51.3 MB view details)

Uploaded CPython 3.8

ray-1.5.1-cp38-cp38-macosx_10_13_x86_64.whl (53.4 MB view details)

Uploaded CPython 3.8macOS 10.13+ x86-64

ray-1.5.1-cp37-cp37m-win_amd64.whl (16.0 MB view details)

Uploaded CPython 3.7mWindows x86-64

ray-1.5.1-cp37-cp37m-manylinux2014_x86_64.whl (51.5 MB view details)

Uploaded CPython 3.7m

ray-1.5.1-cp37-cp37m-macosx_10_13_intel.whl (53.5 MB view details)

Uploaded CPython 3.7mmacOS 10.13+ Intel (x86-64, i386)

ray-1.5.1-cp36-cp36m-win_amd64.whl (16.0 MB view details)

Uploaded CPython 3.6mWindows x86-64

ray-1.5.1-cp36-cp36m-manylinux2014_x86_64.whl (51.5 MB view details)

Uploaded CPython 3.6m

ray-1.5.1-cp36-cp36m-macosx_10_13_intel.whl (53.6 MB view details)

Uploaded CPython 3.6mmacOS 10.13+ Intel (x86-64, i386)

File details

Details for the file ray-1.5.1-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: ray-1.5.1-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 15.9 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.10

File hashes

Hashes for ray-1.5.1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 8cdf7c341f8d1f8c20fe35fd2025880801f619fee38022ea615efb1035e03826
MD5 02e7583a036e0c52e1d595ea1661d8a1
BLAKE2b-256 d7bd5967980c6ffe8a60d4bd04a7595936d5dc5a160529a799cd94da6073dced

See more details on using hashes here.

File details

Details for the file ray-1.5.1-cp39-cp39-manylinux2014_x86_64.whl.

File metadata

  • Download URL: ray-1.5.1-cp39-cp39-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 51.3 MB
  • Tags: CPython 3.9
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.10

File hashes

Hashes for ray-1.5.1-cp39-cp39-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 21650055dcd2bc6e37a0bf50605ee3a2f5852b33c0f7efb606271ce34ac18ea2
MD5 8dbbde0d68341b44f1257155dcf88baf
BLAKE2b-256 108cafa3333bcf27860ffa184a8f1796390807455b88dfa0309c7bdc2e647495

See more details on using hashes here.

File details

Details for the file ray-1.5.1-cp39-cp39-macosx_10_13_x86_64.whl.

File metadata

  • Download URL: ray-1.5.1-cp39-cp39-macosx_10_13_x86_64.whl
  • Upload date:
  • Size: 53.4 MB
  • Tags: CPython 3.9, macOS 10.13+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.10

File hashes

Hashes for ray-1.5.1-cp39-cp39-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 06883069e51cbaf0fd1a66dbb12f2ebfa1c71ae8c4d5a8f0a79db6627f4525cf
MD5 cf7fb5f7946a87b76bd8ef1e3d3c8bcf
BLAKE2b-256 39e391d7b93667f05ee53f26ab8f2bcbbbae939ee9a7840dc83dc55348f91569

See more details on using hashes here.

File details

Details for the file ray-1.5.1-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: ray-1.5.1-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 15.9 MB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.10

File hashes

Hashes for ray-1.5.1-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 9e67b3bf67f6ad9ac732e5d508301036af1c5c40058993554e8477cbe536dc22
MD5 acca07150db939b933b6300043536ae2
BLAKE2b-256 2883a422c854edcc0096cf1e18265552f33f6ba96e690eecb2d68f4acae3babf

See more details on using hashes here.

File details

Details for the file ray-1.5.1-cp38-cp38-manylinux2014_x86_64.whl.

File metadata

  • Download URL: ray-1.5.1-cp38-cp38-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 51.3 MB
  • Tags: CPython 3.8
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.10

File hashes

Hashes for ray-1.5.1-cp38-cp38-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cc6ff47835cacc97cf131a3cb4f0d43088c6927915b78a8a9d6516533c8b2212
MD5 7974a67f9e07bf2106cc50e90f63fc42
BLAKE2b-256 619334776d97c51eb099bbcc789d10057e8891024b85d376c55fa7313ed4ba8e

See more details on using hashes here.

File details

Details for the file ray-1.5.1-cp38-cp38-macosx_10_13_x86_64.whl.

File metadata

  • Download URL: ray-1.5.1-cp38-cp38-macosx_10_13_x86_64.whl
  • Upload date:
  • Size: 53.4 MB
  • Tags: CPython 3.8, macOS 10.13+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.10

File hashes

Hashes for ray-1.5.1-cp38-cp38-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 907aad8f3696fe3c6f3b8041d51dd779a73994b97e3d67caa8bca1c6c9ced972
MD5 5f8e2e17f68787786b5d12088702110a
BLAKE2b-256 852040d0b5a467fc3e6156b3f3b239336fc9cd453bf3f19f626b6a227c091e93

See more details on using hashes here.

File details

Details for the file ray-1.5.1-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: ray-1.5.1-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 16.0 MB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.10

File hashes

Hashes for ray-1.5.1-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 ce88cff4f58ce2c1cb8fd02e9f66abe11b09ebe9287987035b8940d2c1d60f37
MD5 e2e7ce33b8dd2ce83d3c22cd3706c627
BLAKE2b-256 e9bba357e6968bf38a34ea192607728f4088e755a0c458f039646760df7e7d37

See more details on using hashes here.

File details

Details for the file ray-1.5.1-cp37-cp37m-manylinux2014_x86_64.whl.

File metadata

  • Download URL: ray-1.5.1-cp37-cp37m-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 51.5 MB
  • Tags: CPython 3.7m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.10

File hashes

Hashes for ray-1.5.1-cp37-cp37m-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e5731425dfc46d9e9fdab3b5e2f8f58837d6d8048393e4de5f1659afd1d73c1d
MD5 1f084c84cabd6046081ff994774c6784
BLAKE2b-256 1951ac3db6e90d2cd3ab9c1bf69be65e014e812ebfa87f11a557715d68b75903

See more details on using hashes here.

File details

Details for the file ray-1.5.1-cp37-cp37m-macosx_10_13_intel.whl.

File metadata

  • Download URL: ray-1.5.1-cp37-cp37m-macosx_10_13_intel.whl
  • Upload date:
  • Size: 53.5 MB
  • Tags: CPython 3.7m, macOS 10.13+ Intel (x86-64, i386)
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.10

File hashes

Hashes for ray-1.5.1-cp37-cp37m-macosx_10_13_intel.whl
Algorithm Hash digest
SHA256 93e8316e537709253e316b608cf60b5d3fe11c25b7fd05ba5ad413ba33ba2a2a
MD5 a42d5ad71a3ba627063ccc5f40d60471
BLAKE2b-256 0952e682cb1e4a198a1c70d8c64f5ba6d40c07c3d0e2084053485f7e1591d304

See more details on using hashes here.

File details

Details for the file ray-1.5.1-cp36-cp36m-win_amd64.whl.

File metadata

  • Download URL: ray-1.5.1-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 16.0 MB
  • Tags: CPython 3.6m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.10

File hashes

Hashes for ray-1.5.1-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 38c1a3c45ac508f254f1065e6bbad2fc67813b20fda45a52512cceab2874c810
MD5 9e4bedad79e22a5ab6788dcce9db9e1f
BLAKE2b-256 829cfc34b2e9c14d6943ba6fea922870744de46ffb5069a523e5448b19dbd87b

See more details on using hashes here.

File details

Details for the file ray-1.5.1-cp36-cp36m-manylinux2014_x86_64.whl.

File metadata

  • Download URL: ray-1.5.1-cp36-cp36m-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 51.5 MB
  • Tags: CPython 3.6m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.10

File hashes

Hashes for ray-1.5.1-cp36-cp36m-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 810acf08088e96fb9fe8ea883d6bb8a9eba10fe65284f7253c90d9fc1e4ead09
MD5 d9834e572fa9b8032f87bfd6f5127546
BLAKE2b-256 6c80a0ff857edaad0487e08dcd333ba0eb7a6cae91439ff34abef37f48948129

See more details on using hashes here.

File details

Details for the file ray-1.5.1-cp36-cp36m-macosx_10_13_intel.whl.

File metadata

  • Download URL: ray-1.5.1-cp36-cp36m-macosx_10_13_intel.whl
  • Upload date:
  • Size: 53.6 MB
  • Tags: CPython 3.6m, macOS 10.13+ Intel (x86-64, i386)
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.10

File hashes

Hashes for ray-1.5.1-cp36-cp36m-macosx_10_13_intel.whl
Algorithm Hash digest
SHA256 e851c78d22ec1da3a6921681adeaee4b2d09e150a135cf1694c69975eeda9643
MD5 ca9745538f4795cc375b385df3a32df6
BLAKE2b-256 a16015e16af9707152848616f42225791c5863694c8cc49d03b521eb7fe9409d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page