Article·ray.io
distributed-computingparallel-processingreinforcement-learningpythonray
Ray
Learn how to use Ray, an open-source framework, to scale your Python applications and AI workloads with easy-to-use APIs for distributed computing.
beginner15 minutes6 steps
The play
- Install RayInstall Ray using pip. This will give you the core Ray libraries and command-line tools.
- Initialize RayInitialize a Ray cluster. This starts the Ray runtime environment.
- Define a Ray TaskDefine a Python function and decorate it with `@ray.remote` to turn it into a Ray task. Ray tasks can be executed in parallel on the Ray cluster.
- Execute Tasks in ParallelCall the remote function using `.remote()` to submit the task to the Ray cluster. This returns a `Future` (an `ObjectID`) immediately.
- Retrieve ResultsUse `ray.get()` to retrieve the results of the Ray tasks. `ray.get()` blocks until the results are available.
- Shutdown RayShutdown the Ray cluster when you are finished.
Starter code
Start by installing Ray and initializing a local Ray cluster. Then, define a simple function and use `@ray.remote` to turn it into a Ray task. Submit several tasks in parallel and retrieve the results.
Source