Ray Jobs
Ray Jobs allow you to submit locally developed applications to a remote Ray Cluster for execution. It simplifies the experience of packaging, deploying, and managing a Ray application.
Check workspaces to learn more about the recommended way to develop Ray applications on the Anyscale platform.
Getting started
Setup your environment
Install the latest ray and Anyscale:
pip install ray
pip install -U anyscale
Clone the Anyscale Examples Repo.
git clone https://github.com/anyscale/docs_examples.git anyscale_doc_examples
cd anyscale_doc_examples
We will use hello_world.py
from the examples repo in this guide.
Minimalist guide on using ray jobs
Ray versions 1.11+ support Ray Jobs to support work from your laptop to a cluster. Make sure you set the --working-dir
flag to upload your working directory to the cluster.
$ export RAY_ADDRESS=anyscale://project_name/example_cluster
# Start a cluster, then run `python hello_world.py` on the cluster
$ ray job submit --working-dir="." -- python hello_world.py
Starting cluster example_cluster:
... [some logs omitted]
link: https://console.anyscale.com/projects/prj_xQEUDtTyHnTLLx77QG9jRvWY/clusters/ses_qNvKb7xEgg2tn7Rwp4KUQcnz
... [some logs omitted]
Hello World!
We have successfully run a Ray Job on Anyscale!
Logs for your job are persisted by Anyscale. They are automatically streamed to your laptop, and you can view them in the UI.
You can view your cluster in the UI by clicking the link in the output above. Ray Jobs appear under the "Interactive Sessions" tab in the UI.
Making changes
Let's make an edit to hello_world.py
.
import ray
@ray.remote
def hello_world():
- return "Hello World!"
+ return "Hello Anyscale!"
result = ray.get(hello_world.remote())
print(result)
Now when we resubmit the Job, it should reflect our changes.
# Start a cluster, then run `python hello_world.py` on the cluster
$ ray job submit --working-dir="." -- python hello_world.py
Cluster example_cluster is currently running.
Connecting to this cluster:
... [some logs omitted]
link: https://console.anyscale.com/projects/prj_xQEUDtTyHnTLLx77QG9jRvWY/clusters/ses_qNvKb7xEgg2tn7Rwp4KUQcnz
... [some logs omitted]
Hello Anyscale!
That's it! To view more configuration options for Ray Jobs, please refer to the Ray Documentation.
Check workspaces to learn more about the recommended way to develop Ray applications on the Anyscale platform.