Compare commits

...
Author SHA1 Message Date
gericdongandGitHub 3ebb74e97a Merge branch 'main' into model_monitor_batch 2022-09-23 14:17:14 -04:00
15912adeaf Update the vizier sample to replace the gapic library with new Vertex Vizier SDK. (#979)
* Update the vizier codelab to replace the gapic library with new Vertex Vizier SDK.

* Added the [project_id] and [region] in the parameter field.

* Fixed the lint errors for vizier sample.

Co-authored-by: Ivan Cheung <ivans.mailbox@gmail.com>
Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-09-23 11:12:28 -07:00
gericdongandGitHub a992a5530d Merge branch 'main' into model_monitor_batch 2022-09-23 13:37:58 -04:00
Ivan NardiniandGitHub 35fdba7e1c Vertex AI Experiments - Title fix (#982)
* title fix

* linter test passed
2022-09-23 07:17:58 -07:00
f403fa9051 Made UUID changes for Sdk automl tabular regression batch bq (#976)
* Made UUID changes

* Ran lintertest

Co-authored-by: Ivan Cheung <ivans.mailbox@gmail.com>
Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-09-22 14:45:45 -07:00
0d346b136e Vertex AI Experiments - Comparing local trained models notebook - update (#971)
* clean and update comparing_local_trained_models based on feedback

* linter test passed

* fix libraries

* linter test passed

* andy review fixes

* linter test passed

Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-09-22 12:21:22 -07:00
Andrew FerlitschandGitHub 24e0e92f8d Merge branch 'main' into model_monitor_batch 2022-09-22 11:30:51 -07:00
Andrew Ferlitsch bc4ec36914 fix: batch monitoring notebook 2022-09-22 17:33:24 +00:00
Andrew Ferlitsch 5387799f32 fix: batch monitoring notebook 2022-09-22 17:30:24 +00:00
Andrew FerlitschandGitHub 60d71d29cc update: add explain example (#974) 2022-09-22 09:35:13 -07:00
28c872f4b6 chore(deps): update python docker tag to v3.10 (#977)
Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-09-21 17:09:31 -07:00
Andrew FerlitschandGitHub c637d693b7 tune: pricing, branding, combining text cells (#966)
* tune: pricing, branding, combining text cells

* fix: lint
2022-09-21 13:20:01 -07:00
Andrew FerlitschandGitHub 5c3a216eb7 feat: Add notebook for automl text model online predict (#973) 2022-09-21 14:34:10 -04:00
Ivan CheungandGitHub 0b7831b0f4 Added Dockerfile for linter (#975)
Updated Dockerfile
2022-09-21 09:26:42 -07:00
Andrew FerlitschandGitHub 6a6f077ae4 update: add explain (#972) 2022-09-20 18:40:49 -04:00
Andrew FerlitschandGitHub 27f0a4bb63 feat: notebook for automl tabular online serving (#961)
* feat: notebook for automl tabular online serving

* feat: notebook for AutoML tabular model online prediction

* updates: add explain
2022-09-20 12:54:46 -07:00
1476453603 Moves Sentiment-Analysis notebook from community to official folder (#868)
* moves the sentiment_analysis notebook from community to official folder after making the updates

* removes unused modules

* ran linter test

* updates the dataset's GCS links and notebook links in the heading

* ran linter test

* fixes the typo(=)

* ran linter test

* removes wait() calls and IS_TESTING condition

* ran linter test

Co-authored-by: Ivan Cheung <ivans.mailbox@gmail.com>
Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-09-20 07:35:15 -07:00
dbafcb47ea Modified notebook UJ4 Vertex SDK AutoML Tabular Binary Classification (#891)
* modified notebook

* ran linter

* tensorflow was used only for file reading.So replaced tensorflow with pandas

* ran linter

* made text changes

* ran linter

* latest andrew domments addressed

* ran linter

Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-09-19 14:46:22 -07:00
f20700f25a Model monitoring (#964)
* Changed protobuf version

* ran linter test

* Cleared execution outputs

* Ran Linter test

Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-09-19 11:31:01 -07:00
Andrew FerlitschandGitHub d1ca1cd7f8 fix: reported issues (#968) 2022-09-19 14:11:56 -04:00
15 changed files with 6916 additions and 3783 deletions
+20
View File
@@ -0,0 +1,20 @@
# To use this image, run this command with the desired notebook args from the top-level vertex-ai-samples directory:
# 1. To lint all changed notebooks:
# docker run -v ${PWD}:/setup/app gcr.io/python-docs-samples-tests/notebook_linter:latest
# 2. To lint specific notebooks:
# docker run -v ${PWD}:/setup/app gcr.io/python-docs-samples-tests/notebook_linter:latest notebooks/1.ipynb notebooks/2.ipynb
FROM python:3.10
WORKDIR setup
COPY ./requirements.txt .
COPY ./run_linter.sh .
# Install dependencies.
RUN pip install --upgrade pip
RUN pip install -r requirements.txt
WORKDIR app
ENTRYPOINT ["/setup/run_linter.sh"]
+14 -4
View File
@@ -47,12 +47,22 @@ done
echo "Test mode: $is_test"
# Read in user-provided notebooks
notebooks=()
for arg in "$@"; do
if [[ $arg == *.ipynb ]]; then
notebooks+=("$arg")
fi
done
# Only check notebooks in test folders modified in this pull request.
# Note: Use process substitution to persist the data in the array
notebooks=()
while read -r file || [ -n "$line" ]; do
notebooks+=("$file")
done < <(git diff --name-only main... | grep '\.ipynb$')
if [ ${#notebooks[@]} -eq 0 ]; then
echo "Checking for changed notebooked using git"
while read -r file || [ -n "$line" ]; do
notebooks+=("$file")
done < <(git diff --name-only main... | grep '\.ipynb$')
fi
problematic_notebooks=()
if [ ${#notebooks[@]} -gt 0 ]; then
@@ -62,7 +62,7 @@
"## Overview\n",
"\n",
"\n",
"This tutorial demonstrates how to use the Vertex AI SDK to create image classification models and do batch prediction using a Vertex AI [AutoML](https://cloud.google.com/vertex-ai/docs/start/automl-users) model."
"This tutorial demonstrates how to use the Vertex AI SDK to create image classification models and do online prediction using a Vertex AI [AutoML](https://cloud.google.com/vertex-ai/docs/start/automl-users) model."
]
},
{
@@ -78,8 +78,10 @@
"This tutorial uses the following Google Cloud ML services and resources:\n",
"\n",
"- `Vertex AutoML`\n",
"- `Vertex AI Online Prediction`\n",
"- `Vertex AI Prediction`\n",
"- `Vertex AI Datasets`\n",
"- `Vertex AI Models`\n",
"- `Vertex AI Endpoints`\n",
"\n",
"The steps performed include:\n",
"\n",
@@ -628,7 +630,7 @@
"id": "tutorial_start:automl"
},
"source": [
"# Tutorial\n",
"## AutoML Image model training\n",
"\n",
"Now you are ready to start creating your own AutoML image classification model."
]
@@ -718,7 +720,7 @@
"dataset = aiplatform.ImageDataset.create(\n",
" display_name=\"Flowers\" + \"_\" + UUID,\n",
" gcs_source=[IMPORT_FILE],\n",
" import_schema_uri=aiplatform.schema.dataset.ioformat.image.single_label_classification,\n",
" import_schema_uri=aiplatform.schema.dataset.ioformat.image.single_label_classification\n",
")\n",
"\n",
"print(dataset.resource_name)"
@@ -943,9 +945,9 @@
"id": "make_prediction"
},
"source": [
"## Send a online prediction request\n",
"## Send an online prediction request\n",
"\n",
"Send a online prediction to your deployed model."
"Send an online prediction to your deployed model."
]
},
{
File diff suppressed because it is too large Load Diff
@@ -3,7 +3,6 @@
{
"cell_type": "code",
"execution_count": null,
"id": "d3069d95",
"metadata": {
"cellView": "form",
"id": "d3069d95"
@@ -11,7 +10,7 @@
"outputs": [],
"source": [
"# @title Copyright & License (click to expand)\n",
"# Copyright 2021 Google LLC\n",
"# Copyright 2022 Google LLC\n",
"#\n",
"# Licensed under the Apache License, Version 2.0 (the \"License\");\n",
"# you may not use this file except in compliance with the License.\n",
@@ -28,7 +27,6 @@
},
{
"cell_type": "markdown",
"id": "546c53de",
"metadata": {
"id": "546c53de"
},
@@ -46,13 +44,16 @@
" <img src=\"https://cloud.google.com/ml-engine/images/github-logo-32px.png\" alt=\"GitHub logo\">\n",
" View on GitHub\n",
" </a>\n",
" </td>\n",
" </td><td>\n",
" <a href=\"https://console.cloud.google.com/ai-platform/notebooks/deploy-notebook?name=Model%20Monitoring&download_url=https%3A%2F%2Fraw.githubusercontent.com%2FGoogleCloudPlatform%2Fvertex-ai-samples%2Fmain%2Fnotebooks%2Fcommunity%2Fmodel_monitoring%2Fbatch_prediction_model_monitoring.ipynb\">\n",
" <img src=\"https://www.gstatic.com/cloud/images/navigation/vertex-ai.svg\" alt=\"Google Cloud Notebooks\">Open in Workbench AI Notebook\n",
" </a>\n",
" </td> \n",
"</table>"
]
},
{
"cell_type": "markdown",
"id": "53fd1070",
"metadata": {
"id": "53fd1070"
},
@@ -64,7 +65,6 @@
},
{
"cell_type": "markdown",
"id": "8b26c855",
"metadata": {
"id": "8b26c855"
},
@@ -98,7 +98,6 @@
},
{
"cell_type": "markdown",
"id": "d52ba95b",
"metadata": {
"id": "d52ba95b"
},
@@ -110,7 +109,6 @@
},
{
"cell_type": "markdown",
"id": "e64fb18a",
"metadata": {
"id": "e64fb18a"
},
@@ -123,7 +121,6 @@
},
{
"cell_type": "markdown",
"id": "9d839347",
"metadata": {
"id": "9d839347"
},
@@ -142,7 +139,6 @@
},
{
"cell_type": "markdown",
"id": "738fce1f",
"metadata": {
"id": "738fce1f"
},
@@ -155,7 +151,6 @@
{
"cell_type": "code",
"execution_count": null,
"id": "4536fe4e",
"metadata": {
"id": "4536fe4e"
},
@@ -178,14 +173,13 @@
" USER_FLAG = \"--user\"\n",
"\n",
"# Install Python package dependencies.\n",
"! pip3 install -q tensorflow-data-validation $USER_FLAG\n",
"! pip3 install -q google-api-core $USER_FLAG\n",
"! pip3 install -q google-cloud-aiplatform $USER_FLAG"
"! pip3 install -q {USER_FLAG} tensorflow-data-validation \\\n",
" google-api-core \\\n",
" google-cloud-aiplatform"
]
},
{
"cell_type": "markdown",
"id": "6e98402b",
"metadata": {
"id": "6e98402b"
},
@@ -198,7 +192,6 @@
{
"cell_type": "code",
"execution_count": null,
"id": "9775c9ff",
"metadata": {
"id": "9775c9ff"
},
@@ -217,7 +210,6 @@
},
{
"cell_type": "markdown",
"id": "d5737134",
"metadata": {
"id": "d5737134"
},
@@ -242,7 +234,6 @@
},
{
"cell_type": "markdown",
"id": "cfb1a1d5",
"metadata": {
"id": "cfb1a1d5"
},
@@ -255,50 +246,33 @@
{
"cell_type": "code",
"execution_count": null,
"id": "cf8535e4",
"metadata": {
"id": "cf8535e4"
},
"outputs": [],
"source": [
"import os\n",
"\n",
"PROJECT_ID = \"\"\n",
"\n",
"# Get your Google Cloud project ID from gcloud\n",
"if not os.getenv(\"IS_TESTING\"):\n",
" shell_output = ! gcloud config list --format 'value(core.project)' 2>/dev/null\n",
" PROJECT_ID = shell_output[0]\n",
" print(\"Project ID: \", PROJECT_ID)"
]
},
{
"cell_type": "markdown",
"id": "05a2d397",
"metadata": {
"id": "05a2d397"
},
"source": [
"Otherwise, set your project ID here.\n"
"PROJECT_ID = \"[your-project-id]\" # @param {type:\"string\"}"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1c2be4bd",
"metadata": {
"id": "1c2be4bd"
},
"outputs": [],
"source": [
"if PROJECT_ID == \"\" or PROJECT_ID is None:\n",
" PROJECT_ID = \"python-docs-samples-tests\" # @param {type:\"string\"}"
"if PROJECT_ID == \"\" or not PROJECT_ID or PROJECT_ID == \"[your-project-id]\":\n",
" PROJECT_ID = \"[your-project-id]\" # @param {type:\"string\"}\n",
" # Get your GCP project id from gcloud\n",
" shell_output = ! gcloud config list --format 'value(core.project)' 2>/dev/null\n",
" PROJECT_ID = shell_output[0]\n",
" print(\"Project ID:\", PROJECT_ID)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c129705c",
"metadata": {
"id": "c129705c"
},
@@ -309,32 +283,6 @@
},
{
"cell_type": "markdown",
"id": "71404c9f",
"metadata": {
"id": "71404c9f"
},
"source": [
"#### Set your email address\n",
"This is used for delivering model monitoring notifications.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4b1d2b69",
"metadata": {
"id": "4b1d2b69"
},
"outputs": [],
"source": [
"EMAIL_ADDRESS = \"[your-email-address]\" # @param {type:\"string\"}\n",
"if not EMAIL_ADDRESS or EMAIL_ADDRESS == \"[your-email-address]\":\n",
" print(\"EMAIL_ADDRESS not specified, please correct before proceeding.\")"
]
},
{
"cell_type": "markdown",
"id": "83340af4",
"metadata": {
"id": "83340af4"
},
@@ -356,18 +304,73 @@
{
"cell_type": "code",
"execution_count": null,
"id": "4814ea21",
"metadata": {
"id": "4814ea21"
},
"outputs": [],
"source": [
"REGION = \"us-central1\" # @param {type: \"string\"}"
"REGION = \"[your-region]\" # @param {type: \"string\"}\n",
"\n",
"if REGION == \"[your-region]\":\n",
" REGION = \"us-central1\""
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "06571eb4063b"
},
"source": [
"#### UUID\n",
"\n",
"If you are in a live tutorial session, you might be using a shared test account or project. To avoid name collisions between users on resources created, you create a uuid for each instance session, and append it onto the name of resources you create in this tutorial."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "4e166d927e36"
},
"outputs": [],
"source": [
"import random\n",
"import string\n",
"\n",
"\n",
"# Generate a uuid of a specifed length(default=8)\n",
"def generate_uuid(length: int = 8) -> str:\n",
" return \"\".join(random.choices(string.ascii_lowercase + string.digits, k=length))\n",
"\n",
"\n",
"UUID = generate_uuid()"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "71404c9f"
},
"source": [
"#### Set your email address\n",
"This is used for delivering model monitoring notifications.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "4b1d2b69"
},
"outputs": [],
"source": [
"EMAIL_ADDRESS = \"[your-email-address]\" # @param {type:\"string\"}\n",
"if not EMAIL_ADDRESS or EMAIL_ADDRESS == \"[your-email-address]\":\n",
" print(\"EMAIL_ADDRESS not specified, please correct before proceeding.\")"
]
},
{
"cell_type": "markdown",
"id": "20a546c3",
"metadata": {
"id": "20a546c3"
},
@@ -375,16 +378,35 @@
"### Authenticate your Google Cloud account\n",
"\n",
"**If you are using Vertex AI Workbench notebooks**, your environment is already\n",
"authenticated. Skip this step.\n",
"authenticated.\n",
"\n",
"**If you are using Colab**, run the cell below and follow the instructions\n",
"when prompted to authenticate your account via oAuth.\n"
"when prompted to authenticate your account via oAuth.\n",
"\n",
"**Otherwise**, follow these steps:\n",
"\n",
"1. In the Cloud Console, go to the [**Create service account key**\n",
" page](https://console.cloud.google.com/apis/credentials/serviceaccountkey).\n",
"\n",
"2. Click **Create service account**.\n",
"\n",
"3. In the **Service account name** field, enter a name, and\n",
" click **Create**.\n",
"\n",
"4. In the **Grant this service account access to project** section, click the **Role** drop-down list. Type \"Vertex AI\"\n",
"into the filter box, and select\n",
" **Vertex AI Administrator**. Type \"Storage Object Admin\" into the filter box, and select **Storage Object Admin**.\n",
"\n",
"5. Click **Create**. A JSON file that contains your key downloads to your\n",
"local environment.\n",
"\n",
"6. Enter the path to your service account key as the\n",
"`GOOGLE_APPLICATION_CREDENTIALS` variable in the cell below and run the cell."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "06c51076",
"metadata": {
"id": "06c51076"
},
@@ -421,73 +443,284 @@
},
{
"cell_type": "markdown",
"id": "6b01af18",
"metadata": {
"id": "6b01af18"
"id": "bucket:custom"
},
"source": [
"### Upload the model\n",
"### Create a Cloud Storage bucket\n",
"\n",
"The churn propensity model you'll be using in this notebook has been trained in BigQuery ML and exported to a Google Cloud Storage bucket. This illustrates how you can easily export a trained model and move a model from one cloud service to another. \n",
"**The following steps are required, regardless of your notebook environment.**\n",
"\n",
"Next, import the model. **If you've already imported your model, you can skip this step.**"
]
},
{
"cell_type": "markdown",
"id": "9638ad2c",
"metadata": {
"id": "9638ad2c"
},
"source": [
"<span id=\"papermill-error-cell\" style=\"color:red; font-family:Helvetica Neue, Helvetica, Arial, sans-serif; font-size:2em;\">Execution using papermill encountered an exception here and stopped:</span>"
"Set the name of your Cloud Storage bucket below, which you use in this tutorial to upload the `input schema` for the monitoring service.\n",
"\n",
"Bucket names must be globally unique across all Google Cloud projects, including those outside of your organization."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "926e3ba8",
"metadata": {
"id": "926e3ba8"
"id": "bucket"
},
"outputs": [],
"source": [
"from datetime import datetime\n",
"import json\n",
"import time\n",
"import re\n",
"import tensorflow as tf\n",
"BUCKET_NAME = \"[your-bucket-name]\" # @param {type:\"string\"}\n",
"BUCKET_URI = f\"gs://{BUCKET_NAME}\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "autoset_bucket"
},
"outputs": [],
"source": [
"if BUCKET_NAME == \"\" or BUCKET_NAME is None or BUCKET_NAME == \"[your-bucket-name]\":\n",
" BUCKET_NAME = PROJECT_ID + \"aip-\" + UUID\n",
" BUCKET_URI = \"gs://\" + BUCKET_NAME"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "create_bucket"
},
"source": [
"**Only if your bucket doesn't already exist**: Run the following cell to create your Cloud Storage bucket."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "create_bucket"
},
"outputs": [],
"source": [
"! gsutil mb -l $REGION $BUCKET_URI"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "validate_bucket"
},
"source": [
"Finally, validate access to your Cloud Storage bucket by examining its contents:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "validate_bucket"
},
"outputs": [],
"source": [
"! gsutil ls -al $BUCKET_URI"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "a0d294ff6d10"
},
"source": [
"### Import libraries"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "bd7a633296eb"
},
"outputs": [],
"source": [
"import google.cloud.aiplatform as aiplatform\n",
"import tensorflow_data_validation as tfdv\n",
"from tensorflow_data_validation.utils import io_util \n",
"from tensorflow_metadata.proto.v0 import statistics_pb2\n",
"\n",
"MODEL_DISPLAY_NAME=f\"batch_prediction_monitoring_test_model_{datetime.now().strftime('%Y%m%d%H%M%S')}\"\n",
"CONTAINER_IMAGE_URI=\"us-docker.pkg.dev/cloud-aiplatform/prediction/tf2-cpu.2-4:latest\"\n",
"ARTIFACT_URI=\"gs://mco-mm/churn\"\n",
"\n",
"output = ! gcloud ai models upload \\\n",
" --region=$REGION \\\n",
" --display-name=$MODEL_DISPLAY_NAME \\\n",
" --artifact-uri=$ARTIFACT_URI \\\n",
" --container-image-uri=$CONTAINER_IMAGE_URI \\\n",
" --format=\"value(model)\"\n",
"MODEL_ID = output[1].split(\"/\")[5]\n",
"print(f\"Model {MODEL_ID} created.\")"
"from tensorflow_data_validation.utils import io_util\n",
"from tensorflow_metadata.proto.v0 import statistics_pb2"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "init_aip:mbsdk,all"
},
"source": [
"### Initialize Vertex AI SDK for Python\n",
"\n",
"Initialize the Vertex AI SDK for Python for your project and corresponding bucket."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "init_aip:mbsdk,all"
},
"outputs": [],
"source": [
"aiplatform.init(project=PROJECT_ID, location=REGION)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "accelerators:training,prediction"
},
"source": [
"#### Set hardware accelerators\n",
"\n",
"You can set hardware accelerators for prediction (e.g., GPUs) or choose not to use any (CPU). Hardware accelertors lower the latency response for a prediction request. When choosing a hardware accelerators, consider the additional cost trade-off over latency.\n",
"\n",
"Set the variables `DEPLOY_GPU/DEPLOY_NGPU` to use a container image supporting a GPU and the number of GPUs allocated to the virtual machine (VM) instance. For example, to use a GPU container image with 4 Nvidia Tesla K80 GPUs allocated to each VM, you would specify:\n",
"\n",
" (aiplatform.gapic.AcceleratorType.NVIDIA_TESLA_K80, 4)\n",
"\n",
"See the [locations where accelerators are available](https://cloud.google.com/vertex-ai/docs/general/locations#accelerators).\n",
"\n",
"Otherwise specify `(None, None)` to use a container image to run on a CPU."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "xd5PLXDTlugv"
},
"outputs": [],
"source": [
"GPU = False\n",
"if GPU:\n",
" DEPLOY_GPU, DEPLOY_NGPU = (aiplatform.gapic.AcceleratorType.NVIDIA_TESLA_K80, 1)\n",
"else:\n",
" DEPLOY_GPU, DEPLOY_NGPU = (None, None)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "container:training,prediction"
},
"source": [
"#### Set pre-built containers\n",
"\n",
"Set the pre-built Docker container image for prediction.\n",
"\n",
"For the latest list, see [Pre-built containers for prediction](https://cloud.google.com/ai-platform-unified/docs/predictions/pre-built-containers)."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "1u1mr18jlugv"
},
"outputs": [],
"source": [
"if GPU:\n",
" DEPLOY_VERSION = \"tf2-gpu.2-5\"\n",
"else:\n",
" DEPLOY_VERSION = \"tf2-cpu.2-5\"\n",
"\n",
"DEPLOY_IMAGE = \"{}-docker.pkg.dev/vertex-ai/prediction/{}:latest\".format(\n",
" REGION.split(\"-\")[0], DEPLOY_VERSION\n",
")\n",
"\n",
"print(\"Deployment:\", DEPLOY_IMAGE, DEPLOY_GPU, DEPLOY_NGPU)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "machine:training,prediction"
},
"source": [
"#### Set machine types\n",
"\n",
"Next, set the machine types to use for training and prediction.\n",
"\n",
"- Set the variable `DEPLOY_COMPUTE` to configure your compute resources for prediction.\n",
" - `machine type`\n",
" - `n1-standard`: 3.75GB of memory per vCPU\n",
" - `n1-highmem`: 6.5GB of memory per vCPU\n",
" - `n1-highcpu`: 0.9 GB of memory per vCPU\n",
" - `vCPUs`: number of \\[2, 4, 8, 16, 32, 64, 96 \\]\n",
"\n",
"*Note: You may also use n2 and e2 machine types for training and deployment, but they do not support GPUs*."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "YAXwbqKKlugv"
},
"outputs": [],
"source": [
"MACHINE_TYPE = \"n1-standard\"\n",
"\n",
"VCPU = \"4\"\n",
"TRAIN_COMPUTE = MACHINE_TYPE + \"-\" + VCPU\n",
"print(\"Train machine type\", TRAIN_COMPUTE)\n",
"\n",
"MACHINE_TYPE = \"n1-standard\"\n",
"\n",
"VCPU = \"4\"\n",
"DEPLOY_COMPUTE = MACHINE_TYPE + \"-\" + VCPU\n",
"print(\"Deploy machine type\", DEPLOY_COMPUTE)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "9bf06cd476e9"
},
"source": [
"### Upload the model artifacts as a `Vertex AI Model` resource\n",
"\n",
"First, you upload the pre-trained custom tabular model artifacts as a `Vertex AI Model` resource using the `upload()` method, with the following parameters:\n",
"\n",
"- `display_name`: The human readable name for the `Model` resource.\n",
"- `artifact_uri`: The Cloud Storage location of the model artifacts.\n",
"- `serving_container_image`: The serving container image to use when the model is deployed to a `Vertex AI Endpoint` resource.\n",
"- `sync`: Whether to wait for the process to complete, or return immediately (async)."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "0193f247e216"
},
"outputs": [],
"source": [
"MODEL_ARTIFACT_URI = \"gs://mco-mm/churn\"\n",
"\n",
"model = aiplatform.Model.upload(\n",
" display_name=\"churn_\" + UUID,\n",
" artifact_uri=MODEL_ARTIFACT_URI,\n",
" serving_container_image_uri=DEPLOY_IMAGE,\n",
" sync=True,\n",
")\n",
"\n",
"print(model)"
]
},
{
"cell_type": "markdown",
"id": "a4305ddf",
"metadata": {
"id": "a4305ddf"
},
"source": [
"## Submit a batch prediction request with model monitoring enabled"
"## Submit a batch prediction request with model monitoring enabled\n"
]
},
{
"cell_type": "markdown",
"id": "053fde99",
"metadata": {
"id": "053fde99"
},
@@ -503,7 +736,6 @@
{
"cell_type": "code",
"execution_count": null,
"id": "b832ad31",
"metadata": {
"id": "b832ad31"
},
@@ -511,20 +743,17 @@
"source": [
"# Copy files to your projects gs bucket to avoid permission issues.\n",
"# Ignore any error(s) for bucket already exists.\n",
"OUTPUT_GS_PATH = f\"gs://{PROJECT_ID.replace('-', '_')}_bp_mm_output\"\n",
"INPUT_GS_PATH = f\"gs://{PROJECT_ID.replace('-', '_')}_bp_mm_input\"\n",
"OUTPUT_GS_PATH = f\"{BUCKET_URI}/bp_mm_output\"\n",
"INPUT_GS_PATH = f\"{BUCKET_URI}/bp_mm_input\"\n",
"PUBLIC_TRAINING_DATASET = \"gs://bp_mm_public_data/churn/churn_bp_insample.csv\"\n",
"TRAINING_DATASET = f\"{INPUT_GS_PATH}/churn_bp_insample.csv\"\n",
"TRAINING_DATASET_FORMAT = \"csv\"\n",
"\n",
"! gsutil mb -p {PROJECT_ID} -l {REGION} -b on {INPUT_GS_PATH}\n",
"! gsutil mb -p {PROJECT_ID} -l {REGION} -b on {OUTPUT_GS_PATH}\n",
"! gsutil copy $PUBLIC_TRAINING_DATASET $INPUT_GS_PATH"
]
},
{
"cell_type": "markdown",
"id": "34c95126",
"metadata": {
"id": "34c95126"
},
@@ -541,21 +770,18 @@
{
"cell_type": "code",
"execution_count": null,
"id": "3a54368a",
"metadata": {
"id": "3a54368a"
},
"outputs": [],
"source": [
"now = datetime.now()\n",
"INPUT_URI = \"gs://bp_mm_public_data/churn/churn_bp_outsample.jsonl\"\n",
"OUTPUT_URI = OUTPUT_GS_PATH\n",
"INSTANCES_FORMAT = \"jsonl\"\n",
"PREDICTIONS_FORMAT = \"jsonl\"\n",
"JOB_NAME_PREFIX = \"bp_mm_demo\"\n",
"MODEL_NAME = f\"projects/{PROJECT_ID}/locations/{REGION}/models/{MODEL_ID}\"\n",
"MACHINE_TYPE = \"n1-standard-8\"\n",
"BATCH_PREDICTION_JOB_NAME = JOB_NAME_PREFIX + \"_\" + now.strftime(\"%Y%m%d%H%M%S\")\n",
"MODEL_NAME = model.resource_name\n",
"BATCH_PREDICTION_JOB_NAME = JOB_NAME_PREFIX + \"_\" + UUID\n",
"\n",
"from google.cloud.aiplatform_v1beta1.types import (\n",
" BatchDedicatedResources, BatchPredictionJob, GcsDestination, GcsSource,\n",
@@ -573,7 +799,7 @@
" gcs_destination=GcsDestination(output_uri_prefix=OUTPUT_URI),\n",
" ),\n",
" dedicated_resources=BatchDedicatedResources(\n",
" machine_spec=MachineSpec(machine_type=MACHINE_TYPE),\n",
" machine_spec=MachineSpec(machine_type=DEPLOY_COMPUTE),\n",
" starting_replica_count=1,\n",
" max_replica_count=1,\n",
" ),\n",
@@ -604,7 +830,6 @@
},
{
"cell_type": "markdown",
"id": "cae39778",
"metadata": {
"id": "cae39778"
},
@@ -617,7 +842,6 @@
{
"cell_type": "code",
"execution_count": null,
"id": "bcdd4a47",
"metadata": {
"id": "bcdd4a47"
},
@@ -638,7 +862,6 @@
},
{
"cell_type": "markdown",
"id": "49ec90a0",
"metadata": {
"id": "49ec90a0"
},
@@ -651,7 +874,6 @@
{
"cell_type": "code",
"execution_count": null,
"id": "c30496b5",
"metadata": {
"id": "c30496b5"
},
@@ -664,7 +886,6 @@
},
{
"cell_type": "markdown",
"id": "831651c2",
"metadata": {
"id": "831651c2"
},
@@ -684,7 +905,6 @@
{
"cell_type": "code",
"execution_count": null,
"id": "a705c10b",
"metadata": {
"id": "a705c10b"
},
@@ -695,7 +915,6 @@
},
{
"cell_type": "markdown",
"id": "2bbdddac",
"metadata": {
"id": "2bbdddac"
},
@@ -708,7 +927,6 @@
{
"cell_type": "code",
"execution_count": null,
"id": "f6c674e9",
"metadata": {
"id": "f6c674e9"
},
@@ -746,7 +964,6 @@
},
{
"cell_type": "markdown",
"id": "233b1266",
"metadata": {
"id": "233b1266"
},
@@ -759,7 +976,6 @@
{
"cell_type": "code",
"execution_count": null,
"id": "4e8c00a7",
"metadata": {
"id": "4e8c00a7"
},
@@ -774,7 +990,6 @@
},
{
"cell_type": "markdown",
"id": "497a0016",
"metadata": {
"id": "497a0016"
},
@@ -790,7 +1005,6 @@
{
"cell_type": "code",
"execution_count": null,
"id": "eabc3f81",
"metadata": {
"id": "eabc3f81"
},
@@ -806,7 +1020,6 @@
},
{
"cell_type": "markdown",
"id": "0aa0219d",
"metadata": {
"id": "0aa0219d"
},
+24 -40
View File
@@ -29,6 +29,8 @@
"id": "JAPoU8Sm5E6e"
},
"source": [
"# [TODO] Add your H1 title heading here\n",
"\n",
"<table align=\"left\">\n",
"\n",
" <td>\n",
@@ -80,7 +82,7 @@
"\n",
"The steps performed include:\n",
"\n",
"- * {TODO: Add high level bullets for the steps of performed in the notebook}"
"- *{TODO: Add high level bullets for the steps of performed in the notebook}*"
]
},
{
@@ -109,35 +111,31 @@
"This tutorial uses billable components of Google Cloud:\n",
"\n",
"* Vertex AI\n",
"* {TODO: BigQyuery}\n",
"* Cloud Storage\n",
"\n",
"{TODO: Include links to pricing documentation for each product you listed above.}\n",
"{TODO: Include links to pricing documentation for each product you listed above.\n",
" NOTE: If you use BigQuery or Dataflow, you need to add this to the pricing.\n",
"}\n",
"\n",
"Learn about [Vertex AI\n",
"pricing](https://cloud.google.com/vertex-ai/pricing) and [Cloud Storage\n",
"pricing](https://cloud.google.com/storage/pricing), and use the [Pricing\n",
"Calculator](https://cloud.google.com/products/calculator/)\n",
"Learn about [Vertex AI pricing](https://cloud.google.com/vertex-ai/pricing),\n",
"{ TODO: [BigQuery pricing](https://cloud.google.com/bigquery/pricing), }\n",
"and [Cloud Storage pricing](https://cloud.google.com/storage/pricing), \n",
"and use the [Pricing Calculator](https://cloud.google.com/products/calculator/)\n",
"to generate a cost estimate based on your projected usage."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "ze4-nDLfK4pw"
},
"source": [
"### Set up your local development environment\n",
"\n",
"**If you are using Colab or Vertex AI Workbench Notebooks**, your environment already meets\n",
"all the requirements to run this notebook. You can skip this step."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "gCuSR8GkAgzl"
},
"source": [
"### Set up your local development environment\n",
"\n",
"**If you are using Colab or Vertex AI Workbench Notebooks**, your environment already meets\n",
"all the requirements to run this notebook. You can skip this step.\n",
"\n",
"**Otherwise**, make sure your environment meets this notebook's requirements.\n",
"You need the following:\n",
"\n",
@@ -204,7 +202,7 @@
" USER_FLAG = \"--user\"\n",
"\n",
"! pip3 install --upgrade google-cloud-aiplatform {USER_FLAG} -q\n",
"# TODO: Add remaining package installs here"
"# TODO: Add remaining package installs here. All packages should be on a single pip install to resolve dependencies"
]
},
{
@@ -237,21 +235,14 @@
" app.kernel.do_shutdown(True)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "lWEdiXsJg0XY"
},
"source": [
"## Before you begin"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "BF1j6f9HApxa"
},
"source": [
"## Before you begin\n",
"\n",
"### Set up your Google Cloud project\n",
"\n",
"**The following steps are required, regardless of your notebook environment.**\n",
@@ -412,21 +403,14 @@
{
"cell_type": "markdown",
"metadata": {
"id": "dr--iN2kAylZ"
"id": "sBCra4QMA2wR"
},
"source": [
"### Authenticate your Google Cloud account\n",
"\n",
"**If you are using Vertex AI Workbench Notebooks**, your environment is already\n",
"authenticated. Skip this step."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "sBCra4QMA2wR"
},
"source": [
"authenticated. \n",
"\n",
"**If you are using Colab**, run the cell below and follow the instructions\n",
"when prompted to authenticate your account via oAuth.\n",
"\n",
@@ -481,7 +465,7 @@
" # path to your service account key and run this cell to authenticate your GCP\n",
" # account.\n",
" elif not os.getenv(\"IS_TESTING\"):\n",
" %env GOOGLE_APPLICATION_CREDENTIALS ''"
" %env GOOGLE_APPLICATION_CREDENTIALS '[your-service-account-key-path]'"
]
},
{
@@ -497,7 +481,7 @@
"\n",
"{TODO: Adjust wording in the first paragraph to fit your use case - explain how your tutorial uses the Cloud Storage bucket. The example below shows how Vertex AI uses the bucket for training.}\n",
"\n",
"When you submit a training job using the Cloud SDK, you upload a Python package\n",
"When you submit a training job using the Vertex AI SDK, you upload a Python package\n",
"containing your training code to a Cloud Storage bucket. Vertex AI runs\n",
"the code from this package. In this tutorial, Vertex AI also saves the\n",
"trained model that results from your job in the same bucket. Using this model artifact, you can then\n",
@@ -8,7 +8,7 @@
},
"outputs": [],
"source": [
"# Copyright 2022 Google LLC\n",
"# Copyright 2022 Google LLC.\n",
"#\n",
"# Licensed under the Apache License, Version 2.0 (the \"License\");\n",
"# you may not use this file except in compliance with the License.\n",
File diff suppressed because it is too large Load Diff
@@ -32,19 +32,64 @@
"# Vertex AI: Vertex AI Migration: AutoML Tabular Binary Classification\n",
"\n",
"<table align=\"left\">\n",
"\n",
" <td>\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/ai-platform-samples/blob/master/vertex-ai-samples/tree/master/notebooks/official/migration/UJ4%20Vertex%20SDK%20AutoML%20Tabular%20Binary%20Classification.ipynb\">\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/migration/UJ4 Vertex SDK AutoML Tabular Binary Classification.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/colab-logo-32px.png\" alt=\"Colab logo\"> Run in Colab\n",
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://github.com/GoogleCloudPlatform/ai-platform-samples/blob/master/vertex-ai-samples/tree/master/notebooks/official/migration/UJ4%20Vertex%20SDK%20AutoML%20Tabular%20Binary%20Classification.ipynb\">\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/migration/UJ4 Vertex SDK AutoML Tabular Binary Classification.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/github-logo-32px.png\" alt=\"GitHub logo\">\n",
" View on GitHub\n",
" </a>\n",
" </td>\n",
"</table>\n",
"<br/><br/><br/>"
" <td>\n",
" <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/migration/UJ4 Vertex SDK AutoML Tabular Binary Classification.ipynb\">\n",
" <img src=\"https://lh3.googleusercontent.com/UiNooY4LUgW_oTvpsNhPpQzsstV5W8F7rYgxgGBD85cWJoLmrOzhVs_ksK_vgx40SHs7jCqkTkCk=e14-rj-sc0xffffff-h130-w32\" alt=\"Vertex AI logo\">\n",
" Open in Vertex AI Workbench\n",
" </a>\n",
" </td> \n",
"</table>"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "fb82f94bbbc7"
},
"source": [
"## Overview\n",
"\n",
"\n",
"This tutorial demonstrates how to use the Vertex AI SDK to create tabular binary classification models and do online prediction using a Google Cloud [AutoML](https://cloud.google.com/vertex-ai/docs/start/automl-users) model."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "9f80bba45dd5"
},
"source": [
"### Objective\n",
"\n",
"In this tutorial, you create an AutoML tabular binary classification model and deploy for online prediction from a Python script using the Vertex AI SDK. You can alternatively create and deploy models using the `gcloud` command-line tool or online using the Cloud Console.\n",
"\n",
"This tutorial uses the following Google Cloud ML services and resources:\n",
"\n",
"- Vertex AI managed Datasets\n",
"- Vertex AI Training\n",
"- Vertex AI Endpoints\n",
"- Vertex AI prediction\n",
"\n",
"The steps performed include:\n",
"\n",
"- Create a Vertex `Dataset` resource.\n",
"- Train the model.\n",
"- View the model evaluation.\n",
"- Deploy the `Model` resource to a serving `Endpoint` resource.\n",
"- Make a prediction.\n",
"- Undeploy the `Model`"
]
},
{
@@ -55,7 +100,7 @@
"source": [
"### Dataset\n",
"\n",
"The dataset used for this tutorial is the Bank Marketing. This dataset does not require any feature engineering. The version of the dataset you will use in this tutorial is stored in a public Cloud Storage bucket."
"The dataset used for this tutorial is the [Bank Marketing](https://pantheon.corp.google.com/storage/browser/_details/cloud-ml-tables-data/bank-marketing.csv) . This dataset does not require any feature engineering. The version of the dataset you use in this tutorial is stored in a public Cloud Storage bucket."
]
},
{
@@ -86,29 +131,38 @@
"source": [
"### Set up your local development environment\n",
"\n",
"If you are using Colab or Google Cloud Notebooks, your environment already meets all the requirements to run this notebook. You can skip this step.\n",
"**If you are using Colab or Vertex AI Workbench Notebooks**, your environment already meets\n",
"all the requirements to run this notebook. You can skip this step.\n",
"\n",
"Otherwise, make sure your environment meets this notebook's requirements. You need the following:\n",
"**Otherwise**, make sure your environment meets this notebook's requirements.\n",
"You need the following:\n",
"\n",
"- The Cloud Storage SDK\n",
"- Git\n",
"- Python 3\n",
"- virtualenv\n",
"- Jupyter notebook running in a virtual environment with Python 3\n",
"* The Google Cloud SDK\n",
"* Git\n",
"* Python 3\n",
"* virtualenv\n",
"* Jupyter notebook running in a virtual environment with Python 3\n",
"\n",
"The Cloud Storage guide to [Setting up a Python development environment](https://cloud.google.com/python/setup) and the [Jupyter installation guide](https://jupyter.org/install) provide detailed instructions for meeting these requirements. The following steps provide a condensed set of instructions:\n",
"The Google Cloud guide to [Setting up a Python development\n",
"environment](https://cloud.google.com/python/setup) and the [Jupyter\n",
"installation guide](https://jupyter.org/install) provide detailed instructions\n",
"for meeting these requirements. The following steps provide a condensed set of\n",
"instructions:\n",
"\n",
"1. [Install and initialize the SDK](https://cloud.google.com/sdk/docs/).\n",
"1. [Install and initialize the Cloud SDK.](https://cloud.google.com/sdk/docs/)\n",
"\n",
"2. [Install Python 3](https://cloud.google.com/python/setup#installing_python).\n",
"1. [Install Python 3.](https://cloud.google.com/python/setup#installing_python)\n",
"\n",
"3. [Install virtualenv](https://cloud.google.com/python/setup#installing_and_using_virtualenv) and create a virtual environment that uses Python 3. Activate the virtual environment.\n",
"1. [Install\n",
" virtualenv](https://cloud.google.com/python/setup#installing_and_using_virtualenv)\n",
" and create a virtual environment that uses Python 3. Activate the virtual environment.\n",
"\n",
"4. To install Jupyter, run `pip3 install jupyter` on the command-line in a terminal shell.\n",
"1. To install Jupyter, run `pip3 install jupyter` on the\n",
"command-line in a terminal shell.\n",
"\n",
"5. To launch Jupyter, run `jupyter notebook` on the command-line in a terminal shell.\n",
"1. To launch Jupyter, run `jupyter notebook` on the command-line in a terminal shell.\n",
"\n",
"6. Open this notebook in the Jupyter Notebook Dashboard.\n"
"1. Open this notebook in the Jupyter Notebook Dashboard."
]
},
{
@@ -119,7 +173,7 @@
"source": [
"## Installation\n",
"\n",
"Install the latest version of Vertex SDK for Python."
"Install the following packages required to execute this notebook. "
]
},
{
@@ -132,33 +186,18 @@
"source": [
"import os\n",
"\n",
"# Google Cloud Notebook\n",
"if os.path.exists(\"/opt/deeplearning/metadata/env_version\"):\n",
" USER_FLAG = \"--user\"\n",
"else:\n",
" USER_FLAG = \"\"\n",
"# The Vertex AI Workbench Notebook product has specific requirements\n",
"IS_WORKBENCH_NOTEBOOK = os.getenv(\"DL_ANACONDA_HOME\")\n",
"IS_USER_MANAGED_WORKBENCH_NOTEBOOK = os.path.exists(\n",
" \"/opt/deeplearning/metadata/env_version\"\n",
")\n",
"\n",
"! pip3 install --upgrade google-cloud-aiplatform $USER_FLAG"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "install_storage"
},
"source": [
"Install the latest GA version of *google-cloud-storage* and *tensorflow* libraries as well."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "install_storage"
},
"outputs": [],
"source": [
"! pip3 install -U google-cloud-storage tensorflow $USER_FLAG"
"# Vertex AI Notebook requires dependencies to be installed with '--user'\n",
"USER_FLAG = \"\"\n",
"if IS_WORKBENCH_NOTEBOOK:\n",
" USER_FLAG = \"--user\"\n",
"\n",
"! pip3 install --upgrade google-cloud-aiplatform fsspec gcsfs $USER_FLAG"
]
},
{
@@ -169,7 +208,7 @@
"source": [
"### Restart the kernel\n",
"\n",
"Once you've installed the additional packages, you need to restart the notebook kernel so it can find the packages."
"After you install the additional packages, you need to restart the notebook kernel so it can find the packages."
]
},
{
@@ -180,6 +219,7 @@
},
"outputs": [],
"source": [
"# Automatically restart kernel after installs\n",
"import os\n",
"\n",
"if not os.getenv(\"IS_TESTING\"):\n",
@@ -193,31 +233,38 @@
{
"cell_type": "markdown",
"metadata": {
"id": "before_you_begin:nogpu"
"id": "c27795e4f4a1"
},
"source": [
"## Before you begin\n",
"\n",
"### GPU runtime\n",
"\n",
"This tutorial does not require a GPU runtime.\n",
"\n",
"### Set up your Google Cloud project\n",
"\n",
"**The following steps are required, regardless of your notebook environment.**\n",
"\n",
"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 free credit towards your compute/storage costs.\n",
"\n",
"2. [Make sure that billing is enabled for your project.](https://cloud.google.com/billing/docs/how-to/modify-project)\n",
"1. [Make sure that billing is enabled for your project](https://cloud.google.com/billing/docs/how-to/modify-project).\n",
"\n",
"3. [Enable the following APIs: Vertex AI APIs, Compute Engine APIs, and Cloud Storage.](https://console.cloud.google.com/flows/enableapi?apiid=ml.googleapis.com,compute_component,storage-component.googleapis.com)\n",
"1. [Enable the Vertex AI API](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com). \n",
"\n",
"4. If you are running this notebook locally, you will need to install the [Cloud SDK]((https://cloud.google.com/sdk)).\n",
"1. If you are running this notebook locally, you need to install the [Cloud SDK](https://cloud.google.com/sdk).\n",
"\n",
"5. Enter your project ID in the cell below. Then run the cell to make sure the\n",
"1. Enter your project ID in the cell below. Then run the cell to make sure the\n",
"Cloud SDK uses the right project for all the commands in this notebook.\n",
"\n",
"**Note**: Jupyter runs lines prefixed with `!` as shell commands, and it interpolates Python variables prefixed with `$`."
"**Note**: Jupyter runs lines prefixed with `!` as shell commands, and it interpolates Python variables prefixed with `$` into these commands."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "1460fd744366"
},
"source": [
"#### Set your project ID\n",
"\n",
"**If you don't know your project ID**, you may be able to get your project ID using `gcloud`."
]
},
{
@@ -266,7 +313,7 @@
"#### Region\n",
"\n",
"You can also change the `REGION` variable, which is used for operations\n",
"throughout the rest of this notebook. Below are regions supported for Vertex AI. We recommend that you choose the region closest to you.\n",
"throughout the rest of this notebook. Below are regions supported for Vertex AI. It is recommended that you choose the region closest to you.\n",
"\n",
"- Americas: `us-central1`\n",
"- Europe: `europe-west4`\n",
@@ -274,7 +321,7 @@
"\n",
"You may not use a multi-regional bucket for training with Vertex AI. Not all regions provide support for all Vertex AI services.\n",
"\n",
"Learn more about [Vertex AI regions](https://cloud.google.com/vertex-ai/docs/general/locations)"
"Learn more about [Vertex AI regions](https://cloud.google.com/vertex-ai/docs/general/locations)."
]
},
{
@@ -285,7 +332,10 @@
},
"outputs": [],
"source": [
"REGION = \"us-central1\" # @param {type: \"string\"}"
"REGION = \"[your-region]\" # @param {type: \"string\"}\n",
"\n",
"if REGION == \"[your-region]\":\n",
" REGION = \"us-central1\""
]
},
{
@@ -294,9 +344,9 @@
"id": "timestamp"
},
"source": [
"#### Timestamp\n",
"#### UUID\n",
"\n",
"If you are in a live tutorial session, you might be using a shared test account or project. To avoid name collisions between users on resources created, you create a timestamp for each instance session, and append the timestamp onto the name of resources you create in this tutorial."
"If you are in a live tutorial session, you might be using a shared test account or project. To avoid name collisions between users on resources created, you create a uuid for each instance session, and append it onto the name of resources you create in this tutorial."
]
},
{
@@ -307,36 +357,52 @@
},
"outputs": [],
"source": [
"from datetime import datetime\n",
"import random\n",
"import string\n",
"\n",
"TIMESTAMP = datetime.now().strftime(\"%Y%m%d%H%M%S\")"
"\n",
"# Generate a uuid of a specifed length(default=8)\n",
"def generate_uuid(length: int = 8) -> str:\n",
" return \"\".join(random.choices(string.ascii_lowercase + string.digits, k=length))\n",
"\n",
"\n",
"UUID = generate_uuid()"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "gcp_authenticate"
"id": "32e1cd21a5d5"
},
"source": [
"### Authenticate your Google Cloud account\n",
"\n",
"**If you are using Google Cloud Notebooks**, your environment is already authenticated. Skip this step.\n",
"**If you are using Vertex AI Workbench Notebooks**, your environment is already\n",
"authenticated. \n",
"\n",
"**If you are using Colab**, run the cell below and follow the instructions when prompted to authenticate your account via oAuth.\n",
"\n",
"**If you are using Colab**, run the cell below and follow the instructions\n",
"when prompted to authenticate your account via oAuth.\n",
"\n",
"**Otherwise**, follow these steps:\n",
"\n",
"In the Cloud Console, go to the [Create service account key](https://console.cloud.google.com/apis/credentials/serviceaccountkey) page.\n",
"1. In the Cloud Console, go to the [**Create service account key**\n",
" page](https://console.cloud.google.com/apis/credentials/serviceaccountkey).\n",
"\n",
"**Click Create service account**.\n",
"2. Click **Create service account**.\n",
"\n",
"In the **Service account name** field, enter a name, and click **Create**.\n",
"3. In the **Service account name** field, enter a name, and\n",
" click **Create**.\n",
"\n",
"In the **Grant this service account access to project** section, click the Role drop-down list. Type \"Vertex\" into the filter box, and select **Vertex Administrator**. Type \"Storage Object Admin\" into the filter box, and select **Storage Object Admin**.\n",
"4. In the **Grant this service account access to project** section, click the **Role** drop-down list. Type \"Vertex AI\"\n",
"into the filter box, and select\n",
" **Vertex AI Administrator**. Type \"Storage Object Admin\" into the filter box, and select **Storage Object Admin**.\n",
"\n",
"Click Create. A JSON file that contains your key downloads to your local environment.\n",
"5. Click *Create*. A JSON file that contains your key downloads to your\n",
"local environment.\n",
"\n",
"Enter the path to your service account key as the GOOGLE_APPLICATION_CREDENTIALS variable in the cell below and run the cell."
"6. Enter the path to your service account key as the\n",
"`GOOGLE_APPLICATION_CREDENTIALS` variable in the cell below and run the cell."
]
},
{
@@ -355,8 +421,11 @@
"import os\n",
"import sys\n",
"\n",
"# If on Google Cloud Notebook, then don't execute this code\n",
"if not os.path.exists(\"/opt/deeplearning/metadata/env_version\"):\n",
"# If on Vertex AI Workbench, then don't execute this code\n",
"IS_COLAB = \"google.colab\" in sys.modules\n",
"if not os.path.exists(\"/opt/deeplearning/metadata/env_version\") and not os.getenv(\n",
" \"DL_ANACONDA_HOME\"\n",
"):\n",
" if \"google.colab\" in sys.modules:\n",
" from google.colab import auth as google_auth\n",
"\n",
@@ -379,7 +448,7 @@
"\n",
"**The following steps are required, regardless of your notebook environment.**\n",
"\n",
"When you initialize the Vertex SDK for Python, you specify a Cloud Storage staging bucket. The staging bucket is where all the data associated with your dataset and model resources are retained across sessions.\n",
"When you initialize the Vertex AI SDK for Python, you specify a Cloud Storage staging bucket. The staging bucket is where all the data associated with your dataset and model resources are retained across sessions.\n",
"\n",
"Set the name of your Cloud Storage bucket below. Bucket names must be globally unique across all Google Cloud projects, including those outside of your organization."
]
@@ -392,7 +461,8 @@
},
"outputs": [],
"source": [
"BUCKET_NAME = \"gs://[your-bucket-name]\" # @param {type:\"string\"}"
"BUCKET_NAME = \"[your-bucket-name]\" # @param {type:\"string\"}\n",
"BUCKET_URI = f\"gs://{BUCKET_NAME}\""
]
},
{
@@ -403,8 +473,9 @@
},
"outputs": [],
"source": [
"if BUCKET_NAME == \"\" or BUCKET_NAME is None or BUCKET_NAME == \"gs://[your-bucket-name]\":\n",
" BUCKET_NAME = \"gs://\" + PROJECT_ID + \"aip-\" + TIMESTAMP"
"if BUCKET_NAME == \"\" or BUCKET_NAME is None or BUCKET_NAME == \"[your-bucket-name]\":\n",
" BUCKET_NAME = PROJECT_ID + \"aip-\" + UUID\n",
" BUCKET_URI = f\"gs://{BUCKET_NAME}\""
]
},
{
@@ -424,7 +495,7 @@
},
"outputs": [],
"source": [
"! gsutil mb -l $REGION $BUCKET_NAME"
"! gsutil mb -l $REGION -p $PROJECT_ID $BUCKET_URI"
]
},
{
@@ -444,7 +515,7 @@
},
"outputs": [],
"source": [
"! gsutil ls -al $BUCKET_NAME"
"! gsutil ls -al $BUCKET_URI"
]
},
{
@@ -453,9 +524,6 @@
"id": "setup_vars"
},
"source": [
"### Set up variables\n",
"\n",
"Next, set up some variables used throughout the tutorial.\n",
"### Import libraries and define constants"
]
},
@@ -467,7 +535,8 @@
},
"outputs": [],
"source": [
"import google.cloud.aiplatform as aip"
"import google.cloud.aiplatform as aip\n",
"import pandas as pd"
]
},
{
@@ -476,9 +545,9 @@
"id": "init_aip:mbsdk"
},
"source": [
"## Initialize Vertex SDK for Python\n",
"## Initialize Vertex AI SDK for Python\n",
"\n",
"Initialize the Vertex SDK for Python for your project and corresponding bucket."
"Initialize the Vertex AI SDK for Python for your project and corresponding bucket."
]
},
{
@@ -594,7 +663,7 @@
"outputs": [],
"source": [
"dataset = aip.TabularDataset.create(\n",
" display_name=\"Bank Marketing\" + \"_\" + TIMESTAMP, gcs_source=[IMPORT_FILE]\n",
" display_name=\"Bank Marketing\" + \"_\" + UUID, gcs_source=[IMPORT_FILE]\n",
")\n",
"\n",
"print(dataset.resource_name)"
@@ -678,13 +747,13 @@
},
"outputs": [],
"source": [
"dag = aip.AutoMLTabularTrainingJob(\n",
" display_name=\"bank_\" + TIMESTAMP,\n",
"job = aip.AutoMLTabularTrainingJob(\n",
" display_name=\"bank_\" + UUID,\n",
" optimization_prediction_type=\"classification\",\n",
" optimization_objective=\"minimize-log-loss\",\n",
")\n",
"\n",
"print(dag)"
"print(job)"
]
},
{
@@ -730,9 +799,9 @@
},
"outputs": [],
"source": [
"model = dag.run(\n",
"model = job.run(\n",
" dataset=dataset,\n",
" model_display_name=\"bank_\" + TIMESTAMP,\n",
" model_display_name=\"bank_\" + UUID,\n",
" training_fraction_split=0.6,\n",
" validation_fraction_split=0.2,\n",
" test_fraction_split=0.2,\n",
@@ -808,7 +877,7 @@
"outputs": [],
"source": [
"# Get model resource ID\n",
"models = aip.Model.list(filter=\"display_name=bank_\" + TIMESTAMP)\n",
"models = aip.Model.list(filter=\"display_name=bank_\" + UUID)\n",
"\n",
"# Get a reference to the Model Service client\n",
"client_options = {\"api_endpoint\": f\"{REGION}-aiplatform.googleapis.com\"}\n",
@@ -887,7 +956,7 @@
"source": [
"### Make test items\n",
"\n",
"You will use synthetic data as a test data items. Don't be concerned that we are using synthetic data -- we just want to demonstrate how to make a prediction."
"You use synthetic data as a test data items. Don't be concerned that we are using synthetic data -- we just want to demonstrate how to make a prediction."
]
},
{
@@ -898,7 +967,7 @@
"source": [
"### Make the batch input file\n",
"\n",
"Now make a batch input file, which you will store in your local Cloud Storage bucket. Unlike image, video and text, the batch input file for tabular is only supported for CSV. For CSV file, you make:\n",
"Now make a batch input file, which you store in your local Cloud Storage bucket. Unlike image, video and text, the batch input file for tabular is only supported for CSV. For CSV file, you make:\n",
"\n",
"- The first line is the heading with the feature (fields) heading names.\n",
"- Each remaining line is a separate prediction request with the corresponding feature values.\n",
@@ -922,7 +991,7 @@
"\n",
"! cut -d, -f1-16 tmp.csv > batch.csv\n",
"\n",
"gcs_input_uri = BUCKET_NAME + \"/test.csv\"\n",
"gcs_input_uri = BUCKET_URI + \"/test.csv\"\n",
"\n",
"! gsutil cp batch.csv $gcs_input_uri"
]
@@ -954,9 +1023,9 @@
"outputs": [],
"source": [
"batch_predict_job = model.batch_predict(\n",
" job_display_name=\"bank_\" + TIMESTAMP,\n",
" job_display_name=\"bank_\" + UUID,\n",
" gcs_source=gcs_input_uri,\n",
" gcs_destination_prefix=BUCKET_NAME,\n",
" gcs_destination_prefix=BUCKET_URI,\n",
" instances_format=\"csv\",\n",
" predictions_format=\"csv\",\n",
" sync=False,\n",
@@ -1064,21 +1133,20 @@
},
"outputs": [],
"source": [
"import tensorflow as tf\n",
"\n",
"bp_iter_outputs = batch_predict_job.iter_outputs()\n",
"\n",
"prediction_results = list()\n",
"for blob in bp_iter_outputs:\n",
" if blob.name.split(\"/\")[-1].startswith(\"prediction\"):\n",
" if blob.name.split(\"/\")[-1].startswith(\"prediction.results\"):\n",
" prediction_results.append(blob.name)\n",
"\n",
"tags = list()\n",
"for prediction_result in prediction_results:\n",
" gfile_name = f\"gs://{bp_iter_outputs.bucket.name}/{prediction_result}\"\n",
" with tf.io.gfile.GFile(name=gfile_name, mode=\"r\") as gfile:\n",
" for line in gfile.readlines():\n",
" print(line)"
" df = pd.read_csv(gfile_name)\n",
" print(f\"File name: {gfile_name}\")\n",
" print(\"Prediction: \\n\\n\\n\\n\")\n",
" print(df)\n",
" print(\"\\n\\n\\n\")"
]
},
{
@@ -1089,11 +1157,20 @@
"source": [
"*Example Output:*\n",
"\n",
" Age,Job,MaritalStatus,Education,Default,Balance,Housing,Loan,Contact,Day,Month,Duration,Campaign,PDays,Previous,POutcome,Deposit_1_scores,Deposit_2_scores\n",
" File name: gs://vertex-ai-devaip-5j22pmou/prediction-bank_5j22pmou-2022_08_24T01_05_46_028Z/prediction.results-00005-of-00008.csv\n",
"Prediction: \n",
"\n",
" 72,retired,married,secondary,no,5715,no,no,cellular,17,nov,1127,5,184,3,success,0.4721628427505493,0.5278371572494507\n",
"\n",
" 57,blue-collar,married,secondary,no,668,no,no,telephone,17,nov,508,4,-1,0,unknown,0.9005520343780518,0.09944798052310944"
"\n",
"\n",
" Age Job MaritalStatus Education Default Balance Housing Loan \\\n",
"0 57 blue-collar married secondary no 668 no no \n",
"\n",
" Contact Day Month Duration Campaign PDays Previous POutcome \\\n",
"0 telephone 17 nov 508 4 -1 0 unknown \n",
"\n",
" Deposit_1_scores Deposit_2_scores \n",
"0 0.847498 0.152502 "
]
},
{
@@ -1173,7 +1250,7 @@
"source": [
"### Make test item\n",
"\n",
"You will use synthetic data as a test data item. Don't be concerned that we are using synthetic data -- we just want to demonstrate how to make a prediction."
"You use synthetic data as a test data item. Don't be concerned that we are using synthetic data -- we just want to demonstrate how to make a prediction."
]
},
{
@@ -1293,13 +1370,10 @@
"Otherwise, you can delete the individual resources you created in this tutorial:\n",
"\n",
"- Dataset\n",
"- Pipeline\n",
"- Model\n",
"- Endpoint\n",
"- AutoML Training Job\n",
"- Batch Job\n",
"- Custom Job\n",
"- Hyperparameter Tuning Job\n",
"- Cloud Storage Bucket"
]
},
@@ -1311,60 +1385,24 @@
},
"outputs": [],
"source": [
"delete_all = True\n",
"# Delete the dataset using the Vertex dataset object\n",
"dataset.delete()\n",
"\n",
"if delete_all:\n",
" # Delete the dataset using the Vertex dataset object\n",
" try:\n",
" if \"dataset\" in globals():\n",
" dataset.delete()\n",
" except Exception as e:\n",
" print(e)\n",
"# Delete the model using the Vertex model object\n",
"model.delete()\n",
"\n",
" # Delete the model using the Vertex model object\n",
" try:\n",
" if \"model\" in globals():\n",
" model.delete()\n",
" except Exception as e:\n",
" print(e)\n",
"# Delete the endpoint using the Vertex endpoint object\n",
"endpoint.delete()\n",
"\n",
" # Delete the endpoint using the Vertex endpoint object\n",
" try:\n",
" if \"endpoint\" in globals():\n",
" endpoint.delete()\n",
" except Exception as e:\n",
" print(e)\n",
"# Delete the AutoML or Pipeline trainig job\n",
"job.delete()\n",
"\n",
" # Delete the AutoML or Pipeline trainig job\n",
" try:\n",
" if \"dag\" in globals():\n",
" dag.delete()\n",
" except Exception as e:\n",
" print(e)\n",
"# Delete the batch prediction job using the Vertex batch prediction object\n",
"batch_predict_job.delete()\n",
"\n",
" # Delete the custom trainig job\n",
" try:\n",
" if \"job\" in globals():\n",
" job.delete()\n",
" except Exception as e:\n",
" print(e)\n",
"\n",
" # Delete the batch prediction job using the Vertex batch prediction object\n",
" try:\n",
" if \"batch_predict_job\" in globals():\n",
" batch_predict_job.delete()\n",
" except Exception as e:\n",
" print(e)\n",
"\n",
" # Delete the hyperparameter tuning job using the Vertex hyperparameter tuning object\n",
" try:\n",
" if \"hpt_job\" in globals():\n",
" hpt_job.delete()\n",
" except Exception as e:\n",
" print(e)\n",
"\n",
" if \"BUCKET_NAME\" in globals():\n",
" ! gsutil rm -r $BUCKET_NAME"
"delete_bucket = False\n",
"if delete_bucket or os.getenv(\"IS_TESTING\"):\n",
" ! gsutil -m rm -r $BUCKET_URI"
]
}
],
@@ -238,7 +238,8 @@
" google-auth-httplib2 \\\n",
" oauth2client \\\n",
" requests \\\n",
" google-cloud-storage==1.32.0"
" protobuf==3.20.* \\\n",
" google-cloud-storage==1.32.0 "
]
},
{
@@ -123,6 +123,7 @@
"if IS_WORKBENCH_NOTEBOOK:\n",
" USER_FLAG = \"--user\"\n",
"\n",
"! pip3 install google-vizier==0.0.4\n",
"! pip3 install --upgrade google-cloud-aiplatform {USER_FLAG} -q"
]
},
@@ -350,9 +351,9 @@
"outputs": [],
"source": [
"import datetime\n",
"import json\n",
"\n",
"from google.cloud import aiplatform"
"from google.cloud import aiplatform\n",
"from google.cloud.aiplatform.vizier import Study, pyvizier"
]
},
{
@@ -384,11 +385,9 @@
"# These will be automatically filled in.\n",
"STUDY_DISPLAY_NAME = \"{}_study_{}\".format(\n",
" PROJECT_ID.replace(\"-\", \"\"), datetime.datetime.now().strftime(\"%Y%m%d_%H%M%S\")\n",
") # @param {type: 'string'}\n",
"ENDPOINT = REGION + \"-aiplatform.googleapis.com\"\n",
")\n",
"PARENT = \"projects/{}/locations/{}\".format(PROJECT_ID, REGION)\n",
"\n",
"print(\"ENDPOINT: {}\".format(ENDPOINT))\n",
"print(\"REGION: {}\".format(REGION))\n",
"print(\"PARENT: {}\".format(PARENT))"
]
@@ -413,34 +412,21 @@
"outputs": [],
"source": [
"# Parameter Configuration\n",
"\n",
"param_r = {\"parameter_id\": \"r\", \"double_value_spec\": {\"min_value\": 0, \"max_value\": 1}}\n",
"\n",
"param_theta = {\n",
" \"parameter_id\": \"theta\",\n",
" \"double_value_spec\": {\"min_value\": 0, \"max_value\": 1.57},\n",
"}\n",
"problem = pyvizier.StudyConfig()\n",
"problem.algorithm = pyvizier.Algorithm.RANDOM_SEARCH\n",
"\n",
"# Objective Metrics\n",
"metric_y1 = {\"metric_id\": \"y1\", \"goal\": \"MINIMIZE\"}\n",
"problem.metric_information.append(\n",
" pyvizier.MetricInformation(name=\"y1\", goal=pyvizier.ObjectiveMetricGoal.MINIMIZE)\n",
")\n",
"problem.metric_information.append(\n",
" pyvizier.MetricInformation(name=\"y2\", goal=pyvizier.ObjectiveMetricGoal.MAXIMIZE)\n",
")\n",
"\n",
"# Objective Metrics\n",
"metric_y2 = {\"metric_id\": \"y2\", \"goal\": \"MAXIMIZE\"}\n",
"\n",
"# Put it all together in a study configuration\n",
"study = {\n",
" \"display_name\": STUDY_DISPLAY_NAME,\n",
" \"study_spec\": {\n",
" \"algorithm\": \"RANDOM_SEARCH\",\n",
" \"parameters\": [\n",
" param_r,\n",
" param_theta,\n",
" ],\n",
" \"metrics\": [metric_y1, metric_y2],\n",
" },\n",
"}\n",
"\n",
"print(json.dumps(study, indent=2, sort_keys=True))"
"# Defines the parameters configuration.\n",
"root = problem.search_space.select_root()\n",
"root.add_float_param(\"r\", 0, 1.0, scale_type=pyvizier.ScaleType.LINEAR)\n",
"root.add_float_param(\"theta\", 0, 1.57, scale_type=pyvizier.ScaleType.LINEAR)"
]
},
{
@@ -462,10 +448,9 @@
},
"outputs": [],
"source": [
"vizier_client = aiplatform.gapic.VizierServiceClient(\n",
" client_options=dict(api_endpoint=ENDPOINT)\n",
")\n",
"study = vizier_client.create_study(parent=PARENT, study=study)\n",
"aiplatform.init(project=PROJECT_ID, location=REGION)\n",
"study = Study.create_or_load(display_name=STUDY_DISPLAY_NAME, problem=problem)\n",
"\n",
"STUDY_ID = study.name\n",
"print(\"STUDY_ID: {}\".format(STUDY_ID))"
]
@@ -515,11 +500,12 @@
" r, theta, y1, y2\n",
" )\n",
" )\n",
" metric1 = {\"metric_id\": \"y1\", \"value\": y1}\n",
" metric2 = {\"metric_id\": \"y2\", \"value\": y2}\n",
" measurement = pyvizier.Measurement()\n",
" measurement.metrics[\"y1\"] = y1\n",
" measurement.metrics[\"y2\"] = y2\n",
"\n",
" # Return the results for this trial\n",
" return [metric1, metric2]"
" return measurement"
]
},
{
@@ -545,11 +531,11 @@
},
"outputs": [],
"source": [
"client_id = \"client1\" # @param {type: 'string'}\n",
"suggestion_count_per_request = 5 # @param {type: 'integer'}\n",
"max_trial_id_to_stop = 4 # @param {type: 'integer'}\n",
"worker_id = \"worker1\" # @param {type: 'string'}\n",
"suggestion_count_per_request = 3 # @param {type: 'integer'}\n",
"max_trial_id_to_stop = 6 # @param {type: 'integer'}\n",
"\n",
"print(\"client_id: {}\".format(client_id))\n",
"print(\"worker_id: {}\".format(worker_id))\n",
"print(\"suggestion_count_per_request: {}\".format(suggestion_count_per_request))\n",
"print(\"max_trial_id_to_stop: {}\".format(max_trial_id_to_stop))"
]
@@ -573,42 +559,17 @@
},
"outputs": [],
"source": [
"trial_id = 0\n",
"while int(trial_id) < max_trial_id_to_stop:\n",
" suggest_response = vizier_client.suggest_trials(\n",
" {\n",
" \"parent\": STUDY_ID,\n",
" \"suggestion_count\": suggestion_count_per_request,\n",
" \"client_id\": client_id,\n",
" }\n",
" )\n",
"while len(study.trials()) < max_trial_id_to_stop:\n",
" trials = study.suggest(count=suggestion_count_per_request, worker=worker_id)\n",
"\n",
" for suggested_trial in suggest_response.result().trials:\n",
" trial_id = suggested_trial.name.split(\"/\")[-1]\n",
" trial = vizier_client.get_trial({\"name\": suggested_trial.name})\n",
"\n",
" if trial.state in [\"COMPLETED\", \"INFEASIBLE\"]:\n",
" continue\n",
"\n",
" for param in trial.parameters:\n",
" if param.parameter_id == \"r\":\n",
" r = param.value\n",
" elif param.parameter_id == \"theta\":\n",
" theta = param.value\n",
" print(\"Trial : r is {}, theta is {}.\".format(r, theta))\n",
"\n",
" vizier_client.add_trial_measurement(\n",
" {\n",
" \"trial_name\": suggested_trial.name,\n",
" \"measurement\": {\n",
" \"metrics\": CreateMetrics(suggested_trial.name, r, theta)\n",
" },\n",
" }\n",
" for suggested_trial in trials:\n",
" measurement = CreateMetrics(\n",
" suggested_trial.name,\n",
" suggested_trial.parameters[\"r\"].value,\n",
" suggested_trial.parameters[\"theta\"].value,\n",
" )\n",
"\n",
" response = vizier_client.complete_trial(\n",
" {\"name\": suggested_trial.name, \"trial_infeasible\": False}\n",
" )"
" suggested_trial.add_measurement(measurement=measurement)\n",
" suggested_trial.complete(measurement=measurement)"
]
},
{
@@ -630,8 +591,7 @@
},
"outputs": [],
"source": [
"optimal_trials = vizier_client.list_optimal_trials({\"parent\": STUDY_ID})\n",
"\n",
"optimal_trials = study.optimal_trials()\n",
"print(\"optimal_trials: {}\".format(optimal_trials))"
]
},
@@ -655,7 +615,7 @@
},
"outputs": [],
"source": [
"vizier_client.delete_study({\"name\": STUDY_ID})"
"study.delete()"
]
}
],