diff --git a/demo-notebooks/additional-demos/remote_ray_job_client.ipynb b/demo-notebooks/additional-demos/remote_ray_job_client.ipynb new file mode 100644 index 000000000..b2be68260 --- /dev/null +++ b/demo-notebooks/additional-demos/remote_ray_job_client.ipynb @@ -0,0 +1,103 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Submit a training job remotely to Ray Dashboard protected by oAuth.\n", + "This notebook will demonstrate how to submit Ray jobs to an existing Raycluster, using the CodeFlare SDK.\n", + "\n", + "### Requirements\n", + "* Ray Cluster running in OpenShift protected by oAuth.\n", + "* The Ray Dashboard URL for the Ray Cluster.\n", + "* An OpenShift authorization token with permissions to access the Route.\n", + "* A training job, defined in python, within the working directory.\n", + "* A requirements.txt or equivalent file containing any additional packages to install onto the Ray images." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Import dependencies from codeflare-sdk\n", + "from codeflare_sdk import RayJobClient" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Setup Authentication Configuration \n", + "auth_token = \"XXXX\" # Replace with the actual token\n", + "header = {\n", + " 'Authorization': f'Bearer {auth_token}'\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Gather the dashboard URL (provided by the creator of the RayCluster)\n", + "ray_dashboard = \"XXXX\" # Replace with the Ray dashboard URL" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#Initialize the RayJobClient\n", + "client = RayJobClient(address=ray_dashboard, headers=header, verify=True)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Submit a job using the RayJobClient\n", + "entrypoint_command = \"python XXXX\" # Replace with the training script name\n", + "submission_id = client.submit_job(\n", + " entrypoint=entrypoint_command,\n", + " runtime_env={\"working_dir\": \"./\",\"pip\": \"requirements.txt\"},\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Get the job's status\n", + "client.get_job_status(submission_id)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Get the job's logs\n", + "client.get_job_logs(submission_id)" + ] + } + ], + "metadata": { + "language_info": { + "name": "python" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}