|
45 | 45 | " </a>\n",
|
46 | 46 | " </td>\n",
|
47 | 47 | " <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", |
48 | 54 | " <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/ray_on_vertex_ai/ray_cluster_management.ipynb\">\n",
|
49 | 55 | " <img src=\"https://cloud.google.com/ml-engine/images/github-logo-32px.png\" alt=\"GitHub logo\"> <br>\n",
|
50 | 56 | " View on GitHub\n",
|
51 | 57 | " </a>\n",
|
52 | 58 | " </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", |
59 | 59 | "</table>"
|
60 | 60 | ]
|
61 | 61 | },
|
|
82 | 82 | "\n",
|
83 | 83 | "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",
|
84 | 84 | "\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", |
86 | 86 | "\n",
|
87 | 87 | "- [Ray on Vertex AI](https://cloud.google.com/vertex-ai/docs/open-source/ray-on-vertex-ai/overview)\n",
|
88 | 88 | "\n",
|
|
116 | 116 | {
|
117 | 117 | "cell_type": "markdown",
|
118 | 118 | "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" |
132 | 120 | },
|
133 |
| - "outputs": [], |
134 | 121 | "source": [
|
135 |
| - "! pip3 install --upgrade --quiet google-cloud-aiplatform[ray]" |
| 122 | + "## Getting Started" |
136 | 123 | ]
|
137 | 124 | },
|
138 | 125 | {
|
139 | 126 | "cell_type": "markdown",
|
140 | 127 | "metadata": {
|
141 |
| - "id": "58707a750154" |
| 128 | + "id": "i7EUnXsZhAGF" |
142 | 129 | },
|
143 | 130 | "source": [
|
144 |
| - "### Colab only: Uncomment the following cell to restart the kernel." |
| 131 | + "### Install Vertex AI SDK and other required packages" |
145 | 132 | ]
|
146 | 133 | },
|
147 | 134 | {
|
148 | 135 | "cell_type": "code",
|
149 | 136 | "execution_count": null,
|
150 | 137 | "metadata": {
|
151 |
| - "id": "f200f10a1da3" |
| 138 | + "id": "2b4ef9b72d43" |
152 | 139 | },
|
153 | 140 | "outputs": [],
|
154 | 141 | "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]" |
180 | 143 | ]
|
181 | 144 | },
|
182 | 145 | {
|
183 | 146 | "cell_type": "markdown",
|
184 | 147 | "metadata": {
|
185 |
| - "id": "WReHDGG5g0XY" |
| 148 | + "id": "58707a750154" |
186 | 149 | },
|
187 | 150 | "source": [
|
188 |
| - "#### Set your project ID\n", |
| 151 | + "### Restart runtime (Colab only)\n", |
189 | 152 | "\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." |
194 | 154 | ]
|
195 | 155 | },
|
196 | 156 | {
|
197 | 157 | "cell_type": "code",
|
198 | 158 | "execution_count": null,
|
199 | 159 | "metadata": {
|
200 |
| - "id": "oM1iC_MfAts1" |
| 160 | + "id": "f200f10a1da3" |
201 | 161 | },
|
202 | 162 | "outputs": [],
|
203 | 163 | "source": [
|
204 |
| - "PROJECT_ID = \"[your-project-id]\" # @param {type:\"string\"}\n", |
| 164 | + "import sys\n", |
205 | 165 | "\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", |
217 | 167 | "\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", |
239 | 169 | "\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)" |
241 | 172 | ]
|
242 | 173 | },
|
243 | 174 | {
|
244 | 175 | "cell_type": "markdown",
|
245 | 176 | "metadata": {
|
246 |
| - "id": "74ccc9e52986" |
| 177 | + "id": "7b49231643e4" |
247 | 178 | },
|
248 | 179 | "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" |
251 | 183 | ]
|
252 | 184 | },
|
253 | 185 | {
|
254 | 186 | "cell_type": "markdown",
|
255 | 187 | "metadata": {
|
256 |
| - "id": "de775a3773ba" |
| 188 | + "id": "7176ea64999b" |
257 | 189 | },
|
258 | 190 | "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" |
260 | 194 | ]
|
261 | 195 | },
|
262 | 196 | {
|
263 | 197 | "cell_type": "code",
|
264 | 198 | "execution_count": null,
|
265 | 199 | "metadata": {
|
266 |
| - "id": "254614fa0c46" |
| 200 | + "id": "7de6ef0fac42" |
267 | 201 | },
|
268 | 202 | "outputs": [],
|
269 | 203 | "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()" |
271 | 211 | ]
|
272 | 212 | },
|
273 | 213 | {
|
274 | 214 | "cell_type": "markdown",
|
275 | 215 | "metadata": {
|
276 |
| - "id": "ef21552ccea8" |
| 216 | + "id": "WReHDGG5g0XY" |
277 | 217 | },
|
278 | 218 | "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)." |
280 | 222 | ]
|
281 | 223 | },
|
282 | 224 | {
|
283 | 225 | "cell_type": "code",
|
284 | 226 | "execution_count": null,
|
285 | 227 | "metadata": {
|
286 |
| - "id": "603adbbf0532" |
| 228 | + "id": "oM1iC_MfAts1" |
287 | 229 | },
|
288 | 230 | "outputs": [],
|
289 | 231 | "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", |
311 | 238 | "\n",
|
312 |
| - "Create a storage bucket to store intermediate artifacts such as datasets.\n", |
| 239 | + "from google.cloud import aiplatform\n", |
313 | 240 | "\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)" |
326 | 242 | ]
|
327 | 243 | },
|
328 | 244 | {
|
329 | 245 | "cell_type": "markdown",
|
330 | 246 | "metadata": {
|
331 |
| - "id": "-EcIXiGsCePi" |
| 247 | + "id": "init_aip:mbsdk,all" |
332 | 248 | },
|
333 | 249 | "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." |
335 | 253 | ]
|
336 | 254 | },
|
337 | 255 | {
|
338 | 256 | "cell_type": "code",
|
339 | 257 | "execution_count": null,
|
340 | 258 | "metadata": {
|
341 |
| - "id": "NIq7R4HZCfIc" |
| 259 | + "id": "3927074343e3" |
342 | 260 | },
|
343 | 261 | "outputs": [],
|
344 | 262 | "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" |
346 | 266 | ]
|
347 | 267 | },
|
348 | 268 | {
|
|
362 | 282 | },
|
363 | 283 | "outputs": [],
|
364 | 284 | "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" |
408 | 286 | ]
|
409 | 287 | },
|
410 | 288 | {
|
|
435 | 313 | " vertex_ray.Resources(\n",
|
436 | 314 | " machine_type=\"n1-standard-8\",\n",
|
437 | 315 | " node_count=2, # Can be > 1\n",
|
438 |
| - " accelerator_type=\"NVIDIA_TESLA_K80\",\n", |
| 316 | + " accelerator_type=\"NVIDIA_TESLA_T4\",\n", |
439 | 317 | " accelerator_count=1,\n",
|
440 | 318 | " )\n",
|
441 | 319 | "]\n",
|
|
614 | 492 | },
|
615 | 493 | "outputs": [],
|
616 | 494 | "source": [
|
617 |
| - "import os\n", |
618 |
| - "\n", |
619 | 495 | "# 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)" |
626 | 497 | ]
|
627 | 498 | }
|
628 | 499 | ],
|
|
0 commit comments