Skip to content

Commit 263dba5

Browse files
krishr2d2rohith-egenkrishr2d2
authored
fix, refactor(egen): Replaces K80 with T4 GPUs, corrections from template (#3013)
* fix: n1-standard-8 changed to n1-standard-16 and Tesla K80 changed to Tesla T4 + refactored code according to the template * refactor: keeping the machine types same. Original issue with the K80 accelerators as they're no longer supported --------- Co-authored-by: rohith-egen <[email protected]> Co-authored-by: krishr2d2 <[email protected]>
1 parent 86243a1 commit 263dba5

File tree

1 file changed

+62
-191
lines changed

1 file changed

+62
-191
lines changed

Diff for: notebooks/official/ray_on_vertex_ai/ray_cluster_management.ipynb

+62-191
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,17 @@
4545
" </a>\n",
4646
" </td>\n",
4747
" <td style=\"text-align: center\">\n",
48+
" <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://raw.githubusercontent.com/GoogleCloudPlatform/vertex-ai-samples/main/notebooks/official/ray_on_vertex_ai/ray_cluster_management.ipynb\">\n",
49+
" <img src=\"https://lh3.googleusercontent.com/UiNooY4LUgW_oTvpsNhPpQzsstV5W8F7rYgxgGBD85cWJoLmrOzhVs_ksK_vgx40SHs7jCqkTkCk=e14-rj-sc0xffffff-h130-w32\" alt=\"Vertex AI logo\"> <br>\n",
50+
" Open in Vertex AI Workbench\n",
51+
" </a>\n",
52+
" </td>\n",
53+
"<td style=\"text-align: center\">\n",
4854
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/ray_on_vertex_ai/ray_cluster_management.ipynb\">\n",
4955
" <img src=\"https://cloud.google.com/ml-engine/images/github-logo-32px.png\" alt=\"GitHub logo\"> <br>\n",
5056
" View on GitHub\n",
5157
" </a>\n",
5258
" </td>\n",
53-
" <td style=\"text-align: center\">\n",
54-
" <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://raw.githubusercontent.com/GoogleCloudPlatform/vertex-ai-samples/main/notebooks/official/ray_on_vertex_ai/ray_cluster_management.ipynb\">\n",
55-
" <img src=\"https://lh3.googleusercontent.com/UiNooY4LUgW_oTvpsNhPpQzsstV5W8F7rYgxgGBD85cWJoLmrOzhVs_ksK_vgx40SHs7jCqkTkCk=e14-rj-sc0xffffff-h130-w32\" alt=\"Vertex AI logo\"> <br>\n",
56-
" Open in Vertex AI Workbench\n",
57-
" </a>\n",
58-
" </td> \n",
5959
"</table>"
6060
]
6161
},
@@ -82,7 +82,7 @@
8282
"\n",
8383
"In this tutorial, you learn how to create a cluster, list existing clusters, get a cluster, update (manually scaling) a cluster, and delete a cluster.\n",
8484
"\n",
85-
"This tutorial uses the following Google Cloud ML services and resources:\n",
85+
"This tutorial uses the following Vertex AI services and resources:\n",
8686
"\n",
8787
"- [Ray on Vertex AI](https://cloud.google.com/vertex-ai/docs/open-source/ray-on-vertex-ai/overview)\n",
8888
"\n",
@@ -116,233 +116,153 @@
116116
{
117117
"cell_type": "markdown",
118118
"metadata": {
119-
"id": "i7EUnXsZhAGF"
120-
},
121-
"source": [
122-
"## Installation\n",
123-
"\n",
124-
"Install the following packages required to execute this notebook. \n"
125-
]
126-
},
127-
{
128-
"cell_type": "code",
129-
"execution_count": null,
130-
"metadata": {
131-
"id": "2b4ef9b72d43"
119+
"id": "8925ff9e165e"
132120
},
133-
"outputs": [],
134121
"source": [
135-
"! pip3 install --upgrade --quiet google-cloud-aiplatform[ray]"
122+
"## Getting Started"
136123
]
137124
},
138125
{
139126
"cell_type": "markdown",
140127
"metadata": {
141-
"id": "58707a750154"
128+
"id": "i7EUnXsZhAGF"
142129
},
143130
"source": [
144-
"### Colab only: Uncomment the following cell to restart the kernel."
131+
"### Install Vertex AI SDK and other required packages"
145132
]
146133
},
147134
{
148135
"cell_type": "code",
149136
"execution_count": null,
150137
"metadata": {
151-
"id": "f200f10a1da3"
138+
"id": "2b4ef9b72d43"
152139
},
153140
"outputs": [],
154141
"source": [
155-
"# import IPython\n",
156-
"\n",
157-
"# app = IPython.Application.instance()\n",
158-
"# app.kernel.do_shutdown(True)"
159-
]
160-
},
161-
{
162-
"cell_type": "markdown",
163-
"metadata": {
164-
"id": "BF1j6f9HApxa"
165-
},
166-
"source": [
167-
"## Before you begin\n",
168-
"\n",
169-
"### Set up your Google Cloud project\n",
170-
"\n",
171-
"**The following steps are required, regardless of your notebook environment.**\n",
172-
"\n",
173-
"1. [Select or create a Google Cloud project](https://console.cloud.google.com/cloud-resource-manager). When you first create an account, you get a $300 credit towards your compute/storage costs.\n",
174-
"\n",
175-
"2. [Make sure that billing is enabled for your project](https://cloud.google.com/billing/docs/how-to/modify-project).\n",
176-
"\n",
177-
"3. [Enable the Vertex AI API](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com).\n",
178-
"\n",
179-
"4. If you are running this notebook locally, you need to install the [Cloud SDK](https://cloud.google.com/sdk)."
142+
"! pip3 install --upgrade --quiet google-cloud-aiplatform[ray]"
180143
]
181144
},
182145
{
183146
"cell_type": "markdown",
184147
"metadata": {
185-
"id": "WReHDGG5g0XY"
148+
"id": "58707a750154"
186149
},
187150
"source": [
188-
"#### Set your project ID\n",
151+
"### Restart runtime (Colab only)\n",
189152
"\n",
190-
"**If you don't know your project ID**, try the following:\n",
191-
"* Run `gcloud config list`.\n",
192-
"* Run `gcloud projects list`.\n",
193-
"* See the support page: [Locate the project ID](https://support.google.com/googleapi/answer/7014113)"
153+
"To use the newly installed packages, you must restart the runtime on Google Colab."
194154
]
195155
},
196156
{
197157
"cell_type": "code",
198158
"execution_count": null,
199159
"metadata": {
200-
"id": "oM1iC_MfAts1"
160+
"id": "f200f10a1da3"
201161
},
202162
"outputs": [],
203163
"source": [
204-
"PROJECT_ID = \"[your-project-id]\" # @param {type:\"string\"}\n",
164+
"import sys\n",
205165
"\n",
206-
"# Set the project id\n",
207-
"! gcloud config set project {PROJECT_ID}"
208-
]
209-
},
210-
{
211-
"cell_type": "markdown",
212-
"metadata": {
213-
"id": "region"
214-
},
215-
"source": [
216-
"#### Region\n",
166+
"if \"google.colab\" in sys.modules:\n",
217167
"\n",
218-
"You can also change the `REGION` variable used by Vertex AI. Learn more about [Vertex AI regions](https://cloud.google.com/vertex-ai/docs/general/locations)."
219-
]
220-
},
221-
{
222-
"cell_type": "code",
223-
"execution_count": null,
224-
"metadata": {
225-
"id": "region"
226-
},
227-
"outputs": [],
228-
"source": [
229-
"REGION = \"us-central1\" # @param {type: \"string\"}"
230-
]
231-
},
232-
{
233-
"cell_type": "markdown",
234-
"metadata": {
235-
"id": "sBCra4QMA2wR"
236-
},
237-
"source": [
238-
"### Authenticate your Google Cloud account\n",
168+
" import IPython\n",
239169
"\n",
240-
"Depending on your Jupyter environment, you may have to manually authenticate. Follow the relevant instructions below."
170+
" app = IPython.Application.instance()\n",
171+
" app.kernel.do_shutdown(True)"
241172
]
242173
},
243174
{
244175
"cell_type": "markdown",
245176
"metadata": {
246-
"id": "74ccc9e52986"
177+
"id": "7b49231643e4"
247178
},
248179
"source": [
249-
"**1. Vertex AI Workbench**\n",
250-
"* Do nothing as you are already authenticated."
180+
"<div class=\"alert alert-block alert-warning\">\n",
181+
"<b>⚠️ The kernel is going to restart. Please wait until it is finished before continuing to the next step. ⚠️</b>\n",
182+
"</div>\n"
251183
]
252184
},
253185
{
254186
"cell_type": "markdown",
255187
"metadata": {
256-
"id": "de775a3773ba"
188+
"id": "7176ea64999b"
257189
},
258190
"source": [
259-
"**2. Local JupyterLab instance, uncomment and run:**"
191+
"### Authenticate your notebook environment (Colab only)\n",
192+
"\n",
193+
"Authenticate your environment on Google Colab.\n"
260194
]
261195
},
262196
{
263197
"cell_type": "code",
264198
"execution_count": null,
265199
"metadata": {
266-
"id": "254614fa0c46"
200+
"id": "7de6ef0fac42"
267201
},
268202
"outputs": [],
269203
"source": [
270-
"# ! gcloud auth login"
204+
"import sys\n",
205+
"\n",
206+
"if \"google.colab\" in sys.modules:\n",
207+
"\n",
208+
" from google.colab import auth\n",
209+
"\n",
210+
" auth.authenticate_user()"
271211
]
272212
},
273213
{
274214
"cell_type": "markdown",
275215
"metadata": {
276-
"id": "ef21552ccea8"
216+
"id": "WReHDGG5g0XY"
277217
},
278218
"source": [
279-
"**3. Colab, uncomment and run:**"
219+
"### Set Google Cloud project information and initialize Vertex AI SDK\n",
220+
"\n",
221+
"To get started using Vertex AI, you must have an existing Google Cloud project and [enable the Vertex AI API](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com). Learn more about [setting up a project and a development environment](https://cloud.google.com/vertex-ai/docs/start/cloud-environment)."
280222
]
281223
},
282224
{
283225
"cell_type": "code",
284226
"execution_count": null,
285227
"metadata": {
286-
"id": "603adbbf0532"
228+
"id": "oM1iC_MfAts1"
287229
},
288230
"outputs": [],
289231
"source": [
290-
"# from google.colab import auth\n",
291-
"# auth.authenticate_user()"
292-
]
293-
},
294-
{
295-
"cell_type": "markdown",
296-
"metadata": {
297-
"id": "f6b2ccc891ed"
298-
},
299-
"source": [
300-
"**4. Service account or other**\n",
301-
"* See how to grant Cloud Storage permissions to your service account at https://cloud.google.com/storage/docs/gsutil/commands/iam#ch-examples."
302-
]
303-
},
304-
{
305-
"cell_type": "markdown",
306-
"metadata": {
307-
"id": "zgPO1eR3CYjk"
308-
},
309-
"source": [
310-
"### Create a Cloud Storage bucket\n",
232+
"PROJECT_ID = \"[your-project-id]\" # @param {type:\"string\"}\n",
233+
"LOCATION = \"us-central1\" # @param {type:\"string\"}\n",
234+
"\n",
235+
"# Retrieve the project number\n",
236+
"PROJECT_NUMBER = !gcloud projects list --filter=\"PROJECT_ID:'{PROJECT_ID}'\" --format='value(PROJECT_NUMBER)'\n",
237+
"PROJECT_NUMBER = PROJECT_NUMBER[0]\n",
311238
"\n",
312-
"Create a storage bucket to store intermediate artifacts such as datasets.\n",
239+
"from google.cloud import aiplatform\n",
313240
"\n",
314-
"- *{Note to notebook author: For any user-provided strings that need to be unique (like bucket names or model ID's), append \"-unique\" to the end so proper testing can occur}*"
315-
]
316-
},
317-
{
318-
"cell_type": "code",
319-
"execution_count": null,
320-
"metadata": {
321-
"id": "MzGDU7TWdts_"
322-
},
323-
"outputs": [],
324-
"source": [
325-
"BUCKET_URI = f\"gs://your-bucket-name-{PROJECT_ID}-unique\" # @param {type:\"string\"}"
241+
"aiplatform.init(project=PROJECT_ID, location=LOCATION)"
326242
]
327243
},
328244
{
329245
"cell_type": "markdown",
330246
"metadata": {
331-
"id": "-EcIXiGsCePi"
247+
"id": "init_aip:mbsdk,all"
332248
},
333249
"source": [
334-
"**If your bucket doesn't already exist**: Run the following cell to create your Cloud Storage bucket."
250+
"### Set network information\n",
251+
"\n",
252+
"[Set up a VPC peering network](https://cloud.google.com/vertex-ai/docs/general/vpc-peering) and private services connection to access Vertex AI."
335253
]
336254
},
337255
{
338256
"cell_type": "code",
339257
"execution_count": null,
340258
"metadata": {
341-
"id": "NIq7R4HZCfIc"
259+
"id": "3927074343e3"
342260
},
343261
"outputs": [],
344262
"source": [
345-
"! gsutil mb -l {REGION} -p {PROJECT_ID} {BUCKET_URI}"
263+
"VPC_NETWORK = \"[your-network-name]\" # @param {type:\"string\"}\n",
264+
"VPC_NETWORK_FULL = \"projects/{}/global/networks/{}\".format(PROJECT_NUMBER, VPC_NETWORK)\n",
265+
"VPC_NETWORK_FULL"
346266
]
347267
},
348268
{
@@ -362,49 +282,7 @@
362282
},
363283
"outputs": [],
364284
"source": [
365-
"import vertex_ray\n",
366-
"from google.cloud import aiplatform"
367-
]
368-
},
369-
{
370-
"cell_type": "markdown",
371-
"metadata": {
372-
"id": "init_aip:mbsdk,all"
373-
},
374-
"source": [
375-
"### Initialize Vertex AI SDK for Python\n",
376-
"\n",
377-
"Initialize the Vertex AI SDK for Python for your project.\n",
378-
"\n",
379-
"[Set up a VPC peering network](https://cloud.google.com/vertex-ai/docs/general/vpc-peering) and private services connection to access Vertex AI."
380-
]
381-
},
382-
{
383-
"cell_type": "code",
384-
"execution_count": null,
385-
"metadata": {
386-
"id": "3927074343e3"
387-
},
388-
"outputs": [],
389-
"source": [
390-
"# Retrieve the project number\n",
391-
"PROJECT_NUMBER = !gcloud projects list --filter=\"PROJECT_ID:'{PROJECT_ID}'\" --format='value(PROJECT_NUMBER)'\n",
392-
"PROJECT_NUMBER = PROJECT_NUMBER[0]\n",
393-
"\n",
394-
"VPC_NETWORK = \"[your-network-name]\"\n",
395-
"VPC_NETWORK_FULL = \"projects/{}/global/networks/{}\".format(PROJECT_NUMBER, VPC_NETWORK)\n",
396-
"VPC_NETWORK_FULL"
397-
]
398-
},
399-
{
400-
"cell_type": "code",
401-
"execution_count": null,
402-
"metadata": {
403-
"id": "init_aip:mbsdk,all"
404-
},
405-
"outputs": [],
406-
"source": [
407-
"aiplatform.init(project=PROJECT_ID, location=REGION, staging_bucket=BUCKET_URI)"
285+
"import vertex_ray"
408286
]
409287
},
410288
{
@@ -435,7 +313,7 @@
435313
" vertex_ray.Resources(\n",
436314
" machine_type=\"n1-standard-8\",\n",
437315
" node_count=2, # Can be > 1\n",
438-
" accelerator_type=\"NVIDIA_TESLA_K80\",\n",
316+
" accelerator_type=\"NVIDIA_TESLA_T4\",\n",
439317
" accelerator_count=1,\n",
440318
" )\n",
441319
"]\n",
@@ -614,15 +492,8 @@
614492
},
615493
"outputs": [],
616494
"source": [
617-
"import os\n",
618-
"\n",
619495
"# Delete the cluster\n",
620-
"vertex_ray.delete_ray_cluster(cluster.cluster_resource_name)\n",
621-
"\n",
622-
"# Delete Cloud Storage objects that were created\n",
623-
"delete_bucket = False\n",
624-
"if delete_bucket or os.getenv(\"IS_TESTING\"):\n",
625-
" ! gsutil -m rm -r $BUCKET_URI"
496+
"vertex_ray.delete_ray_cluster(cluster.cluster_resource_name)"
626497
]
627498
}
628499
],

0 commit comments

Comments
 (0)