Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OA] [1/2] Intro jobs template for OA #105

Merged
merged 7 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 123 additions & 0 deletions templates/intro-jobs/README.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@

{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Introduction to Jobs\n",
"\n",
"This tutorial shows you how to:\n",
"1. Run a Ray app non-interactively in Anyscale as an \"Anyscale Job\".\n",
"2. Configure and debug Anyscale Jobs.\n",
"\n",
"**Note**: This tutorial is run within a workspace. Please overview the `Introduction to Workspaces` template first before this tutorial.\n",
"\n",
"## Key features of Anyscale Jobs\n",
"\n",
"Typically, we recommend running batch Ray apps as Anyscale Jobs when moving to production. Like workspaces, Anyscale Jobs run with their own Ray cluster, so you can run the exact same Ray program in a workspace as a Job too.\n",
"\n",
"Key features of Anyscale Jobs:\n",
"- Programmatic submission API\n",
"- Automated failure handling\n",
"- Automated email alerting\n",
"- Record and persist outputs such as logs\n",
"\n",
"\n",
"**Note**: Ray also has an internal concept of a \"Ray job\", which is created when running a Ray app. Anyscale Jobs, Workspaces, and Services all launch Ray jobs internally."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Walkthrough\n",
"\n",
"First, let's run the following app first interactively in the current workspace.\n",
"\n",
"This template includes a simple processing job in **./main.py** that runs a few Ray tasks. Run the cell below in the workspace, you should see it print the result after a few seconds."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# First install the necessary `emoji` dependency.\n",
"!pip install emoji"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Then run the Ray app script.\n",
"!python main.py"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Next, let's try submitting the app to Anyscale Jobs. Within a workspace, you can use the \"ray job submit\" (job runs will be managed by Anyscale Jobs) functionality for this.\n",
"\n",
"The following cell should also run to completion within a few minutes and print the same result. Note however that the Ray app was not run within the workspace cluster (you can check the ``Ray Dashboard`` to verify). It was submitted to Anyscale for execution on a new Ray cluster."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Second, submit the Ray app for execution on a new Ray cluster.\n",
"# The execution will be managed by Anyscale Jobs.\n",
"!ray job submit --wait -- python main.py\n",
"\n",
"# Tip: You can run any Ray app as a job by prefixing its entrypoint with \"ray job submit --\"."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Job UI Overview\n",
"\n",
"You can view active and historical job runs at (`Home > Jobs`). Click into the job run created by the above cell to inspect its results.\n",
"\n",
"You should see the job state and its output on the overview page.\n",
"\n",
"<img src=\"assets/anyscale-job.png\" height=400px>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This concludes the Anyscale Jobs tutorial. To learn more about how to configure Anyscale Jobs, see the [Anyscale documentation](https://docs.endpoints.anyscale.com/preview/)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Summary\n",
"\n",
"This notebook:\n",
"- Ran a simple Ray app in the local workspace.\n",
"- Submitted the same Ray app as an Anyscale Job."
]
}
],
"metadata": {
"language_info": {
"name": "python"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}
67 changes: 67 additions & 0 deletions templates/intro-jobs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Introduction to Jobs

This tutorial shows you how to:
1. Run a Ray app non-interactively in Anyscale as an "Anyscale Job".
2. Configure and debug Anyscale Jobs.

**Note**: This tutorial is run within a workspace. Please overview the `Introduction to Workspaces` template first before this tutorial.

## Key features of Anyscale Jobs

Typically, we recommend running batch Ray apps as Anyscale Jobs when moving to production. Like workspaces, Anyscale Jobs run with their own Ray cluster, so you can run the exact same Ray program in a workspace as a Job too.

Key features of Anyscale Jobs:
- Programmatic submission API
- Automated failure handling
- Automated email alerting
- Record and persist outputs such as logs


**Note**: Ray also has an internal concept of a "Ray job", which is created when running a Ray app. Anyscale Jobs, Workspaces, and Services all launch Ray jobs internally.

## Walkthrough

First, let's run the following app first interactively in the current workspace.

This template includes a simple processing job in **./main.py** that runs a few Ray tasks. Run the cell below in the workspace, you should see it print the result after a few seconds.


```python
# First install the necessary `emoji` dependency.
!pip install emoji
```


```python
# Then run the Ray app script.
!python main.py
```

Next, let's try submitting the app to Anyscale Jobs. Within a workspace, you can use the "ray job submit" (job runs will be managed by Anyscale Jobs) functionality for this.

The following cell should also run to completion within a few minutes and print the same result. Note however that the Ray app was not run within the workspace cluster (you can check the ``Ray Dashboard`` to verify). It was submitted to Anyscale for execution on a new Ray cluster.


```python
# Second, submit the Ray app for execution on a new Ray cluster.
# The execution will be managed by Anyscale Jobs.
!ray job submit --wait -- python main.py

# Tip: You can run any Ray app as a job by prefixing its entrypoint with "ray job submit --".
```

### Job UI Overview

You can view active and historical job runs at (`Home > Jobs`). Click into the job run created by the above cell to inspect its results.

You should see the job state and its output on the overview page.

<img src="https://raw.githubusercontent.com/anyscale/templates/main/templates/intro-jobs/assets/anyscale-job.png" height=400px>

This concludes the Anyscale Jobs tutorial. To learn more about how to configure Anyscale Jobs, see the [Anyscale documentation](https://docs.endpoints.anyscale.com/preview/).

## Summary

This notebook:
- Ran a simple Ray app in the local workspace.
- Submitted the same Ray app as an Anyscale Job.
Binary file added templates/intro-jobs/assets/anyscale-job.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions templates/intro-jobs/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import ray
import emoji
import time

@ray.remote
def process(x):
print(emoji.emojize("Processing :thumbs_up:"), x)
time.sleep(1)
return x * 2

result = ray.get([process.remote(x) for x in range(10)])
print("The job result is", result)
Loading