Compare commits

...
Author SHA1 Message Date
Andrew FerlitschandGitHub 0a5cafc1b7 Merge branch 'main' into official_fix22 2022-09-28 15:33:39 -07:00
Andrew FerlitschandGitHub c4cda29095 fix: bad links (#1026)
* fix: bad links

* fix: bad links
2022-09-28 15:33:25 -07:00
Andrew Ferlitsch dc603f237a fix: bad links 2022-09-28 22:21:20 +00:00
Andrew Ferlitsch 30a082ed8c fix: bad links 2022-09-28 22:21:04 +00:00
Andrew FerlitschandGitHub 47725449b5 fix: bad link (#1005)
* fix: bad link

* fix: bad link
2022-09-28 15:01:44 -07:00
Andrew FerlitschandGitHub 2eba462437 fix: bad link (#1010)
* fix: bad link

* fix: bad link
2022-09-28 14:31:37 -07:00
Andrew FerlitschandGitHub 97a3f4d3dd fix: add abbr (#1024) 2022-09-28 14:28:34 -07:00
Andrew FerlitschandGitHub 531e567358 fix: bad links (#1009)
* fix: bad link

* fix: bad link
2022-09-28 14:12:58 -07:00
Andrew FerlitschandGitHub 1f7c7105bb fix: link, title, format (#1018)
* fix: link, title, format

* fix: link, title, format
2022-09-28 14:12:29 -07:00
Andrew FerlitschandGitHub b109183d52 fix: bad links (#1011)
* fix: bad link

* fix: bad link
2022-09-28 13:53:45 -07:00
Andrew FerlitschandGitHub 72ed00fe0f fix: bad links (#1012)
* fix: bad link

* fix: bad link
2022-09-28 13:53:27 -07:00
Andrew FerlitschandGitHub e8d9137a50 fix: bad links (#1013)
* fix: bad link

* fix: bad link
2022-09-28 13:52:51 -07:00
Andrew FerlitschandGitHub 872e98c544 fix: bad links (#1014)
* fix: bad link

* fix: bad link
2022-09-28 13:52:17 -07:00
Andrew FerlitschandGitHub 0966fc56a4 fix: bad links, missing title (#1015)
* fix: bad link, missing title

* fix: bad link, missing title
2022-09-28 13:51:56 -07:00
Andrew FerlitschandGitHub e8d1e58fc6 fix: bad link, title (#1016)
* fix: bad link, correct title

* fix: bad link, correct title
2022-09-28 13:50:44 -07:00
Andrew FerlitschandGitHub f73ff8a44f fix: bad link, title (#1017)
* fix: bad link, correct title

* fix: bad link, correct title
2022-09-28 13:49:53 -07:00
Andrew FerlitschandGitHub 48c5810bd7 fix: bad link, title (#1019)
* fix: bad link, title

* fix: bad link, title
2022-09-28 13:49:25 -07:00
Andrew FerlitschandGitHub 9821d8986c fix: bad link, title (#1020)
* fix: bad link, title

* fix: bad link, title
2022-09-28 13:48:57 -07:00
Andrew FerlitschandGitHub 207d5db3e9 fix: bad link, title (#1021)
* fix: bad link, title

* fix: bad link, title
2022-09-28 13:48:29 -07:00
Andrew FerlitschandGitHub 9deb05e3e7 fix: bad link (#1022)
* fix: bad links

* fix: bad links
2022-09-28 13:47:59 -07:00
Andrew FerlitschandGitHub 8dafc25aab fix: bad link (#1006)
* fix: bad link

* fix: bad link
2022-09-28 13:47:25 -07:00
ef10e7db53 Vertex AI Model Registry - AutoML model management notebook (#995)
* new notebook

* linter test passed

* linter test passed

* andy review

* linter test passed

* add codeowner

Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-09-28 09:41:50 -07:00
Andrew FerlitschandGitHub cba907ddf8 fix: tuning the script (#1004) 2022-09-28 12:21:47 -04:00
16c3d7fe25 automl_video_classification_model_evaluation (#960)
* added model evaluation component

* linter test cases

* linter test cases

* model_name param issues resolved

* linter test case

* import issues resloved

* linter test cases

* made review changes

* made review changes

* ran linter test

* made review changes

* made review changes

* made review changes

* linter test

* ran linter test

* made review changes

* ran linter test

* made review changes

* ran linter test

* linter test

* review changes

* ran linter test

Co-authored-by: Ivan Cheung <ivans.mailbox@gmail.com>
Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-09-28 07:33:08 -07:00
60e1f92ef4 Vertex AI Model Registry - BQML and custom model management notebook (#991)
* add new notebook

* linter test passed

* clean text

* linter test passed

* add code owner new model registry notebook

* add more description

* linter test passed

* align with new template

* linter test passed

* andy reviews

* linter test passed

Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-09-28 00:05:41 -07:00
Andrew FerlitschandGitHub fb392c6375 Issue 937 (#998)
* fix: issue 937

* fix: issue 937

* fix: wrong method for service account

* fix: wrong method for service account
2022-09-27 21:33:12 -07:00
b4d10bc5aa Modified SDK_Custom_Training_Python_Package_Managed_Text_Dataset_Tensorflow_Serving_Container.ipynb (#996)
* modified notebook, resolved error and modified notebook according to template

* ran linter

Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-09-27 19:51:55 -07:00
4049250bad chore: Fix Workbench links. (#983)
Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-09-27 15:24:51 -07:00
923db816e1 Added changes such as timestamp, removed colab references, added markup text mentioning usage of flag -q in a command for the file SDK_Custom_Container_Prediction (#503)
* Added changes in notebook

* Ran linter test

* Replaced Timestamp with UUID; Added 'delete-bucket' in cleanup; Added condition for repo creation and few other minor changes

* Ran Linter Test

* Made some minor changes to install packages

* Made minor changes to fix linter failed tests

* ran linter test

* Made some minor changes

* ran linter test

* addresses the review comments: fixes container build steps, license year, updates according to the template

* ran linter test

* removes beta from gcloud to avoid timeouts

* ran linter test

Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
Co-authored-by: Karl Weinmeister <11586922+kweinmeister@users.noreply.github.com>
Co-authored-by: SamyuktaDR <samyukta.dontireddy@springml.com>
Co-authored-by: SamyuktaDR <45586340+SamyuktaDR@users.noreply.github.com>
Co-authored-by: Krishna Chaitanya Movva <krishr2d2@gmail.com>
Co-authored-by: krishr2d2 <krishna.movva@springml.com>
2022-09-27 15:13:29 -07:00
Andrew FerlitschandGitHub 872f1561cd fix: argument handling improvements (#999) 2022-09-27 16:51:41 -04:00
8d7832de6e fix: issue 241479124 (#997)
* fix: issue 241479124

* fix: issue 241479124

Co-authored-by: gericdong <itseric@google.com>
2022-09-27 15:08:10 -04:00
Michael HuandGitHub f840017cda fix: bump gcpc version for bqml arima notebook (#985)
* fix: bump gcpc version for bqml arima notebook

* pr fixes
2022-09-27 11:02:38 -07:00
de3f35b8a6 Modified notebook sdk_automl_tabular_forecasting_batch.ipynb (#896)
* modified notebook

* ran linter

Co-authored-by: Ivan Cheung <ivans.mailbox@gmail.com>
Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-09-26 20:17:58 -07:00
b746bc80d4 Resolves shell-output issue in google_cloud_pipeline_components_model_upload_predict_evaluate.ipynb notebook (#878)
* resolves the shell-output issue + updates the structure based on the template

* ran linter test

* fixes issues from review: textual updates, delete_bucket=False

* ran linter test

Co-authored-by: Ivan Cheung <ivans.mailbox@gmail.com>
Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-09-26 16:27:29 -07:00
2001604d37 Modified pricing-optimization.ipynb (#867)
* modified notebook according to notebook_template.

* ran linter

* Added create dataset step

* ran linter

* replaced hardcoded dataset name with a variable

* ran linter

* changes suggested by nadrew done

* ran linter

* followed prolong lin comments, data cleaning now done in bigquery

* ran linter

Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
Co-authored-by: Ivan Cheung <ivans.mailbox@gmail.com>
2022-09-26 15:37:48 -07:00
faa148f66e Bqml vertex model registry (#993)
* Add bqml-vertexai-model-registry notebook

* Run linter

* Add notebook to CODEOWNERS file

* Update the links

* Ran linter again

* Rename bigquey-ml folder to model-registry

* Add bigquery-ml folder

* Moved the notebook

* Deleted folder

* Resolve comments

* Use UUID

* Remove using existing endpoint

* Remove try statement

* Get model sample based on model's name

* Use job.result to check query job status

* Run linter

* Fix dataset not found error by adding region in bq client creation

* Revert changes

* Fix bq bugs

* Run linter

* Resolve comments

* Display dataframe

* Updated the codeowner file

* Updated the links and editted text

* Run linter

* Remove repeated resources

* Run linter

* Resolve comments

* Run linter

* Install pyarrow

Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-09-26 18:22:57 -04:00
f184411666 Create a function to get notebook python version for execution (#828)
* Create a function to get notebook python version for execution

* Inject python version to yaml file

* Fix python version references

* Add python string to python version variable

* add python version extraction script (untested)

* Create a function to get notebook python version for execution

* Inject python version to yaml file

* Fix python version references

* Add python string to python version variable

* Remove one notebook condition

* Remove extra check and use python 3 as default version

* Use python3.9 as default version

* Update python version notebook parser

* Add python version to the notebook template

* Fix bug

* Update python version parser function

* Add python version to a notebook for testing

* Run linter

* Use regex in python version parser function

* Add new notebook for testing

* Use better variable name

* fix typo

* Use f string instead +

* Use python from env instead of using _PYTHON_VERSION

* Use simpler regex

* Add python version test notebook

* Fixed a mistake

* Updated notebook template with python version

* Fixed python version format

* Print log contents to stdout

* Remove failing notebook

* Run linter

* Remove extra steps in the printed log

* Edit comments

* Run linter

* Run linter

* Revert test changes

Co-authored-by: AG Sol <aarongabriel@google.com>
2022-09-26 14:32:53 -07:00
bdad774100 Vertex SDK AutoML Text Sentiment Analysis (#824)
* new changes for sentiment analysis notebook

* new changes for sentiment analysis notebook

* changed back to year 2021 text

* changed back to year 2021 text

Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-09-25 08:37:58 -07:00
9abe9a643b Added Custom tabular regression model evaluation file (#942)
* added file

* removed unnecessary imports

* ran linter

* removed extra batch prediction component

* ran linter

* moved file to official

* changed links to point to official

* ran linter

* Jason comments addressed

* ran linter

* comments addressed

* ran linter

* comments addresed

* ran linter

* added predictionschema instance schema files

* ran linter

* Followed Karen Lin's comments

* ran linter

* replaced old prebuilt containers with latest ones

* ran linter

Co-authored-by: Ivan Cheung <ivans.mailbox@gmail.com>
Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-09-24 11:12:06 -07:00
ab230ca06f add fixes to sdk-feature-store.ipynb (formatting, link edits) (#913)
* fix sdk-feature-store.ipynb Workbench link

* adding changes

* fixing links

* lint issues:

Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-09-24 09:37:06 -07:00
dcbd3702d2 Made uuid changes and cleaned Uj6 vertex sdk auto ml text classification notebook (#904)
* Made some minor changes to notebook

* Ran linter test

* Ran linter test

Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-09-24 09:03:11 -07:00
0505d0c04c Vizier sdk (#981)
* update: replace GAPIC with SDK

* update: replace GAPIC with SDK

Co-authored-by: gericdong <itseric@google.com>
2022-09-23 16:27:36 -04:00
a47e0aacbb Model monitor batch (#980)
* fix: batch monitoring notebook

* fix: batch monitoring notebook

Co-authored-by: gericdong <itseric@google.com>
2022-09-23 15:10:54 -04:00
48 changed files with 15560 additions and 5965 deletions
@@ -17,13 +17,16 @@ import concurrent
import dataclasses
import datetime
import functools
import json
import git
import operator
import os
import pathlib
import re
import subprocess
import utils
from typing import List, Optional
from utils import util
import execute_notebook_helper
import execute_notebook_remote
@@ -35,6 +38,7 @@ from utils import NotebookProcessors, util
# A buffer so that workers finish before the orchestrating job
WORKER_TIMEOUT_BUFFER_IN_SECONDS: int = 60 * 60
PYTHON_VERSION = "3.9" # Set default python version
def format_timedelta(delta: datetime.timedelta) -> str:
@@ -66,6 +70,7 @@ class NotebookExecutionResult:
log_url: str
output_uri: str
build_id: str
logs_bucket: str
error_message: Optional[str]
@property
@@ -110,6 +115,33 @@ def _process_notebook(
nbformat.write(nb, new_file)
def _get_notebook_python_version(notebook_path: str) -> str:
"""
Get the python version for running the notebook if it is specified in
the notebook.
"""
python_version = PYTHON_VERSION
# Load the notebook
file = open(notebook_path)
src = file.read()
nb_json = json.loads(src)
#Iterate over the cells in the ipynb
for cell in nb_json['cells']:
if cell['cell_type'] == 'markdown':
markdown = str.join('', cell['source'])
# Look for the python version specification pattern
re_match = re.search('python version = (\d\.\d)', markdown, flags=re.IGNORECASE)
if re_match:
# get the version number
python_version = re_match.group(1)
break
return python_version
def _create_tag(filepath: str) -> str:
tag = os.path.basename(os.path.normpath(filepath))
tag = re.sub("[^0-9a-zA-Z_.-]+", "-", tag)
@@ -160,6 +192,7 @@ def process_and_execute_notebook(
output_uri=notebook_output_uri,
log_url="",
build_id="",
logs_bucket="",
error_message=None,
)
@@ -167,6 +200,10 @@ def process_and_execute_notebook(
time_start = datetime.datetime.now()
operation = None
try:
# Get the python version for running the notebook if specified
notebook_exec_python_version = _get_notebook_python_version(notebook_path=notebook)
print(f"Running notebook with python {notebook_exec_python_version}")
# Pre-process notebook by substituting variable names
_process_notebook(
notebook_path=notebook,
@@ -193,11 +230,13 @@ def process_and_execute_notebook(
private_pool_id=private_pool_id,
private_pool_region=variable_region,
timeout_in_seconds=timeout_in_seconds,
python_version=notebook_exec_python_version
)
operation_metadata = BuildOperationMetadata(mapping=operation.metadata)
result.build_id = operation_metadata.build.id
result.log_url = operation_metadata.build.log_url
result.logs_bucket = operation_metadata.build.logs_bucket
# Block and wait for the result
operation_result = operation.result()
@@ -339,7 +378,7 @@ def process_and_execute_notebooks(
seconds=max(timeout - WORKER_TIMEOUT_BUFFER_IN_SECONDS, 0)
)
if len(notebooks) > 1:
if len(notebooks) >= 1:
notebook_execution_results: List[NotebookExecutionResult] = []
print(f"Found {len(notebooks)} modified notebooks: {notebooks}")
@@ -404,6 +443,7 @@ def process_and_execute_notebooks(
result.log_url,
result.output_uri,
result.output_uri_web,
result.logs_bucket
]
for result in results_sorted
],
@@ -414,10 +454,35 @@ def process_and_execute_notebooks(
"log_url",
"output_uri",
"output_uri_web",
"logs_bucket"
],
)
)
if len(notebooks) == 1:
print("="*100)
print("The notebook execution build log:\n")
print("="*100)
build_id = results_sorted[0].build_id
logs_bucket_name = (results_sorted[0].logs_bucket).removeprefix("gs://")
log_file_name = f"log-{build_id}.txt"
log_contents = util.download_blob_into_memory(
bucket_name=logs_bucket_name,
blob_name=log_file_name,
download_as_text=True
)
# Remove extra steps from the log
match = re.search("starting Step #4", log_contents, flags=re.IGNORECASE)
if match is not None:
match_index = match.span()[0]
print(log_contents[match_index:])
else:
print(log_contents)
print("\n=== END RESULTS===\n")
total_notebook_duration = functools.reduce(
@@ -433,25 +498,5 @@ def process_and_execute_notebooks(
# Raise error if any notebooks failed
if not all([result.is_pass for result in results_sorted]):
raise RuntimeError("Notebook failures detected. See logs for details")
elif len(notebooks) == 1:
notebook = notebooks[0]
# Pre-process notebook by substituting variable names
_process_notebook(
notebook_path=notebook,
variable_project_id=variable_project_id,
variable_region=variable_region,
variable_service_account=variable_service_account,
variable_vpc_network=variable_vpc_network,
)
execute_notebook_helper.execute_notebook(
notebook_source=notebook,
output_file_or_uri="/".join(
[artifacts_bucket, pathlib.Path(notebook).name]
),
should_log_output=True,
)
else:
print("No notebooks modified in this pull request.")
+5
View File
@@ -40,6 +40,7 @@ def execute_notebook_remote(
private_pool_region: Optional[str],
tag: Optional[str],
timeout_in_seconds: Optional[int] = None,
python_version: Optional[str] = None
) -> operation.Operation:
"""Create and execute a single notebook on Google Cloud Build"""
# Load build steps from YAML
@@ -50,8 +51,12 @@ def execute_notebook_remote(
"_PYTHON_IMAGE": container_uri,
"_NOTEBOOK_GCS_URI": notebook_uri,
"_NOTEBOOK_OUTPUT_GCS_URI": notebook_output_uri,
"_PYTHON_VERSION" : f"python{python_version}"
}
if python_version is not None:
substitutions["_PYTHON_VERSION"] = "python" + python_version
build = cloudbuild_v1.Build()
options: Optional[client_options.ClientOptions] = None
@@ -10,21 +10,21 @@ steps:
entrypoint: /bin/sh
args:
- -c
- python3 .cloud-build/CheckPythonVersion.py -q
- ${_PYTHON_VERSION} .cloud-build/CheckPythonVersion.py -q
# Create a virtual environment
- name: ${_PYTHON_IMAGE}
entrypoint: /bin/sh
args:
- -c
- python3 -m venv workspace/env
- ${_PYTHON_VERSION} -m venv workspace/env
# Install Python dependencies
- name: ${_PYTHON_IMAGE}
entrypoint: /bin/sh
args:
- -c
- . workspace/env/bin/activate &&
python3 -m pip -q install -U pip &&
python3 -m pip -q install -U -r .cloud-build/requirements.txt
python -m pip -q install -U pip &&
python -m pip -q install -U -r .cloud-build/requirements.txt
# Install Python dependencies and run testing script
- name: ${_PYTHON_IMAGE}
entrypoint: /bin/sh
@@ -32,7 +32,7 @@ steps:
- -c
- |
. workspace/env/bin/activate &&
python3 .cloud-build/execute_notebook_cli.py --notebook_source "${_NOTEBOOK_GCS_URI}" --output_file_or_uri "${_NOTEBOOK_OUTPUT_GCS_URI}"
python .cloud-build/execute_notebook_cli.py --notebook_source "${_NOTEBOOK_GCS_URI}" --output_file_or_uri "${_NOTEBOOK_OUTPUT_GCS_URI}"
env:
- 'IS_TESTING=1'
timeout: 86400s
+3 -2
View File
@@ -1,5 +1,6 @@
notebooks/official/vizier/gapic-vizier-multi-objective-optimization.ipynb
notebooks/official/pipelines/lightweight_functions_component_io_kfp.ipynb
notebooks/official/ml_metadata/sdk-metric-parameter-tracking-for-locally-trained-models.ipynb
notebooks/official/pipelines/metrics_viz_run_compare_kfp.ipynb
notebooks/official/matching_engine/sdk_matching_engine_for_indexing.ipynb
notebooks/official/custom/custom-tabular-bq-managed-dataset.ipynb
notebooks/official/matching_engine/sdk_matching_engine_for_indexing.ipynb
.cloud-build/tests/python_version_test.ipynb
+1 -1
View File
@@ -1 +1 @@
notebooks/official/pipelines/metrics_viz_run_compare_kfp.ipynb
notebooks/official/custom/custom-tabular-bq-managed-dataset.ipynb
@@ -0,0 +1,61 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "57a3d44ed8a8"
},
"source": [
"### Set up your Google Cloud project\n",
"\n",
"**_NOTE_**: This notebook has been tested in the following environment:\n",
"\n",
"* Python version = 3.7\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",
"1. [Make sure that billing is enabled for your project](https://cloud.google.com/billing/docs/how-to/modify-project).\n",
"\n",
"1. [Enable the Vertex AI API and Compute Engine API](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com,compute_component).\n",
"\n",
"1. If you are running this notebook locally, you will need to install the [Cloud SDK](https://cloud.google.com/sdk).\n",
"\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 `$` into these commands."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "c6516f90311b"
},
"outputs": [],
"source": [
"# test if the right python version is being used\n",
"import sys\n",
"\n",
"actual_python_version = f\"{sys.version_info.major}.{sys.version_info.minor}\"\n",
"print(f\"Runtime python version: {actual_python_version}\")\n",
"\n",
"assert actual_python_version == \"3.7\", \"Wrong python version!\""
]
}
],
"metadata": {
"colab": {
"name": "python_version_test.ipynb",
"toc_visible": true
},
"kernelspec": {
"display_name": "Python 3",
"name": "python3"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
+32 -1
View File
@@ -3,7 +3,7 @@ import subprocess
import tarfile
import uuid
from datetime import datetime
from typing import Optional
from typing import Optional, Union
from google.auth import credentials as auth_credentials
from google.cloud import storage
@@ -58,3 +58,34 @@ def archive_code_and_upload(staging_bucket: str):
print(f"Uploaded source code archive to {source_archived_file_gcs}")
return source_archived_file_gcs
def download_blob_into_memory(
bucket_name: str,
blob_name: str,
download_as_text: Optional[bool]=False
) -> Union[bytes, str]:
"""
Downloads a blob into memory as byte or as text if
download_as_text is set to True.
"""
storage_client = storage.Client()
bucket = storage_client.bucket(bucket_name)
# Construct a client side representation of a blob.
blob = bucket.blob(blob_name)
# Download the blob content
if download_as_text:
contents = blob.download_as_text()
else:
contents = blob.download_as_bytes()
print(
f"Downloaded storage object {blob_name} from bucket {bucket_name}."
)
return contents
+2
View File
@@ -31,3 +31,5 @@
/notebooks/community/pipelines/google_cloud_pipeline_components_bqml_pipeline_demand_forecasting.ipynb @inardini
/notebooks/community/ml_ops/stage2/get_started_vertex_hpt_r_kernel.ipynb @fhirschmann
/notebooks/community/ml_ops/stage2/get_started_vertex_training_r_using_r_kernel.ipynb @fhirschmann
/notebooks/community/vertex-ai-samples/notebooks/community/model_registry/vertex_ai_model_registry_bqml_custom_model_versioning.ipynb @inardini
/notebooks/community/vertex-ai-samples/notebooks/community/model_registry/vertex_ai_model_registry_automl_model_versioning.ipynb @inardini
@@ -39,18 +39,15 @@
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage1/mlops_data_management.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://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://raw.githubusercontent.com/GoogleCloudPlatform/vertex-ai-samples/main/notebooks/community/ml_ops/stage1/mlops_data_management.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>\n",
"<br/><br/><br/>"
"<br/><br/><br/>\n",
"\n",
"*Note: This notebook is not supported for execution in Colab*"
]
},
{
@@ -169,21 +166,20 @@
"if IS_WORKBENCH_NOTEBOOK:\n",
" USER_FLAG = \"--user\"\n",
"\n",
"ONCE_ONLY = True\n",
"ONCE_ONLY = False\n",
"if ONCE_ONLY:\n",
" ! pip3 install -U tensorflow==2.5 $USER_FLAG -q\n",
" ! pip3 install -U tensorflow-data-validation==1.2 $USER_FLAG -q\n",
" ! pip3 install -U tensorflow-transform==1.2 $USER_FLAG -q\n",
" ! pip3 install -U tensorflow-io==0.18 $USER_FLAG -q\n",
" ! pip3 install --upgrade google-cloud-aiplatform[tensorboard] $USER_FLAG -q\n",
" ! pip3 install --upgrade google-cloud-pipeline-components $USER_FLAG -q\n",
" ! pip3 install --upgrade google-cloud-bigquery $USER_FLAG -q\n",
" ! pip3 install --upgrade google-cloud-logging $USER_FLAG -q\n",
" ! pip3 install --upgrade apache-beam[gcp]==2.33.0 $USER_FLAG -q\n",
" ! pip3 install --upgrade pyarrow $USER_FLAG -q\n",
" ! pip3 install --upgrade cloudml-hypertune $USER_FLAG -q\n",
" ! pip3 install --upgrade kfp $USER_FLAG -q\n",
" ! pip3 install future $USER_FLAG -q"
" ! pip3 install -U {USER_FLAG} -q tensorflow==2.5 \\\n",
" tensorflow-data-validation==1.2 \\\n",
" tensorflow-transform==1.2 \\\n",
" tensorflow-io==0.18 \n",
" \n",
" ! pip3 install --upgrade {USER_FLAG} -q google-cloud-aiplatform[tensorboard] \\\n",
" google-cloud-pipeline-components \\\n",
" google-cloud-bigquery \\\n",
" google-cloud-logging \\\n",
" apache-beam[gcp] \\\n",
" pyarrow \\\n",
" cloudml-hypertune\n"
]
},
{
@@ -355,7 +351,7 @@
"source": [
"### Authenticate your Google Cloud account\n",
"\n",
"**If you are using Vertex AI Workbench Notebooks**, your environment is already authenticated. Skip this step.\n",
"**If you are using Vertex AI Workbench Notebooks**, your environment is already 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",
@@ -417,7 +413,7 @@
"\n",
"**The following steps are required, regardless of your notebook environment.**\n",
"\n",
"When you submit a custom training job using the Vertex SDK, you upload a Python package\n",
"When you submit a custom 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. You can then\n",
@@ -84,7 +84,8 @@
"The steps performed include:\n",
"\n",
"- Hyperparameter tuning with Random algorithm.\n",
"- Hyperparameter tuning with Vizier (Bayesian) algorithm."
"- Hyperparameter tuning with Vizier (Bayesian) algorithm.\n",
"- Suggesting trials and updating results for Vizier study"
]
},
{
@@ -187,7 +188,8 @@
"if IS_WORKBENCH_NOTEBOOK:\n",
" USER_FLAG = \"--user\"\n",
"\n",
"! pip3 install --upgrade google-cloud-aiplatform[tensorboard] $USER_FLAG -q"
"! pip3 install --upgrade $USER_FLAG -q google-cloud-aiplatform \\\n",
" google-vizier==0.0.4"
]
},
{
@@ -329,25 +331,32 @@
{
"cell_type": "markdown",
"metadata": {
"id": "timestamp"
"id": "06571eb4063b"
},
"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."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "timestamp"
"id": "4e166d927e36"
},
"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()"
]
},
{
@@ -358,7 +367,7 @@
"source": [
"### Authenticate your Google Cloud account\n",
"\n",
"**If you are using Vertex AI Workbench Notebooks**, your environment is already authenticated. Skip this step.\n",
"**If you are using Vertex AI Workbench Notebooks**, your environment is already 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",
@@ -446,7 +455,7 @@
"outputs": [],
"source": [
"if BUCKET_URI == \"\" or BUCKET_URI is None or BUCKET_URI == \"gs://[your-bucket-name]\":\n",
" BUCKET_URI = \"gs://\" + PROJECT_ID + \"aip-\" + TIMESTAMP"
" BUCKET_URI = \"gs://\" + PROJECT_ID + \"aip-\" + UUID"
]
},
{
@@ -509,7 +518,8 @@
},
"outputs": [],
"source": [
"import google.cloud.aiplatform as aip"
"import google.cloud.aiplatform as aip\n",
"from google.cloud.aiplatform.vizier import Study, pyvizier"
]
},
{
@@ -534,35 +544,6 @@
"aip.init(project=PROJECT_ID, staging_bucket=BUCKET_URI)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "aip_constants"
},
"source": [
"#### Vertex AI constants\n",
"\n",
"Setup up the following constants for Vertex AI:\n",
"\n",
"- `API_ENDPOINT`: The Vertex AI API service endpoint for `Dataset`, `Model`, `Job`, `Pipeline` and `Endpoint` services.\n",
"- `PARENT`: The Vertex AI location root path for `Dataset`, `Model`, `Job`, `Pipeline` and `Endpoint` resources."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "aip_constants"
},
"outputs": [],
"source": [
"# API service endpoint\n",
"API_ENDPOINT = \"{}-aiplatform.googleapis.com\".format(REGION)\n",
"\n",
"# Vertex location root path for your dataset, model and endpoint resources\n",
"PARENT = \"projects/\" + PROJECT_ID + \"/locations/\" + REGION"
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -626,7 +607,7 @@
"if os.getenv(\"IS_TESTING_TF\"):\n",
" TF = os.getenv(\"IS_TESTING_TF\")\n",
"else:\n",
" TF = \"2.1\".replace(\".\", \"-\")\n",
" TF = \"2.5\".replace(\".\", \"-\")\n",
"\n",
"if TF[0] == \"2\":\n",
" if TRAIN_GPU:\n",
@@ -1031,7 +1012,7 @@
},
"outputs": [],
"source": [
"JOB_NAME = \"custom_job_\" + TIMESTAMP\n",
"JOB_NAME = \"custom_job_\" + UUID\n",
"MODEL_DIR = \"{}/{}\".format(BUCKET_URI, JOB_NAME)\n",
"\n",
"if not TRAIN_NGPU or TRAIN_NGPU < 2:\n",
@@ -1094,9 +1075,7 @@
},
"outputs": [],
"source": [
"job = aip.CustomJob(\n",
" display_name=\"boston_\" + TIMESTAMP, worker_pool_specs=worker_pool_spec\n",
")"
"job = aip.CustomJob(display_name=\"boston_\" + UUID, worker_pool_specs=worker_pool_spec)"
]
},
{
@@ -1128,7 +1107,7 @@
"from google.cloud.aiplatform import hyperparameter_tuning as hpt\n",
"\n",
"hpt_job = aip.HyperparameterTuningJob(\n",
" display_name=\"boston_\" + TIMESTAMP,\n",
" display_name=\"boston_\" + UUID,\n",
" custom_job=job,\n",
" metric_spec={\n",
" \"val_loss\": \"minimize\",\n",
@@ -1309,7 +1288,7 @@
"outputs": [],
"source": [
"job = aip.CustomJob(\n",
" display_name=\"boston_\" + TIMESTAMP,\n",
" display_name=\"boston_\" + UUID,\n",
" worker_pool_specs=worker_pool_spec,\n",
" base_output_dir=MODEL_DIR,\n",
")"
@@ -1344,7 +1323,7 @@
"from google.cloud.aiplatform import hyperparameter_tuning as hpt\n",
"\n",
"hpt_job = aip.HyperparameterTuningJob(\n",
" display_name=\"boston_\" + TIMESTAMP,\n",
" display_name=\"boston_\" + UUID,\n",
" custom_job=job,\n",
" metric_spec={\n",
" \"val_loss\": \"minimize\",\n",
@@ -1513,22 +1492,25 @@
"id": "vizier_client"
},
"source": [
"### Create Vizier client\n",
"### Specify the algorithm used to suggest trial parameters\n",
"\n",
"Create a client side connection to the Vertex AI Vizier service."
"First, you create a `StudyConfig`, and specify the algorithm to suggest the next trial.\n",
"\n",
" GRID_SEARCH: grid search\n",
" RANDOM_SEARCH: random search\n",
" ALGORIGTHM_UNSPECIFIED: Vizier bayesian algorithm"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "vizier_client"
"id": "d7dd26490358"
},
"outputs": [],
"source": [
"vizier_client = aip.gapic.VizierServiceClient(\n",
" client_options=dict(api_endpoint=API_ENDPOINT)\n",
")"
"problem = pyvizier.StudyConfig()\n",
"problem.algorithm = pyvizier.Algorithm.RANDOM_SEARCH"
]
},
{
@@ -1543,7 +1525,15 @@
"\n",
"In the following example, the goal is to maximize y = x^2 with x in the range of \\[-10. 10\\]. This example has only one parameter and uses an easily calculated function to help demonstrate how to use Vizier.\n",
"\n",
"First, you will create the study using the `create_study()` method."
"First, you specify the metrics to minimize or maximize in the study as a list to the property `metric_information`. Then you specify the parameters to the study using the `add_XXX_params()` method for the corresponding data type:\n",
"\n",
" - add_bool_param\n",
" - add_categorical_param\n",
" - add_discrete_param\n",
" - add_float_param\n",
" - add_int_param\n",
"\n",
"You create the study using the `create_or_load()` method."
]
},
{
@@ -1554,28 +1544,19 @@
},
"outputs": [],
"source": [
"STUDY_DISPLAY_NAME = \"xpow2\" + TIMESTAMP\n",
"STUDY_DISPLAY_NAME = \"xpow2\" + UUID\n",
"\n",
"param_x = {\n",
" \"parameter_id\": \"x\",\n",
" \"double_value_spec\": {\"min_value\": -10.0, \"max_value\": 10.0},\n",
"}\n",
"problem.metric_information.append(\n",
" pyvizier.MetricInformation(name=\"y\", goal=pyvizier.ObjectiveMetricGoal.MAXIMIZE)\n",
")\n",
"\n",
"metric_y = {\"metric_id\": \"y\", \"goal\": \"MAXIMIZE\"}\n",
"params = problem.search_space.select_root()\n",
"params.add_float_param(\"x\", -10.0, 10.0, scale_type=pyvizier.ScaleType.LINEAR)\n",
"\n",
"study = {\n",
" \"display_name\": STUDY_DISPLAY_NAME,\n",
" \"study_spec\": {\n",
" \"algorithm\": \"RANDOM_SEARCH\",\n",
" \"parameters\": [param_x],\n",
" \"metrics\": [metric_y],\n",
" },\n",
"}\n",
"study = Study.create_or_load(display_name=STUDY_DISPLAY_NAME, problem=problem)\n",
"\n",
"study = vizier_client.create_study(parent=PARENT, study=study)\n",
"STUDY_NAME = study.name\n",
"\n",
"print(STUDY_NAME)"
"print(\"STUDY_NAME: {}\".format(STUDY_NAME))"
]
},
{
@@ -1586,9 +1567,7 @@
"source": [
"### Get Vizier study\n",
"\n",
"You can get a study using the method `get_study()`, with the following key/value pairs:\n",
"\n",
"- `name`: The name of the study."
"You can get a study using the method `list()`."
]
},
{
@@ -1599,9 +1578,8 @@
},
"outputs": [],
"source": [
"study = vizier_client.get_study({\"name\": STUDY_NAME})\n",
"\n",
"print(study)"
"studies = Study.list()\n",
"print(studies[0].gca_resource)"
]
},
{
@@ -1612,11 +1590,9 @@
"source": [
"### Get suggested trial\n",
"\n",
"Next, query the Vizier service for a suggested trial(s) using the method `suggest_trials`, with the following key/value pairs:\n",
"Next, query the Vizier service for a suggested trial(s) using the method `suggest()`, with the following key/value pairs:\n",
"\n",
"- `parent`: The name of the study.\n",
"- `suggestion_count`: The number of trials to suggest.\n",
"- `client_id`: blah\n",
"- `count`: The number of trials to suggest.\n",
"\n",
"This call is a long running operation. The method `result()` from the response object will wait until the call has completed."
]
@@ -1625,18 +1601,13 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "vizier_suggest_trial"
"id": "11ff2c4562cb"
},
"outputs": [],
"source": [
"SUGGEST_COUNT = 1\n",
"CLIENT_ID = \"1001\"\n",
"\n",
"response = vizier_client.suggest_trials(\n",
" {\"parent\": STUDY_NAME, \"suggestion_count\": SUGGEST_COUNT, \"client_id\": CLIENT_ID}\n",
")\n",
"\n",
"trials = response.result().trials\n",
"trials = study.suggest(count=SUGGEST_COUNT)\n",
"\n",
"print(trials)\n",
"\n",
@@ -1679,12 +1650,10 @@
"source": [
"RESULT = 0.01\n",
"\n",
"vizier_client.add_trial_measurement(\n",
" {\n",
" \"trial_name\": TRIAL_ID,\n",
" \"measurement\": {\"metrics\": [{\"metric_id\": \"y\", \"value\": RESULT}]},\n",
" }\n",
")"
"measurement = pyvizier.Measurement()\n",
"measurement.metrics[\"y\"] = RESULT\n",
"\n",
"trials[0].add_measurement(measurement)"
]
},
{
@@ -1695,7 +1664,7 @@
"source": [
"### Delete the Vizier study\n",
"\n",
"The method 'delete_study()' will delete the study."
"The method 'delete()' will delete the study."
]
},
{
@@ -1706,7 +1675,7 @@
},
"outputs": [],
"source": [
"vizier_client.delete_study({\"name\": STUDY_NAME})"
"study.delete()"
]
},
{
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,13 +210,16 @@
},
{
"cell_type": "markdown",
"id": "d5737134",
"metadata": {
"id": "d5737134"
},
"source": [
"### Set up your Google Cloud project\n",
"\n",
"**_NOTE_**: This notebook has been tested in the following environment:\n",
"\n",
"* Python version = 3.7\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",
@@ -242,7 +238,6 @@
},
{
"cell_type": "markdown",
"id": "cfb1a1d5",
"metadata": {
"id": "cfb1a1d5"
},
@@ -255,50 +250,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 +287,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 +308,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 +382,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 +447,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 +740,6 @@
{
"cell_type": "code",
"execution_count": null,
"id": "b832ad31",
"metadata": {
"id": "b832ad31"
},
@@ -511,20 +747,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 +774,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 +803,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 +834,6 @@
},
{
"cell_type": "markdown",
"id": "cae39778",
"metadata": {
"id": "cae39778"
},
@@ -617,7 +846,6 @@
{
"cell_type": "code",
"execution_count": null,
"id": "bcdd4a47",
"metadata": {
"id": "bcdd4a47"
},
@@ -638,7 +866,6 @@
},
{
"cell_type": "markdown",
"id": "49ec90a0",
"metadata": {
"id": "49ec90a0"
},
@@ -651,7 +878,6 @@
{
"cell_type": "code",
"execution_count": null,
"id": "c30496b5",
"metadata": {
"id": "c30496b5"
},
@@ -664,7 +890,6 @@
},
{
"cell_type": "markdown",
"id": "831651c2",
"metadata": {
"id": "831651c2"
},
@@ -684,7 +909,6 @@
{
"cell_type": "code",
"execution_count": null,
"id": "a705c10b",
"metadata": {
"id": "a705c10b"
},
@@ -695,7 +919,6 @@
},
{
"cell_type": "markdown",
"id": "2bbdddac",
"metadata": {
"id": "2bbdddac"
},
@@ -708,7 +931,6 @@
{
"cell_type": "code",
"execution_count": null,
"id": "f6c674e9",
"metadata": {
"id": "f6c674e9"
},
@@ -746,7 +968,6 @@
},
{
"cell_type": "markdown",
"id": "233b1266",
"metadata": {
"id": "233b1266"
},
@@ -759,7 +980,6 @@
{
"cell_type": "code",
"execution_count": null,
"id": "4e8c00a7",
"metadata": {
"id": "4e8c00a7"
},
@@ -774,7 +994,6 @@
},
{
"cell_type": "markdown",
"id": "497a0016",
"metadata": {
"id": "497a0016"
},
@@ -790,7 +1009,6 @@
{
"cell_type": "code",
"execution_count": null,
"id": "eabc3f81",
"metadata": {
"id": "eabc3f81"
},
@@ -806,7 +1024,6 @@
},
{
"cell_type": "markdown",
"id": "0aa0219d",
"metadata": {
"id": "0aa0219d"
},
@@ -37,7 +37,7 @@
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://console.cloud.google.com/vertex-ai-samples/main/notebooks/community/prediction/custom_prediction_routines/SDK_Custom_Predict_SDK_Integration.ipynb\">\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/community/prediction/custom_prediction_routines/SDK_Custom_Predict_SDK_Integration.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",
@@ -37,7 +37,7 @@
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://console.cloud.google.com/vertex-ai-samples/main/notebooks/community/prediction/custom_prediction_routines/SDK_Pytorch_Custom_Predict.ipynb\">\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/community/prediction/custom_prediction_routines/SDK_Pytorch_Custom_Predict.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",
@@ -37,7 +37,7 @@
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://console.cloud.google.com/vertex-ai-samples/main/notebooks/community/prediction/custom_prediction_routines/SDK_Triton_PyTorch_Local_Prediction.ipynb\">\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/community/prediction/custom_prediction_routines/SDK_Triton_PyTorch_Local_Prediction.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",
+32
View File
@@ -0,0 +1,32 @@
tag,notebook
AutoML,official/automl/automl-text-classification.ipynb
AutoML,official/automl/sdk_automl_tabular_forecasting_batch.ipynb
Tabular Data,official/automl/automl_forecasting_bqml_arima_plus_comparison.ipynb
Tabular Data,official/automl/automl_tabular_on_vertex_pipelines.ipynb
Custom Training,official/custom/sdk-custom-image-classification-batch.ipynb
Custom Training,official/custom/sdk-custom-image-classification-online.ipynb
Vertex Explainable AI,official/explainable_ai/sdk_automl_tabular_binary_classification_batch_explain.ipynb
Vertex Explainable AI,official/explainable_ai/sdk_automl_tabular_classification_online_explain.ipynb
Vertex Explainable AI,official/explainable_ai/sdk_custom_image_classification_batch_explain.ipynb
Vertex Explainable AI,official/explainable_ai/sdk_custom_image_classification_online_explain.ipynb
Vertex Explainable AI,official/explainable_ai/sdk_custom_tabular_regression_batch_explain.ipynb
Vertex Explainable AI,official/explainable_ai/sdk_custom_tabular_regression_online_explain.ipynb
Vertex AI Experiments,official/experiments/comparing_pipeline_runs.ipynb
Vertex AI Experiments,official/experiments/build_model_experimentation_lineage_with_prebuild_code.ipynb
Vertex AI Experiments,official/experiments/comparing_local_trained_models.ipynb
Vertex AI Feature Store,official/feature_store/sdk-feature-store.ipynb
Matching Engine,official/matching_engine/sdk_matching_engine_for_indexing.ipynb
BigQuery ML and Vertex AI Model Registry,official/model-registry/bqml-vertexai-model-registry.ipynb
Vertex ML Metadata,official/ml_metadata/sdk-metric-parameter-tracking-for-custom-jobs.ipynb
Model Monitoring,official/model_monitoring/model_monitoring.ipynb
Vertex AI Pipelines,official/pipelines/lightweight_functions_component_io_kfp.ipynb
Vertex AI Pipelines,official/pipelines/google_cloud_pipeline_components_automl_images.ipynb
Vertex AI Pipelines,official/pipelines/automl_tabular_classification_beans.ipynb
Vertex AI Pipelines,official/pipelines/google_cloud_pipeline_components_automl_tabular.ipynb
Vertex AI Pipelines,official/pipelines/google_cloud_pipeline_components_automl_text.ipynb
Vertex AI Pipelines,official/pipelines/custom_model_training_and_batch_prediction.ipynb
Vertex AI Pipelines,official/pipelines/google_cloud_pipeline_components_model_train_upload_deploy.ipynb
Vertex AI Pipelines,official/pipelines/control_flow_kfp.ipynb
Vertex AI Pipelines,official/pipelines/metrics_viz_run_compare_kfp.ipynb
Vertex AI Pipelines,official/pipelines/pipelines_intro_kfp.ipynb
Vertex AI Vizier,official/vizier/gapic-vizier-multi-objective-optimization.ipynb
1 tag notebook
2 AutoML official/automl/automl-text-classification.ipynb
3 AutoML official/automl/sdk_automl_tabular_forecasting_batch.ipynb
4 Tabular Data official/automl/automl_forecasting_bqml_arima_plus_comparison.ipynb
5 Tabular Data official/automl/automl_tabular_on_vertex_pipelines.ipynb
6 Custom Training official/custom/sdk-custom-image-classification-batch.ipynb
7 Custom Training official/custom/sdk-custom-image-classification-online.ipynb
8 Vertex Explainable AI official/explainable_ai/sdk_automl_tabular_binary_classification_batch_explain.ipynb
9 Vertex Explainable AI official/explainable_ai/sdk_automl_tabular_classification_online_explain.ipynb
10 Vertex Explainable AI official/explainable_ai/sdk_custom_image_classification_batch_explain.ipynb
11 Vertex Explainable AI official/explainable_ai/sdk_custom_image_classification_online_explain.ipynb
12 Vertex Explainable AI official/explainable_ai/sdk_custom_tabular_regression_batch_explain.ipynb
13 Vertex Explainable AI official/explainable_ai/sdk_custom_tabular_regression_online_explain.ipynb
14 Vertex AI Experiments official/experiments/comparing_pipeline_runs.ipynb
15 Vertex AI Experiments official/experiments/build_model_experimentation_lineage_with_prebuild_code.ipynb
16 Vertex AI Experiments official/experiments/comparing_local_trained_models.ipynb
17 Vertex AI Feature Store official/feature_store/sdk-feature-store.ipynb
18 Matching Engine official/matching_engine/sdk_matching_engine_for_indexing.ipynb
19 BigQuery ML and Vertex AI Model Registry official/model-registry/bqml-vertexai-model-registry.ipynb
20 Vertex ML Metadata official/ml_metadata/sdk-metric-parameter-tracking-for-custom-jobs.ipynb
21 Model Monitoring official/model_monitoring/model_monitoring.ipynb
22 Vertex AI Pipelines official/pipelines/lightweight_functions_component_io_kfp.ipynb
23 Vertex AI Pipelines official/pipelines/google_cloud_pipeline_components_automl_images.ipynb
24 Vertex AI Pipelines official/pipelines/automl_tabular_classification_beans.ipynb
25 Vertex AI Pipelines official/pipelines/google_cloud_pipeline_components_automl_tabular.ipynb
26 Vertex AI Pipelines official/pipelines/google_cloud_pipeline_components_automl_text.ipynb
27 Vertex AI Pipelines official/pipelines/custom_model_training_and_batch_prediction.ipynb
28 Vertex AI Pipelines official/pipelines/google_cloud_pipeline_components_model_train_upload_deploy.ipynb
29 Vertex AI Pipelines official/pipelines/control_flow_kfp.ipynb
30 Vertex AI Pipelines official/pipelines/metrics_viz_run_compare_kfp.ipynb
31 Vertex AI Pipelines official/pipelines/pipelines_intro_kfp.ipynb
32 Vertex AI Vizier official/vizier/gapic-vizier-multi-objective-optimization.ipynb
+19 -5
View File
@@ -134,16 +134,30 @@
"### 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",
"all the requirements to run this notebook. You can skip this step."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "24743cf4a1e1"
},
"source": [
"**_NOTE_**: This notebook has been tested in the following environment:\n",
"\n",
"* Python version = 3.9"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "gCuSR8GkAgzl"
},
"source": [
"**Otherwise**, make sure your environment meets this notebook's requirements.\n",
"You need the following:\n",
"\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 Google Cloud guide to [Setting up a Python development\n",
"environment](https://cloud.google.com/python/setup) and the [Jupyter\n",
+37 -8
View File
@@ -3,16 +3,19 @@ import argparse
import json
import os
import urllib.request
import csv
parser = argparse.ArgumentParser()
parser.add_argument('--notebook-dir', dest='notebook_dir',
default=None, type=str, help='Notebook directory')
parser.add_argument('--notebook', dest='notebook',
default=None, type=str, help='Notebook to review')
parser.add_argument('--errors', dest='errors',
default=False, type=bool, help='Report errors')
parser.add_argument('--errors-csv', dest='errors_csv',
default=False, type=bool, help='Report errors as CSV')
parser.add_argument('--notebook-file', dest='notebook_file',
default=None, type=str, help='File with list of notebooks to review')
parser.add_argument('--errors', dest='errors', action='store_true',
default=False, help='Report errors')
parser.add_argument('--errors-csv', dest='errors_csv', action='store_true',
default=False, help='Report errors as CSV')
parser.add_argument('--errors-codes', dest='errors_codes',
default=None, type=str, help='Report only specified errors')
parser.add_argument('--desc', dest='desc',
@@ -67,9 +70,14 @@ def parse_notebook(path):
# cell 2 is title and links
if not cell['source'][0].startswith('# '):
report_error(path, 1, "title cell must start with H1 heading")
title = ''
else:
title = cell['source'][0][2:].strip()
check_sentence_case(path, title)
# H1 title only
if len(cell['source']) == 1:
cell, nth = get_cell(path, cells, nth)
# check links.
source = ''
@@ -287,7 +295,10 @@ def check_text_cell(path, cell):
'Vertex Private Endpoint': 'Vertex AI Private Endpoint',
'Tensorflow': 'TensorFlow',
'Tensorboard': 'TensorBoard',
'Google Cloud Notebooks': 'Vertex AI Workbench Notebooks'
'Google Cloud Notebooks': 'Vertex AI Workbench Notebooks',
'Bigquery': 'BigQuery',
'Pytorch': 'PyTorch',
'Sklearn': 'scikit-learn'
}
for line in cell['source']:
@@ -311,7 +322,7 @@ def check_sentence_case(path, heading):
for word in words[1:]:
word = word.replace(':', '').replace('(', '').replace(')', '')
if word in ['E2E', 'Vertex', 'AutoML', 'ML', 'AI', 'GCP', 'API', 'R', 'CMEK', 'TFX', 'TFDV', 'SDK',
'VM', 'CPR', 'NVIDIA', 'ID', 'DASK']:
'VM', 'CPR', 'NVIDIA', 'ID', 'DASK', 'ARIMA_PLUS', 'KFP', 'I/O']:
continue
if word.isupper():
report_error(path, 3, f"heading is not sentence case: {word}")
@@ -417,6 +428,24 @@ elif args.notebook:
print("Error: not a notebook:", args.notebook)
exit(1)
parse_notebook(args.notebook)
elif args.notebook_file:
if not os.path.isfile(args.notebook_file):
print("Error: file does not exist", args.notebook_file)
else:
with open(args.notebook_file, 'r') as csvfile:
reader = csv.reader(csvfile)
heading = True
for row in reader:
if heading:
heading = False
else:
tag = row[0]
notebook = row[1]
parse_notebook(notebook)
else:
print("Error: must specify a directory or notebook")
exit(1)
print("Error: must specify a directory or notebook")
exit(1)
@@ -52,7 +52,7 @@
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://raw.githubusercontent.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/automl/automl-text-classification.ipynb\">\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/automl/automl-text-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",
@@ -714,8 +714,7 @@
"deployed_model_display_name = f\"e2e-deployed-text-classification-model-{TIMESTAMP}\"\n",
"\n",
"endpoint = model.deploy(\n",
" deployed_model_display_name=deployed_model_display_name, \n",
" sync=True\n",
" deployed_model_display_name=deployed_model_display_name, sync=True\n",
")"
]
},
@@ -29,16 +29,16 @@
"id": "title"
},
"source": [
"# Compare Vertex Forecasting and BQML ARIMA_PLUS\n",
"# Compare Vertex AI Forecasting and BigQuery ML ARIMA_PLUS\n",
"\n",
"<table align=\"left\">\n",
" <td>\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/master/notebooks/official/automl/automl_forecasting_bqml_arima_plus_comparison.ipynb\">\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/automl/automl_forecasting_bqml_arima_plus_comparison.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/vertex-ai-samples/blob/master/notebooks/official/automl/automl_forecasting_bqml_arima_plus_comparison.ipynb\">\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/automl/automl_forecasting_bqml_arima_plus_comparison.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",
@@ -61,18 +61,7 @@
"source": [
"## Overview\n",
"\n",
"In this tutorial, you will take on the role of a store planner who must determine how much inventory they will need to order for each of their products and stores for November 2019. You will accomplish this by training forecasting models using historical sales data. You will start with a baseline model using [BQML ARIMA_PLUS](https://cloud.google.com/bigquery-ml/docs/reference/standard-sql/bigqueryml-syntax-create-time-series) and then compare it against a [Vertex Forecasting](https://cloud.google.com/vertex-ai/docs/tabular-data/forecasting/overview) model."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dataset:covid,forecast"
},
"source": [
"### Dataset\n",
"\n",
"To demonstrate the tradeoffs between using BQML and Vertex Forecasting, this tutorial will use a synthetic dataset where product sales are dependent on a variety of factors such as advertisements, holidays, and locations. You will see how well a univariate model like ARIMA_PLUS can forecast future sales without knowing information about these factors explicitly, and how well a multivariate model like Vertex Forecasting can perform when these factors are known."
"In this tutorial, you take on the role of a store planner who must determine how much inventory they will need to order for each of their products and stores for November 2019. You will accomplish this by training forecasting models using historical sales data. You will start with a baseline model using BigQuery ML (BQML) [ARIMA_PLUS](https://cloud.google.com/bigquery-ml/docs/reference/standard-sql/bigqueryml-syntax-create-time-series) and then compare it against a [Vertex AI Forecasting](https://cloud.google.com/vertex-ai/docs/tabular-data/forecasting/overview) model."
]
},
{
@@ -83,19 +72,30 @@
"source": [
"### Objective\n",
"\n",
"In this tutorial, you create an BQML ARIMA_PLUS model using a training [Vertex Pipeline](https://cloud.google.com/vertex-ai/docs/pipelines/introduction) from [Google Cloud Pipeline Components](https://cloud.google.com/vertex-ai/docs/pipelines/components-introduction) (GCPC), and then do a batch prediction using the corresponding prediction pipeline. You then train a Vertex Forecasting model using the same data and compare the evaluation metrics.\n",
"In this tutorial, you create an BQML ARIMA_PLUS model using a training [Vertex AI Pipeline](https://cloud.google.com/vertex-ai/docs/pipelines/introduction) from [Google Cloud Pipeline Components](https://cloud.google.com/vertex-ai/docs/pipelines/components-introduction) (GCPC), and then do a batch prediction using the corresponding prediction pipeline. You then train a Vertex AI Forecasting model using the same data and compare the evaluation metrics.\n",
"\n",
"The steps performed are:\n",
"\n",
"- Train the BQML ARIMA_PLUS model.\n",
"- View BQML model evaluation.\n",
"- Make a batch prediction with the BQML model.\n",
"- Create a Vertex `Dataset` resource.\n",
"- Train the Vertex Forecasting model.\n",
"- Create a Vertex AI `Dataset` resource.\n",
"- Train the Vertex AI Forecasting model.\n",
"- View the Model evaluation.\n",
"- Make a batch prediction with the Model.\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dataset:covid,forecast"
},
"source": [
"### Dataset\n",
"\n",
"To demonstrate the tradeoffs between using BQML and Vertex AI Forecasting, this tutorial will use a synthetic dataset where product sales are dependent on a variety of factors such as advertisements, holidays, and locations. You will see how well a univariate model like ARIMA_PLUS can forecast future sales without knowing information about these factors explicitly, and how well a multivariate model like Vertex AI Forecasting can perform when these factors are known."
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -155,9 +155,9 @@
"id": "install_aip:mbsdk"
},
"source": [
"## Install additional packages\n",
"## Installation\n",
"\n",
"Install the latest version of the Google Cloud Pipeline Components (GCPC) SDK."
"Install the following packages required to execute this notebook."
]
},
{
@@ -170,8 +170,14 @@
"source": [
"import os\n",
"\n",
"# Google Cloud Notebook\n",
"if os.path.exists(\"/opt/deeplearning/metadata/env_version\"):\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",
"# Vertex AI Notebook requires dependencies to be installed with '--user'\n",
"if IS_WORKBENCH_NOTEBOOK:\n",
" USER_FLAG = \"--user\"\n",
"else:\n",
" USER_FLAG = \"\"\n",
@@ -179,7 +185,7 @@
"! (pip3 install --upgrade $USER_FLAG \\\n",
" google-cloud-bigquery[pandas]==2.34.4 \\\n",
" google-cloud-aiplatform==1.16.1 \\\n",
" google-cloud-pipeline-components==1.0.18)"
" google-cloud-pipeline-components==1.0.23)"
]
},
{
@@ -240,7 +246,7 @@
"5. 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",
"6. (optional) You may also specify a service account to use to run Vertex Pipelines in the project.\n",
"6. (optional) You may also specify a service account to use to run Vertex AI Pipelines in the project.\n",
"\n",
"**Note**: Jupyter runs lines prefixed with `!` as shell commands, and it interpolates Python variables prefixed with `$`."
]
@@ -304,7 +310,7 @@
"#### Region\n",
"All BigQuery operations (`DATA_REGION`) are set to run in the `US` multi-region. This is required by the ARIMA pipeline because the data you will be using is stored in this region. All destination tables will also be stored in this region.\n",
"\n",
"You may change the `REGION` variable, which is used for Vertex Forecasting operations\n",
"You may change the `REGION` variable, which is used for Vertex AI Forecasting 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",
"\n",
"- Americas: `us-central1`\n",
@@ -324,8 +330,11 @@
},
"outputs": [],
"source": [
"REGION = \"[your-region]\" # @param {type: \"string\"}\n",
"DATA_REGION = \"US\" # @param {type: \"string\"}\n",
"REGION = \"[your-region]\" # @param {type: \"string\"}"
"\n",
"if REGION == \"[your-region]\":\n",
" REGION = \"us-central1\""
]
},
{
@@ -334,9 +343,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."
]
},
{
@@ -347,9 +356,16 @@
},
"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()"
]
},
{
@@ -360,7 +376,7 @@
"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 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",
@@ -395,8 +411,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",
@@ -404,10 +423,9 @@
"\n",
" # If you are running this notebook locally, replace the string below with the\n",
" # path to your service account key and run this cell to authenticate your GCP\n",
" # account. Alternatively, you may edit this notebook to authenticate using\n",
" # gcloud.\n",
" # account.\n",
" elif not os.getenv(\"IS_TESTING\"):\n",
" %env GOOGLE_APPLICATION_CREDENTIALS ''"
" %env GOOGLE_APPLICATION_CREDENTIALS '[your-service-account-key-path]'"
]
},
{
@@ -420,7 +438,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."
]
@@ -454,9 +472,9 @@
"outputs": [],
"source": [
"if BUCKET_URI == \"\" or BUCKET_URI is None or BUCKET_URI == \"gs://[your-bucket-name]\":\n",
" BUCKET_URI = \"gs://\" + PROJECT_ID + \"aip-\" + TIMESTAMP\n",
" BUCKET_URI = \"gs://\" + PROJECT_ID + \"aip-\" + UUID\n",
"\n",
"! gsutil ls -b $BUCKET_URI || gsutil mb -l $DATA_REGION $BUCKET_URI"
"! gsutil ls -b $BUCKET_URI || gsutil mb -l $REGION $BUCKET_URI"
]
},
{
@@ -514,9 +532,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."
]
},
{
@@ -558,8 +576,8 @@
},
"outputs": [],
"source": [
"arima_dataset_name = f\"forecasting_demo_arima_{TIMESTAMP}\"\n",
"vertex_dataset_name = f\"forecasting_demo_vertex_{TIMESTAMP}\"\n",
"arima_dataset_name = f\"forecasting_demo_arima_{UUID}\"\n",
"vertex_dataset_name = f\"forecasting_demo_vertex_{UUID}\"\n",
"\n",
"arima_dataset_path = \".\".join([PROJECT_ID, arima_dataset_name])\n",
"vertex_dataset_path = \".\".join([PROJECT_ID, vertex_dataset_name])\n",
@@ -792,15 +810,15 @@
"\n",
"Now you are ready to start creating your own BQML ARIMA_PLUS model.\n",
"\n",
"Like with Vertex Forecasting, the pipeline you will run will train evaluation models using the training and validation sets and use backtesting to create evaluation metrics on the test set. Finally, a serving model will be produced that uses all available data.\n",
"Like with Vertex AI Forecasting, the pipeline you will run will train evaluation models using the training and validation sets and use backtesting to create evaluation metrics on the test set. Finally, a serving model will be produced that uses all available data.\n",
"\n",
"**How do you estimate the cost?**\n",
"\n",
"Backtesting will involve training a single BQML model for each period in the test set, so the cost will be a function of the length of the test set. The cost is also multiplied by the number of candidate models trained, which is determined by `max_order`.\n",
"Backtesting involves training a single BQML model for each period in the test set, so the cost is a function of the length of the test set after any downsampling done by the windowing strategy. The cost is also multiplied by the number of candidate models trained, which is determined by `max_order`.\n",
"\n",
"According to [BQ pricing](https://cloud.google.com/bigquery-ml/pricing), BQML model creation costs $250 per TB. We'll use a max order of 3, which translates to 20 candidate models when there are multiple time series. Our demo dataset is 3 MB in size, and includes 31 test periods.\n",
"According to [BQ pricing](https://cloud.google.com/bigquery-ml/pricing), BQML model creation costs $250 per TB. We'll use a max order of 3, which translates to 20 candidate models when there are multiple time series. Our demo dataset is 3 MB in size, and includes 31 test periods. We window with a stride length of 1, so all periods are used for evaluation.\n",
"\n",
"In this tutorial, the model create stage of the pipeline costs `3 MB * ($250 / 1024^2) * 31 periods * 20 candidates = $0.44`."
"In this tutorial, the model create stage of the pipeline costs `3 MB * ($250 / 1024^2) * (31 / 1) periods * 20 candidates = $0.44`."
]
},
{
@@ -821,47 +839,23 @@
"\n",
"- `bigquery_destination_uri`: (optional) BigQuery Dataset URI. Used to export the metrics table and model. If not given, we will create one for the user.\n",
"- `data_granularity_unit`: Enum used to specify the time granularity (hour, day, week, month, etc).\n",
"- `data_source`: JSON for specifying the input data source URI and type. Similar to a Vertex Dataset. Currently supports BigQuery and CSV (in GCS) data sources.\n",
"\n",
" It can look like either:\n",
" ```json\n",
" {\n",
" \"big_query_data_source\": {\n",
" \"big_query_table_path\": \"bq://[PROJECT].[DATASET].[TABLE]\"\n",
" }\n",
" }\n",
" ```\n",
" or\n",
" ```json\n",
" {\n",
" \"csv_data_source\": {\n",
" \"csv_filenames\": [ [GCS_PATHS] ],\n",
" }\n",
" ```\n",
"- `data_source_csv_filenames` or `data_source_bigquery_table_path`: A URI for either a CSV stored in GCR or a BigQuery table, respectively.\n",
"- `evaluated_examples_destination_uri\t`: (optional) BigQuery Dataset URI OR Table URI. Used to export the evaluated examples table. Will use bigquery_destination_uri if not provided.\n",
"- `forecast_horizon`: Integer number of periods to predict.\n",
"- `split_spec`: JSON for specifying how data should be split. Supports predefined split and fractional split.\n",
" \n",
" It can look like either:\n",
" ```json\n",
" {\"predefined_split\": {\"key\": \"[SPLIT_COLUMN]\"}}\n",
" ```\n",
" or\n",
" ```json\n",
" {\n",
" \"fraction_split\": {\n",
" \"training_fraction\": 0.8,\n",
" \"validation_fraction\": 0.1,\n",
" \"test_fraction\": 0.1,\n",
" },\n",
" }\n",
" ```\n",
"- `target_column_name`: Name of target column.\n",
"- A data splitting strategy of either:\n",
" - `predefined_split_key`: A column containing `TRAIN`, `VALIDATE`, or `TEST` to denote the splits for each row.\n",
" - `training_fraction`, `validation_fraction`, and `test_fraction` to set the fractions to split on chronologically on the time column.\n",
" - `timestamp_split_key` plus the fractions in the previous option to perform fractional splitting on a column other than the time column.\n",
"- A windowing strategy of either:\n",
" - `window_column`: A boolean column decides whether or now each row gets considered when calculating the evaluation metrics.\n",
" - `window_stride_length`: Every N rows will be used to compute the evaluation metrics.\n",
" - `window_max_count`: Downsample rows such that only the given number are used to calculate the evaluation metrics.\n",
"- `target_column`: Name of target column.\n",
"- `time_column`: Name of time column.\n",
"- `time_series_identifier_column`: Name of id column.\n",
"- `max_order`: Integer between 1 and 5 representing the size of the parameter search space for ARIMA_PLUS. 5 would result in the highest accuracy model, but also the longest training runtime/cost.\n",
"\n",
"The execution of the training pipeline will take around **20 minutes**."
"The execution of the training pipeline may take around **20 minutes**."
]
},
{
@@ -878,31 +872,24 @@
"forecast_horizon = 30 # @param {type: \"integer\"}\n",
"data_granularity_unit = \"day\" # @param {type: \"string\"}\n",
"split_column = \"split\" # @param {type: \"string\"}\n",
"window_stride_length = 1 # @param {type: \"integer\"}\n",
"max_order = 3 # @param {type: \"integer\"}\n",
"override_destination = True # @param {type: \"boolean\"}\n",
"\n",
"split_spec = {\"predefined_split\": {\"key\": split_column}}\n",
"data_source = {\n",
" \"big_query_data_source\": {\n",
" \"big_query_table_path\": TRAINING_DATASET_BQ_PATH,\n",
" },\n",
"}\n",
"window_config = {\"stride\": 1}\n",
"\n",
"(\n",
" train_job_spec_path,\n",
" train_parameter_values,\n",
") = utils.get_bqml_arima_train_pipeline_and_parameters(\n",
" project=PROJECT_ID,\n",
" location=DATA_REGION,\n",
" location=REGION,\n",
" time_column=time_column,\n",
" time_series_identifier_column=time_series_identifier_column,\n",
" target_column_name=target_column,\n",
" target_column=target_column,\n",
" forecast_horizon=forecast_horizon,\n",
" data_granularity_unit=data_granularity_unit,\n",
" split_spec=split_spec,\n",
" data_source=data_source,\n",
" window_config=window_config,\n",
" predefined_split_key=split_column,\n",
" data_source_bigquery_table_path=TRAINING_DATASET_BQ_PATH,\n",
" window_stride_length=window_stride_length,\n",
" bigquery_destination_uri=arima_dataset_path,\n",
" override_destination=override_destination,\n",
" max_order=max_order,\n",
@@ -917,9 +904,9 @@
"source": [
"### Run the training pipeline\n",
"\n",
"Use the Vertex Python SDK to kick off a training pipeline run. Once the run has started, the following cell will output a link that will allow you to monitor the run. The link should look like this: \n",
"Use the Vertex AI Python SDK to kick off a training pipeline run. Once the run has started, the following cell will output a link that will allow you to monitor the run. The link should look like this: \n",
"\n",
"`https://console.cloud.google.com/vertex-ai/locations/[DATA_REGION]/pipelines/runs/[DISPLAY_NAME]`"
"`https://console.cloud.google.com/vertex-ai/locations/[REGION]/pipelines/runs/[DISPLAY_NAME]`"
]
},
{
@@ -931,8 +918,7 @@
"outputs": [],
"source": [
"# The display name should be unique even if this cell is rerun.\n",
"now = datetime.now().strftime(\"%Y%m%d%H%M%S\")\n",
"DISPLAY_NAME = f\"forecasting-demo-train-{now}\"\n",
"DISPLAY_NAME = f\"forecasting-demo-train-{generate_uuid()}\"\n",
"\n",
"job = aiplatform.PipelineJob(\n",
" job_id=DISPLAY_NAME,\n",
@@ -1003,27 +989,11 @@
"Now that your Model resource is trained, you can make a batch prediction using the prediction pipeline, with the following parameters:\n",
"\n",
"- `bigquery_destination_uri`: (optional) BigQuery Dataset URI. Used to export the metrics table and model. If not given, we will create one for the user.\n",
"- `data_source`: JSON for specifying the input data source URI and type. Similar to a Vertex Dataset. Currently supports BigQuery and CSV (in GCS) data sources.\n",
"\n",
" It can look like either:\n",
" ```json\n",
" {\n",
" \"big_query_data_source\": {\n",
" \"big_query_table_path\": \"bq://[PROJECT].[DATASET].[TABLE]\"\n",
" }\n",
" }\n",
" ```\n",
" or\n",
" ```json\n",
" {\n",
" \"csv_data_source\": {\n",
" \"csv_filenames\": [ [GCS_PATHS] ],\n",
" }\n",
" ```\n",
"- `data_source_csv_filenames` or `data_source_bigquery_table_path`: A URI for either a CSV stored in GCR or a BigQuery table, respectively.\n",
"- `generate_explanation`: If True, the predictions table will have some extra xAI columns.\n",
"- `model_name`: Name of an existing BQML ARIMA_PLUS model to use for predictions.\n",
"\n",
"The execution of the prediction pipeline will take around **5 minutes**."
"The execution of the prediction pipeline may take around **5 minutes**."
]
},
{
@@ -1034,14 +1004,8 @@
},
"outputs": [],
"source": [
"data_source = {\n",
" \"big_query_data_source\": {\n",
" \"big_query_table_path\": PREDICTION_DATASET_BQ_PATH,\n",
" },\n",
"}\n",
"\n",
"# Get the model name programmatically, you can also find this by looking at the\n",
"# execution graph in Vertex Pipelines.\n",
"# execution graph in Vertex AI Pipelines.\n",
"for task_detail in job.gca_resource.job_detail.task_details:\n",
" if task_detail.task_name == \"bigquery-create-model-job\":\n",
" model_name = task_detail.outputs[\"model\"].artifacts[0].metadata[\"modelId\"]\n",
@@ -1055,9 +1019,9 @@
" predict_parameter_values,\n",
") = utils.get_bqml_arima_predict_pipeline_and_parameters(\n",
" project=PROJECT_ID,\n",
" location=DATA_REGION,\n",
" location=REGION,\n",
" model_name=f\"{arima_dataset_path}.{model_name}\",\n",
" data_source=data_source,\n",
" data_source_bigquery_table_path=PREDICTION_DATASET_BQ_PATH,\n",
" bigquery_destination_uri=arima_dataset_path,\n",
")"
]
@@ -1070,9 +1034,9 @@
"source": [
"### Run the prediction pipeline\n",
"\n",
"Use the Vertex Python SDK to kick off a prediction pipeline run. Once the run has started, the following cell will output a link that will allow you to monitor the run. The link should look like this: \n",
"Use the Vertex AI Python SDK to kick off a prediction pipeline run. Once the run has started, the following cell will output a link that will allow you to monitor the run. The link should look like this: \n",
"\n",
"`https://console.cloud.google.com/vertex-ai/locations/[DATA_REGION]/pipelines/runs/[DISPLAY_NAME]`"
"`https://console.cloud.google.com/vertex-ai/locations/[REGION]/pipelines/runs/[DISPLAY_NAME]`"
]
},
{
@@ -1084,8 +1048,7 @@
"outputs": [],
"source": [
"# The display name should be unique even if this cell is rerun.\n",
"now = datetime.now().strftime(\"%Y%m%d%H%M%S\")\n",
"DISPLAY_NAME = f\"forecasting-demo-predict-{now}\"\n",
"DISPLAY_NAME = f\"forecasting-demo-predict-{generate_uuid()}\"\n",
"\n",
"job = aiplatform.PipelineJob(\n",
" job_id=DISPLAY_NAME,\n",
@@ -1117,7 +1080,7 @@
"outputs": [],
"source": [
"# Get the prediction table programmatically, you can also find this by looking at the\n",
"# execution graph in Vertex Pipelines.\n",
"# execution graph in Vertex AI Pipelines.\n",
"for task_detail in job.gca_resource.job_detail.task_details:\n",
" if task_detail.task_name == \"bigquery-query-job\":\n",
" pred_table = (\n",
@@ -1242,7 +1205,7 @@
"id": "59qKXL9ARO97"
},
"source": [
"# Compare Against Vertex Forecasting"
"# Compare Against Vertex AI Forecasting"
]
},
{
@@ -1271,7 +1234,7 @@
"outputs": [],
"source": [
"dataset = aiplatform.TimeSeriesDataset.create(\n",
" display_name=\"forecasting_demo_train\" + \"_\" + TIMESTAMP,\n",
" display_name=\"forecasting_demo_train\" + \"_\" + UUID,\n",
" bq_source=[TRAINING_DATASET_BQ_PATH],\n",
")\n",
"print(dataset.resource_name)"
@@ -1317,11 +1280,12 @@
" \"product\": \"categorical\",\n",
" \"holiday\": \"categorical\",\n",
"}\n",
"available_at_forecast_columns = [\n",
"available_at_forecast_columns_ = [\n",
" \"date\",\n",
" \"advertisement\",\n",
" \"holiday\",\n",
"] # @param {type: \"raw\"}\n",
"]\n",
"available_at_forecast_columns = available_at_forecast_columns_ # @param {type: \"raw\"}\n",
"unavailable_at_forecast_columns = [\"sales\"] # @param {type: \"raw\"}\n",
"time_series_attribute_columns = [\"store\", \"product\"] # @param {type: \"raw\"}\n",
"context_window = 30 # @param {type: \"integer\"}\n",
@@ -1337,7 +1301,7 @@
},
"outputs": [],
"source": [
"MODEL_DISPLAY_NAME = f\"forecasting-demo-model_{TIMESTAMP}\"\n",
"MODEL_DISPLAY_NAME = f\"forecasting-demo-model_{UUID}\"\n",
"\n",
"training_job = aiplatform.AutoMLForecastingTrainingJob(\n",
" display_name=MODEL_DISPLAY_NAME,\n",
@@ -1373,7 +1337,7 @@
"\n",
"The `run` method, when completed, returns the `Model` resource.\n",
"\n",
"The execution of the training pipeline will take up to **one hour**. You can learn about the pricing for Vertex Forecasting [here](https://cloud.google.com/vertex-ai/pricing#tabular-data)."
"The execution of the training pipeline may take up to **one hour**. You can learn about the pricing for Vertex AI Forecasting [here](https://cloud.google.com/vertex-ai/pricing#tabular-data)."
]
},
{
@@ -1400,6 +1364,7 @@
" budget_milli_node_hours=budget_milli_node_hours,\n",
" model_display_name=MODEL_DISPLAY_NAME,\n",
" predefined_split_column_name=split_column,\n",
" window_stride_length=window_stride_length,\n",
")"
]
},
@@ -1456,7 +1421,7 @@
"\n",
"Now that you have backtesting metrics from both models, you can compare the two side-by-side.\n",
"\n",
"Since the sales in this dataset were a function of covariates, we should expect the MAE, RMSE, and MAPE to be lower when using Vertex Forecasting. The BQML ARIMA_PLUS evaluation metrics show the relative impact of including these additional features in a model."
"Since the sales in this dataset were a function of covariates, we should expect the MAE, RMSE, and MAPE to be lower when using Vertex AI Forecasting. The BQML ARIMA_PLUS evaluation metrics show the relative impact of including these additional features in a model."
]
},
{
@@ -1478,7 +1443,7 @@
"source": [
"## Send a batch prediction request\n",
"\n",
"The following section shows how you can send a batch prediction to your Vertex Forecasting model in case you want to compare the models at serving time."
"The following section shows how you can send a batch prediction to your Vertex AI Forecasting model in case you want to compare the models at serving time."
]
},
{
@@ -1510,7 +1475,7 @@
"outputs": [],
"source": [
"batch_prediction_job = model.batch_predict(\n",
" job_display_name=f\"forecasting_demo_predictions_{TIMESTAMP}\",\n",
" job_display_name=f\"forecasting_demo_predictions_{UUID}\",\n",
" bigquery_source=PREDICTION_DATASET_BQ_PATH,\n",
" instances_format=\"bigquery\",\n",
" bigquery_destination_prefix=f\"bq://{vertex_dataset_path}\",\n",
@@ -1531,7 +1496,7 @@
"\n",
"Next, wait for the batch job to complete. Alternatively, you can set the parameter `sync` to `True` in the `batch_predict()` method to block until the batch prediction job is completed.\n",
"\n",
"The execution of the prediction pipeline will take up to 30 minutes.\n"
"The execution of the prediction pipeline may take up to 30 minutes.\n"
]
},
{
@@ -1598,7 +1563,7 @@
},
"outputs": [],
"source": [
"print(\"Click the link below to view Vertex Forecasting predictions:\")\n",
"print(\"Click the link below to view Vertex AI Forecasting predictions:\")\n",
"print(\n",
" get_data_studio_link(\n",
" batch_prediction_bq_input_uri=actuals_table,\n",
@@ -1616,7 +1581,7 @@
"id": "cleanup:mbsdk"
},
"source": [
"## Clean up Vertex and BigQuery resources\n",
"## Clean up Vertex AI and BigQuery resources\n",
"\n",
"To clean up all Google Cloud resources used in this project, you can [delete the Google Cloud\n",
"project](https://cloud.google.com/resource-manager/docs/creating-managing-projects#shutting_down_projects) you used for the tutorial.\n",
@@ -68,18 +68,7 @@
{
"cell_type": "markdown",
"metadata": {
"id": "dataset:covid,forecast"
},
"source": [
"### Dataset\n",
"\n",
"The dataset used for this tutorial a time series dataset containing samples drawn from the Iowa Liquor Retail Sales dataset. Data were made available by the Iowa Department of Commerce. It is provided under the Creative Commons Zero v1.0 Universal license. For more details, see: https://console.cloud.google.com/marketplace/product/iowa-department-of-commerce/iowa-liquor-sales. This dataset does not require any feature engineering. The version of the dataset you will use in this tutorial is stored in BigQuery."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "objective:automl,training,batch_prediction"
"id": "02b9af111927"
},
"source": [
"### Objective\n",
@@ -97,7 +86,18 @@
"- Create a `Vertex AI Dataset` resource.\n",
"- Train an `AutoML` tabular forecasting `Model` resource.\n",
"- Obtain the evaluation metrics for the `Model` resource.\n",
"- Make a batch prediction.\n"
"- Make a batch prediction."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dataset:covid,forecast"
},
"source": [
"### Dataset\n",
"\n",
"The dataset used for this tutorial is a time series dataset containing samples drawn from the Iowa Liquor Retail Sales dataset. Data is made available by the Iowa Department of Commerce. It is provided under the Creative Commons Zero v1.0 Universal license. For more details, see: https://console.cloud.google.com/marketplace/product/iowa-department-of-commerce/iowa-liquor-sales. This dataset does not require any feature engineering. The version of the dataset you use in this tutorial is stored in BigQuery."
]
},
{
@@ -128,29 +128,38 @@
"source": [
"### Set up your local development environment\n",
"\n",
"If you are using Colab or Workbench AI 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."
]
},
{
@@ -161,7 +170,7 @@
"source": [
"## Installation\n",
"\n",
"Install the latest version of Vertex AI SDK for Python."
"Install the following packages required to execute this notebook. "
]
},
{
@@ -175,7 +184,7 @@
"import os\n",
"\n",
"# The Vertex AI Workbench Notebook product has specific requirements\n",
"IS_WORKBENCH_NOTEBOOK = os.getenv(\"DL_ANACONDA_HOME\") and not os.getenv(\"VIRTUAL_ENV\")\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",
@@ -185,8 +194,7 @@
"if IS_WORKBENCH_NOTEBOOK:\n",
" USER_FLAG = \"--user\"\n",
"\n",
"! pip3 install --upgrade google-cloud-aiplatform $USER_FLAG -q\n",
"! pip3 install --upgrade tensorflow $USER_FLAG -q"
"! pip3 install --upgrade google-cloud-aiplatform $USER_FLAG -q"
]
},
{
@@ -197,7 +205,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."
]
},
{
@@ -208,6 +216,7 @@
},
"outputs": [],
"source": [
"# Automatically restart kernel after installs\n",
"import os\n",
"\n",
"if not os.getenv(\"IS_TESTING\"):\n",
@@ -218,34 +227,48 @@
" app.kernel.do_shutdown(True)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "0e3cab0cc491"
},
"source": [
"## Before you begin"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "before_you_begin:nogpu"
},
"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`."
]
},
{
@@ -294,7 +317,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",
@@ -302,7 +325,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)."
]
},
{
@@ -325,9 +348,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."
]
},
{
@@ -338,9 +361,16 @@
},
"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()"
]
},
{
@@ -351,23 +381,31 @@
"source": [
"### Authenticate your Google Cloud account\n",
"\n",
"**If you are using Workbench AI Notebooks**, your environment is already authenticated. Skip this step.\n",
"**If you are using Vertex AI Workbench Notebooks**, your environment is already\n",
"authenticated. Skip this step.\n",
"\n",
"**If you are using Colab**, run the cell below and follow the instructions when prompted to authenticate your account via oAuth.\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.\n"
]
},
{
@@ -438,9 +476,9 @@
},
"outputs": [],
"source": [
"if BUCKET_URI == \"\" or BUCKET_URI is None or BUCKET_URI == \"gs://[your-bucket-name]\":\n",
" BUCKET_NAME = PROJECT_ID + \"aip-\" + TIMESTAMP\n",
" BUCKET_URI = \"gs://\" + BUCKET_NAME"
"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}\""
]
},
{
@@ -460,7 +498,7 @@
},
"outputs": [],
"source": [
"! gsutil mb -l $REGION $BUCKET_URI"
"! gsutil mb -l $REGION -p $PROJECT_ID $BUCKET_URI"
]
},
{
@@ -489,9 +527,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"
]
},
@@ -503,7 +538,10 @@
},
"outputs": [],
"source": [
"import google.cloud.aiplatform as aiplatform"
"import urllib\n",
"\n",
"import google.cloud.aiplatform as aiplatform\n",
"from google.cloud import bigquery"
]
},
{
@@ -589,7 +627,7 @@
"outputs": [],
"source": [
"dataset = aiplatform.TimeSeriesDataset.create(\n",
" display_name=\"iowa_liquor_sales_train\" + \"_\" + TIMESTAMP,\n",
" display_name=\"iowa_liquor_sales_train\" + \"_\" + UUID,\n",
" bq_source=[TRAINING_DATASET_BQ_PATH],\n",
")\n",
"\n",
@@ -649,7 +687,7 @@
},
"outputs": [],
"source": [
"MODEL_DISPLAY_NAME = f\"iowa-liquor-sales-forecast-model_{TIMESTAMP}\"\n",
"MODEL_DISPLAY_NAME = f\"iowa-liquor-sales-forecast-model_{UUID}\"\n",
"\n",
"training_job = aiplatform.AutoMLForecastingTrainingJob(\n",
" display_name=MODEL_DISPLAY_NAME,\n",
@@ -772,11 +810,7 @@
},
"outputs": [],
"source": [
"import os\n",
"\n",
"from google.cloud import bigquery\n",
"\n",
"batch_predict_bq_output_dataset_name = f\"iowa_liquor_sales_predictions_{TIMESTAMP}\"\n",
"batch_predict_bq_output_dataset_name = f\"iowa_liquor_sales_predictions_{UUID}\"\n",
"batch_predict_bq_output_dataset_path = \"{}.{}\".format(\n",
" PROJECT_ID, batch_predict_bq_output_dataset_name\n",
")\n",
@@ -820,7 +854,7 @@
")\n",
"\n",
"batch_prediction_job = model.batch_predict(\n",
" job_display_name=f\"iowa_liquor_sales_forecasting_predictions_{TIMESTAMP}\",\n",
" job_display_name=f\"iowa_liquor_sales_forecasting_predictions_{UUID}\",\n",
" bigquery_source=PREDICTION_DATASET_BQ_PATH,\n",
" instances_format=\"bigquery\",\n",
" bigquery_destination_prefix=batch_predict_bq_output_uri_prefix,\n",
@@ -901,8 +935,6 @@
},
"outputs": [],
"source": [
"import urllib\n",
"\n",
"tables = client.list_tables(batch_predict_bq_output_dataset_path)\n",
"\n",
"prediction_table_id = \"\"\n",
@@ -1012,9 +1044,6 @@
},
"outputs": [],
"source": [
"# Set this to true only if you'd like to delete your bucket\n",
"delete_bucket = False\n",
"\n",
"# Delete dataset\n",
"dataset.delete()\n",
"\n",
@@ -1027,6 +1056,9 @@
"# Delete batch prediction job\n",
"batch_prediction_job.delete()\n",
"\n",
"# Set this to true only if you'd like to delete your bucket\n",
"delete_bucket = False\n",
"\n",
"if delete_bucket or os.getenv(\"IS_TESTING\"):\n",
" ! gsutil rm -r $BUCKET_URI"
]
@@ -29,12 +29,23 @@
"id": "JAPoU8Sm5E6e"
},
"source": [
"# Deploying Iris-detection model using FastAPI and Vertex AI custom container serving\n",
"\n",
"<table align=\"left\">\n",
" <td>\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/master/notebooks/community/sdk/SDK_Custom_Container_Prediction.ipynb\">\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/custom/SDK_Custom_Container_Prediction.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/vertex-ai-samples/blob/main/notebooks/official/custom/SDK_Custom_Container_Prediction.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",
" <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/custom/SDK_Custom_Container_Prediction.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>"
]
@@ -47,38 +58,67 @@
"source": [
"## Overview\n",
"\n",
"This tutorial walks through building a custom container to serve a scikit-learn model on Vertex Predictions. You will use the FastAPI Python web server framework to create a prediction and health endpoint.\n",
"You will also cover incorporating a pre-processor from training into your online serving.\n",
"This tutorial walks you through building a custom container to serve a scikit-learn model on Vertex AI. You use the FastAPI Python web server framework to create a prediction and health endpoint. You also incorporate a pre-processor from training pipeline into your online serving application."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "cbd99f7bfc8e"
},
"source": [
"### Objective\n",
"\n",
"The objective of this notebook is to create, deploy and serve a custom classification model on Vertex AI. This notebook focuses more on deploying the model than on the design of the model itself. \n",
"\n",
"\n",
"This tutorial uses the following Google Cloud ML services and resources:\n",
"\n",
"- Vertex AI Models\n",
"- Vertex AI Endpoints\n",
"\n",
"The steps performed include:\n",
"\n",
"- Train a model that uses flower's measurements as input to predict the class of iris.\n",
"- Save the model and its serialized pre-processor.\n",
"- Build a FastAPI server to handle predictions and health checks.\n",
"- Build a custom container with model artifacts.\n",
"- Upload and deploy custom container to Vertex AI Endpoints."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "0fe0bb78c9ce"
},
"source": [
"### Dataset\n",
"\n",
"This tutorial uses R.A. Fisher's Iris dataset, a small dataset that is popular for trying out machine learning techniques. Each instance has four numerical features, which are different measurements of a flower, and a target label that\n",
"This tutorial uses R.A. Fisher's Iris dataset, a small dataset that is a popular choice for trying out machine learning techniques. Each instance has four numerical features, which are different measurements of a flower, and a target label that\n",
"marks it as one of three types of iris: Iris setosa, Iris versicolour, or Iris virginica.\n",
"\n",
"This tutorial uses [the copy of the Iris dataset included in the\n",
"scikit-learn library](https://scikit-learn.org/stable/datasets/index.html#iris-dataset).\n",
"\n",
"### Objective\n",
"\n",
"The goal is to:\n",
"- Train a model that uses a flower's measurements as input to predict what type of iris it is.\n",
"- Save the model and its serialized pre-processor\n",
"- Build a FastAPI server to handle predictions and health checks\n",
"- Build a custom container with model artifacts\n",
"- Upload and deploy custom container to Vertex Prediction\n",
"\n",
"This tutorial focuses more on deploying this model with Vertex AI than on\n",
"the design of the model itself.\n",
"\n",
"scikit-learn library](https://scikit-learn.org/stable/modules/generated/sklearn.datasets.load_iris.html#sklearn.datasets.load_iris)."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "c681f532cf64"
},
"source": [
"### Costs \n",
"\n",
"This tutorial uses billable components of Google Cloud:\n",
"\n",
"* Vertex AI\n",
"* Cloud Storage\n",
"* Artifact Registry\n",
"* Cloud Build\n",
"\n",
"Learn about [Vertex AI\n",
"pricing](https://cloud.google.com/vertex-ai/pricing), and use the [Pricing\n",
"pricing](https://cloud.google.com/vertex-ai/pricing), [Cloud Storage\n",
"pricing](https://cloud.google.com/storage/pricing), [Artifact Registry pricing](https://cloud.google.com/artifact-registry/pricing) and [Cloud Build pricing](https://cloud.google.com/build/pricing) and use the [Pricing\n",
"Calculator](https://cloud.google.com/products/calculator/)\n",
"to generate a cost estimate based on your projected usage."
]
@@ -91,8 +131,10 @@
"source": [
"### Set up your local development environment\n",
"\n",
"**If you are using Colab or Google Cloud Notebooks**, your environment already meets\n",
"all the requirements to run this notebook. You can skip this step."
"**If you are using Colab or Vertex AI Workbench notebooks**, your environment already meets\n",
"all the requirements to run this notebook.\n",
"\n",
"**If you are using Colab**, docker related steps are skipped as Colab doesn't fully support docker yet."
]
},
{
@@ -139,7 +181,7 @@
"id": "i7EUnXsZhAGF"
},
"source": [
"### Install additional packages\n",
"## Install additional packages\n",
"\n",
"Install additional package dependencies not installed in your notebook environment, such as NumPy, Scikit-learn, FastAPI, Uvicorn, and joblib. Use the latest major GA version of each package."
]
@@ -163,18 +205,31 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "wyy5Lbnzg5fi"
"id": "1fd00fa70a2a"
},
"outputs": [],
"source": [
"import os\n",
"\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",
"# Vertex AI Notebook requires dependencies to be installed with '--user'\n",
"USER_FLAG = \"\"\n",
"if IS_WORKBENCH_NOTEBOOK:\n",
" USER_FLAG = \"--user\"\n",
"\n",
"# Required in Docker serving container\n",
"%pip install -U --user -r requirements.txt\n",
"! pip3 install -U {USER_FLAG} -r requirements.txt -q\n",
"\n",
"# For local FastAPI development and running\n",
"%pip install -U --user \"uvicorn[standard]>=0.12.0,<0.14.0\" fastapi~=0.63\n",
"! pip3 install -U {USER_FLAG} \"uvicorn[standard]>=0.12.0,<0.14.0\" fastapi~=0.63 -q\n",
"\n",
"# Vertex SDK for Python\n",
"%pip install -U --user google-cloud-aiplatform"
"! pip3 install -U {USER_FLAG} google-cloud-aiplatform -q"
]
},
{
@@ -230,14 +285,14 @@
"\n",
"1. [Make sure that billing is enabled for your project](https://cloud.google.com/billing/docs/how-to/modify-project).\n",
"\n",
"1. [Enable the Vertex AI API and Compute Engine API](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com,compute_component).\n",
"1. [Enable the APIs for Vertex AI, Compute Engine and Artifact Registry](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com,compute.googleapis.com,artifactregistry.googleapis.com).\n",
"\n",
"1. 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",
"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 `!` or `%` as shell commands, and it interpolates Python variables with `$` or `{}` into these commands."
"**Note**: Jupyter runs lines prefixed with `!` as shell commands, and it interpolates Python variables prefixed with `$` into these commands."
]
},
{
@@ -251,6 +306,17 @@
"**If you don't know your project ID**, you may be able to get your project ID using `gcloud`."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "cde8e0876d62"
},
"outputs": [],
"source": [
"PROJECT_ID = \"[your-project-id]\" # @param {type:\"string\"}"
]
},
{
"cell_type": "code",
"execution_count": null,
@@ -259,24 +325,11 @@
},
"outputs": [],
"source": [
"# Get your Google Cloud project ID from gcloud\n",
"shell_output=!gcloud config list --format 'value(core.project)' 2>/dev/null\n",
"\n",
"try:\n",
"if PROJECT_ID == \"\" or PROJECT_ID is None or PROJECT_ID == \"[your-project-id]\":\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",
"except IndexError:\n",
" PROJECT_ID = None\n",
"\n",
"print(\"Project ID:\", PROJECT_ID)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "qJYoRfYng0XZ"
},
"source": [
"Otherwise, set your project ID here."
" print(\"Project ID:\", PROJECT_ID)"
]
},
{
@@ -287,28 +340,85 @@
},
"outputs": [],
"source": [
"if PROJECT_ID == \"\" or PROJECT_ID is None:\n",
" PROJECT_ID = \"[your-project-id]\" # @param {type:\"string\"}"
"! gcloud config set project $PROJECT_ID"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dr--iN2kAylZ"
"id": "becb6514d26a"
},
"source": [
"#### 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. It is recommended that you choose the region closest to you.\n",
"\n",
"- Americas: `us-central1`\n",
"- Europe: `europe-west4`\n",
"- Asia Pacific: `asia-east1`\n",
"\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)."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "959545da671a"
},
"outputs": [],
"source": [
"REGION = \"[your-region]\" # @param {type: \"string\"}\n",
"\n",
"if REGION == \"[your-region]\":\n",
" REGION = \"us-central1\""
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "e663bd062c6f"
},
"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": "953fa6e5ddda"
},
"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": "40206eb20b53"
},
"source": [
"### Authenticate your Google Cloud account\n",
"\n",
"**If you are using Google Cloud Notebooks**, your environment is already\n",
"authenticated. Skip this step."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "sBCra4QMA2wR"
},
"source": [
"**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\n",
"when prompted to authenticate your account via oAuth.\n",
"\n",
@@ -337,20 +447,23 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "PyQmSRbKA8r-"
"id": "4dd67f16eff2"
},
"outputs": [],
"source": [
"import os\n",
"import sys\n",
"\n",
"# If you are running this notebook in Colab, run this cell and follow the\n",
"# instructions to authenticate your GCP account. This provides access to your\n",
"# Cloud Storage bucket and lets you submit training jobs and prediction\n",
"# requests.\n",
"\n",
"# If on Google Cloud Notebooks, then don't execute this code\n",
"if not os.path.exists(\"/opt/deeplearning/metadata/env_version\"):\n",
"import os\n",
"import sys\n",
"\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",
@@ -359,57 +472,10 @@
" # If you are running this notebook locally, replace the string below with the\n",
" # path to your service account key and run this cell to authenticate your GCP\n",
" # account.\n",
" elif not os.getenv(\"IS_TESTING\") and not os.getenv(\n",
" \"GOOGLE_APPLICATION_CREDENTIALS\"\n",
" ):\n",
" elif not os.getenv(\"IS_TESTING\"):\n",
" %env GOOGLE_APPLICATION_CREDENTIALS ''"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "XoEqT2Y4DJmf"
},
"source": [
"### Configure project and resource names"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "MzGDU7TWdts_"
},
"outputs": [],
"source": [
"REGION = \"us-central1\" # @param {type:\"string\"}\n",
"MODEL_ARTIFACT_DIR = \"custom-container-prediction-model\" # @param {type:\"string\"}\n",
"REPOSITORY = \"custom-container-prediction\" # @param {type:\"string\"}\n",
"IMAGE = \"sklearn-fastapi-server\" # @param {type:\"string\"}\n",
"MODEL_DISPLAY_NAME = \"sklearn-custom-container\" # @param {type:\"string\"}"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "ca1a915d641d"
},
"source": [
"`REGION` - Used for operations\n",
"throughout the rest of this notebook. Make sure to [choose a region where Cloud\n",
"Vertex AI services are\n",
"available](https://cloud.google.com/vertex-ai/docs/general/locations#feature-availability). You may\n",
"not use a Multi-Regional Storage bucket for training with Vertex AI.\n",
"\n",
"`MODEL_ARTIFACT_DIR` - Folder directory path to your model artifacts within a Cloud Storage bucket, for example: \"my-models/fraud-detection/trial-4\"\n",
"\n",
"`REPOSITORY` - Name of the Artifact Repository to create or use.\n",
"\n",
"`IMAGE` - Name of the container image that will be pushed.\n",
"\n",
"`MODEL_DISPLAY_NAME` - Display name of Vertex AI Model resource."
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -420,8 +486,8 @@
"\n",
"**The following steps are required, regardless of your notebook environment.**\n",
"\n",
"To update your model artifacts without re-building the container, you must upload your model\n",
"artifacts and any custom code to Cloud Storage.\n",
"To update your model artifacts without re-building the container, you upload your model\n",
"artifacts and any custom code to Cloud Storage bucket.\n",
"\n",
"Set the name of your Cloud Storage bucket below. It must be unique across all\n",
"Cloud Storage buckets. "
@@ -435,7 +501,21 @@
},
"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}\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "db3de5b7b0a4"
},
"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 = f\"gs://{BUCKET_NAME}\""
]
},
{
@@ -455,7 +535,7 @@
},
"outputs": [],
"source": [
"! gsutil mb -l $REGION $BUCKET_NAME"
"! gsutil mb -l $REGION $BUCKET_URI"
]
},
{
@@ -475,7 +555,95 @@
},
"outputs": [],
"source": [
"! gsutil ls -al $BUCKET_NAME"
"! gsutil ls -al $BUCKET_URI"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "d3938f6d37a1"
},
"source": [
"## Import libraries"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "e95ca1e5e07c"
},
"outputs": [],
"source": [
"from google.cloud import aiplatform"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "750d53e37094"
},
"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": "1a3aa2d4a74f"
},
"outputs": [],
"source": [
"aiplatform.init(project=PROJECT_ID, location=REGION)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "XoEqT2Y4DJmf"
},
"source": [
"### Configure resource names\n",
"\n",
"Set a name for the following resources:\n",
"\n",
"`MODEL_ARTIFACT_DIR` - Folder directory path to your model artifacts within a Cloud Storage bucket, for example: \"my-models/fraud-detection/trial-4\"\n",
"\n",
"`REPOSITORY` - Name of the Artifact Repository to create or use.\n",
"\n",
"`IMAGE` - Name of the container image that is pushed to the repository.\n",
"\n",
"`MODEL_DISPLAY_NAME` - Display name of Vertex AI Model resource."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "MzGDU7TWdts_"
},
"outputs": [],
"source": [
"MODEL_ARTIFACT_DIR = \"[your-artifact-directory]\" # @param {type:\"string\"}\n",
"REPOSITORY = \"[your-repository-name]\" # @param {type:\"string\"}\n",
"IMAGE = \"[your-image-name]\" # @param {type:\"string\"}\n",
"MODEL_DISPLAY_NAME = \"[your-model-display-name]\" # @param {type:\"string\"}\n",
"\n",
"# Set the defaults if no names were specified\n",
"if MODEL_ARTIFACT_DIR == \"[your-artifact-directory]\":\n",
" MODEL_ARTIFACT_DIR = \"custom-container-prediction-model\"\n",
"\n",
"if REPOSITORY == \"[your-repository-name]\":\n",
" REPOSITORY = \"custom-container-prediction\"\n",
"\n",
"if IMAGE == \"[your-image-name]\":\n",
" IMAGE = \"sklearn-fastapi-server\"\n",
"\n",
"if MODEL_DISPLAY_NAME == \"[your-model-display-name]\":\n",
" MODEL_DISPLAY_NAME = \"sklearn-custom-container\""
]
},
{
@@ -485,9 +653,9 @@
},
"source": [
"## Write your pre-processor\n",
"Scaling training data so each numerical feature column has a mean of 0 and a standard deviation of 1 [can improve your model](https://developers.google.com/machine-learning/crash-course/representation/cleaning-data).\n",
"Standardize the training data so each numerical feature column has a mean of 0 and a standard deviation of 1 [can improve your model](https://developers.google.com/machine-learning/crash-course/representation/cleaning-data).\n",
"\n",
"Create `preprocess.py`, which contains a class to do this scaling:"
"Define a `app` folder and create `preprocess.py`, which contains a class to perform standardization."
]
},
{
@@ -538,7 +706,7 @@
"## Train and store model with pre-processor\n",
"Next, use `preprocess.MySimpleScaler` to preprocess the iris data, then train a model using scikit-learn.\n",
"\n",
"At the end, export your trained model as a joblib (`.joblib`) file and export your `MySimpleScaler` instance as a pickle (`.pkl`) file:"
"At the end, export your trained model as a joblib (`.joblib`) file and export your `MySimpleScaler` instance as a pickle (`.pkl`) file."
]
},
{
@@ -596,7 +764,7 @@
},
"outputs": [],
"source": [
"!gsutil cp model.joblib preprocessor.pkl {BUCKET_NAME}/{MODEL_ARTIFACT_DIR}/\n",
"!gsutil cp model.joblib preprocessor.pkl {BUCKET_URI}/{MODEL_ARTIFACT_DIR}/\n",
"%cd .."
]
},
@@ -606,7 +774,9 @@
"id": "480a1d88ecdb"
},
"source": [
"## Build a FastAPI server"
"## Build a FastAPI server\n",
"\n",
"To serve predictions from the classification model, build a FastAPI server application."
]
},
{
@@ -674,7 +844,7 @@
},
"source": [
"### Add pre-start script\n",
"FastAPI will execute this script before starting up the server. The `PORT` environment variable is set to equal `AIP_HTTP_PORT` in order to run FastAPI on same the port expected by Vertex AI."
"FastAPI executes the following script before starting up the server. The `PORT` environment variable is set to equal to `AIP_HTTP_PORT` in order to run FastAPI on the same port expected by Vertex AI."
]
},
{
@@ -696,7 +866,7 @@
"id": "8b62ddf1def3"
},
"source": [
"### Store test instances to use later\n",
"### Create test instances\n",
"To learn more about formatting input instances in JSON, [read the documentation.](https://cloud.google.com/vertex-ai/docs/predictions/online-predictions-custom-models#request-body-details)"
]
},
@@ -726,35 +896,13 @@
"## Build and push container to Artifact Registry"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "3bdb9a7768a5"
},
"source": [
"### Build your container\n",
"Optionally copy in your credentials to run the container locally."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "fbb77f4f56c7"
},
"outputs": [],
"source": [
"# NOTE: Copy in credentials to run locally, this step can be skipped for deployment\n",
"%cp $GOOGLE_APPLICATION_CREDENTIALS app/credentials.json"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "240578ec9efe"
},
"source": [
"Write the Dockerfile, using `tiangolo/uvicorn-gunicorn-fastapi` as a base image. This will automatically run FastAPI for you using Gunicorn and Uvicorn. Visit [the FastAPI docs to read more about deploying FastAPI with Docker](https://fastapi.tiangolo.com/deployment/docker/)."
"Write the `Dockerfile`, using `tiangolo/uvicorn-gunicorn-fastapi` as a base image. This automatically runs FastAPI for you using Gunicorn and Uvicorn. Visit [the FastAPI docs to read more about deploying FastAPI with Docker](https://fastapi.tiangolo.com/deployment/docker/) to learn more."
]
},
{
@@ -767,7 +915,7 @@
"source": [
"%%writefile Dockerfile\n",
"\n",
"FROM tiangolo/uvicorn-gunicorn-fastapi:python3.7\n",
"FROM tiangolo/uvicorn-gunicorn-fastapi:python3.9\n",
"\n",
"COPY ./app /app\n",
"COPY requirements.txt requirements.txt\n",
@@ -781,7 +929,11 @@
"id": "04c988201499"
},
"source": [
"Build the image and tag the Artifact Registry path that you will push to."
"### Build the image locally (optional)\n",
"\n",
"Build the image using docker to test it locally.\n",
"\n",
"**Note:** Docker is only being used to test the container locally. For deployment to Artifact registry, Cloud-Build is used."
]
},
{
@@ -792,9 +944,10 @@
},
"outputs": [],
"source": [
"!docker build \\\n",
" --tag={REGION}-docker.pkg.dev/{PROJECT_ID}/{REPOSITORY}/{IMAGE} \\\n",
" ."
"if not IS_COLAB and not os.getenv(\"IS_TESTING\"):\n",
" ! sudo docker build \\\n",
" --tag=\"{REGION}-docker.pkg.dev/{PROJECT_ID}/{REPOSITORY}/{IMAGE}\" \\\n",
" ."
]
},
{
@@ -805,7 +958,7 @@
"source": [
"### Run and test the container locally (optional)\n",
"\n",
"Run the container locally in detached mode and provide the environment variables that the container requires. These env vars will be provided to the container by Vertex Prediction once deployed. Test the `/health` and `/predict` routes, then stop the running image."
"Test running the container locally in detached mode and provide the environment variables that the container requires. These variables are provided to the container by Vertex AI once deployed. Test the `/health` and `/predict` routes and then stop the running image."
]
},
{
@@ -816,15 +969,25 @@
},
"outputs": [],
"source": [
"!docker rm local-iris\n",
"!docker run -d -p 80:8080 \\\n",
" --name=local-iris \\\n",
" -e AIP_HTTP_PORT=8080 \\\n",
" -e AIP_HEALTH_ROUTE=/health \\\n",
" -e AIP_PREDICT_ROUTE=/predict \\\n",
" -e AIP_STORAGE_URI={BUCKET_NAME}/{MODEL_ARTIFACT_DIR} \\\n",
" -e GOOGLE_APPLICATION_CREDENTIALS=credentials.json \\\n",
" {REGION}-docker.pkg.dev/{PROJECT_ID}/{REPOSITORY}/{IMAGE}"
"if not IS_COLAB and not os.getenv(\"IS_TESTING\"):\n",
" ! sudo docker stop local-iris\n",
" ! sudo docker rm local-iris\n",
" ! sudo docker run -d -p 80:8080 \\\n",
" --name=local-iris \\\n",
" -e AIP_HTTP_PORT=8080 \\\n",
" -e AIP_HEALTH_ROUTE=/health \\\n",
" -e AIP_PREDICT_ROUTE=/predict \\\n",
" -e AIP_STORAGE_URI={BUCKET_URI}/{MODEL_ARTIFACT_DIR} \\\n",
" \"{REGION}-docker.pkg.dev/{PROJECT_ID}/{REPOSITORY}/{IMAGE}\""
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "248f481e8e90"
},
"source": [
"Ping the health route."
]
},
{
@@ -835,7 +998,17 @@
},
"outputs": [],
"source": [
"!curl localhost/health"
"if not IS_COLAB and not os.getenv(\"IS_TESTING\"):\n",
" ! curl localhost/health"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "2d6821fb2b7d"
},
"source": [
"Pass the `instances.json` and test the predict route."
]
},
{
@@ -846,10 +1019,20 @@
},
"outputs": [],
"source": [
"!curl -X POST \\\n",
" -d @instances.json \\\n",
" -H \"Content-Type: application/json; charset=utf-8\" \\\n",
" localhost/predict"
"if not IS_COLAB and not os.getenv(\"IS_TESTING\"):\n",
" ! curl -X POST \\\n",
" -d @instances.json \\\n",
" -H \"Content-Type: application/json; charset=utf-8\" \\\n",
" localhost/predict"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "d1d6ee697180"
},
"source": [
"Stop and delete the container locally."
]
},
{
@@ -860,7 +1043,9 @@
},
"outputs": [],
"source": [
"!docker stop local-iris"
"if not IS_COLAB and not os.getenv(\"IS_TESTING\"):\n",
" ! sudo docker stop local-iris\n",
" ! sudo docker rm local-iris"
]
},
{
@@ -871,31 +1056,32 @@
"source": [
"### Push the container to artifact registry\n",
"\n",
"Configure Docker to access Artifact Registry. Then push your container image to your Artifact Registry repository."
"Create your repository in the Artifact registry and push your container image to the repository.\n",
"Run this below cell once to create the artifact repository."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "09ffe2434e3d"
"id": "5f98a42332e5"
},
"outputs": [],
"source": [
"!gcloud beta artifacts repositories create {REPOSITORY} \\\n",
"!gcloud artifacts repositories create {REPOSITORY} \\\n",
" --repository-format=docker \\\n",
" --location=$REGION"
]
},
{
"cell_type": "code",
"execution_count": null,
"cell_type": "markdown",
"metadata": {
"id": "293437024749"
"id": "d2e0b8b700aa"
},
"outputs": [],
"source": [
"!gcloud auth configure-docker {REGION}-docker.pkg.dev"
"Push the image to the created artifact repository using Cloud-Build.\n",
"\n",
"**Note:** The following command automatically considers the Dockerfile from the directory it is being run from."
]
},
{
@@ -906,7 +1092,7 @@
},
"outputs": [],
"source": [
"!docker push {REGION}-docker.pkg.dev/{PROJECT_ID}/{REPOSITORY}/{IMAGE}"
"!gcloud builds submit --region={REGION} --tag={REGION}-docker.pkg.dev/{PROJECT_ID}/{REPOSITORY}/{IMAGE}"
]
},
{
@@ -915,9 +1101,7 @@
"id": "b438bfa2129f"
},
"source": [
"## Deploy to Vertex AI\n",
"\n",
"Use the Python SDK to upload and deploy your model."
"## Deploy to Vertex AI"
]
},
{
@@ -926,29 +1110,8 @@
"id": "4ae19df6a33e"
},
"source": [
"### Upload the custom container model"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "8d682d8388ec"
},
"outputs": [],
"source": [
"from google.cloud import aiplatform"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "574fb82d3eed"
},
"outputs": [],
"source": [
"aiplatform.init(project=PROJECT, location=REGION)"
"### Create Vertex AI model using artifact uri\n",
"Use the Python SDK to upload and deploy your model from the artifact registry."
]
},
{
@@ -961,7 +1124,7 @@
"source": [
"model = aiplatform.Model.upload(\n",
" display_name=MODEL_DISPLAY_NAME,\n",
" artifact_uri=f\"{BUCKET_NAME}/{MODEL_ARTIFACT_DIR}\",\n",
" artifact_uri=f\"{BUCKET_URI}/{MODEL_ARTIFACT_DIR}\",\n",
" serving_container_image_uri=f\"{REGION}-docker.pkg.dev/{PROJECT_ID}/{REPOSITORY}/{IMAGE}\",\n",
")"
]
@@ -972,8 +1135,9 @@
"id": "bd1b85afc7df"
},
"source": [
"### Deploy the model on Vertex AI\n",
"After this step completes, the model is deployed and ready for online prediction."
"### Deploy the model to Vertex AI Endpoints\n",
"\n",
"Deploy the model to a Vertex AI Endpoint. After this step completes, the model is deployed and ready for online predictions."
]
},
{
@@ -993,9 +1157,13 @@
"id": "6883e7b07143"
},
"source": [
"## Send predictions\n",
"## Request predictions\n",
"\n",
"### Using Python SDK"
"Send online requests to the model deployed to the endpoint and get predictions.\n",
"\n",
"### Using Python SDK\n",
"\n",
"Get predictions from the endpoint for a sample input using python SDK."
]
},
{
@@ -1015,7 +1183,9 @@
"id": "370d22f53427"
},
"source": [
"### Using REST"
"### Using REST\n",
"\n",
"Get predictions from the endpoint using curl request."
]
},
{
@@ -1050,7 +1220,9 @@
"id": "fa71174a7dd0"
},
"source": [
"### Using gcloud CLI"
"### Using gcloud CLI\n",
"\n",
"Get predictions from the endpoint using gcloud CLI."
]
},
{
@@ -1061,7 +1233,7 @@
},
"outputs": [],
"source": [
"!gcloud beta ai endpoints predict $ENDPOINT_ID \\\n",
"!gcloud ai endpoints predict $ENDPOINT_ID \\\n",
" --region=$REGION \\\n",
" --json-request=instances.json"
]
@@ -1077,7 +1249,13 @@
"To clean up all Google Cloud resources used in this project, you can [delete the Google Cloud\n",
"project](https://cloud.google.com/resource-manager/docs/creating-managing-projects#shutting_down_projects) you used for the tutorial.\n",
"\n",
"Otherwise, you can delete the individual resources you created in this tutorial:"
"Otherwise, you can delete the individual resources you created in this tutorial:\n",
"\n",
"- Model\n",
"- Endpoint\n",
"- Artifact Registry Image\n",
"- Artifact Repository: Set `delete_art_repo` to **True** to delete the repository created in this tutorial.\n",
"- Cloud Storage bucket: Set `delete_bucket` to **True** to delete the Cloud Storage bucket used in this tutorial."
]
},
{
@@ -1088,24 +1266,36 @@
},
"outputs": [],
"source": [
"delete_bucket = False\n",
"delete_art_repo = False\n",
" \n",
"# Undeploy model and delete endpoint\n",
"endpoint.delete(force=True)\n",
"endpoint.undeploy_all()\n",
"endpoint.delete()\n",
"\n",
"# Delete the model resource\n",
"#Delete the model resource\n",
"model.delete()\n",
"\n",
"# Delete the container image from Artifact Registry\n",
"!gcloud artifacts docker images delete \\\n",
" --quiet \\\n",
" --delete-tags \\\n",
" {REGION}-docker.pkg.dev/{PROJECT_ID}/{REPOSITORY}/{IMAGE}"
" {REGION}-docker.pkg.dev/{PROJECT_ID}/{REPOSITORY}/{IMAGE}\n",
"\n",
"# Delete the artifact registry\n",
"if delete_art_repo or os.getenv(\"IS_TESTING\"):\n",
" ! gcloud artifacts repositories delete {REPOSITORY} --location=$REGION -q\n",
" \n",
"# Delete the Cloud Storage bucket\n",
"if delete_bucket or os.getenv(\"IS_TESTING\"):\n",
" ! gsutil -m rm -r $BUCKET_URI"
]
}
],
"metadata": {
"colab": {
"collapsed_sections": [],
"name": "AI_Platform_(Unified)_SDK_Custom_Container_Prediction.ipynb",
"name": "SDK_Custom_Container_Prediction.ipynb",
"toc_visible": true
},
"kernelspec": {
@@ -29,6 +29,8 @@
"id": "JAPoU8Sm5E6e"
},
"source": [
"# Build Vertex AI Experiment lineage for custom training\n",
"\n",
"<table align=\"left\">\n",
"\n",
" <td>\n",
@@ -43,7 +45,7 @@
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/experiments/build_model_experimentation_lineage_with_prebuild_code.ipynb\">\n",
" <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://raw.githubusercontent.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/experiments/build_model_experimentation_lineage_with_prebuild_code.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",
@@ -29,27 +29,27 @@
"id": "JAPoU8Sm5E6e"
},
"source": [
"## Vertex AI: Track parameters and metrics for locally trained models\n",
"# Vertex AI: Track parameters and metrics for locally trained models\n",
"\n",
"<table align=\"left\">\n",
"\n",
" <td>\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_metadata/sdk-metric-parameter-tracking-for-locally-trained-models.ipynb\">\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/experiments/comparing_local_trained_models.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/vertex-ai-samples/blob/main/notebooks/community/ml_metadata/sdk-metric-parameter-tracking-for-locally-trained-models.ipynb\">\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/experiments/comparing_local_trained_models.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",
" <td>\n",
" <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/notebook_template.ipynb\">\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/experiments/comparing_local_trained_models.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",
" </a>\n",
" </td> \n",
"</table>"
]
},
@@ -3,7 +3,6 @@
{
"cell_type": "code",
"execution_count": null,
"id": "ed0fca3f",
"metadata": {
"id": "ur8xi4C7S06n"
},
@@ -26,21 +25,12 @@
},
{
"cell_type": "markdown",
"id": "6e92def7-b4f0-4100-b981-82972665d19d",
"metadata": {
"id": "847715f095b5"
},
"source": [
"# Vertex AI: Comparing Pipeline Runs"
]
},
{
"cell_type": "markdown",
"id": "ffada1ce",
"metadata": {
"id": "JAPoU8Sm5E6e"
},
"source": [
"# Compare pipeline runs with Vertex AI Experiments\n",
"\n",
"<table align=\"left\">\n",
"\n",
" <td>\n",
@@ -65,13 +55,10 @@
},
{
"cell_type": "markdown",
"id": "d118d181",
"metadata": {
"id": "tvgnzT1CKxrO"
},
"source": [
"# Compare pipeline runs with Vertex AI Experiments\n",
"\n",
"## Overview\n",
"\n",
"Depending on the model life cycle of your data science team, you would like to experiment and track training Pipeline runs and its associated parameters. Then, you would to compare runs of these Pipelines to each others in order to figure out which is the best configuration generates the model you will register in the Vertex AI Model Registry."
@@ -79,7 +66,6 @@
},
{
"cell_type": "markdown",
"id": "b6201ad0-af42-48fd-b03d-403fd235e268",
"metadata": {
"id": "d220917f1302"
},
@@ -101,7 +87,6 @@
},
{
"cell_type": "markdown",
"id": "cffa7608-f550-4913-8f88-30cbcd525685",
"metadata": {
"id": "263933842022"
},
@@ -113,7 +98,6 @@
},
{
"cell_type": "markdown",
"id": "b46c0eb6-e65d-4b28-b17d-dc9bf9b08120",
"metadata": {
"id": "de76bb18c85b"
},
@@ -134,7 +118,6 @@
},
{
"cell_type": "markdown",
"id": "ee1e6851",
"metadata": {
"id": "gCuSR8GkAgzl"
},
@@ -177,7 +160,6 @@
},
{
"cell_type": "markdown",
"id": "97e5b386",
"metadata": {
"id": "i7EUnXsZhAGF"
},
@@ -190,7 +172,6 @@
{
"cell_type": "code",
"execution_count": null,
"id": "5b01540f",
"metadata": {
"id": "2b4ef9b72d43"
},
@@ -215,7 +196,6 @@
},
{
"cell_type": "markdown",
"id": "c6806ee8",
"metadata": {
"id": "hhq5zEbGg0XX"
},
@@ -228,7 +208,6 @@
{
"cell_type": "code",
"execution_count": null,
"id": "584f0887",
"metadata": {
"id": "EzrelQZ22IZj"
},
@@ -247,7 +226,6 @@
},
{
"cell_type": "markdown",
"id": "bb098c06",
"metadata": {
"id": "lWEdiXsJg0XY"
},
@@ -257,7 +235,6 @@
},
{
"cell_type": "markdown",
"id": "3706598b",
"metadata": {
"id": "BF1j6f9HApxa"
},
@@ -282,7 +259,6 @@
},
{
"cell_type": "markdown",
"id": "c7f6a1ea",
"metadata": {
"id": "WReHDGG5g0XY"
},
@@ -295,7 +271,6 @@
{
"cell_type": "code",
"execution_count": null,
"id": "6984e874-ae15-4094-9c5b-8d12661645c9",
"metadata": {
"id": "3c8049930470"
},
@@ -307,7 +282,6 @@
{
"cell_type": "code",
"execution_count": null,
"id": "ebaef2f9",
"metadata": {
"id": "oM1iC_MfAts1"
},
@@ -325,7 +299,6 @@
{
"cell_type": "code",
"execution_count": null,
"id": "d9745b2b-cd37-4a1c-aae7-4cd75a3c126c",
"metadata": {
"id": "f2e3c0f2cbfb"
},
@@ -336,7 +309,6 @@
},
{
"cell_type": "markdown",
"id": "fff3c4af",
"metadata": {
"id": "qJYoRfYng0XZ"
},
@@ -347,7 +319,6 @@
{
"cell_type": "code",
"execution_count": null,
"id": "89a05131",
"metadata": {
"id": "riG_qUokg0XZ"
},
@@ -359,7 +330,6 @@
},
{
"cell_type": "markdown",
"id": "9aa4ad5f",
"metadata": {
"id": "2aa333eca058"
},
@@ -381,7 +351,6 @@
{
"cell_type": "code",
"execution_count": null,
"id": "244d416e",
"metadata": {
"id": "d8b34ef9a3d0"
},
@@ -395,7 +364,6 @@
},
{
"cell_type": "markdown",
"id": "eed6c3ba",
"metadata": {
"id": "126548a06aa1"
},
@@ -408,7 +376,6 @@
{
"cell_type": "code",
"execution_count": null,
"id": "6ef7c7b1",
"metadata": {
"id": "e660b8504e63"
},
@@ -428,7 +395,6 @@
},
{
"cell_type": "markdown",
"id": "5763da2c",
"metadata": {
"id": "sBCra4QMA2wR"
},
@@ -470,7 +436,6 @@
{
"cell_type": "code",
"execution_count": null,
"id": "85b826d2",
"metadata": {
"id": "PyQmSRbKA8r-"
},
@@ -503,7 +468,6 @@
},
{
"cell_type": "markdown",
"id": "3d31b8b8",
"metadata": {
"id": "zgPO1eR3CYjk"
},
@@ -520,7 +484,6 @@
{
"cell_type": "code",
"execution_count": null,
"id": "95a18950",
"metadata": {
"id": "MzGDU7TWdts_"
},
@@ -533,7 +496,6 @@
{
"cell_type": "code",
"execution_count": null,
"id": "379d758a",
"metadata": {
"id": "cf221059d072"
},
@@ -546,7 +508,6 @@
},
{
"cell_type": "markdown",
"id": "50b86adc",
"metadata": {
"id": "-EcIXiGsCePi"
},
@@ -557,7 +518,6 @@
{
"cell_type": "code",
"execution_count": null,
"id": "564ce38f",
"metadata": {
"id": "NIq7R4HZCfIc"
},
@@ -568,7 +528,6 @@
},
{
"cell_type": "markdown",
"id": "a4324d2e",
"metadata": {
"id": "ucvCsknMCims"
},
@@ -579,7 +538,6 @@
{
"cell_type": "code",
"execution_count": null,
"id": "df030498-f6e7-4e45-96f4-0d36590865aa",
"metadata": {
"id": "vhOb7YnwClBb"
},
@@ -590,7 +548,6 @@
},
{
"cell_type": "markdown",
"id": "49d12f54",
"metadata": {
"id": "b7e24e522bee"
},
@@ -603,7 +560,6 @@
{
"cell_type": "code",
"execution_count": null,
"id": "8da829a1",
"metadata": {
"id": "77b01a1fdbb4"
},
@@ -615,7 +571,6 @@
{
"cell_type": "code",
"execution_count": null,
"id": "f2c8c41d",
"metadata": {
"id": "121d7ca29426"
},
@@ -645,7 +600,6 @@
},
{
"cell_type": "markdown",
"id": "f0552e61",
"metadata": {
"id": "aa175e2960ac"
},
@@ -658,7 +612,6 @@
{
"cell_type": "code",
"execution_count": null,
"id": "abbfcad3",
"metadata": {
"id": "f88cb0488c08"
},
@@ -671,7 +624,6 @@
},
{
"cell_type": "markdown",
"id": "2689f52b",
"metadata": {
"id": "fXUqOdIaLbjf"
},
@@ -682,7 +634,6 @@
{
"cell_type": "code",
"execution_count": null,
"id": "754e5f7b",
"metadata": {
"id": "9fYX14c0LfmU"
},
@@ -695,7 +646,6 @@
},
{
"cell_type": "markdown",
"id": "231e5499",
"metadata": {
"id": "XoEqT2Y4DJmf"
},
@@ -706,7 +656,6 @@
{
"cell_type": "code",
"execution_count": null,
"id": "884b2d31",
"metadata": {
"id": "pRUOFELefqf1"
},
@@ -732,7 +681,6 @@
{
"cell_type": "code",
"execution_count": null,
"id": "20e96b6b",
"metadata": {
"id": "OAY0QKZD8qNP"
},
@@ -753,7 +701,6 @@
},
{
"cell_type": "markdown",
"id": "3fb7c387",
"metadata": {
"id": "inR70nh38PeK"
},
@@ -766,7 +713,6 @@
{
"cell_type": "code",
"execution_count": null,
"id": "6eb614be",
"metadata": {
"id": "Nz0nasrh8T3c"
},
@@ -777,7 +723,6 @@
},
{
"cell_type": "markdown",
"id": "01448e2a",
"metadata": {
"id": "container:training,prediction,xgboost"
},
@@ -796,7 +741,6 @@
{
"cell_type": "code",
"execution_count": null,
"id": "ece742dc",
"metadata": {
"id": "XujRA5ueox9U"
},
@@ -809,7 +753,6 @@
},
{
"cell_type": "markdown",
"id": "32a2397a",
"metadata": {
"id": "t1NLYz1R-KWv"
},
@@ -819,7 +762,6 @@
},
{
"cell_type": "markdown",
"id": "64570881",
"metadata": {
"id": "jnfKxpj0-Z0H"
},
@@ -832,7 +774,6 @@
{
"cell_type": "code",
"execution_count": null,
"id": "f612dbf2",
"metadata": {
"id": "jv_-vU46_eFN"
},
@@ -971,7 +912,6 @@
},
{
"cell_type": "markdown",
"id": "bf048b2a",
"metadata": {
"id": "U1UiTZhkVoFM"
},
@@ -984,7 +924,6 @@
{
"cell_type": "code",
"execution_count": null,
"id": "7684850a",
"metadata": {
"id": "9Gfr6pNLU-dB"
},
@@ -1007,7 +946,6 @@
},
{
"cell_type": "markdown",
"id": "cb6cae0b",
"metadata": {
"id": "RkfZ7qVAVjBO"
},
@@ -1018,7 +956,6 @@
{
"cell_type": "code",
"execution_count": null,
"id": "c6b9ec3f",
"metadata": {
"id": "oYlLBGUSVibG"
},
@@ -1029,7 +966,6 @@
},
{
"cell_type": "markdown",
"id": "cc940f17",
"metadata": {
"id": "95vG4-zPWc0B"
},
@@ -1039,7 +975,6 @@
},
{
"cell_type": "markdown",
"id": "bb2b2eb4",
"metadata": {
"id": "ZNb6kZ2l5t-O"
},
@@ -1052,7 +987,6 @@
{
"cell_type": "code",
"execution_count": null,
"id": "77314a6f",
"metadata": {
"id": "XPy0Jc8xXgpa"
},
@@ -1070,7 +1004,6 @@
{
"cell_type": "code",
"execution_count": null,
"id": "aee97ebf",
"metadata": {
"id": "G0hm1no_WY8o"
},
@@ -1094,7 +1027,6 @@
},
{
"cell_type": "markdown",
"id": "0ca08588",
"metadata": {
"id": "O8TV4q535c2M"
},
@@ -1107,7 +1039,6 @@
{
"cell_type": "code",
"execution_count": null,
"id": "a65f2574",
"metadata": {
"id": "dlCEJKfH5xR7"
},
@@ -1119,7 +1050,6 @@
},
{
"cell_type": "markdown",
"id": "f605666a-9f2a-479f-9948-6f2f29e4e76b",
"metadata": {
"id": "98c022ca36b4"
},
@@ -1130,7 +1060,6 @@
{
"cell_type": "code",
"execution_count": null,
"id": "dc6661c5",
"metadata": {
"id": "FA9W85vs7LLD"
},
@@ -1157,7 +1086,6 @@
{
"cell_type": "code",
"execution_count": null,
"id": "ef041ba2",
"metadata": {
"id": "ISsK9Msi-Kqs"
},
@@ -1172,7 +1100,6 @@
},
{
"cell_type": "markdown",
"id": "02a718ab",
"metadata": {
"id": "TpV-iwP9qw9c"
},
@@ -1188,7 +1115,6 @@
{
"cell_type": "code",
"execution_count": null,
"id": "e90fb0b1",
"metadata": {
"id": "6xbYQn5t5Noe"
},
@@ -33,18 +33,18 @@
"\n",
"<table align=\"left\">\n",
" <td>\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/automl/sdk_automl_tabular_classification_online_explain.ipynb\">\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/explainable_ai/sdk_automl_tabular_classification_online_explain.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/vertex-ai-samples/blob/main/notebooks/official/automl/sdk_automl_tabular_classification_online_explain.ipynb\">\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/explainable_ai/sdk_automl_tabular_classification_online_explain.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",
" <td>\n",
" <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://raw.githubusercontent.com/GoogleCloudPlatform/vertex-ai-samples/tree/main/notebooks/official/explainable_ai/sdk_automl_tabular_binary_classification_online_explain.ipynb\">\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/explainable_ai/sdk_automl_tabular_binary_classification_online_explain.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",
@@ -44,7 +44,7 @@
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://raw.githubusercontent.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/explainable_ai/sdk_custom_image_classification_batch_explain.ipynb\">\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/explainable_ai/sdk_custom_image_classification_batch_explain.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",
@@ -33,18 +33,18 @@
"\n",
"<table align=\"left\">\n",
" <td>\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/automl/sdk_custom_image_classification_online_explain.ipynb\">\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/explainable_ai/sdk_custom_image_classification_online_explain.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/vertex-ai-samples/blob/main/notebooks/official/automl/sdk_custom_image_classification_online_explain.ipynb\">\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/explainable_ai/sdk_custom_image_classification_online_explain.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",
" <td>\n",
" <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://raw.githubusercontent.com/GoogleCloudPlatform/vertex-ai-samples/tree/main/notebooks/official/explainable_ai/sdk_custom_image_classification_online_explain.ipynb\">\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/explainable_ai/sdk_custom_image_classification_online_explain.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",
@@ -33,18 +33,18 @@
"\n",
"<table align=\"left\">\n",
" <td>\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/automl/sdk_custom_tabular_regression_batch_explain.ipynb\">\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/explainable_ai/sdk_custom_tabular_regression_batch_explain.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/vertex-ai-samples/blob/main/notebooks/official/automl/sdk_custom_tabular_regression_batch_explain.ipynb\">\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/explainable_ai/sdk_custom_tabular_regression_batch_explain.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",
" <td>\n",
" <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://raw.githubusercontent.com/GoogleCloudPlatform/vertex-ai-samples/tree/main/notebooks/official/explainable_ai/sdk_custom_tabular_regression_batch_explain.ipynb\">\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/explainable_ai/sdk_custom_tabular_regression_batch_explain.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",
@@ -33,18 +33,18 @@
"\n",
"<table align=\"left\">\n",
" <td>\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/tree/master/notebooks/official/automl/sdk_custom_tabular_regression_online_explain.ipynb\">\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/master/notebooks/official/explainable_ai/sdk_custom_tabular_regression_online_explain.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/vertex-ai-samples/tree/master/notebooks/official/automl/sdk_custom_tabular_regression_online_explain.ipynb\">\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/master/notebooks/official/explainable_ai/sdk_custom_tabular_regression_online_explain.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",
" <td>\n",
" <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://raw.githubusercontent.com/GoogleCloudPlatform/vertex-ai-samples/tree/main/notebooks/official/explainable_ai/sdk_custom_tabular_regression_online_explain.ipynb\">\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/explainable_ai/sdk_custom_tabular_regression_online_explain.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",
@@ -33,19 +33,20 @@
"\n",
"<table align=\"left\">\n",
" <td>\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/tree/master/notebooks/official/automl/sdk_custom_tabular_regression_online_explain_get_metadata.ipynb\">\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/explainable_ai/sdk_custom_tabular_regression_online_explain_get_metadata.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/vertex-ai-samples/tree/master/notebooks/official/automl/sdk_custom_tabular_regression_online_explain_get_metadata.ipynb\">\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/explainable_ai/sdk_custom_tabular_regression_online_explain_get_metadata.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",
" <td>\n",
" <a href=\"https://console.cloud.google.com/ai/platform/notebooks/deploy-notebook?download_url=https://github.com/GoogleCloudPlatform/vertex-ai-samples/tree/master/notebooks/official/automl/sdk_custom_tabular_regression_online_explain_get_metadata.ipynb\">\n",
" Open in Google Cloud Notebooks\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/explainable_ai/sdk_custom_tabular_regression_online_explain_get_metadata.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>\n",
@@ -33,16 +33,18 @@
"\n",
"<table align=\"left\">\n",
" <td>\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/feature_store/sdk-feature-store.ipynb\">\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/feature_store/sdk-feature-store.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/vertex-ai-samples/blob/main/notebooks/community/feature_store/sdk-feature-store.ipynb\">\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/feature_store/sdk-feature-store.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",
" <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/notebook_template.ipynb\">\n",
" </td>\n",
" <td>\n",
" <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/feature_store/sdk-feature-store.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",
@@ -77,8 +79,6 @@
"\n",
"- `Vertex AI Feature Store`\n",
"\n",
"\n",
"\n",
"The steps performed include:\n",
"\n",
"- Create featurestore, entity type, and feature resources.\n",
@@ -393,7 +393,7 @@
"### Authenticate your Google Cloud account\n",
"\n",
"**If you are using Vertex AI Workbench notebooks**, your environment is already\n",
"authenticated. Skip this step."
"authenticated."
]
},
{
@@ -822,7 +822,7 @@
"source": [
"## Import Feature Values\n",
"\n",
"You need to import feature values before you can use them for online/offline serving. In this step, you learn how to import feature values by ingesting the values from GCS (Google Cloud Storage). You can also import feature values from BigQuery or a Pandas dataframe.\n"
"You need to import feature values before you can use them for online/offline serving. In this step, you learn how to import feature values by ingesting the values from Cloud Storage. You can also import feature values from BigQuery or a Pandas dataframe.\n"
]
},
{
@@ -1025,7 +1025,7 @@
"source": [
"### Read one entity per request\n",
"\n",
"With the Python SDK, it is easy to read feature values of one entity. By default, the SDK will return the latest value of each feature, meaning the feature values with the most recent timestamp.\n",
"With the Vertex AI SDK, it is easy to read feature values of one entity. By default, the SDK will return the latest value of each feature, meaning the feature values with the most recent timestamp.\n",
"\n",
"To read feature values, specify the entity type ID and features to read. By default all the features of an entity type will be selected. The response will output and display the selected entity type ID and the selected feature values as a Pandas dataframe."
]
@@ -29,12 +29,12 @@
"id": "JAPoU8Sm5E6e"
},
"source": [
"<table align=\"left\">\n",
"# Create Vertex AI Matching Engine index\n",
"\n",
"<table align=\"left\">\n",
" <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/matching_engine/sdk_matching_engine_for_indexing.ipynb\">\n",
" <img src=\"https://lh3.googleusercontent.com/UiNooY4LUgW_oTvpsNhPpQzsstV5W8F7rYgxgGBD85cWJoLmrOzhVs_ksK_vgx40SHs7jCqkTkCk=e14-rj-sc0xffffff-h130-w32\" alt=\"Vertex AI logo\">\n",
" Run in Vertex Workbench\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/matching_engine/sdk_matching_engine_for_indexing.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",
@@ -43,25 +43,32 @@
" View on GitHub\n",
" </a>\n",
" </td>\n",
" <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/matching_engine/sdk_matching_engine_for_indexing.ipynb\">\n",
" <img src=\"https://lh3.googleusercontent.com/UiNooY4LUgW_oTvpsNhPpQzsstV5W8F7rYgxgGBD85cWJoLmrOzhVs_ksK_vgx40SHs7jCqkTkCk=e14-rj-sc0xffffff-h130-w32\" alt=\"Vertex AI logo\">\n",
" Run in Vertex Workbench\n",
" </a>\n",
" </td>\n",
"</table>"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "tvgnzT1CKxrO"
"id": "b0a74aaf1481"
},
"source": [
"## Overview\n",
"\n",
"This example demonstrates how to use the GCP ANN Service. It is a high scale, low latency solution, to find similar vectors (or more specifically \"embeddings\") for a large corpus. Moreover, it is a fully managed offering, further reducing operational overhead. It is built upon [Approximate Nearest Neighbor (ANN) technology](https://ai.googleblog.com/2020/07/announcing-scann-efficient-vector.html) developed by Google Research.\n",
"\n",
"### Dataset\n",
"\n",
"The dataset used for this tutorial is the [GloVe dataset](https://nlp.stanford.edu/projects/glove/).\n",
"\n",
"\"GloVe is an unsupervised learning algorithm for obtaining vector representations for words. Training is performed on aggregated global word-word co-occurrence statistics from a corpus, and the resulting representations showcase interesting linear substructures of the word vector space.\"\n",
"\n",
"This example demonstrates how to use the GCP ANN Service. It is a high scale, low latency solution, to find similar vectors (or more specifically \"embeddings\") for a large corpus. Moreover, it is a fully managed offering, further reducing operational overhead. It is built upon [Approximate Nearest Neighbor (ANN) technology](https://ai.googleblog.com/2020/07/announcing-scann-efficient-vector.html) developed by Google Research."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "34a4b245e795"
},
"source": [
"### Objective\n",
"\n",
"In this notebook, you will learn how to create Approximate Nearest Neighbor (ANN) Index, query against indexes, and validate the performance of the index. \n",
@@ -72,9 +79,28 @@
"* Create an IndexEndpoint with VPC Network\n",
"* Deploy ANN Index and Brute Force Index\n",
"* Perform online query\n",
"* Compute recall\n",
"* Compute recall\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "tvgnzT1CKxrO"
},
"source": [
"### Dataset\n",
"\n",
"The dataset used for this tutorial is the [GloVe dataset](https://nlp.stanford.edu/projects/glove/).\n",
"\n",
"\"GloVe is an unsupervised learning algorithm for obtaining vector representations for words. Training is performed on aggregated global word-word co-occurrence statistics from a corpus, and the resulting representations showcase interesting linear substructures of the word vector space.\"\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "5e2eba58ad71"
},
"source": [
"### Costs \n",
"\n",
"This tutorial uses billable components of Google Cloud:\n",
@@ -89,21 +115,14 @@
"to generate a cost estimate based on your projected usage."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "S5zc4kbEiYCm"
},
"source": [
"## Before you begin"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "d1e95a984673"
},
"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",
@@ -168,18 +187,7 @@
"metadata": {
"id": "3e2b43c2d2bf"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Your browser has been opened to visit:\n",
"\n",
" https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=32555940559.apps.googleusercontent.com&redirect_uri=http%3A%2F%2Flocalhost%3A8085%2F&scope=openid+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloud-platform+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fappengine.admin+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fsqlservice.login+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcompute+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Faccounts.reauth&state=UY9jjYfhoSedWWUOWXp5Pmicq0Ic04&access_type=offline&code_challenge=OQefcewSwkT7ZwfzzOVidtngvZspdY1NgN6rltw8x7A&code_challenge_method=S256\n",
"\n"
]
}
],
"outputs": [],
"source": [
"import os\n",
"import sys\n",
@@ -219,19 +227,11 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"metadata": {
"id": "beb72f394541"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Project ID: python-docs-samples-tests\n"
]
}
],
"outputs": [],
"source": [
"import os\n",
"\n",
File diff suppressed because it is too large Load Diff
@@ -32,17 +32,24 @@
"# Vertex AI: Vertex AI Migration: AutoML Text Sentiment Analysis\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/UJ8%20Vertex%20SDK%20AutoML%20Text%20Sentiment%20Analysis.ipynb\">\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/migration/UJ8 Vertex SDK AutoML Text Sentiment Analysis.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/UJ8%20Vertex%20SDK%20AutoML%20Text%20Sentiment%20Analysis.ipynb\">\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/migration/UJ8 Vertex SDK AutoML Text Sentiment Analysis.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",
" <td>\n",
" <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/migration/UJ8 Vertex SDK AutoML Text Sentiment Analysis.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>\n",
"<br/><br/><br/>"
]
@@ -169,8 +176,7 @@
},
"outputs": [],
"source": [
"if os.getenv(\"IS_TESTING\"):\n",
" ! pip3 install --upgrade tensorflow $USER_FLAG"
"! pip3 install --upgrade tensorflow $USER_FLAG"
]
},
{
@@ -29,21 +29,23 @@
"id": "JAPoU8Sm5E6e"
},
"source": [
"# Vertex AI: Track parameters and metrics for custom training jobs\n",
"\n",
"<table align=\"left\">\n",
"\n",
" <td>\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/master/notebooks/official/ml_metadata/sdk-metric-parameter-tracking-for-custom-jobs.ipynb\">\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/ml_metadata/sdk-metric-parameter-tracking-for-custom-jobs.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/vertex-ai-samples/blob/master/notebooks/official/ml_metadata/sdk-metric-parameter-tracking-for-custom-jobs.ipynb\">\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/ml_metadata/sdk-metric-parameter-tracking-for-custom-jobs.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",
" <td>\n",
" <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/ml_metadata/sdk-metric-parameter-tracking-for-custom-jobs.ipynb\">\n",
" <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://github.com/GoogleCloudPlatform/vertex-ai-samples/main/notebooks/official/ml_metadata/sdk-metric-parameter-tracking-for-custom-jobs.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",
@@ -51,15 +53,6 @@
"</table>"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "j9gUDU_3vV9d"
},
"source": [
"# Vertex AI: Track parameters and metrics for custom training jobs"
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -29,6 +29,8 @@
"id": "JAPoU8Sm5E6e"
},
"source": [
"# Deploy BiqQuery ML Model on Vertex AI Model Registry and make predictions\n",
"\n",
"<table align=\"left\">\n",
"\n",
" <td>\n",
@@ -43,7 +45,7 @@
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://raw.githubusercontent.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/model-registry/bqml-vertexai-model-registry.ipynb\" target=\"_blank\">\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/model-registry/bqml-vertexai-model-registry.ipynb\" target=\"_blank\">\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",
@@ -57,11 +59,9 @@
"id": "tvgnzT1CKxrO"
},
"source": [
"# Deploy BiqQuery ML Model on Vertex AI Model Registry and Make Predictions\n",
"\n",
"## Overview\n",
"\n",
"This tutorial demonstrates how to train a model with BigQuery ML and upload it on Vertex AI model registry, then make batch predictions.\n"
"This tutorial demonstrates how to train a model with BigQuery ML and upload it on Vertex AI Model Registry, then make batch predictions.\n"
]
},
{
@@ -77,15 +77,13 @@
"This tutorial uses the following Google Cloud ML services and resources:\n",
"\n",
"- `Vertex AI Model Registry`\n",
"- `Vertex AI Model` resources \n",
"- `Vertex AI Endpoint` resources\n",
"- `Vertex AI Prediction`\n",
"- `BigQuery ML`\n",
"\n",
"\n",
"The steps performed include:\n",
"\n",
"- Train a model with `BQML`\n",
"- Train a model with `BigQuery ML`\n",
"- Upload the model to `Vertex AI Model Registry` \n",
"- Create a `Vertex AI Endpoint` resource\n",
"- Deploy the `Model` resource to the `Endpoint` resource\n",
@@ -132,15 +130,7 @@
"### 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": [
"all the requirements to run this notebook. You can skip this step.\n",
"**Otherwise**, make sure your environment meets this notebook's requirements.\n",
"You need the following:\n",
"\n",
@@ -185,7 +175,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {
"id": "2b4ef9b72d43"
},
@@ -204,8 +194,7 @@
"if IS_WORKBENCH_NOTEBOOK:\n",
" USER_FLAG = \"--user\"\n",
"\n",
"! pip3 install --upgrade google-cloud-aiplatform {USER_FLAG} -q\n",
"! pip3 install --upgrade google-cloud-bigquery {USER_FLAG} -q"
"! pip3 install --upgrade google-cloud-aiplatform google-cloud-bigquery pyarrow {USER_FLAG} -q"
]
},
{
@@ -393,15 +382,7 @@
"### 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",
"**If you are using Colab**, run the cell below and follow the instructions\n",
"when prompted to authenticate your account via oAuth.\n",
"\n",
@@ -543,15 +524,7 @@
"id": "PKQD2e0eMg3M"
},
"source": [
"### Create BigQuery dataset resource"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "BnXOpvs2MmzF"
},
"source": [
"### Create BigQuery dataset resource\n",
"First, you create an empty dataset resource in your project."
]
},
@@ -566,17 +539,7 @@
"BQ_DATASET_NAME = \"penguins\" + UUID\n",
"DATASET_QUERY = f\"\"\"CREATE SCHEMA {BQ_DATASET_NAME}\"\"\"\n",
"\n",
"job = bqclient.query(DATASET_QUERY)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "59bf85366baf"
},
"outputs": [],
"source": [
"job = bqclient.query(DATASET_QUERY)\n",
"job.result()\n",
"print(job.state)"
]
@@ -588,7 +551,7 @@
},
"source": [
"## Train BigQuery ML model and upload it to Vertex AI Model Registry\n",
"Next, you create and train a BQML tabular regression model from the public dataset penguins and store the model in your project `Vertex AI Model Registry` using the `CREATE MODEL` statement. The model configuration is specified in the `OPTIONS` statement as follows:\n",
"Next, you create and train a `BigQuery ML` tabular regression model from the public dataset penguins and store the model in your project `Vertex AI Model Registry` using the `CREATE MODEL` statement. The model configuration is specified in the `OPTIONS` statement as follows:\n",
"\n",
"- `model_type`: The type and archictecture of tabular model to train, e.g., LOGISTIC_REG.\n",
"\n",
@@ -631,6 +594,7 @@
"id": "eee158e2a375"
},
"source": [
"### Create BigQuery ML Model\n",
"Create the BigQuery ML model using the query above and the BigQuery client that you created previously:"
]
},
@@ -805,15 +769,7 @@
"id": "C39qOaBHZI1G"
},
"source": [
"## Batch Prediction on the BQML model"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "UBffk3GyaPY3"
},
"source": [
"## Batch Prediction on the BigQuery ML model\n",
"Here you request batch predictions directly from the BigQuery ML model; you don't need to deploy the model to an endpoint. For data types that support both batch and online predictions, use batch predictions when you don't require an immediate response and want to process accumulated data by using a single request.\n",
"\n",
"Learn more abount <a href=\"https://cloud.google.com/bigquery-ml/docs/reference/standard-sql/bigqueryml-syntax-predict\" target=\"_blank\">The ML.PREDICT function</a>"
Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

@@ -45,7 +45,7 @@
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooksofficial/pipelines/custom_model_training_and_batch_prediction.ipynb\">\n",
" <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://raw.githubusercontent.com/GoogleCloudPlatform/vertex-ai-samples/main/notebooksofficial/pipelines/custom_model_training_and_batch_prediction.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",
@@ -38,13 +38,13 @@
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/notebooks/blob/master/official/pipelines/google_cloud_pipeline_components_model_upload_predict_evaluate.ipynb\">\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/notebooks/blob/main/official/pipelines/google_cloud_pipeline_components_model_upload_predict_evaluate.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",
" <td>\n",
" <a href=\"https://console.cloud.google.com/ai/platform/notebooks/deploy-notebook?download_url=https://github.com/GoogleCloudPlatform/vertex-ai-samples/notebooks/blob/master/official/pipelines/google_cloud_pipeline_components_model_upload_predict_evaluate.ipynb\">\n",
" <a href=\"https://console.cloud.google.com/ai/platform/notebooks/deploy-notebook?download_url=https://github.com/GoogleCloudPlatform/vertex-ai-samples/notebooks/blob/main/official/pipelines/google_cloud_pipeline_components_model_upload_predict_evaluate.ipynb\"><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",
@@ -63,19 +63,6 @@
"This notebook shows how to use the components defined in [`google_cloud_pipeline_components`](https://github.com/kubeflow/pipelines/tree/master/components/google-cloud) in conjunction with an experimental `evaluation` method, to build a [Vertex AI Pipelines](https://cloud.google.com/vertex-ai/docs/pipelines) workflow that uploads a tabular custom model as a `Model` resource, creates a `BatchPredictionJob` resource, and evaluates the `Model` resource with the `BatchPredictionJob` results to create an evaluation `system.Metrics` artifact."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dataset:bikes_weather,lrg"
},
"source": [
"### Dataset\n",
"\n",
"The dataset used for this tutorial is part of the [safe driver prediction Kaggle competition](https://www.kaggle.com/c/porto-seguro-safe-driver-prediction/overview). The model has been trained on this data, and ground truth will be used for evaluation.\n",
"\n",
"The dataset predicts the whether or not a claim was filed for the policy holder."
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -86,6 +73,12 @@
"\n",
"In this tutorial, you evaluate a custom model using a pipeline with components from `google_cloud_pipeline_components` and a custom pipeline component you build.\n",
"\n",
"This tutorial uses the following Google Cloud ML services and resources:\n",
"\n",
"- Vertex AI Pipelines\n",
"- Vertex AI Model Registry\n",
"- Vertex AI Batch Prediction\n",
"\n",
"The steps performed include:\n",
"\n",
"- Upload a pre-trained model as a `Model` resource.\n",
@@ -94,6 +87,19 @@
"- Compare the evaluation metrics to a threshold.\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dataset:bikes_weather,lrg"
},
"source": [
"### Dataset\n",
"\n",
"The dataset used for this tutorial is part of the [safe driver prediction Kaggle competition](https://www.kaggle.com/c/porto-seguro-safe-driver-prediction/overview). The model has been trained on this data, and ground truth is used for evaluation.\n",
"\n",
"The dataset predicts the whether or not a claim was filed for the policy holder."
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -122,29 +128,38 @@
"source": [
"### Set up your local development environment\n",
"\n",
"If you are using Colab or Google Cloud Notebook, 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.\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](Ihttps://cloud.google.com/python/setup#installing_and_using_virtualenv) and create a virtual environment that uses Python 3.\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. Activate that environment and run `pip3 install Jupyter` in a terminal shell to install Jupyter.\n",
"1. To install Jupyter, run `pip3 install jupyter` on the\n",
"command-line in a terminal shell.\n",
"\n",
"5. Run `jupyter notebook` on the command line in a terminal shell to launch Jupyter.\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."
]
},
{
@@ -155,7 +170,7 @@
"source": [
"## Installation\n",
"\n",
"Install the latest version of Vertex AI SDK for Python."
"Install the latest version of Vertex AI and google-cloud-pipeline-components SDK for Python."
]
},
{
@@ -168,34 +183,21 @@
"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_gcpc"
},
"source": [
"Install the latest GA version of *google-cloud-pipeline-components* library as well."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "wJkgLcdCBfb8"
},
"outputs": [],
"source": [
"! pip3 install --upgrade google-cloud-pipeline-components $USER_FLAG\n",
"! pip3 install --upgrade kfp $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",
"\n",
"! pip3 install --upgrade google-cloud-aiplatform \\\n",
" google-cloud-pipeline-components \\\n",
" kfp $USER_FLAG -q"
]
},
{
@@ -206,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."
]
},
{
@@ -217,6 +219,7 @@
},
"outputs": [],
"source": [
"# Automatically restart kernel after installs\n",
"import os\n",
"\n",
"if not os.getenv(\"IS_TESTING\"):\n",
@@ -233,6 +236,8 @@
"id": "check_versions"
},
"source": [
"### Check package versions\n",
"\n",
"Check the versions of the packages you installed. "
]
},
@@ -248,34 +253,48 @@
"! python3 -c \"import google_cloud_pipeline_components; print('google_cloud_pipeline_components version: {}'.format(google_cloud_pipeline_components.__version__))\""
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "d6a00c14b087"
},
"source": [
"## Before you begin"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "before_you_begin:nogpu"
},
"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 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 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",
"\n",
"4. [The Google Cloud SDK](https://cloud.google.com/sdk) is already installed in Google Cloud Notebook.\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": "50756f65354f"
},
"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`."
]
},
{
@@ -324,7 +343,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",
@@ -332,7 +351,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)."
]
},
{
@@ -343,7 +362,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\""
]
},
{
@@ -352,9 +374,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."
]
},
{
@@ -365,9 +387,16 @@
},
"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()"
]
},
{
@@ -378,23 +407,31 @@
"source": [
"### Authenticate your Google Cloud account\n",
"\n",
"**If you are using Google Cloud Notebook**, 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",
"**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."
]
},
{
@@ -413,8 +450,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",
@@ -450,7 +490,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}\""
]
},
{
@@ -461,8 +502,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}\""
]
},
{
@@ -482,7 +524,7 @@
},
"outputs": [],
"source": [
"! gsutil mb -l $REGION $BUCKET_NAME"
"! gsutil mb -l $REGION -p $PROJECT_ID $BUCKET_URI"
]
},
{
@@ -502,7 +544,7 @@
},
"outputs": [],
"source": [
"! gsutil ls -al $BUCKET_NAME"
"! gsutil ls -al $BUCKET_URI"
]
},
{
@@ -511,9 +553,11 @@
"id": "set_service_account"
},
"source": [
"#### Service Account\n",
"### Service Account\n",
"\n",
"**If you don't know your service account**, try to get your service account using `gcloud` command by executing the second cell below."
"You use a service account to create Vertex AI Pipeline jobs.\n",
"\n",
"If you do not want to use your project's Compute Engine service account, set `SERVICE_ACCOUNT` to another service account ID."
]
},
{
@@ -540,23 +584,19 @@
" or SERVICE_ACCOUNT is None\n",
" or SERVICE_ACCOUNT == \"[your-service-account]\"\n",
"):\n",
" # Get your GCP project id from gcloud\n",
" shell_output = !gcloud auth list 2>/dev/null\n",
" SERVICE_ACCOUNT = shell_output[2].replace(\"*\", \"\").strip()\n",
" # Get your service account from gcloud\n",
" if not IS_COLAB:\n",
" shell_output = !gcloud auth list 2>/dev/null\n",
" SERVICE_ACCOUNT = shell_output[2].replace(\"*\", \"\").strip()\n",
"\n",
" else: # IS_COLAB:\n",
" shell_output = ! gcloud projects describe $PROJECT_ID\n",
" project_number = shell_output[-1].split(\":\")[1].strip().replace(\"'\", \"\")\n",
" SERVICE_ACCOUNT = f\"{project_number}-compute@developer.gserviceaccount.com\"\n",
"\n",
" print(\"Service Account:\", SERVICE_ACCOUNT)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "9ca2fb92cb31"
},
"outputs": [],
"source": [
"shell_output[2].replace(\"*\", \"\").strip()"
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -576,9 +616,9 @@
},
"outputs": [],
"source": [
"! gsutil iam ch serviceAccount:{SERVICE_ACCOUNT}:roles/storage.objectCreator $BUCKET_NAME\n",
"! gsutil iam ch serviceAccount:{SERVICE_ACCOUNT}:roles/storage.objectCreator $BUCKET_URI\n",
"\n",
"! gsutil iam ch serviceAccount:{SERVICE_ACCOUNT}:roles/storage.objectViewer $BUCKET_NAME"
"! gsutil iam ch serviceAccount:{SERVICE_ACCOUNT}:roles/storage.objectViewer $BUCKET_URI"
]
},
{
@@ -587,9 +627,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"
]
},
@@ -601,7 +638,17 @@
},
"outputs": [],
"source": [
"import google.cloud.aiplatform as aip\n",
"import kfp\n",
"from google.cloud import aiplatform\n",
"from google_cloud_pipeline_components.experimental.evaluation import \\\n",
" ModelEvaluationOp as evaluation_op\n",
"from google_cloud_pipeline_components.types import artifact_types\n",
"from google_cloud_pipeline_components.v1.batch_predict_job import \\\n",
" ModelBatchPredictOp as batch_prediction_op\n",
"from google_cloud_pipeline_components.v1.model import \\\n",
" ModelUploadOp as model_upload_op\n",
"from kfp.v2 import compiler\n",
"from kfp.v2.components import importer_node\n",
"from kfp.v2.dsl import Input, Metrics, component"
]
},
@@ -611,8 +658,6 @@
"id": "pipeline_constants"
},
"source": [
"#### Vertex AI Pipelines constants\n",
"\n",
"Setup up the following constant for Vertex AI Pipelines:"
]
},
@@ -624,7 +669,7 @@
},
"outputs": [],
"source": [
"PIPELINE_ROOT = \"{}/pipeline_root/safe_driver\".format(BUCKET_NAME)"
"PIPELINE_ROOT = \"{}/pipeline_root/safe_driver\".format(BUCKET_URI)"
]
},
{
@@ -633,7 +678,7 @@
"id": "init_aip:mbsdk"
},
"source": [
"## Initialize Vertex AI SDK for Python\n",
"### Initialize Vertex AI SDK for Python\n",
"\n",
"Initialize the Vertex AI SDK for Python for your project and corresponding bucket."
]
@@ -646,7 +691,7 @@
},
"outputs": [],
"source": [
"aip.init(project=PROJECT_ID, staging_bucket=BUCKET_NAME, location=REGION)"
"aiplatform.init(project=PROJECT_ID, staging_bucket=BUCKET_URI, location=REGION)"
]
},
{
@@ -657,7 +702,7 @@
"source": [
"## Create component for comparing evalution metrics to a threshold\n",
"\n",
"First, you create your own component that will take as input the evaluation metrics artifact and make a comparison to a threshold and return a yes/no decision that could be used in a subsequent dsl.Condition() to decide whether the model should proceed to the next step -- e.g., online deployment.\n",
"First, you create your own component that takes the evaluation metrics artifact as input, checks the threshold and return yes/no decision. It is used in a subsequent dsl.Condition() to decide whether the model should proceed to the next step i.e., online deployment.\n",
"\n",
"The component takes the following parameters:\n",
"\n",
@@ -690,7 +735,6 @@
" data = json.load(f)\n",
"\n",
" slices = data[\"slicedMetrics\"]\n",
" # print(\"# slices\", len(slices))\n",
"\n",
" metrics = slices[0][\"metrics\"][\"classification\"]\n",
" # print(\"METRIC KEYS\", metrics.keys())\n",
@@ -712,7 +756,7 @@
"\n",
"Next, define the pipeline.\n",
"\n",
"Then, [`google_cloud_pipeline_components`](https://github.com/kubeflow/pipelines/tree/master/components/google-cloud) components are used to define the rest of the pipeline: upload the model, run batch prediction, and evaluate the model with the given predictions.\n",
"[`google_cloud_pipeline_components`](https://github.com/kubeflow/pipelines/tree/master/components/google-cloud) components used to define the pipeline are: upload the model, run batch prediction, and evaluate the model with the given predictions.\n",
"\n",
"View the definition of the [upload model component](https://github.com/kubeflow/pipelines/blob/master/components/google-cloud/google_cloud_pipeline_components/aiplatform/model/upload_model/component.yaml).\n",
"\n",
@@ -729,27 +773,17 @@
},
"outputs": [],
"source": [
"import kfp\n",
"from google_cloud_pipeline_components.experimental.evaluation import \\\n",
" ModelEvaluationOp as evaluation_op\n",
"from google_cloud_pipeline_components.types import artifact_types\n",
"from google_cloud_pipeline_components.v1.batch_predict_job import \\\n",
" ModelBatchPredictOp as batch_prediction_op\n",
"from google_cloud_pipeline_components.v1.model import \\\n",
" ModelUploadOp as model_upload_op\n",
"from kfp.v2.components import importer_node\n",
"\n",
"DATA_URIS = [\n",
" \"gs://cloud-samples-data/vertex-ai/dataset-management/datasets/safe_driver/dataset_safe_driver_train_10k.csv\"\n",
"]\n",
"MODEL_URI = \"gs://cloud-samples-data/vertex-ai/google-cloud-aiplatform-ci-artifacts/models/safe_driver/model\"\n",
"# Create working dir\n",
"WORKING_DIR = f\"{PIPELINE_ROOT}/{TIMESTAMP}\"\n",
"MODEL_DISPLAY_NAME = f\"safe-driver-{TIMESTAMP}\"\n",
"BATCH_PREDICTION_DISPLAY_NAME = f\"batch-prediction-on-pipelines-model-{TIMESTAMP}\"\n",
"WORKING_DIR = f\"{PIPELINE_ROOT}/{UUID}\"\n",
"MODEL_DISPLAY_NAME = f\"safe-driver-{UUID}\"\n",
"BATCH_PREDICTION_DISPLAY_NAME = f\"batch-prediction-on-pipelines-model-{UUID}\"\n",
"\n",
"\n",
"@kfp.dsl.pipeline(name=\"upload-evaluate-\" + TIMESTAMP)\n",
"@kfp.dsl.pipeline(name=\"upload-evaluate-\" + UUID)\n",
"def pipeline(\n",
" metric: str,\n",
" threshold: float,\n",
@@ -829,8 +863,6 @@
},
"outputs": [],
"source": [
"from kfp.v2 import compiler # noqa: F811\n",
"\n",
"compiler.Compiler().compile(\n",
" pipeline_func=pipeline,\n",
" package_path=\"evaluation_demo_pipeline.json\",\n",
@@ -856,9 +888,9 @@
},
"outputs": [],
"source": [
"DISPLAY_NAME = \"safe_driver\" + TIMESTAMP\n",
"DISPLAY_NAME = \"safe_driver\" + UUID\n",
"\n",
"job = aip.PipelineJob(\n",
"job = aiplatform.PipelineJob(\n",
" display_name=DISPLAY_NAME,\n",
" template_path=\"evaluation_demo_pipeline.json\",\n",
" pipeline_root=PIPELINE_ROOT,\n",
@@ -879,7 +911,7 @@
"source": [
"Click on the generated link to see your run in the Cloud Console.\n",
"\n",
"In the UI, many of the pipeline DAG nodes will expand or collapse when you click on them."
"In the UI, the nodes of pipeline DAG expand or collapse when you click on them."
]
},
{
@@ -984,7 +1016,7 @@
"id": "delete_pipeline"
},
"source": [
"### Delete a pipeline job\n",
"### Delete pipeline job\n",
"\n",
"After a pipeline job is completed, you can delete the pipeline job with the method `delete()`. Prior to completion, a pipeline job can be canceled with the method `cancel()`."
]
@@ -1006,16 +1038,16 @@
"id": "cleanup:pipelines"
},
"source": [
"# Cleaning up\n",
"## Cleaning up\n",
"\n",
"To clean up all Google Cloud resources used in this project, you can [delete the Google Cloud\n",
"project](https://cloud.google.com/resource-manager/docs/creating-managing-projects#shutting_down_projects) you used for the tutorial.\n",
"\n",
"Otherwise, you can delete the individual resources you created in this tutorial -- *Note:* this is auto-generated and not all resources may be applicable for this tutorial:\n",
"Otherwise, you can delete the individual resources you created in this tutorial.\n",
"\n",
"- Model\n",
"- Batch Job\n",
"- Cloud Storage Bucket"
"- Cloud Storage Bucket (Set `delete_bucket` to **True** to delete the Cloud Storage bucket)."
]
},
{
@@ -1026,35 +1058,30 @@
},
"outputs": [],
"source": [
"delete_model = True\n",
"delete_batchjob = True\n",
"delete_bucket = True\n",
"delete_bucket = False\n",
"\n",
"try:\n",
" if delete_model and \"MODEL_DISPLAY_NAME\" in globals():\n",
" models = aip.Model.list(\n",
" filter=f\"display_name={MODEL_DISPLAY_NAME}\", order_by=\"create_time\"\n",
" )\n",
" model = models[0]\n",
" aip.Model.delete(model)\n",
" print(\"Deleted model:\", model)\n",
"except Exception as e:\n",
" print(e)\n",
"# Delete the created model\n",
"models = aiplatform.Model.list(\n",
" filter=f\"display_name={MODEL_DISPLAY_NAME}\", order_by=\"create_time\"\n",
")\n",
"if len(models) > 0:\n",
" model = models[0]\n",
" model.delete()\n",
" print(\"Deleted model:\", model)\n",
"\n",
"try:\n",
" if delete_batchjob and \"BATCH_PREDICTION_DISPLAY_NAME\" in globals():\n",
" batch_predictions = aip.BatchPredictionJob.list(\n",
" filter=f\"display_name={BATCH_PREDICTION_DISPLAY_NAME}\",\n",
" order_by=\"create_time\",\n",
" )\n",
" batch_prediction = batch_predictions[0]\n",
" aip.BatchPredictionJob.delete(batch_prediction)\n",
" print(\"Deleted batch prediction job:\", batch_prediction)\n",
"except Exception as e:\n",
" print(e)\n",
"# Delete the created batch-prediction job\n",
"batch_predictions = aiplatform.BatchPredictionJob.list(\n",
" filter=f\"display_name={BATCH_PREDICTION_DISPLAY_NAME}\",\n",
" order_by=\"create_time\",\n",
")\n",
"if len(batch_predictions) > 0:\n",
" batch_prediction = batch_predictions[0]\n",
" batch_prediction.delete()\n",
" print(\"Deleted batch prediction job:\", batch_prediction)\n",
"\n",
"if delete_bucket and \"BUCKET_NAME\" in globals():\n",
" ! gsutil rm -r $BUCKET_NAME"
"# Delete the Cloud Storage bucket\n",
"if delete_bucket or os.getenv(\"IS_TESTING\"):\n",
" ! gsutil -m rm -r $BUCKET_URI"
]
}
],
@@ -29,7 +29,7 @@
"id": "_uIhhWEZdcBb"
},
"source": [
"# Vertex SDK for Python: Custom training using Python package, managed text dataset, and TF Serving container\n",
"# Vertex AI SDK for Python: Custom training using Python package, managed text dataset, and TF Serving container\n",
"<table align=\"left\">\n",
"\n",
" <td>\n",
@@ -60,20 +60,30 @@
"source": [
"## Overview\n",
"\n",
"This notebook demonstrates how to create a Custom Model using Custom Python Package Training, with a Vertex AI Dataset, and how to serve the model using Tensorflow-Serving Container for online prediction, and batch prediction. It will require you provide a bucket where the dataset will be stored.\n",
"This notebook demonstrates how to create a Custom Model using Custom Python Package Training, with a Vertex AI Dataset, and how to serve the model using TensorFlow-Serving Container for online prediction, and batch prediction. It requires you to provide a bucket where the dataset will be stored.\n",
"\n",
"Note: You may incur charges for training, prediction, storage or usage of other GCP products in connection with testing this SDK.\n",
"Note: You may incur charges for training, prediction, storage or usage of other GCP products in connection with testing this SDK.\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "bb0a1d001978"
},
"source": [
"### Objective\n",
"\n",
"## Dataset\n",
"#### Stack Overflow Data\n",
"You download the stack overflow data from from https://storage.googleapis.com/download.tensorflow.org/data/stack_overflow_16k.tar.gz and will create a Vertex AI managed text dataset. \n",
"In this tutorial you learn how to create a Custom Model using Custom Python Package Training and you learn how to serve the model using TensorFlow-Serving Container for online prediction. Then you perform batch prediction on the model. \n",
"\n",
"The Stack Overflow Data is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/ \n",
"This tutorial uses the following Google Cloud ML services and resources:\n",
"\n",
"For more information about this dataset please visit: https://console.cloud.google.com/marketplace/details/stack-exchange/stack-overflow\n",
"- `Vertex AI Dataset`\n",
"- `Veretx AI CustomPythonPackageTrainingJob`\n",
"- `Vertex AI Model` resource\n",
"- `Vertex AI Endpoint` resource\n",
"- `Vertex AI Batch Prediction`\n",
"\n",
"\n",
"## Objective\n",
"The steps performed include:\n",
"\n",
"- Create utility functions to download data and prepare csv files for creating Vertex AI Managed Dataset\n",
"- Download Data\n",
@@ -83,8 +93,31 @@
"- Run Custom Python Package Training with Managed Text Dataset\n",
"- Deploy a Model and Create an Endpoint on Vertex AI\n",
"- Predict on the Endpoint\n",
"- Create a Batch Prediction Job on the Model\n",
"## Costs \n",
"- Create a Batch Prediction Job on the Model"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "63b0c33d2b8c"
},
"source": [
"### Dataset\n",
"#### Stack Overflow Data\n",
"You download the stack overflow data from from https://storage.googleapis.com/download.tensorflow.org/data/stack_overflow_16k.tar.gz and create a Vertex AI managed text dataset. \n",
"\n",
"The Stack Overflow Data is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/ \n",
"\n",
"For more information about this dataset please visit: https://console.cloud.google.com/marketplace/details/stack-exchange/stack-overflow"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "c9a87c7a200c"
},
"source": [
"### Costs \n",
"\n",
"\n",
"This tutorial uses billable components of Google Cloud:\n",
@@ -103,21 +136,14 @@
{
"cell_type": "markdown",
"metadata": {
"id": "b82b8a653933"
"id": "306eb9fb5ac7"
},
"source": [
"### Set up your local development environment\n",
"\n",
"**If you are using Colab or Vertex AI Workbench**, your environment already meets\n",
"all the requirements to run this notebook. You can skip this step."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "306eb9fb5ac7"
},
"source": [
"**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",
@@ -155,7 +181,9 @@
"id": "xOMNWzTbftDr"
},
"source": [
"### Install additional packages\n"
"## Installation\n",
"\n",
"Install the following packages required to execute this notebook. "
]
},
{
@@ -168,23 +196,17 @@
"source": [
"import os\n",
"\n",
"# The Google Cloud Notebook product has specific requirements\n",
"IS_GOOGLE_CLOUD_NOTEBOOK = os.path.exists(\"/opt/deeplearning/metadata/env_version\")\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",
"# Google Cloud Notebook requires dependencies to be installed with '--user'\n",
"# Vertex AI Notebook requires dependencies to be installed with '--user'\n",
"USER_FLAG = \"\"\n",
"if IS_GOOGLE_CLOUD_NOTEBOOK:\n",
" USER_FLAG = \"--user\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "Be020jY-ftDv"
},
"outputs": [],
"source": [
"if IS_WORKBENCH_NOTEBOOK:\n",
" USER_FLAG = \"--user\"\n",
"\n",
"! pip3 install --upgrade google-cloud-aiplatform tensorflow {USER_FLAG} -q"
]
},
@@ -218,21 +240,14 @@
" app.kernel.do_shutdown(True)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "e4f3be5c2830"
},
"source": [
"## Before you begin"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "af017a0645ea"
},
"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",
@@ -241,9 +256,9 @@
"\n",
"1. [Make sure that billing is enabled for your project](https://cloud.google.com/billing/docs/how-to/modify-project).\n",
"\n",
"1. [Enable the Vertex AI API](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com). {TODO: Update the APIs needed for your tutorial. Edit the API names, and update the link to append the API IDs, separating each one with a comma. For example, container.googleapis.com,cloudbuild.googleapis.com}\n",
"1. [Enable the Vertex AI API](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com). \n",
"\n",
"1. 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",
"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",
@@ -270,36 +285,22 @@
},
"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",
"metadata": {
"id": "244af163f3e3"
},
"source": [
"Otherwise, set your project ID here."
"PROJECT_ID = \"[your-project-id]\" # @param {type:\"string\"}"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "547d93dfcc7d"
"id": "5bf9979b96ff"
},
"outputs": [],
"source": [
"if PROJECT_ID == \"\" or PROJECT_ID is None:\n",
" PROJECT_ID = \"[your-project-id]\" # @param {type:\"string\"}"
"if PROJECT_ID == \"\" or PROJECT_ID is None or PROJECT_ID == \"[your-project-id]\":\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)"
]
},
{
@@ -313,15 +314,49 @@
"! gcloud config set project $PROJECT_ID"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "9658ecf524b1"
},
"source": [
"#### 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. It is recommended that you choose the region closest to you.\n",
"\n",
"- Americas: `us-central1`\n",
"- Europe: `europe-west4`\n",
"- Asia Pacific: `asia-east1`\n",
"\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)."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "5c615e53149f"
},
"outputs": [],
"source": [
"REGION = \"[your-region]\" # @param {type: \"string\"}\n",
"\n",
"if REGION == \"[your-region]\":\n",
" REGION = \"us-central1\""
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "e663bd062c6f"
},
"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 it 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."
]
},
{
@@ -332,41 +367,16 @@
},
"outputs": [],
"source": [
"from datetime import datetime\n",
"import random\n",
"import string\n",
"\n",
"TIMESTAMP = datetime.now().strftime(\"%Y%m%d%H%M%S\")"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "b468c1ba2051"
},
"source": [
"#### Declare IS_COLAB variable"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "f5ad5d370123"
},
"outputs": [],
"source": [
"IS_COLAB = False"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "870777863e09"
},
"source": [
"### Authenticate your Google Cloud account\n",
"\n",
"**If you are using Vertex AI Workbench**, your environment is already\n",
"authenticated. Skip this step."
"# 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()"
]
},
{
@@ -375,6 +385,11 @@
"id": "378e70541ba9"
},
"source": [
"### Authenticate your Google Cloud account\n",
"\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\n",
"when prompted to authenticate your account via oAuth.\n",
"\n",
@@ -415,10 +430,12 @@
"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",
" IS_COLAB = True\n",
" from google.colab import auth as google_auth\n",
"\n",
" google_auth.authenticate_user()\n",
@@ -427,7 +444,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]'"
]
},
{
@@ -442,12 +459,15 @@
"\n",
"\n",
"\n",
"Set the name of your Cloud Storage bucket below. It must be unique across all\n",
"Cloud Storage buckets.\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",
"create Vertex AI model and endpoint resources in order to serve\n",
"online predictions.\n",
"\n",
"You may also change the `REGION` variable, which is used for operations\n",
"throughout the rest of this notebook. We suggest that you [choose a region where Vertex AI services are\n",
"available](https://cloud.google.com/vertex-ai/docs/general/locations#available_regions)."
"Set the name of your Cloud Storage bucket below. It must be unique across all\n",
"Cloud Storage buckets."
]
},
{
@@ -458,29 +478,27 @@
},
"outputs": [],
"source": [
"BUCKET_URI = \"gs://[your-bucket-name]\" # @param {type:\"string\"}\n",
"REGION = \"[your-region]\" # @param {type:\"string\"}"
"BUCKET_NAME = \"[your-bucket-name]\" # @param {type:\"string\"}\n",
"BUCKET_URI = f\"gs://{BUCKET_NAME}\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "ff28800dc2f8"
"id": "219a24ea078b"
},
"outputs": [],
"source": [
"if BUCKET_URI == \"\" or BUCKET_URI is None or BUCKET_URI == \"gs://[your-bucket-name]\":\n",
" BUCKET_URI = \"gs://\" + PROJECT_ID + \"aip-\" + TIMESTAMP\n",
"\n",
"if REGION == \"[your-region]\":\n",
" REGION = \"us-central1\""
"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}\""
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "58cb4f5895f0"
"id": "a8a62bec0259"
},
"source": [
"**Only if your bucket doesn't already exist**: Run the following cell to create your Cloud Storage bucket."
@@ -490,7 +508,7 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "5e1288505682"
"id": "91c46850b49b"
},
"outputs": [],
"source": [
@@ -500,7 +518,7 @@
{
"cell_type": "markdown",
"metadata": {
"id": "c664a5abc11a"
"id": "4e69d430073b"
},
"source": [
"Finally, validate access to your Cloud Storage bucket by examining its contents:"
@@ -510,7 +528,7 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "f004d00a7000"
"id": "835eaacd691f"
},
"outputs": [],
"source": [
@@ -776,7 +794,7 @@
"\n",
"Before you can perform custom training with a pre-built container, you must create a [Python Source Distribution](https://docs.python.org/3/distutils/sourcedist.html) that contains your training application and upload it to a Cloud Storage bucket that your Google Cloud project can access.\n",
"\n",
"You will create a directory and write all of our package build artifacts into that folder."
"You create a directory and write all of our package build artifacts into that folder."
]
},
{
@@ -1116,15 +1134,6 @@
"# Create TensorFlow Serving container"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "IH_NAgsaPSij"
},
"source": [
"Create a tag for registering the image and register the image with Cloud Container Registry (gcr.io)."
]
},
{
"cell_type": "code",
"execution_count": null,
@@ -1136,35 +1145,6 @@
"TF_SERVING_CONTAINER_IMAGE_URI = f\"gcr.io/{PROJECT_ID}/tf-serving\""
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "cef092520476"
},
"source": [
"Configure docker authentication with Container Registry\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "7d5e234cecab"
},
"outputs": [],
"source": [
"! gcloud auth configure-docker gcr.io --quiet"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "aGIs4XJ3QFdE"
},
"source": [
"Executes in Vertex AI Workbench"
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -1183,12 +1163,41 @@
"outputs": [],
"source": [
"if not IS_COLAB:\n",
" !docker pull tensorflow/serving:latest\n",
" !docker pull tensorflow/serving:2.8.0\n",
"else:\n",
" # install docker daemon\n",
" ! apt-get -qq install docker.io"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "33d70b04763b"
},
"source": [
"Configure docker authentication with Container Registry\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "f729a8ac2c1f"
},
"outputs": [],
"source": [
"! gcloud auth configure-docker gcr.io --quiet"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "b7599a2703e5"
},
"source": [
"Create a tag for registering the image and register the image with Cloud Container Registry (gcr.io)."
]
},
{
"cell_type": "code",
"execution_count": null,
@@ -1198,19 +1207,10 @@
"outputs": [],
"source": [
"if not IS_COLAB:\n",
" !docker tag tensorflow/serving $TF_SERVING_CONTAINER_IMAGE_URI\n",
" !docker tag tensorflow/serving:2.8.0 $TF_SERVING_CONTAINER_IMAGE_URI\n",
" !docker push $TF_SERVING_CONTAINER_IMAGE_URI"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "3GDiMphcNpnb"
},
"source": [
"Executes in Colab\n"
]
},
{
"cell_type": "code",
"execution_count": null,
@@ -1226,8 +1226,8 @@
"set -x\n",
"dockerd -b none --iptables=0 -l warn &\n",
"for i in $(seq 5); do [ ! -S \"/var/run/docker.sock\" ] && sleep 2 || break; done\n",
"docker pull \"tensorflow/serving:latest\"\n",
"docker tag tensorflow/serving $2\n",
"docker pull tensorflow/serving:2.8.0\n",
"docker tag tensorflow/serving:2.8.0 $2\n",
"docker push $2\n",
"kill $(jobs -p)"
]
@@ -1270,7 +1270,7 @@
},
"source": [
"## Create a Vertex AI dataset resource\n",
"You will now create a Vertex AI text dataset using the previously prepared csv files. Choose one of the options below. "
"You create a Vertex AI text dataset using the previously prepared csv files. Choose one of the options below. "
]
},
{
@@ -1291,7 +1291,7 @@
"id": "kyLoUsx9rKok"
},
"source": [
"#### Option 1: Create a dataset with csv file"
"#### Create a dataset with csv file"
]
},
{
@@ -1309,57 +1309,6 @@
")"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "xksBj3M0rKok"
},
"source": [
"#### Option 2: Create a dataset, then import csv file"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "93w8LGlx7uWy"
},
"source": [
"```\n",
"dataset = aiplatform.TextDataset.create(\n",
" display_name=dataset_display_name,\n",
")\n",
"dataset.import_data(\n",
" gcs_source=gcs_source, \n",
" import_schema_uri=aiplatform.schema.dataset.ioformat.text.single_label_classification,\n",
" sync=False\n",
")\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "ncP9QwvkrKok"
},
"source": [
"#### Option 3: Retrieve a dataset on Vertex AI\n",
"If you have previously created a Dataset on Vertex AI, you can retrieve the dataset using the `dataset_name`."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "OmiQDoS_7ncz"
},
"source": [
"```\n",
"dataset_name = 'YOUR DATASET NAME'\n",
"\n",
"dataset = aiplatform.TextDataset(dataset_name)\n",
"dataset.resource_name\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -29,6 +29,8 @@
"id": "eoXf8TfQoVth"
},
"source": [
"# Optimizing multiple objectives with Vertex AI Vizier\n",
"\n",
"<table align=\"left\">\n",
"\n",
" <td>\n",
@@ -43,7 +45,7 @@
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://console.cloud.google.com/vertex-ai/notebooks/deploy-notebook?download_url=https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/pipelines/gapic-vizier-multi-objective-optimization.ipynb\">\n",
" <a href=\"https://console.cloud.google.com/vertex-ai/notebooks/deploy-notebook?download_url=https://github.com/GoogleCloudPlatform/vertex-ai-samples/main/notebooks/official/vizier/gapic-vizier-multi-objective-optimization.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",
@@ -57,9 +59,9 @@
"id": "AksIKBzZ-nre"
},
"source": [
"# Optimizing multiple objectives\n",
"## Overview\n",
"\n",
"This tutorial demonstrates [Vertex Vizier](https://cloud.google.com/vertex-ai/docs/vizier/overview) multi-objective optimization. Multi-objective optimization is concerned with mathematical optimization problems involving more than one objective function to be optimized simultaneously\n",
"This tutorial demonstrates [Vertex AI Vizier](https://cloud.google.com/vertex-ai/docs/vizier/overview) multi-objective optimization. Multi-objective optimization is concerned with mathematical optimization problems involving more than one objective function to be optimized simultaneously\n",
"\n",
"### Objective\n",
"\n",
File diff suppressed because it is too large Load Diff