|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "id": "8d4a42f6", |
| 6 | + "metadata": {}, |
| 7 | + "source": [ |
| 8 | + "In this notebook, we will go through the basics of using the SDK to:\n", |
| 9 | + " - Spin up a Ray cluster with our desired resources\n", |
| 10 | + " - View the status and specs of our Ray cluster\n", |
| 11 | + " - Take down the Ray cluster when finished" |
| 12 | + ] |
| 13 | + }, |
| 14 | + { |
| 15 | + "cell_type": "code", |
| 16 | + "execution_count": null, |
| 17 | + "id": "b55bc3ea-4ce3-49bf-bb1f-e209de8ca47a", |
| 18 | + "metadata": {}, |
| 19 | + "outputs": [], |
| 20 | + "source": [ |
| 21 | + "# Import pieces from codeflare-sdk\n", |
| 22 | + "from codeflare_sdk import Cluster, ClusterConfiguration, TokenAuthentication" |
| 23 | + ] |
| 24 | + }, |
| 25 | + { |
| 26 | + "cell_type": "code", |
| 27 | + "execution_count": null, |
| 28 | + "id": "614daa0c", |
| 29 | + "metadata": {}, |
| 30 | + "outputs": [], |
| 31 | + "source": [ |
| 32 | + "# Create authentication object for user permissions\n", |
| 33 | + "# IF unused, SDK will automatically check for default kubeconfig, then in-cluster config\n", |
| 34 | + "# KubeConfigFileAuthentication can also be used to specify kubeconfig path manually\n", |
| 35 | + "auth = TokenAuthentication(\n", |
| 36 | + " token = \"XXXXX\",\n", |
| 37 | + " server = \"XXXXX\",\n", |
| 38 | + " skip_tls=False\n", |
| 39 | + ")\n", |
| 40 | + "auth.login()" |
| 41 | + ] |
| 42 | + }, |
| 43 | + { |
| 44 | + "cell_type": "markdown", |
| 45 | + "id": "bc27f84c", |
| 46 | + "metadata": {}, |
| 47 | + "source": [ |
| 48 | + "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", |
| 49 | + "\n", |
| 50 | + "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", |
| 51 | + "If you have your own Ray image which suits your purposes, specify it in image field to override the default image." |
| 52 | + ] |
| 53 | + }, |
| 54 | + { |
| 55 | + "cell_type": "code", |
| 56 | + "execution_count": null, |
| 57 | + "id": "0f4bc870-091f-4e11-9642-cba145710159", |
| 58 | + "metadata": {}, |
| 59 | + "outputs": [], |
| 60 | + "source": [ |
| 61 | + "# Create and configure our cluster object\n", |
| 62 | + "# The SDK will try to find the name of your default local queue based on the annotation \"kueue.x-k8s.io/default-queue\": \"true\" unless you specify the local queue manually below\n", |
| 63 | + "cluster = Cluster(ClusterConfiguration(\n", |
| 64 | + " name='raytest', \n", |
| 65 | + " head_cpu_requests='500m',\n", |
| 66 | + " head_cpu_limits='500m',\n", |
| 67 | + " head_memory_requests=2,\n", |
| 68 | + " head_memory_limits=2,\n", |
| 69 | + " head_extended_resource_requests={'nvidia.com/gpu':0}, # For GPU enabled workloads set the head_extended_resource_requests and worker_extended_resource_requests\n", |
| 70 | + " worker_extended_resource_requests={'nvidia.com/gpu':0},\n", |
| 71 | + " num_workers=2,\n", |
| 72 | + " worker_cpu_requests='250m',\n", |
| 73 | + " worker_cpu_limits=1,\n", |
| 74 | + " worker_memory_requests=2,\n", |
| 75 | + " worker_memory_limits=2,\n", |
| 76 | + " # image=\"\", # Optional Field \n", |
| 77 | + " write_to_file=False, # When enabled Ray Cluster yaml files are written to /HOME/.codeflare/resources \n", |
| 78 | + " # local_queue=\"local-queue-name\" # Specify the local queue manually\n", |
| 79 | + "))" |
| 80 | + ] |
| 81 | + }, |
| 82 | + { |
| 83 | + "cell_type": "code", |
| 84 | + "execution_count": null, |
| 85 | + "id": "2d8e6ce3", |
| 86 | + "metadata": {}, |
| 87 | + "outputs": [], |
| 88 | + "source": [ |
| 89 | + "cluster.status()" |
| 90 | + ] |
| 91 | + } |
| 92 | + ], |
| 93 | + "metadata": { |
| 94 | + "kernelspec": { |
| 95 | + "display_name": "Python 3 (ipykernel)", |
| 96 | + "language": "python", |
| 97 | + "name": "python3" |
| 98 | + }, |
| 99 | + "language_info": { |
| 100 | + "codemirror_mode": { |
| 101 | + "name": "ipython", |
| 102 | + "version": 3 |
| 103 | + }, |
| 104 | + "file_extension": ".py", |
| 105 | + "mimetype": "text/x-python", |
| 106 | + "name": "python", |
| 107 | + "nbconvert_exporter": "python", |
| 108 | + "pygments_lexer": "ipython3", |
| 109 | + "version": "3.9.19" |
| 110 | + }, |
| 111 | + "vscode": { |
| 112 | + "interpreter": { |
| 113 | + "hash": "f9f85f796d01129d0dd105a088854619f454435301f6ffec2fea96ecbd9be4ac" |
| 114 | + } |
| 115 | + } |
| 116 | + }, |
| 117 | + "nbformat": 4, |
| 118 | + "nbformat_minor": 5 |
| 119 | +} |
0 commit comments