|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": {}, |
| 6 | + "source": [ |
| 7 | + "In this notebook we will go over the basics of creating Kueue enabled resources with the SDK" |
| 8 | + ] |
| 9 | + }, |
| 10 | + { |
| 11 | + "cell_type": "code", |
| 12 | + "execution_count": null, |
| 13 | + "metadata": {}, |
| 14 | + "outputs": [], |
| 15 | + "source": [ |
| 16 | + "# Import pieces from codeflare-sdk\n", |
| 17 | + "from codeflare_sdk import Cluster, ClusterConfiguration, TokenAuthentication" |
| 18 | + ] |
| 19 | + }, |
| 20 | + { |
| 21 | + "cell_type": "code", |
| 22 | + "execution_count": null, |
| 23 | + "metadata": {}, |
| 24 | + "outputs": [], |
| 25 | + "source": [ |
| 26 | + "# Create authentication object for user permissions\n", |
| 27 | + "# IF unused, SDK will automatically check for default kubeconfig, then in-cluster config\n", |
| 28 | + "# KubeConfigFileAuthentication can also be used to specify kubeconfig path manually\n", |
| 29 | + "auth = TokenAuthentication(\n", |
| 30 | + " token = \"XXXXX\",\n", |
| 31 | + " server = \"XXXXX\",\n", |
| 32 | + " skip_tls=False\n", |
| 33 | + ")\n", |
| 34 | + "auth.login()" |
| 35 | + ] |
| 36 | + }, |
| 37 | + { |
| 38 | + "cell_type": "code", |
| 39 | + "execution_count": null, |
| 40 | + "metadata": {}, |
| 41 | + "outputs": [], |
| 42 | + "source": [ |
| 43 | + "# Create and configure our cluster object\n", |
| 44 | + "# The SDK will try to find the name of your default local queue based on the annotation \"kueue.x-k8s.io/default-queue\": \"true\"\n", |
| 45 | + "cluster = Cluster(ClusterConfiguration(\n", |
| 46 | + " name='kueue-test',\n", |
| 47 | + " namespace='default',\n", |
| 48 | + " num_workers=2,\n", |
| 49 | + " min_cpus=1,\n", |
| 50 | + " max_cpus=1,\n", |
| 51 | + " min_memory=4,\n", |
| 52 | + " max_memory=4,\n", |
| 53 | + " num_gpus=0,\n", |
| 54 | + " image=\"quay.io/project-codeflare/ray:latest-py39-cu118\",\n", |
| 55 | + " # local_queue=\"local-queue-name\" # Specify the local queue manually\n", |
| 56 | + "))" |
| 57 | + ] |
| 58 | + }, |
| 59 | + { |
| 60 | + "cell_type": "code", |
| 61 | + "execution_count": null, |
| 62 | + "metadata": {}, |
| 63 | + "outputs": [], |
| 64 | + "source": [ |
| 65 | + "cluster.up()" |
| 66 | + ] |
| 67 | + }, |
| 68 | + { |
| 69 | + "cell_type": "code", |
| 70 | + "execution_count": null, |
| 71 | + "metadata": {}, |
| 72 | + "outputs": [], |
| 73 | + "source": [ |
| 74 | + "cluster.wait_ready()" |
| 75 | + ] |
| 76 | + }, |
| 77 | + { |
| 78 | + "cell_type": "code", |
| 79 | + "execution_count": null, |
| 80 | + "metadata": {}, |
| 81 | + "outputs": [], |
| 82 | + "source": [ |
| 83 | + "cluster.status()" |
| 84 | + ] |
| 85 | + }, |
| 86 | + { |
| 87 | + "cell_type": "code", |
| 88 | + "execution_count": null, |
| 89 | + "metadata": {}, |
| 90 | + "outputs": [], |
| 91 | + "source": [ |
| 92 | + "cluster.details()" |
| 93 | + ] |
| 94 | + }, |
| 95 | + { |
| 96 | + "cell_type": "code", |
| 97 | + "execution_count": null, |
| 98 | + "metadata": {}, |
| 99 | + "outputs": [], |
| 100 | + "source": [ |
| 101 | + "cluster.down()" |
| 102 | + ] |
| 103 | + }, |
| 104 | + { |
| 105 | + "cell_type": "markdown", |
| 106 | + "metadata": {}, |
| 107 | + "source": [ |
| 108 | + "Now, we will submit Jobs directly to Kueue, which will schedule a Batch Job to run with the requested resources using the Kueue Torchx scheduler:\n", |
| 109 | + "\n", |
| 110 | + "NOTE: To test this demo in an air-gapped/ disconnected environment alter the training script to use a local dataset." |
| 111 | + ] |
| 112 | + }, |
| 113 | + { |
| 114 | + "cell_type": "code", |
| 115 | + "execution_count": null, |
| 116 | + "metadata": {}, |
| 117 | + "outputs": [], |
| 118 | + "source": [ |
| 119 | + "from codeflare_sdk import DDPJobDefinition\n", |
| 120 | + "jobdef = DDPJobDefinition(\n", |
| 121 | + " name=\"mnistjob\",\n", |
| 122 | + " script=\"mnist.py\",\n", |
| 123 | + " # script=\"mnist_disconnected.py\", # training script for disconnected environment\n", |
| 124 | + " scheduler_args={\"namespace\": \"default\"},\n", |
| 125 | + " j=\"1x1\",\n", |
| 126 | + " gpu=0,\n", |
| 127 | + " cpu=1,\n", |
| 128 | + " memMB=8000,\n", |
| 129 | + " image=\"quay.io/project-codeflare/mnist-job-test:v0.0.1\",\n", |
| 130 | + ")\n", |
| 131 | + "job = jobdef.submit()" |
| 132 | + ] |
| 133 | + }, |
| 134 | + { |
| 135 | + "cell_type": "code", |
| 136 | + "execution_count": null, |
| 137 | + "metadata": {}, |
| 138 | + "outputs": [], |
| 139 | + "source": [ |
| 140 | + "job.status()" |
| 141 | + ] |
| 142 | + }, |
| 143 | + { |
| 144 | + "cell_type": "code", |
| 145 | + "execution_count": null, |
| 146 | + "metadata": {}, |
| 147 | + "outputs": [], |
| 148 | + "source": [ |
| 149 | + "job.logs()" |
| 150 | + ] |
| 151 | + }, |
| 152 | + { |
| 153 | + "cell_type": "markdown", |
| 154 | + "metadata": {}, |
| 155 | + "source": [ |
| 156 | + "This time, once the pods complete, we can clean them up alongside any other associated resources. The following command can also be used to delete jobs early for Kueue submission:" |
| 157 | + ] |
| 158 | + }, |
| 159 | + { |
| 160 | + "cell_type": "code", |
| 161 | + "execution_count": null, |
| 162 | + "metadata": {}, |
| 163 | + "outputs": [], |
| 164 | + "source": [ |
| 165 | + "job.cancel()" |
| 166 | + ] |
| 167 | + }, |
| 168 | + { |
| 169 | + "cell_type": "code", |
| 170 | + "execution_count": null, |
| 171 | + "metadata": {}, |
| 172 | + "outputs": [], |
| 173 | + "source": [ |
| 174 | + "auth.logout()" |
| 175 | + ] |
| 176 | + } |
| 177 | + ], |
| 178 | + "metadata": { |
| 179 | + "language_info": { |
| 180 | + "name": "python" |
| 181 | + } |
| 182 | + }, |
| 183 | + "nbformat": 4, |
| 184 | + "nbformat_minor": 2 |
| 185 | +} |
0 commit comments