Skip to content

Intuit python version for compatible Ray image #711

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

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
8 changes: 6 additions & 2 deletions demo-notebooks/additional-demos/hf_interactive.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,12 @@
"source": [
"Here, we want to define our cluster by specifying the resources we require for our batch workload. Below, we define our cluster object (which generates a corresponding Ray Cluster).\n",
"\n",
"NOTE: 'quay.io/modh/ray:2.35.0-py39-cu121' is the default image used by the CodeFlare SDK for creating a RayCluster resource. \n",
"If you have your own Ray image which suits your purposes, specify it in image field to override the default image."
"NOTE: The default images used by the CodeFlare SDK for creating a RayCluster resource depend on the installed Python version:\n",
"\n",
"- For Python 3.9: 'quay.io/modh/ray:2.35.0-py39-cu121'\n",
"- For Python 3.11: 'quay.io/modh/ray:2.35.0-py311-cu121'\n",
"\n",
"If you prefer to use a custom Ray image that better suits your needs, you can specify it in the image field to override the default."
]
},
{
Expand Down
8 changes: 6 additions & 2 deletions demo-notebooks/additional-demos/local_interactive.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,12 @@
"metadata": {},
"source": [
"\n",
"NOTE: 'quay.io/modh/ray:2.35.0-py39-cu121' is the default image used by the CodeFlare SDK for creating a RayCluster resource. \n",
"If you have your own Ray image which suits your purposes, specify it in image field to override the default image."
"NOTE: The default images used by the CodeFlare SDK for creating a RayCluster resource depend on the installed Python version:\n",
"\n",
"- For Python 3.9: 'quay.io/modh/ray:2.35.0-py39-cu121'\n",
"- For Python 3.11: 'quay.io/modh/ray:2.35.0-py311-cu121'\n",
"\n",
"If you prefer to use a custom Ray image that better suits your needs, you can specify it in the image field to override the default."
]
},
{
Expand Down
8 changes: 6 additions & 2 deletions demo-notebooks/additional-demos/ray_job_client.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,12 @@
"metadata": {},
"source": [
"\n",
"NOTE: 'quay.io/modh/ray:2.35.0-py39-cu121' is the default image used by the CodeFlare SDK for creating a RayCluster resource. \n",
"If you have your own Ray image which suits your purposes, specify it in image field to override the default image."
"NOTE: The default images used by the CodeFlare SDK for creating a RayCluster resource depend on the installed Python version:\n",
"\n",
"- For Python 3.9: 'quay.io/modh/ray:2.35.0-py39-cu121'\n",
"- For Python 3.11: 'quay.io/modh/ray:2.35.0-py311-cu121'\n",
"\n",
"If you prefer to use a custom Ray image that better suits your needs, you can specify it in the image field to override the default."
]
},
{
Expand Down
8 changes: 6 additions & 2 deletions demo-notebooks/guided-demos/0_basic_ray.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,12 @@
"source": [
"Here, we want to define our cluster by specifying the resources we require for our batch workload. Below, we define our cluster object (which generates a corresponding RayCluster).\n",
"\n",
"NOTE: 'quay.io/modh/ray:2.35.0-py39-cu121' is the default image used by the CodeFlare SDK for creating a RayCluster resource. \n",
"If you have your own Ray image which suits your purposes, specify it in image field to override the default image."
"NOTE: The default images used by the CodeFlare SDK for creating a RayCluster resource depend on the installed Python version:\n",
"\n",
"- For Python 3.9: 'quay.io/modh/ray:2.35.0-py39-cu121'\n",
"- For Python 3.11: 'quay.io/modh/ray:2.35.0-py311-cu121'\n",
"\n",
"If you prefer to use a custom Ray image that better suits your needs, you can specify it in the image field to override the default."
]
},
{
Expand Down
8 changes: 6 additions & 2 deletions demo-notebooks/guided-demos/1_cluster_job_client.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,12 @@
"source": [
"Here, we want to define our cluster by specifying the resources we require for our batch workload. Below, we define our cluster object (which generates a corresponding RayCluster).\n",
"\n",
"NOTE: 'quay.io/modh/ray:2.35.0-py39-cu121' is the default image used by the CodeFlare SDK for creating a RayCluster resource. \n",
"If you have your own Ray image which suits your purposes, specify it in image field to override the default image."
"NOTE: The default images used by the CodeFlare SDK for creating a RayCluster resource depend on the installed Python version:\n",
"\n",
"- For Python 3.9: 'quay.io/modh/ray:2.35.0-py39-cu121'\n",
"- For Python 3.11: 'quay.io/modh/ray:2.35.0-py311-cu121'\n",
"\n",
"If you prefer to use a custom Ray image that better suits your needs, you can specify it in the image field to override the default."
]
},
{
Expand Down
8 changes: 6 additions & 2 deletions demo-notebooks/guided-demos/2_basic_interactive.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,12 @@
"source": [
"Once again, let's start by running through the same cluster setup as before:\n",
"\n",
"NOTE: 'quay.io/modh/ray:2.35.0-py39-cu121' is the default image used by the CodeFlare SDK for creating a RayCluster resource. \n",
"If you have your own Ray image which suits your purposes, specify it in image field to override the default image."
"NOTE: The default images used by the CodeFlare SDK for creating a RayCluster resource depend on the installed Python version:\n",
"\n",
"- For Python 3.9: 'quay.io/modh/ray:2.35.0-py39-cu121'\n",
"- For Python 3.11: 'quay.io/modh/ray:2.35.0-py311-cu121'\n",
"\n",
"If you prefer to use a custom Ray image that better suits your needs, you can specify it in the image field to override the default."
]
},
{
Expand Down
8 changes: 6 additions & 2 deletions demo-notebooks/guided-demos/3_widget_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,12 @@
"source": [
"Here, we want to define our cluster by specifying the resources we require for our batch workload. Below, we define our cluster object (which generates a corresponding RayCluster).\n",
"\n",
"NOTE: 'quay.io/modh/ray:2.35.0-py39-cu121' is the default image used by the CodeFlare SDK for creating a RayCluster resource. \n",
"If you have your own Ray image which suits your purposes, specify it in image field to override the default image."
"NOTE: The default images used by the CodeFlare SDK for creating a RayCluster resource depend on the installed Python version:\n",
"\n",
"- For Python 3.9: 'quay.io/modh/ray:2.35.0-py39-cu121'\n",
"- For Python 3.11: 'quay.io/modh/ray:2.35.0-py311-cu121'\n",
"\n",
"If you prefer to use a custom Ray image that better suits your needs, you can specify it in the image field to override the default."
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,12 @@
"source": [
"Here, we want to define our cluster by specifying the resources we require for our batch workload. Below, we define our cluster object (which generates a corresponding RayCluster).\n",
"\n",
"NOTE: 'quay.io/modh/ray:2.35.0-py39-cu121' is the default image used by the CodeFlare SDK for creating a RayCluster resource. \n",
"If you have your own Ray image which suits your purposes, specify it in image field to override the default image."
"NOTE: The default images used by the CodeFlare SDK for creating a RayCluster resource depend on the installed Python version:\n",
"\n",
"- For Python 3.9: 'quay.io/modh/ray:2.35.0-py39-cu121'\n",
"- For Python 3.11: 'quay.io/modh/ray:2.35.0-py311-cu121'\n",
"\n",
"If you prefer to use a custom Ray image that better suits your needs, you can specify it in the image field to override the default."
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,12 @@
"source": [
"Here, we want to define our cluster by specifying the resources we require for our batch workload. Below, we define our cluster object (which generates a corresponding RayCluster).\n",
"\n",
"NOTE: 'quay.io/modh/ray:2.35.0-py39-cu121' is the default image used by the CodeFlare SDK for creating a RayCluster resource. \n",
"If you have your own Ray image which suits your purposes, specify it in image field to override the default image."
"NOTE: The default images used by the CodeFlare SDK for creating a RayCluster resource depend on the installed Python version:\n",
"\n",
"- For Python 3.9: 'quay.io/modh/ray:2.35.0-py39-cu121'\n",
"- For Python 3.11: 'quay.io/modh/ray:2.35.0-py311-cu121'\n",
"\n",
"If you prefer to use a custom Ray image that better suits your needs, you can specify it in the image field to override the default."
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,12 @@
"source": [
"Once again, let's start by running through the same cluster setup as before:\n",
"\n",
"NOTE: 'quay.io/modh/ray:2.35.0-py39-cu121' is the default image used by the CodeFlare SDK for creating a RayCluster resource. \n",
"If you have your own Ray image which suits your purposes, specify it in image field to override the default image."
"NOTE: The default images used by the CodeFlare SDK for creating a RayCluster resource depend on the installed Python version:\n",
"\n",
"- For Python 3.9: 'quay.io/modh/ray:2.35.0-py39-cu121'\n",
"- For Python 3.11: 'quay.io/modh/ray:2.35.0-py311-cu121'\n",
"\n",
"If you prefer to use a custom Ray image that better suits your needs, you can specify it in the image field to override the default."
]
},
{
Expand Down
8 changes: 6 additions & 2 deletions demo-notebooks/guided-demos/preview_nbs/0_basic_ray.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,12 @@
"source": [
"Here, we want to define our cluster by specifying the resources we require for our batch workload. Below, we define our cluster object (which generates a corresponding RayCluster).\n",
"\n",
"NOTE: 'quay.io/modh/ray:2.35.0-py39-cu121' is the default image used by the CodeFlare SDK for creating a RayCluster resource. \n",
"If you have your own Ray image which suits your purposes, specify it in image field to override the default image."
"NOTE: The default images used by the CodeFlare SDK for creating a RayCluster resource depend on the installed Python version:\n",
"\n",
"- For Python 3.9: 'quay.io/modh/ray:2.35.0-py39-cu121'\n",
"- For Python 3.11: 'quay.io/modh/ray:2.35.0-py311-cu121'\n",
"\n",
"If you prefer to use a custom Ray image that better suits your needs, you can specify it in the image field to override the default."
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,12 @@
"source": [
"Here, we want to define our cluster by specifying the resources we require for our batch workload. Below, we define our cluster object (which generates a corresponding RayCluster).\n",
"\n",
"NOTE: 'quay.io/modh/ray:2.35.0-py39-cu121' is the default image used by the CodeFlare SDK for creating a RayCluster resource. \n",
"If you have your own Ray image which suits your purposes, specify it in image field to override the default image."
"NOTE: The default images used by the CodeFlare SDK for creating a RayCluster resource depend on the installed Python version:\n",
"\n",
"- For Python 3.9: 'quay.io/modh/ray:2.35.0-py39-cu121'\n",
"- For Python 3.11: 'quay.io/modh/ray:2.35.0-py311-cu121'\n",
"\n",
"If you prefer to use a custom Ray image that better suits your needs, you can specify it in the image field to override the default."
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,12 @@
"source": [
"Once again, let's start by running through the same cluster setup as before:\n",
"\n",
"NOTE: 'quay.io/modh/ray:2.35.0-py39-cu121' is the default image used by the CodeFlare SDK for creating a RayCluster resource. \n",
"If you have your own Ray image which suits your purposes, specify it in image field to override the default image."
"NOTE: The default images used by the CodeFlare SDK for creating a RayCluster resource depend on the installed Python version:\n",
"\n",
"- For Python 3.9: 'quay.io/modh/ray:2.35.0-py39-cu121'\n",
"- For Python 3.11: 'quay.io/modh/ray:2.35.0-py311-cu121'\n",
"\n",
"If you prefer to use a custom Ray image that better suits your needs, you can specify it in the image field to override the default."
]
},
{
Expand Down
13 changes: 9 additions & 4 deletions docs/sphinx/user-docs/cluster-configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,15 @@ requirements for creating the Ray Cluster.
))

.. note::
`quay.io/modh/ray:2.35.0-py39-cu121` is the default image used by
the CodeFlare SDK for creating a RayCluster resource. If you have your
own Ray image which suits your purposes, specify it in image field to
override the default image. If you are using ROCm compatible GPUs you
The default images used by the CodeFlare SDK for creating
a RayCluster resource depend on the installed Python version:

- For Python 3.9: `quay.io/modh/ray:2.35.0-py39-cu121`
- For Python 3.11: `quay.io/modh/ray:2.35.0-py311-cu121`

If you prefer to use a custom Ray image that better suits your
needs, you can specify it in the image field to override the default.
If you are using ROCm compatible GPUs you
can use `quay.io/modh/ray:2.35.0-py39-rocm61`. You can also find
documentation on building a custom image
`here <https://github.com/opendatahub-io/distributed-workloads/tree/main/images/runtime/examples>`__.
Expand Down
20 changes: 17 additions & 3 deletions src/codeflare_sdk/ray/cluster/generate_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
"""

import json
import sys
import typing
import warnings
import yaml
import os
import uuid
Expand All @@ -31,6 +33,11 @@
)
import codeflare_sdk

SUPPORTED_PYTHON_VERSIONS = {
"3.9": "quay.io/modh/ray@sha256:0d715f92570a2997381b7cafc0e224cfa25323f18b9545acfd23bc2b71576d06",
"3.11": "quay.io/modh/ray@sha256:db667df1bc437a7b0965e8031e905d3ab04b86390d764d120e05ea5a5c18d1b4",
}


def read_template(template):
with open(template, "r") as stream:
Expand Down Expand Up @@ -88,9 +95,16 @@ def update_names(

def update_image(spec, image):
containers = spec.get("containers")
if image != "":
for container in containers:
container["image"] = image
if not image:
python_version = f"{sys.version_info.major}.{sys.version_info.minor}"
if python_version in SUPPORTED_PYTHON_VERSIONS:
image = SUPPORTED_PYTHON_VERSIONS[python_version]
else:
warnings.warn(
f"No default Ray image defined for {python_version}. Please provide your own image or use one of the following python versions: {', '.join(SUPPORTED_PYTHON_VERSIONS.keys())}."
)
for container in containers:
container["image"] = image


def update_image_pull_secrets(spec, image_pull_secrets):
Expand Down
38 changes: 37 additions & 1 deletion src/codeflare_sdk/ray/cluster/test_generate_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from codeflare_sdk.ray.cluster.generate_yaml import gen_names
from collections import namedtuple
import sys
from .generate_yaml import gen_names, update_image
import uuid


Expand All @@ -32,3 +34,37 @@ def test_gen_names_without_name(mocker):
appwrapper_name, cluster_name = gen_names(None)
assert appwrapper_name.startswith("appwrapper-")
assert cluster_name.startswith("cluster-")


def test_update_image_without_supported_python_version(mocker):
# Mock SUPPORTED_PYTHON_VERSIONS
mocker.patch.dict(
"codeflare_sdk.ray.cluster.generate_yaml.SUPPORTED_PYTHON_VERSIONS",
{
"3.9": "ray-py3.9",
"3.11": "ray-py3.11",
},
)

# Create a namedtuple to mock sys.version_info
VersionInfo = namedtuple(
"version_info", ["major", "minor", "micro", "releaselevel", "serial"]
)
mocker.patch.object(sys, "version_info", VersionInfo(3, 8, 0, "final", 0))

# Mock warnings.warn to check if it gets called
warn_mock = mocker.patch("warnings.warn")

# Create a sample spec
spec = {"containers": [{"image": None}]}

# Call the update_image function with no image provided
update_image(spec, None)

# Assert that the warning was called with the expected message
warn_mock.assert_called_once_with(
"No default Ray image defined for 3.8. Please provide your own image or use one of the following python versions: 3.9, 3.11."
)

# Assert that no image was set in the containers since the Python version is not supported
assert spec["containers"][0]["image"] is None
2 changes: 0 additions & 2 deletions src/codeflare_sdk/ray/templates/base-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ spec:
containers:
# The Ray head pod
- name: ray-head
image: quay.io/modh/ray@sha256:0d715f92570a2997381b7cafc0e224cfa25323f18b9545acfd23bc2b71576d06
imagePullPolicy: Always
ports:
- containerPort: 6379
Expand Down Expand Up @@ -150,7 +149,6 @@ spec:
spec:
containers:
- name: machine-learning # must consist of lower case alphanumeric characters or '-', and must start and end with an alphanumeric character (e.g. 'my-name', or '123-abc'
image: quay.io/modh/ray@sha256:0d715f92570a2997381b7cafc0e224cfa25323f18b9545acfd23bc2b71576d06
# environment variables to set in the container.Optional.
# Refer to https://kubernetes.io/docs/tasks/inject-data-application/define-environment-variable-container/
lifecycle:
Expand Down