Skip to content

Commit d1faddb

Browse files
authored
Added guided demos to SDK repo (#97)
* Added guided demos to SDK repo * Review feedback applied
1 parent 9c9e833 commit d1faddb

23 files changed

+8182
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
{
2+
"cells": [
3+
{
4+
"attachments": {},
5+
"cell_type": "markdown",
6+
"id": "8d4a42f6",
7+
"metadata": {},
8+
"source": [
9+
"In this first notebook, we will go through the basics of using the SDK to:\n",
10+
" - Spin up a Ray cluster with our desired resources\n",
11+
" - View the status and specs of our Ray cluster\n",
12+
" - Take down the Ray cluster when finished"
13+
]
14+
},
15+
{
16+
"cell_type": "code",
17+
"execution_count": null,
18+
"id": "b55bc3ea-4ce3-49bf-bb1f-e209de8ca47a",
19+
"metadata": {},
20+
"outputs": [],
21+
"source": [
22+
"# Import pieces from codeflare-sdk\n",
23+
"from codeflare_sdk.cluster.cluster import Cluster, ClusterConfiguration\n",
24+
"from codeflare_sdk.cluster.auth import TokenAuthentication"
25+
]
26+
},
27+
{
28+
"cell_type": "code",
29+
"execution_count": null,
30+
"id": "614daa0c",
31+
"metadata": {},
32+
"outputs": [],
33+
"source": [
34+
"# Create authentication object for oc user permissions\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 AppWrapper)."
49+
]
50+
},
51+
{
52+
"cell_type": "code",
53+
"execution_count": null,
54+
"id": "0f4bc870-091f-4e11-9642-cba145710159",
55+
"metadata": {},
56+
"outputs": [],
57+
"source": [
58+
"# Create and configure our cluster object (and appwrapper)\n",
59+
"cluster = Cluster(ClusterConfiguration(\n",
60+
" name='raytest',\n",
61+
" namespace='default',\n",
62+
" min_worker=2,\n",
63+
" max_worker=2,\n",
64+
" min_cpus=1,\n",
65+
" max_cpus=1,\n",
66+
" min_memory=4,\n",
67+
" max_memory=4,\n",
68+
" gpu=0,\n",
69+
" instascale=False\n",
70+
"))"
71+
]
72+
},
73+
{
74+
"cell_type": "markdown",
75+
"id": "12eef53c",
76+
"metadata": {},
77+
"source": [
78+
"Next, we want to bring our cluster up, so we call the `up()` function below to submit our cluster AppWrapper yaml onto the MCAD queue, and begin the process of obtaining our resource cluster."
79+
]
80+
},
81+
{
82+
"cell_type": "code",
83+
"execution_count": null,
84+
"id": "f0884bbc-c224-4ca0-98a0-02dfa09c2200",
85+
"metadata": {},
86+
"outputs": [],
87+
"source": [
88+
"# Bring up the cluster\n",
89+
"cluster.up()"
90+
]
91+
},
92+
{
93+
"attachments": {},
94+
"cell_type": "markdown",
95+
"id": "657ebdfb",
96+
"metadata": {},
97+
"source": [
98+
"Now, we want to check on the status of our resource cluster, and wait until it is finally ready for use."
99+
]
100+
},
101+
{
102+
"cell_type": "code",
103+
"execution_count": null,
104+
"id": "3c1b4311-2e61-44c9-8225-87c2db11363d",
105+
"metadata": {},
106+
"outputs": [],
107+
"source": [
108+
"cluster.status()"
109+
]
110+
},
111+
{
112+
"cell_type": "code",
113+
"execution_count": null,
114+
"id": "a99d5aff",
115+
"metadata": {},
116+
"outputs": [],
117+
"source": [
118+
"cluster.wait_ready()"
119+
]
120+
},
121+
{
122+
"cell_type": "code",
123+
"execution_count": null,
124+
"id": "df71c1ed",
125+
"metadata": {},
126+
"outputs": [],
127+
"source": [
128+
"cluster.status()"
129+
]
130+
},
131+
{
132+
"attachments": {},
133+
"cell_type": "markdown",
134+
"id": "b3a55fe4",
135+
"metadata": {},
136+
"source": [
137+
"Let's quickly verify that the specs of the cluster are as expected."
138+
]
139+
},
140+
{
141+
"cell_type": "code",
142+
"execution_count": null,
143+
"id": "7fd45bc5-03c0-4ae5-9ec5-dd1c30f1a084",
144+
"metadata": {},
145+
"outputs": [],
146+
"source": [
147+
"cluster.details()"
148+
]
149+
},
150+
{
151+
"cell_type": "markdown",
152+
"id": "5af8cd32",
153+
"metadata": {},
154+
"source": [
155+
"Finally, we bring our resource cluster down and release/terminate the associated resources, bringing everything back to the way it was before our cluster was brought up."
156+
]
157+
},
158+
{
159+
"cell_type": "code",
160+
"execution_count": null,
161+
"id": "5f36db0f-31f6-4373-9503-dc3c1c4c3f57",
162+
"metadata": {},
163+
"outputs": [],
164+
"source": [
165+
"cluster.down()"
166+
]
167+
},
168+
{
169+
"cell_type": "code",
170+
"execution_count": null,
171+
"id": "0d41b90e",
172+
"metadata": {},
173+
"outputs": [],
174+
"source": [
175+
"auth.logout()"
176+
]
177+
}
178+
],
179+
"metadata": {
180+
"kernelspec": {
181+
"display_name": "Python 3",
182+
"language": "python",
183+
"name": "python3"
184+
},
185+
"language_info": {
186+
"codemirror_mode": {
187+
"name": "ipython",
188+
"version": 3
189+
},
190+
"file_extension": ".py",
191+
"mimetype": "text/x-python",
192+
"name": "python",
193+
"nbconvert_exporter": "python",
194+
"pygments_lexer": "ipython3",
195+
"version": "3.9.13"
196+
},
197+
"vscode": {
198+
"interpreter": {
199+
"hash": "f9f85f796d01129d0dd105a088854619f454435301f6ffec2fea96ecbd9be4ac"
200+
}
201+
}
202+
},
203+
"nbformat": 4,
204+
"nbformat_minor": 5
205+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
{
2+
"cells": [
3+
{
4+
"attachments": {},
5+
"cell_type": "markdown",
6+
"id": "9865ee8c",
7+
"metadata": {},
8+
"source": [
9+
"In this second notebook, we will go over the basics of using InstaScale to scale up/down necessary resources that are not currently available on your OpenShift Cluster (in cloud environments)."
10+
]
11+
},
12+
{
13+
"cell_type": "code",
14+
"execution_count": null,
15+
"id": "b55bc3ea-4ce3-49bf-bb1f-e209de8ca47a",
16+
"metadata": {},
17+
"outputs": [],
18+
"source": [
19+
"# Import pieces from codeflare-sdk\n",
20+
"from codeflare_sdk.cluster.cluster import Cluster, ClusterConfiguration\n",
21+
"from codeflare_sdk.cluster.auth import TokenAuthentication"
22+
]
23+
},
24+
{
25+
"cell_type": "code",
26+
"execution_count": null,
27+
"id": "614daa0c",
28+
"metadata": {},
29+
"outputs": [],
30+
"source": [
31+
"# Create authentication object for oc user permissions\n",
32+
"auth = TokenAuthentication(\n",
33+
" token = \"XXXXX\",\n",
34+
" server = \"XXXXX\",\n",
35+
" skip_tls=False\n",
36+
")\n",
37+
"auth.login()"
38+
]
39+
},
40+
{
41+
"attachments": {},
42+
"cell_type": "markdown",
43+
"id": "bc27f84c",
44+
"metadata": {},
45+
"source": [
46+
"This time, we are working in a cloud environment, and our OpenShift cluster does not have the resources needed for our desired workloads. We will use InstaScale to dynamically scale-up guaranteed resources based on our request (that will also automatically scale-down when we are finished working):"
47+
]
48+
},
49+
{
50+
"cell_type": "code",
51+
"execution_count": null,
52+
"id": "0f4bc870-091f-4e11-9642-cba145710159",
53+
"metadata": {},
54+
"outputs": [],
55+
"source": [
56+
"# Create and configure our cluster object (and appwrapper)\n",
57+
"cluster = Cluster(ClusterConfiguration(\n",
58+
" name='instascaletest',\n",
59+
" namespace='default',\n",
60+
" min_worker=2,\n",
61+
" max_worker=2,\n",
62+
" min_cpus=2,\n",
63+
" max_cpus=2,\n",
64+
" min_memory=8,\n",
65+
" max_memory=8,\n",
66+
" gpu=1,\n",
67+
" instascale=True, # InstaScale now enabled, will scale OCP cluster to guarantee resource request\n",
68+
" machine_types=[\"m5.xlarge\", \"g4dn.xlarge\"] # Head, worker AWS machine types desired\n",
69+
"))"
70+
]
71+
},
72+
{
73+
"attachments": {},
74+
"cell_type": "markdown",
75+
"id": "12eef53c",
76+
"metadata": {},
77+
"source": [
78+
"Same as last time, we will bring the cluster up, wait for it to be ready, and confirm that the specs are as-requested:"
79+
]
80+
},
81+
{
82+
"cell_type": "code",
83+
"execution_count": null,
84+
"id": "f0884bbc-c224-4ca0-98a0-02dfa09c2200",
85+
"metadata": {},
86+
"outputs": [],
87+
"source": [
88+
"# Bring up the cluster\n",
89+
"cluster.up()\n",
90+
"cluster.wait_ready()"
91+
]
92+
},
93+
{
94+
"attachments": {},
95+
"cell_type": "markdown",
96+
"id": "6abfe904",
97+
"metadata": {},
98+
"source": [
99+
"While the resources are being scaled, we can also go into the console and take a look at the InstaScale logs, as well as the new machines/nodes spinning up.\n",
100+
"\n",
101+
"Once the cluster is ready, we can confirm the specs:"
102+
]
103+
},
104+
{
105+
"cell_type": "code",
106+
"execution_count": null,
107+
"id": "7fd45bc5-03c0-4ae5-9ec5-dd1c30f1a084",
108+
"metadata": {},
109+
"outputs": [],
110+
"source": [
111+
"cluster.details()"
112+
]
113+
},
114+
{
115+
"cell_type": "markdown",
116+
"id": "5af8cd32",
117+
"metadata": {},
118+
"source": [
119+
"Finally, we bring our resource cluster down and release/terminate the associated resources, bringing everything back to the way it was before our cluster was brought up."
120+
]
121+
},
122+
{
123+
"cell_type": "code",
124+
"execution_count": null,
125+
"id": "5f36db0f-31f6-4373-9503-dc3c1c4c3f57",
126+
"metadata": {},
127+
"outputs": [],
128+
"source": [
129+
"cluster.down()"
130+
]
131+
},
132+
{
133+
"attachments": {},
134+
"cell_type": "markdown",
135+
"id": "c883caea",
136+
"metadata": {},
137+
"source": [
138+
"Once again, we can look at the machines/nodes and see that everything has been successfully scaled down!"
139+
]
140+
},
141+
{
142+
"cell_type": "code",
143+
"execution_count": null,
144+
"id": "0d41b90e",
145+
"metadata": {},
146+
"outputs": [],
147+
"source": [
148+
"auth.logout()"
149+
]
150+
}
151+
],
152+
"metadata": {
153+
"kernelspec": {
154+
"display_name": "Python 3",
155+
"language": "python",
156+
"name": "python3"
157+
},
158+
"language_info": {
159+
"codemirror_mode": {
160+
"name": "ipython",
161+
"version": 3
162+
},
163+
"file_extension": ".py",
164+
"mimetype": "text/x-python",
165+
"name": "python",
166+
"nbconvert_exporter": "python",
167+
"pygments_lexer": "ipython3",
168+
"version": "3.9.13"
169+
},
170+
"vscode": {
171+
"interpreter": {
172+
"hash": "f9f85f796d01129d0dd105a088854619f454435301f6ffec2fea96ecbd9be4ac"
173+
}
174+
}
175+
},
176+
"nbformat": 4,
177+
"nbformat_minor": 5
178+
}

0 commit comments

Comments
 (0)