mirror of
https://github.com/GoogleCloudPlatform/vertex-ai-samples.git
synced 2026-09-27 15:42:05 +00:00
Compare commits
69
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
06daeb1575 | ||
|
|
2074fb56a9 | ||
|
|
1bdbb7921a | ||
|
|
7154a722ba | ||
|
|
99d4a8c31a | ||
|
|
f9cedf2850 | ||
|
|
f4f0112a6a | ||
|
|
e441568c38 | ||
|
|
fee8c969e4 | ||
|
|
bdac091e3f | ||
|
|
ff9338ed3c | ||
|
|
1a538fd249 | ||
|
|
4f09c94b5f | ||
|
|
bcf3e6b0f5 | ||
|
|
fbcf783064 | ||
|
|
2f5fe80f34 | ||
|
|
a850f3a88a | ||
|
|
de91feaca1 | ||
|
|
a7fd0734dc | ||
|
|
ce1b167f08 | ||
|
|
65ff3cab60 | ||
|
|
c7ef72f1d3 | ||
|
|
bd58428857 | ||
|
|
a4a6ed848b | ||
|
|
b753bc58d3 | ||
|
|
6279e12eea | ||
|
|
fc0c34c905 | ||
|
|
ef388ecf30 | ||
|
|
bafb2c6f59 | ||
|
|
f2d431c182 | ||
|
|
2e4b6a1b1b | ||
|
|
95cebcbf8f | ||
|
|
08f1b659c5 | ||
|
|
86ba71931d | ||
|
|
d811306fb9 | ||
|
|
4173e6d561 | ||
|
|
499d25055a | ||
|
|
60776de953 | ||
|
|
182ebcf285 | ||
|
|
39359a5b21 | ||
|
|
0d72cfe070 | ||
|
|
64fef140a2 | ||
|
|
015809b948 | ||
|
|
faccdd081f | ||
|
|
3e8a3cf28e | ||
|
|
821bba2776 | ||
|
|
c82bdee299 | ||
|
|
c27381139b | ||
|
|
01236836f2 | ||
|
|
b8380650bd | ||
|
|
69d266cb90 | ||
|
|
530524ac6e | ||
|
|
ba66961fce | ||
|
|
aca7035482 | ||
|
|
3d270cde69 | ||
|
|
9754c265ff | ||
|
|
f5d730c9f1 | ||
|
|
acd42a3a1b | ||
|
|
eb7cf4b6bc | ||
|
|
34b1011ac9 | ||
|
|
239d664990 | ||
|
|
920c771238 | ||
|
|
e7c68ecb78 | ||
|
|
cfeb118d8b | ||
|
|
2c9c8db15c | ||
|
|
6778a2cfbf | ||
|
|
26c5d56e6d | ||
|
|
527fe79f15 | ||
|
|
2a003fa9c3 |
@@ -7,7 +7,7 @@
|
||||
/gapic @andrewferlitsch
|
||||
/gapic/custom/showcase_custom_image_classification_online_explain_example_based_api.ipynb @inardini
|
||||
/ml_ops @andrewferlitsch
|
||||
/model_monitoring/* @mco-gh
|
||||
/model_monitoring/* @andrewferlitsch
|
||||
/structured_data/rapid_prototyping_* @rafael-carvalho
|
||||
|
||||
/managed_notebooks/
|
||||
@@ -33,3 +33,4 @@
|
||||
/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
|
||||
/notebooks/community/vizier/conversions_vertex_vizier_and_open_source_vizier.ipynb @halio-g
|
||||
|
||||
@@ -14,5 +14,5 @@ The purpose of this set of notebooks and markdown files is to demonstrate Google
|
||||
4. [Evaluation](stage4)
|
||||
5. [Deployment](stage5)
|
||||
6. [Serving](stage6)
|
||||
7. Monitoring
|
||||
7. Monitoring(stage7)
|
||||
8. Continuous Training
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
## Before you begin
|
||||
|
||||
### Set up your Google Cloud project
|
||||
|
||||
**The following steps are required, regardless of your notebook environment.**
|
||||
|
||||
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.
|
||||
|
||||
1. [Make sure that billing is enabled for your project](https://cloud.google.com/billing/docs/how-to/modify-project).
|
||||
|
||||
1. [Enable the Vertex AI, BigQuery, Compute Engine and Cloud Storage APIs](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com,bigquery,compute_component,storage_component).
|
||||
|
||||
1. If you are running this notebook locally, you need to install the [Cloud SDK](https://cloud.google.com/sdk).
|
||||
|
||||
1. Enter your project ID in the cell below. Then run the cell to make sure the
|
||||
Cloud SDK uses the right project for all the commands in this notebook.
|
||||
|
||||
**Note**: Jupyter runs lines prefixed with `!` as shell commands, and it interpolates Python variables prefixed with `$` into these commands.
|
||||
|
||||
### Set up your local development environment
|
||||
|
||||
**If you are using Colab or Vertex AI Workbench Notebooks**, your environment already meets all the requirements to run this notebook. You can skip this step.
|
||||
|
||||
**Otherwise**, make sure your environment meets this notebook's requirements. You need the following:
|
||||
|
||||
- The Cloud Storage SDK
|
||||
- Python 3
|
||||
- virtualenv
|
||||
- Jupyter notebook running in a virtual environment with Python 3
|
||||
|
||||
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:
|
||||
|
||||
1. [Install and initialize the SDK](https://cloud.google.com/sdk/docs/).
|
||||
|
||||
2. [Install Python 3](https://cloud.google.com/python/setup#installing_python).
|
||||
|
||||
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.
|
||||
|
||||
4. To install Jupyter, run `pip3 install jupyter` on the command-line in a terminal shell.
|
||||
|
||||
5. To launch Jupyter, run `jupyter notebook` on the command-line in a terminal shell.
|
||||
|
||||
6. Open this notebook in the Jupyter Notebook Dashboard.
|
||||
@@ -0,0 +1,112 @@
|
||||
import os
|
||||
import sys
|
||||
import argparse
|
||||
import subprocess
|
||||
import random
|
||||
import string
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--bucket', dest='bucket_required', action='store_true',
|
||||
default=False, help='Bucket required')
|
||||
parser.add_argument('--email', dest='email_required', action='store_true',
|
||||
default=False, help='Email required')
|
||||
parser.add_argument('--sa', dest='sa_required', action='store_true',
|
||||
default=False, help='Service account required')
|
||||
parser.add_argument('--packages', dest='extra_packages',
|
||||
default='', type=str, help='additional required packages')
|
||||
args = parser.parse_args()
|
||||
|
||||
extra_pkgs = args.extra_packages
|
||||
|
||||
|
||||
# Installation
|
||||
|
||||
|
||||
# The Vertex AI Workbench Notebook product has specific requirements
|
||||
IS_WORKBENCH_NOTEBOOK = os.getenv("DL_ANACONDA_HOME")
|
||||
IS_USER_MANAGED_WORKBENCH_NOTEBOOK = os.path.exists(
|
||||
"/opt/deeplearning/metadata/env_version"
|
||||
)
|
||||
IS_COLAB = "google.colab" in sys.modules
|
||||
|
||||
# Vertex AI Notebook requires dependencies to be installed with '--user'
|
||||
USER_FLAG = ""
|
||||
if IS_WORKBENCH_NOTEBOOK:
|
||||
USER_FLAG = "--user"
|
||||
|
||||
# not used
|
||||
'''
|
||||
print("Installing packages")
|
||||
os.system(f"pip3 install --upgrade --quiet {USER_FLAG} google-cloud-aiplatform {args.extra_packages}")
|
||||
print("Done installation")
|
||||
'''
|
||||
|
||||
# Authenticate
|
||||
if IS_COLAB:
|
||||
from google.colab import auth as google_auth
|
||||
|
||||
google_auth.authenticate_user()
|
||||
|
||||
|
||||
# project ID
|
||||
if IS_WORKBENCH_NOTEBOOK:
|
||||
shell_output = subprocess.check_output("gcloud config list --format 'value(core.project)' 2>/dev/null", shell=True)
|
||||
PROJECT_ID = shell_output[0:-1].decode('utf-8')
|
||||
print("PROJECT ID: ", PROJECT_ID)
|
||||
else:
|
||||
PROJECT_ID = input("Enter PROJECT_ID: ")
|
||||
os.system(f"gcloud config set project {PROJECT_ID}")
|
||||
|
||||
# email
|
||||
if args.email_required:
|
||||
shell_output = subprocess.check_output("gcloud config list --format 'value(core.account)' 2>/dev/null", shell=True)
|
||||
EMAIL_ADDR = shell_output[0:-1].decode('utf-8')
|
||||
if EMAIL_ADDR == '':
|
||||
EMAIL_ADDR = input("Enter Email Address: ")
|
||||
print("EMAIL_ADDR: ", EMAIL_ADDR)
|
||||
|
||||
# region
|
||||
shell_output = subprocess.check_output("gcloud config list --format 'value(ai.region)'", shell=True)
|
||||
REGION = shell_output[0:-1].decode('utf-8')
|
||||
if REGION == '':
|
||||
REGION = input("Enter REGION: ")
|
||||
print("REGION: ", REGION)
|
||||
|
||||
# multi-region
|
||||
MULTI_REGION = REGION.split('-')[0]
|
||||
|
||||
|
||||
# UUID
|
||||
# Generate a uuid of a specifed length(default=8)
|
||||
def generate_uuid(length: int = 8) -> str:
|
||||
return "".join(random.choices(string.ascii_lowercase + string.digits, k=length))
|
||||
|
||||
|
||||
UUID = generate_uuid()
|
||||
print("UUID", UUID)
|
||||
|
||||
# Bucket
|
||||
if args.bucket_required:
|
||||
BUCKET_NAME = PROJECT_ID + "aip-" + UUID
|
||||
BUCKET_URI = f"gs://{BUCKET_NAME}"
|
||||
os.system(f"gsutil mb -l {REGION} {BUCKET_URI}")
|
||||
print("BUCKET_URI", BUCKET_URI)
|
||||
|
||||
|
||||
# Project Number
|
||||
if args.sa_required:
|
||||
if IS_WORKBENCH_NOTEBOOK:
|
||||
shell_output = subprocess.check_output("gcloud auth list 2>/dev/null", shell=True)
|
||||
SERVICE_ACCOUNT = shell_output[:-1].decode('utf-8').split('\n')[2].strip()
|
||||
PROJECT_NUMBER = SERVICE_ACCOUNT.split('-')[0]
|
||||
else:
|
||||
shell_output = subprocess.check_output(f"gcloud projects describe {PROJECT_ID}", shell=True)
|
||||
try:
|
||||
PROJECT_NUMBER = shell_output[:-1].decode('utf-8').split('\n')[7].split(':')[-1].strip().replace("'", "")
|
||||
SERVICE_ACCOUNT = f"{PROJECT_NUMBER}-compute@developer.gserviceaccount.com"
|
||||
except:
|
||||
PROJECT_NUMBER = input("Enter project number: ")
|
||||
SERVICE_ACCOUNT = f"{PROJECT_NUMBER}-compute@developer.gserviceaccount.com"
|
||||
|
||||
print("SERVICE_ACCOUNT", SERVICE_ACCOUNT)
|
||||
print("PROJECT_NUMBER", PROJECT_NUMBER)
|
||||
@@ -120,7 +120,7 @@
|
||||
" - XGBoost model training:\n",
|
||||
" - Use BigQuery ML built-in XGBoost training.\n",
|
||||
" - Alternatively, create a DMatrix generator from CSV files extracted from BigQuery table.\n",
|
||||
" - Pytorch model training:\n",
|
||||
" - PyTorch model training:\n",
|
||||
" - Extract the BigQuery to a pandas dataframe.\n",
|
||||
" - Preprocess the data in the dataframe.\n",
|
||||
" - Create a DataLoader generator from the pandas dataframe.\n",
|
||||
@@ -191,13 +191,8 @@
|
||||
"if IS_WORKBENCH_NOTEBOOK:\n",
|
||||
" USER_FLAG = \"--user\"\n",
|
||||
"\n",
|
||||
"# Install the packages\n",
|
||||
"! pip3 install --upgrade pyarrow $USER_FLAG -q\n",
|
||||
"! pip3 install --upgrade google-cloud-bigquery $USER_FLAG -q\n",
|
||||
"! pip3 install --upgrade google-cloud-aiplatform $USER_FLAG -q\n",
|
||||
"! pip3 install -U xgboost $USER_FLAG -q\n",
|
||||
"! pip3 install -U tensorflow $USER_FLAG -q\n",
|
||||
"! pip3 install -U tensorflow-io==0.18 $USER_FLAG -q"
|
||||
"extra_pkgs = \"tensorflow tensorflow-io==0.18 pyarrow xgboost google-cloud-bigquery\"\n",
|
||||
"! pip3 install --upgrade --quiet {USER_FLAG} google-cloud-aiplatform $extra_pkgs"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -219,9 +214,9 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import os\n",
|
||||
"import sys\n",
|
||||
"\n",
|
||||
"if not os.getenv(\"IS_TESTING\"):\n",
|
||||
"if \"google.colab\" in sys.modules:\n",
|
||||
" # Automatically restart kernel after installs\n",
|
||||
" import IPython\n",
|
||||
"\n",
|
||||
@@ -232,274 +227,42 @@
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "84cd83853240"
|
||||
"id": "fc8fb52b5cca"
|
||||
},
|
||||
"source": [
|
||||
"## Before you begin\n",
|
||||
"### Common setup\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",
|
||||
"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, BigQuery, Compute Engine and Cloud Storage APIs](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com,bigquery,compute_component,storage_component).\n",
|
||||
"\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 `!` as shell commands, and it interpolates Python variables prefixed with `$` into these commands."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "project_id"
|
||||
},
|
||||
"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`."
|
||||
"Now, execute the common setup for the notebook tutorials."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "set_project_id"
|
||||
"id": "001a0fcd5d78"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"PROJECT_ID = \"[your-project-id]\" # @param {type:\"string\"}"
|
||||
"# Common code setup for notebook tutorials\n",
|
||||
"\n",
|
||||
"! wget https://raw.githubusercontent.com/GoogleCloudPlatform/vertex-ai-samples/main/notebooks/community/ml_ops/setup.py -O setup.py\n",
|
||||
"\n",
|
||||
"%run setup.py --bucket"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "autoset_project_id"
|
||||
"id": "d809f07a8935"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"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)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "set_gcloud_project_id"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"! gcloud config set project $PROJECT_ID"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "region"
|
||||
},
|
||||
"source": [
|
||||
"#### Region\n",
|
||||
"# Other Common setup instructions for notebook tutorials\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",
|
||||
"! wget https://raw.githubusercontent.com/GoogleCloudPlatform/vertex-ai-samples/main/notebooks/community/ml_ops/setup.md -O setup.md\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": "region"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"REGION = \"[your-region]\" # @param {type: \"string\"}\n",
|
||||
"\n",
|
||||
"if REGION == \"[your-region]\":\n",
|
||||
" REGION = \"us-central1\""
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "timestamp"
|
||||
},
|
||||
"source": [
|
||||
"#### Timestamp\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."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "timestamp"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from datetime import datetime\n",
|
||||
"\n",
|
||||
"TIMESTAMP = datetime.now().strftime(\"%Y%m%d%H%M%S\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "77c385f0db59"
|
||||
},
|
||||
"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",
|
||||
"\n",
|
||||
"**If you are using Colab**, run the cell below and follow the instructions 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",
|
||||
"\n",
|
||||
"1. **Click Create service account**.\n",
|
||||
"\n",
|
||||
"2. In the **Service account name** field, enter a name, and click **Create**.\n",
|
||||
"\n",
|
||||
"3. In the **Grant this service account access to project** section, click the Role drop-down list. Type \"Vertex AI\" into the filter box, and select **Vertex AI Administrator**. Type \"Storage Object Admin\" into the filter box, and select **Storage Object Admin**.\n",
|
||||
"\n",
|
||||
"4. Click Create. A JSON file that contains your key downloads to your local environment.\n",
|
||||
"\n",
|
||||
"5. Enter the path to your service account key as the GOOGLE_APPLICATION_CREDENTIALS variable in the cell below and run the cell."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "535223fa4b84"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# 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",
|
||||
"import os\n",
|
||||
"import sys\n",
|
||||
"\n",
|
||||
"# If on Vertex AI Workbench, then don't execute this code\n",
|
||||
"IS_COLAB = False\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",
|
||||
"\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.\n",
|
||||
" elif not os.getenv(\"IS_TESTING\"):\n",
|
||||
" %env GOOGLE_APPLICATION_CREDENTIALS ''"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "bucket:custom"
|
||||
},
|
||||
"source": [
|
||||
"### Create a Cloud Storage bucket\n",
|
||||
"\n",
|
||||
"**The following steps are required, regardless of your notebook environment.**\n",
|
||||
"\n",
|
||||
"When you create a dataset resource using the Vertex SDK, you can provide a Cloud Storage bucket that contains the data. Vertex AI creates the dataset resource from the data. In this tutorial, Vertex AI also creates a dataset resource from your data in the Cloud Storage bucket.\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."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "bucket"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"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_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"
|
||||
]
|
||||
},
|
||||
{
|
||||
"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"
|
||||
"%load setup.md"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -620,7 +383,7 @@
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"dataset = aiplatform.TabularDataset.create(\n",
|
||||
" display_name=\"NOAA historical weather data\" + \"_\" + TIMESTAMP,\n",
|
||||
" display_name=\"NOAA historical weather data\" + \"_\" + UUID,\n",
|
||||
" bq_source=[IMPORT_FILE],\n",
|
||||
" labels={\"user_metadata\": BUCKET_URI[5:]},\n",
|
||||
")\n",
|
||||
@@ -695,7 +458,7 @@
|
||||
"gcs_source = IMPORT_FILES\n",
|
||||
"\n",
|
||||
"dataset = aiplatform.TabularDataset.create(\n",
|
||||
" display_name=\"NOAA historical weather data\" + \"_\" + TIMESTAMP,\n",
|
||||
" display_name=\"NOAA historical weather data\" + \"_\" + UUID,\n",
|
||||
" gcs_source=gcs_source,\n",
|
||||
" labels={\"user_metadata\": BUCKET_URI[5:]},\n",
|
||||
")\n",
|
||||
@@ -737,10 +500,10 @@
|
||||
" or BQ_MY_DATASET is None\n",
|
||||
" or BQ_MY_DATASET == \"[your-dataset-name]\"\n",
|
||||
"):\n",
|
||||
" BQ_MY_DATASET = \"mlops_dataset_\" + TIMESTAMP\n",
|
||||
" BQ_MY_DATASET = \"mlops_dataset_\" + UUID\n",
|
||||
"\n",
|
||||
"if BQ_MY_TABLE == \"\" or BQ_MY_TABLE is None or BQ_MY_TABLE == \"[your-view-name]\":\n",
|
||||
" BQ_MY_TABLE = \"mlops_view_\" + TIMESTAMP"
|
||||
" BQ_MY_TABLE = \"mlops_view_\" + UUID"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -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://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage1/get_started_dataflow.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/ml_ops/stage1/get_started_dataflow.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",
|
||||
@@ -186,13 +186,9 @@
|
||||
"if IS_WORKBENCH_NOTEBOOK:\n",
|
||||
" USER_FLAG = \"--user\"\n",
|
||||
"\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 $USER_FLAG -q\n",
|
||||
"! pip3 install --upgrade google-cloud-bigquery $USER_FLAG -q\n",
|
||||
"! pip3 install --upgrade apache-beam[gcp] $USER_FLAG -q"
|
||||
"extra_pkgs = \"tensorflow==2.5 tensorflow-data-validation==1.2 tensorflow-transform==1.2 \\\n",
|
||||
" tensorflow-io==0.18 pyarrow pandas apache-beam[gcp] google-cloud-bigquery\"\n",
|
||||
"! pip3 install --upgrade --quiet {USER_FLAG} google-cloud-aiplatform $extra_pkgs"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -214,9 +210,9 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import os\n",
|
||||
"import sys\n",
|
||||
"\n",
|
||||
"if not os.getenv(\"IS_TESTING\"):\n",
|
||||
"if \"google.colab\" in sys.modules:\n",
|
||||
" # Automatically restart kernel after installs\n",
|
||||
" import IPython\n",
|
||||
"\n",
|
||||
@@ -227,279 +223,42 @@
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "84cd83853240"
|
||||
"id": "fc8fb52b5cca"
|
||||
},
|
||||
"source": [
|
||||
"## Before you begin\n",
|
||||
"### Common setup\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",
|
||||
"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, BigQuery, Compute Engine and Cloud Storage APIs](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com,bigquery,compute_component,storage_component).\n",
|
||||
"\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 `!` as shell commands, and it interpolates Python variables prefixed with `$` into these commands."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "project_id"
|
||||
},
|
||||
"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`."
|
||||
"Now, execute the common setup for the notebook tutorials."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "set_project_id"
|
||||
"id": "001a0fcd5d78"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"PROJECT_ID = \"[your-project-id]\" # @param {type:\"string\"}"
|
||||
"# Common code setup for notebook tutorials\n",
|
||||
"\n",
|
||||
"! wget https://raw.githubusercontent.com/GoogleCloudPlatform/vertex-ai-samples/main/notebooks/community/ml_ops/setup.py -O setup.py\n",
|
||||
"\n",
|
||||
"%run setup.py --bucket"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "autoset_project_id"
|
||||
"id": "d809f07a8935"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"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)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "set_gcloud_project_id"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"! gcloud config set project $PROJECT_ID"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "region"
|
||||
},
|
||||
"source": [
|
||||
"#### Region\n",
|
||||
"# Other Common setup instructions for notebook tutorials\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",
|
||||
"! wget https://raw.githubusercontent.com/GoogleCloudPlatform/vertex-ai-samples/main/notebooks/community/ml_ops/setup.md -O setup.md\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": "region"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"REGION = \"[your-region]\" # @param {type: \"string\"}\n",
|
||||
"\n",
|
||||
"if REGION == \"[your-region]\":\n",
|
||||
" REGION = \"us-central1\""
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "timestamp"
|
||||
},
|
||||
"source": [
|
||||
"#### Timestamp\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."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "timestamp"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from datetime import datetime\n",
|
||||
"\n",
|
||||
"TIMESTAMP = datetime.now().strftime(\"%Y%m%d%H%M%S\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "77c385f0db59"
|
||||
},
|
||||
"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",
|
||||
"\n",
|
||||
"**If you are using Colab**, run the cell below and follow the instructions 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",
|
||||
"\n",
|
||||
"1. **Click Create service account**.\n",
|
||||
"\n",
|
||||
"2. In the **Service account name** field, enter a name, and click **Create**.\n",
|
||||
"\n",
|
||||
"3. In the **Grant this service account access to project** section, click the Role drop-down list. Type \"Vertex AI\" into the filter box, and select **Vertex AI Administrator**. Type \"Storage Object Admin\" into the filter box, and select **Storage Object Admin**.\n",
|
||||
"\n",
|
||||
"4. Click Create. A JSON file that contains your key downloads to your local environment.\n",
|
||||
"\n",
|
||||
"5. Enter the path to your service account key as the GOOGLE_APPLICATION_CREDENTIALS variable in the cell below and run the cell."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "535223fa4b84"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# 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",
|
||||
"import os\n",
|
||||
"import sys\n",
|
||||
"\n",
|
||||
"# If on Vertex AI Workbench, then don't execute this code\n",
|
||||
"IS_COLAB = False\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",
|
||||
"\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.\n",
|
||||
" elif not os.getenv(\"IS_TESTING\"):\n",
|
||||
" %env GOOGLE_APPLICATION_CREDENTIALS ''"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "bucket:custom"
|
||||
},
|
||||
"source": [
|
||||
"### Create a Cloud Storage bucket\n",
|
||||
"\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",
|
||||
"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",
|
||||
"create an `Endpoint` resource based on this output in order to serve\n",
|
||||
"online predictions.\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."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "bucket"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"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-\" + TIMESTAMP\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"
|
||||
"%load setup.md "
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -1319,7 +1078,7 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"delete_storage = True\n",
|
||||
"delete_storage = False\n",
|
||||
"\n",
|
||||
"if delete_storage or os.getenv(\"IS_TESTING\"):\n",
|
||||
" if \"BUCKET_URI\" in globals():\n",
|
||||
|
||||
@@ -33,12 +33,12 @@
|
||||
"\n",
|
||||
"<table align=\"left\">\n",
|
||||
" <td>\n",
|
||||
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage1/get_started_vertex_datasets.ipynb\">\n",
|
||||
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage1/get_started_vertex_datasets.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/ai/platform/notebooks/deploy-notebook?download_url=https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage1/get_started_vertex_datasets.ipynb\">\n",
|
||||
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage1/get_started_vertex_datasets.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",
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -73,7 +73,7 @@
|
||||
"source": [
|
||||
"### Objective\n",
|
||||
"\n",
|
||||
"In this tutorial, you learn how to use `BigQueryML` (BQML) for training with `Vertex AI`.\n",
|
||||
"In this tutorial, you learn how to use `BigQueryML` for training with `Vertex AI`.\n",
|
||||
"\n",
|
||||
"This tutorial uses the following Google Cloud ML services:\n",
|
||||
"\n",
|
||||
@@ -84,12 +84,12 @@
|
||||
"The steps performed include:\n",
|
||||
"\n",
|
||||
"- Create a local BigQuery table in your project\n",
|
||||
"- Train a BQML model\n",
|
||||
"- Evaluate the BQML model\n",
|
||||
"- Export the BQML model as a cloud model\n",
|
||||
"- Train a BigQuery ML model\n",
|
||||
"- Evaluate the BigQuery ML model\n",
|
||||
"- Export the BigQuery ML model as a cloud model\n",
|
||||
"- Upload the exported model as a `Vertex AI Model` resource\n",
|
||||
"- Hyperparameter tune a BQML model with `Vertex AI Vizier`\n",
|
||||
"- Automatically register a BQML model to `Vertex AI Model Registry`"
|
||||
"- Hyperparameter tune a BigQuery ML model with `Vertex AI Vizier`\n",
|
||||
"- Automatically register a BigQuery ML model to `Vertex AI Model Registry`"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -749,9 +749,9 @@
|
||||
"id": "bqml_create_model"
|
||||
},
|
||||
"source": [
|
||||
"### Train BQML model\n",
|
||||
"### Train BigQuery ML model\n",
|
||||
"\n",
|
||||
"Next, you create and train a BQML tabular classification model from the public dataset penguins and store the model in your project 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 classification model from the public dataset penguins and store the model in your project 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., DNN classification.\n",
|
||||
"- `labels`: The column which are the labels.\n",
|
||||
@@ -800,9 +800,9 @@
|
||||
"id": "bqml_eval_model"
|
||||
},
|
||||
"source": [
|
||||
"### Evaluate the trained BQML model\n",
|
||||
"### Evaluate the trained BigQuery ML model\n",
|
||||
"\n",
|
||||
"Next, retrieve the model evaluation for the trained BQML model.\n",
|
||||
"Next, retrieve the model evaluation for the trained BigQuery ML model.\n",
|
||||
"\n",
|
||||
"Learn more about [The ML.EVALUATE function](https://cloud.google.com/bigquery-ml/docs/reference/standard-sql/bigqueryml-syntax-evaluate)."
|
||||
]
|
||||
@@ -833,9 +833,9 @@
|
||||
"id": "bqml_export_model"
|
||||
},
|
||||
"source": [
|
||||
"### Export the model from BQML\n",
|
||||
"### Export the model from BigQuery ML\n",
|
||||
"\n",
|
||||
"The model you trained in BQML is a TensorFlow model. Next, you export the TensorFlow model artifacts in TF.SavedModel format."
|
||||
"The model you trained in BigQuery ML is a TensorFlow model. Next, you export the TensorFlow model artifacts in TF.SavedModel format."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -1028,9 +1028,9 @@
|
||||
"id": "bqml_create_model:vizier"
|
||||
},
|
||||
"source": [
|
||||
"### Hyperparameter Tune and train a BQML model\n",
|
||||
"### Hyperparameter Tune and train a BigQuery ML model\n",
|
||||
"\n",
|
||||
"Next, you train a BQML tabular classification model with hyperparameter tuning using the `Vertex AI Vizier` service. The hyperparameter settings are specified in the `OPTIONS` statement as follows:\n",
|
||||
"Next, you train a BigQuery ML tabular classification model with hyperparameter tuning using the `Vertex AI Vizier` service. The hyperparameter settings are specified in the `OPTIONS` statement as follows:\n",
|
||||
"\n",
|
||||
"- `HPARAM_TUNING_ALGORITHM`: The algorithm for selecting the next trial parameters.\n",
|
||||
"- `num_trials`: The number of trials.\n",
|
||||
@@ -1083,9 +1083,9 @@
|
||||
"id": "bqml_eval_model"
|
||||
},
|
||||
"source": [
|
||||
"### Evaluate the BQML trained model\n",
|
||||
"### Evaluate the BigQuery ML trained model\n",
|
||||
"\n",
|
||||
"Next, retrieve the model evaluation results for the trained BQML model.\n",
|
||||
"Next, retrieve the model evaluation results for the trained BigQuery ML model.\n",
|
||||
"\n",
|
||||
"Learn more about [The ML.EVALUATE function](https://cloud.google.com/bigquery-ml/docs/reference/standard-sql/bigqueryml-syntax-evaluate)."
|
||||
]
|
||||
@@ -1142,9 +1142,9 @@
|
||||
"id": "bqml_create_model:xai"
|
||||
},
|
||||
"source": [
|
||||
"### Train a BQML model with Explainability\n",
|
||||
"### Train a BigQuery ML model with Explainability\n",
|
||||
"\n",
|
||||
"Next, you train the same BQML model, but this time you enable Vertex AI Explainability on the model predictions by adding the option:\n",
|
||||
"Next, you train the same BigQuery ML model, but this time you enable Vertex AI Explainability on the model predictions by adding the option:\n",
|
||||
"\n",
|
||||
"- `ENABLE_GLOBAL_EXPLAIN`"
|
||||
]
|
||||
|
||||
@@ -87,7 +87,7 @@
|
||||
"This tutorial uses the following Google Cloud ML services:\n",
|
||||
"\n",
|
||||
"- `Vertex AI Experiments`\n",
|
||||
"- `Vertex AI ML Metadata`\n",
|
||||
"- `Vertex ML Metadata`\n",
|
||||
"- `Vertex AI Training`\n",
|
||||
"\n",
|
||||
"The steps performed include:\n",
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -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/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/community/ml_ops/stage2/get_started_vertex_tensorboard.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",
|
||||
|
||||
@@ -48,7 +48,7 @@
|
||||
" </a>\n",
|
||||
" </td>\n",
|
||||
" <td>\n",
|
||||
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/tree/main/notebooks/community/ml_ops/stage2/get_started_vertex_training_lightgbm.ipynb\">\n",
|
||||
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage2/get_started_vertex_training_lightgbm.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",
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
"id": "title:generic,gcp"
|
||||
},
|
||||
"source": [
|
||||
"# E2E ML on GCP: MLOps stage 2 : experimentation: get started with Vertex AI Training for Pytorch\n",
|
||||
"# E2E ML on GCP: MLOps stage 2 : experimentation: get started with Vertex AI Training for PyTorch\n",
|
||||
"\n",
|
||||
"<table align=\"left\">\n",
|
||||
" <td>\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/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/community/ml_ops/stage2/get_started_vertex_training_pytorch.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",
|
||||
@@ -62,7 +62,7 @@
|
||||
"## Overview\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"This tutorial demonstrates how to use Vertex AI for E2E MLOps on Google Cloud in production. This tutorial covers stage 2 : experimentation: get started with Vertex AI Training for Pytorch."
|
||||
"This tutorial demonstrates how to use Vertex AI for E2E MLOps on Google Cloud in production. This tutorial covers stage 2 : experimentation: get started with Vertex AI Training for PyTorch."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -73,7 +73,7 @@
|
||||
"source": [
|
||||
"### Objective\n",
|
||||
"\n",
|
||||
"In this tutorial, you learn how to use `Vertex AI Training` for training a Pytorch custom model.\n",
|
||||
"In this tutorial, you learn how to use `Vertex AI Training` for training a PyTorch custom model.\n",
|
||||
"\n",
|
||||
"This tutorial uses the following Google Cloud ML services:\n",
|
||||
"\n",
|
||||
@@ -97,7 +97,7 @@
|
||||
"source": [
|
||||
"### Dataset\n",
|
||||
"\n",
|
||||
"The dataset used for this tutorial is the [CIFAR10 dataset](https://pytorch.org/vision/stable/datasets.html#cifar) from [Pytorch Datasets](https://pytorch.org/vision/stable/datasets.html). The version of the dataset is built into TensorFlow. The trained model predicts which type of class an image is from ten classes: airplane, automobile, bird, cat, deer, dog, frog, horse, ship, or truck."
|
||||
"The dataset used for this tutorial is the [CIFAR10 dataset](https://pytorch.org/vision/stable/datasets.html#cifar) from [PyTorch Datasets](https://pytorch.org/vision/stable/datasets.html). The version of the dataset is built into TensorFlow. The trained model predicts which type of class an image is from ten classes: airplane, automobile, bird, cat, deer, dog, frog, horse, ship, or truck."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -672,17 +672,17 @@
|
||||
"id": "pytorch_intro"
|
||||
},
|
||||
"source": [
|
||||
"## Introduction to Pytorch training\n",
|
||||
"## Introduction to PyTorch training\n",
|
||||
"\n",
|
||||
"The Pytorch package supports both single node and distributed model training.\n",
|
||||
"The PyTorch package supports both single node and distributed model training.\n",
|
||||
"\n",
|
||||
"Once you have trained a Pytorch model, you will want to save it at a Cloud Storage location, so it can subsequently be uploaded to a `Vertex AI Model` resource.\n",
|
||||
"The Pytorch package does not have support to save the model to a Cloud Storage location. Instead, you will do the following steps to save to a Cloud Storage location.\n",
|
||||
"Once you have trained a PyTorch model, you will want to save it at a Cloud Storage location, so it can subsequently be uploaded to a `Vertex AI Model` resource.\n",
|
||||
"The PyTorch package does not have support to save the model to a Cloud Storage location. Instead, you will do the following steps to save to a Cloud Storage location.\n",
|
||||
"\n",
|
||||
"1. Save the in-memory model to the local filesystem (e.g., model.pth).\n",
|
||||
"2. Use gsutil to copy the local copy to the specified Cloud Storage location.\n",
|
||||
"\n",
|
||||
"*Note*: You can do hyperparameter tuning with a Pytorch model."
|
||||
"*Note*: You can do hyperparameter tuning with a PyTorch model."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -1069,9 +1069,9 @@
|
||||
"id": "docker_write,prediction,pytorch"
|
||||
},
|
||||
"source": [
|
||||
"### Make Pytorch container for prediction\n",
|
||||
"### Make PyTorch container for prediction\n",
|
||||
"\n",
|
||||
"Currently, Vertex AI does not have a predefined container for making predictions with a deployed Pytorch model. No problem, you can assemble your own custom container. Typically, one would base the container on the `Torch Server`. For demonstration purpose, you build a placeholder container (not complete) that includes the latest `Torch Server` image, and push it to the `Container Registry`."
|
||||
"Currently, Vertex AI does not have a predefined container for making predictions with a deployed PyTorch model. No problem, you can assemble your own custom container. Typically, one would base the container on the `Torch Server`. For demonstration purpose, you build a placeholder container (not complete) that includes the latest `Torch Server` image, and push it to the `Container Registry`."
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
+2
-2
@@ -43,7 +43,7 @@
|
||||
"<table align=\"left\">\n",
|
||||
"\n",
|
||||
" <td>\n",
|
||||
" <a href=\"https://colab.sandbox.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage2/get_started_vertex_training_r_using_r_kernel.ipynb\">\n",
|
||||
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage2/get_started_vertex_training_r_using_r_kernel.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",
|
||||
@@ -109,7 +109,7 @@
|
||||
"source": [
|
||||
"### Dataset\n",
|
||||
"\n",
|
||||
"The dataset used for this tutorial is [California Housing Dataset](https://www.dcc.fc.up.pt/~ltorgo/Regression/cal_housing.html). The data contains information from the 1990 California census. The data set is publicly available from Google Cloud Storage at `gs://cloud-samples-data/ai-platform-unified/datasets/tabular/california-housing-tabular-regression.csv`. The dataset is used to train a Random Forest regressor to predict a median housing price, given a longitude and lattitude along with data from the corresponding census block group. A block group is the smallest geographical unit for which the U.S. Census Bureau publishes sample data (a block group typically has a population of 600 to 3,000 people).\n"
|
||||
"The dataset used for this tutorial is [California Housing Dataset](https://www.dcc.fc.up.pt/~ltorgo/Regression/cal_housing.html). The data contains information from the 1990 California census. The data set is publicly available from Cloud Storage at `gs://cloud-samples-data/ai-platform-unified/datasets/tabular/california-housing-tabular-regression.csv`. The dataset is used to train a Random Forest regressor to predict a median housing price, given a longitude and lattitude along with data from the corresponding census block group. A block group is the smallest geographical unit for which the U.S. Census Bureau publishes sample data (a block group typically has a population of 600 to 3,000 people).\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
" </a>\n",
|
||||
" </td>\n",
|
||||
" <td>\n",
|
||||
" <a href=\"https://console.cloud.google.com/ai/platform/notebooks/deploy-notebook?download_url=https://raw.githubusercontent.com/GoogleCloudPlatform/vertex-ai-samples/main/notebooks/community/ml_ops/stage2/get_started_vertex_training_sklearn.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/ml_ops/stage2/get_started_vertex_training_sklearn.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",
|
||||
|
||||
@@ -297,25 +297,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": "JYtXOocrox9Q"
|
||||
"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()"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -362,12 +369,11 @@
|
||||
"import sys\n",
|
||||
"\n",
|
||||
"# If on Vertex AI Workbench, then don't execute this code\n",
|
||||
"IS_COLAB = False\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",
|
||||
@@ -402,7 +408,8 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"BUCKET_URI = \"gs://[your-bucket-name]\" # @param {type:\"string\"}"
|
||||
"BUCKET_NAME = \"[your-bucket-name]\" # @param {type:\"string\"}\n",
|
||||
"BUCKET_URI = f\"gs://{BUCKET_NAME}\""
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -413,8 +420,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"
|
||||
"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"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -749,6 +757,7 @@
|
||||
"import hypertune\n",
|
||||
"import argparse\n",
|
||||
"import logging\n",
|
||||
"import numpy as np\n",
|
||||
"\n",
|
||||
"from sklearn.model_selection import train_test_split\n",
|
||||
"from sklearn.metrics import accuracy_score\n",
|
||||
@@ -790,16 +799,23 @@
|
||||
"def train_model(dtrain):\n",
|
||||
" logging.info(\"Start training ...\")\n",
|
||||
" # Train XGBoost model\n",
|
||||
" model = xgb.train({}, dtrain, num_boost_round=args.boost_rounds)\n",
|
||||
" params = {\n",
|
||||
" 'objective': 'multi:softprob',\n",
|
||||
" 'num_class': 3\n",
|
||||
" }\n",
|
||||
" model = xgb.train(params, dtrain, num_boost_round=args.boost_rounds)\n",
|
||||
" logging.info(\"Training completed\")\n",
|
||||
" return model\n",
|
||||
"\n",
|
||||
"def evaluate_model(model, test_data, test_labels):\n",
|
||||
" dtest = xgb.DMatrix(test_data)\n",
|
||||
" pred = model.predict(dtest)\n",
|
||||
" predictions = [round(value) for value in pred]\n",
|
||||
" predictions = [np.around(value) for value in pred]\n",
|
||||
" # evaluate predictions\n",
|
||||
" accuracy = accuracy_score(test_labels, predictions)\n",
|
||||
" try:\n",
|
||||
" accuracy = accuracy_score(test_labels, predictions)\n",
|
||||
" except:\n",
|
||||
" accuracy = 0.0\n",
|
||||
" logging.info(f\"Evaluation completed with model accuracy: {accuracy}\")\n",
|
||||
"\n",
|
||||
" # report metric for hyperparameter tuning\n",
|
||||
@@ -893,7 +909,7 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"DISPLAY_NAME = \"iris_\" + TIMESTAMP\n",
|
||||
"DISPLAY_NAME = \"iris_\" + UUID\n",
|
||||
"\n",
|
||||
"job = aip.CustomPythonPackageTrainingJob(\n",
|
||||
" display_name=DISPLAY_NAME,\n",
|
||||
@@ -932,7 +948,7 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"MODEL_DIR = \"{}/{}\".format(BUCKET_URI, TIMESTAMP)\n",
|
||||
"MODEL_DIR = \"{}/{}\".format(BUCKET_URI, UUID)\n",
|
||||
"DATASET_DIR = \"gs://cloud-samples-data/ai-platform/iris\"\n",
|
||||
"\n",
|
||||
"ROUNDS = 20\n",
|
||||
@@ -983,7 +999,7 @@
|
||||
"source": [
|
||||
"if TRAIN_GPU:\n",
|
||||
" model = job.run(\n",
|
||||
" model_display_name=\"iris_\" + TIMESTAMP,\n",
|
||||
" model_display_name=\"iris_\" + UUID,\n",
|
||||
" args=CMDARGS,\n",
|
||||
" replica_count=1,\n",
|
||||
" machine_type=TRAIN_COMPUTE,\n",
|
||||
@@ -994,7 +1010,7 @@
|
||||
" )\n",
|
||||
"else:\n",
|
||||
" model = job.run(\n",
|
||||
" model_display_name=\"iris_\" + TIMESTAMP,\n",
|
||||
" model_display_name=\"iris_\" + UUID,\n",
|
||||
" args=CMDARGS,\n",
|
||||
" replica_count=1,\n",
|
||||
" machine_type=TRAIN_COMPUTE,\n",
|
||||
@@ -1095,7 +1111,7 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"delete_bucket = False\n",
|
||||
"delete_bucket = True\n",
|
||||
"\n",
|
||||
"if delete_bucket or os.getenv(\"IS_TESTING\"):\n",
|
||||
" ! gsutil rm -r $BUCKET_URI"
|
||||
|
||||
@@ -116,7 +116,7 @@
|
||||
"\n",
|
||||
"The dataset used for this tutorial is the [Patent PDF Samples with Extracted Structured Data](https://console.cloud.google.com/marketplace/product/global-patents/labeled-patents) from Google Public Data Sets. \n",
|
||||
"\n",
|
||||
"This dataset includes data extracted from over 300 patent documents issued in the US and EU. The dataset includes links to Google Cloud Storage blobs for the first page of each patent, in addition to a number of extracted entities. \n",
|
||||
"This dataset includes data extracted from over 300 patent documents issued in the US and EU. The dataset includes links to Cloud Storage blobs for the first page of each patent, in addition to a number of extracted entities. \n",
|
||||
"\n",
|
||||
"The data is published as a [public dataset](https://cloud.google.com/bigquery/public-data) on `BigQuery`."
|
||||
]
|
||||
|
||||
+1391
File diff suppressed because it is too large
Load Diff
+1328
File diff suppressed because it is too large
Load Diff
@@ -568,7 +568,6 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import kfp\n",
|
||||
"from google.cloud import aiplatform\n",
|
||||
"from kfp import dsl\n",
|
||||
"from kfp.v2 import compiler\n",
|
||||
@@ -1000,11 +999,7 @@
|
||||
" from google.auth.transport.requests import Request\n",
|
||||
" from google.oauth2 import id_token\n",
|
||||
"\n",
|
||||
" IAM_SCOPE = \"https://www.googleapis.com/auth/iam\"\n",
|
||||
" OAUTH_TOKEN_URI = \"https://www.googleapis.com/oauth2/v4/token\"\n",
|
||||
"\n",
|
||||
" data = '{\"replace_microseconds\":\"false\"}'\n",
|
||||
" context = None\n",
|
||||
"\n",
|
||||
" \"\"\"Makes a POST request to the Composer DAG Trigger API\n",
|
||||
"\n",
|
||||
|
||||
+1
-1
@@ -44,7 +44,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/community/ml_ops/stage3/get_started_with_automl_tabular_pipeline_workflow.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/ml_ops/stage3/get_started_with_automl_tabular_pipeline_workflow.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",
|
||||
|
||||
+2
-2
@@ -39,9 +39,9 @@
|
||||
" </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/blob/main/notebooks/community/ml_ops/stage3/get_started_with_dataflow_pipeline_components.ipynb\">\n",
|
||||
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage3/get_started_with_dataflow_pipeline_components.ipynb\">\n",
|
||||
"<img src=\"https://cloud.google.com/ml-engine/images/colab-logo-32px.png\" alt=\"Colab logo\"> \n",
|
||||
" Colab logo Run in Colab\n",
|
||||
" Run in Colab\n",
|
||||
" </a>\n",
|
||||
" </td>\n",
|
||||
" <td>\n",
|
||||
|
||||
+5
-5
@@ -60,7 +60,7 @@
|
||||
"source": [
|
||||
"## Overview\n",
|
||||
"\n",
|
||||
"This tutorial demonstrates how to use Vertex AI Pipelines to rapid prototype a model using both AutoML and BQML, do an evaluation comparison, for a baseline, before progressing to a custom model.\n",
|
||||
"This tutorial demonstrates how to use Vertex AI Pipelines to rapid prototype a model using both AutoML and BigQuery ML, do an evaluation comparison, for a baseline, before progressing to a custom model.\n",
|
||||
"\n",
|
||||
"<img src=\"https://storage.googleapis.com/rafacarv-public-bucket-do-not-delete/abalone/automl_and_bqml.png\" />"
|
||||
]
|
||||
@@ -834,7 +834,7 @@
|
||||
"source": [
|
||||
"### Create component: Split the dataset into train, test and eval\n",
|
||||
"\n",
|
||||
"For this pipeline, you set aside a portion of the dataset for test evaluation. While both AutoML and BQML will automatically split then datasets, in this example you will explicitly split the datasets into:\n",
|
||||
"For this pipeline, you set aside a portion of the dataset for test evaluation. While both AutoML and BigQuery ML will automatically split then datasets, in this example you will explicitly split the datasets into:\n",
|
||||
"\n",
|
||||
"- TRAIN\n",
|
||||
"- EVALUATE\n",
|
||||
@@ -1000,11 +1000,11 @@
|
||||
"- Construct the CREATE MODEL query using a static Python function `_create_model_query()`, which runs in the context of the pipeline.\n",
|
||||
"- Call the prebuilt component `BigQueryCreateModelOp`, with the constructed query, to train the BigQuery ML model.\n",
|
||||
"\n",
|
||||
"For this tutorial, you use a simple linear regression model on BQML. \n",
|
||||
"For this tutorial, you use a simple linear regression model on BigQuery ML. \n",
|
||||
"\n",
|
||||
"For a full list of models supported by BQML, look here: [End-to-end user journey for each model](https://cloud.google.com/bigquery-ml/docs/reference/standard-sql/bigqueryml-syntax-e2e-journey).\n",
|
||||
"For a full list of models supported by BigQuery ML, look here: [End-to-end user journey for each model](https://cloud.google.com/bigquery-ml/docs/reference/standard-sql/bigqueryml-syntax-e2e-journey).\n",
|
||||
"\n",
|
||||
"As pointed out before, BQML and AutoML use different split terminologies, so we do an adaptation of the <i>split_col</i> column directly on the SELECT portion of the CREATE model query:\n",
|
||||
"As pointed out before, BigQuery ML and AutoML use different split terminologies, so we do an adaptation of the <i>split_col</i> column directly on the SELECT portion of the CREATE model query:\n",
|
||||
"\n",
|
||||
"> When the value of DATA_SPLIT_METHOD is 'CUSTOM', the corresponding column should be of type BOOL. The rows with TRUE or NULL values are used as evaluation data. Rows with FALSE values are used as training data."
|
||||
]
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -658,8 +658,6 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from typing import NamedTuple\n",
|
||||
"\n",
|
||||
"from kfp import dsl\n",
|
||||
"from kfp.v2 import compiler\n",
|
||||
"from kfp.v2.dsl import component"
|
||||
@@ -1866,7 +1864,7 @@
|
||||
" exported_tfrec_prefix=exported_tfrec_prefix,\n",
|
||||
" ).after(dataflow_wait_op)\n",
|
||||
"\n",
|
||||
" dataset_op = gcc_aip.TabularDatasetCreateOp(\n",
|
||||
" _ = gcc_aip.TabularDatasetCreateOp(\n",
|
||||
" project=project,\n",
|
||||
" display_name=display_name,\n",
|
||||
" bq_source=bq_table,\n",
|
||||
@@ -2285,7 +2283,7 @@
|
||||
" },\n",
|
||||
" ).after(model_build_op)\n",
|
||||
"\n",
|
||||
" model_upload = ModelUploadOp(\n",
|
||||
" _ = ModelUploadOp(\n",
|
||||
" project=project,\n",
|
||||
" display_name=display_name,\n",
|
||||
" unmanaged_container_model=import_unmanaged_model_task.outputs[\"artifact\"],\n",
|
||||
@@ -3205,7 +3203,7 @@
|
||||
"\n",
|
||||
" with dsl.Condition(warmup == \"True\", name=\"warmup-model\"):\n",
|
||||
"\n",
|
||||
" warmup_op = gcc_aip.CustomPythonPackageTrainingJobRunOp(\n",
|
||||
" _ = gcc_aip.CustomPythonPackageTrainingJobRunOp(\n",
|
||||
" project=project,\n",
|
||||
" display_name=display_name,\n",
|
||||
" # Warmup Training\n",
|
||||
@@ -3249,7 +3247,7 @@
|
||||
" display_name=display_name,\n",
|
||||
" ).after(training_op)\n",
|
||||
"\n",
|
||||
" deploy_op = ModelDeployOp(\n",
|
||||
" _ = ModelDeployOp(\n",
|
||||
" model=training_op.outputs[\"model\"],\n",
|
||||
" endpoint=endpoint_op.outputs[\"endpoint\"],\n",
|
||||
" dedicated_resources_min_replica_count=1,\n",
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
"id": "title:generic,gcp"
|
||||
},
|
||||
"source": [
|
||||
"# E2E ML on GCP: MLOps stage 4 : formalization: get started with Vertex AI ML Metadata\n",
|
||||
"# E2E ML on GCP: MLOps stage 4 : formalization: get started with Vertex ML Metadata\n",
|
||||
"\n",
|
||||
"<table align=\"left\">\n",
|
||||
" <td>\n",
|
||||
@@ -62,7 +62,7 @@
|
||||
"## Overview\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"This tutorial demonstrates how to use Vertex AI for E2E MLOps on Google Cloud in production. This tutorial covers stage 4 : formalization: get started with Vertex AI ML Metadata."
|
||||
"This tutorial demonstrates how to use Vertex AI for E2E MLOps on Google Cloud in production. This tutorial covers stage 4 : formalization: get started with Vertex ML Metadata."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -73,11 +73,11 @@
|
||||
"source": [
|
||||
"### Objective\n",
|
||||
"\n",
|
||||
"In this tutorial, you learn how to use `Vertex AI ML Metadata`.\n",
|
||||
"In this tutorial, you learn how to use `Vertex ML Metadata`.\n",
|
||||
"\n",
|
||||
"This tutorial uses the following Google Cloud ML services:\n",
|
||||
"\n",
|
||||
"- `Vertex AI ML Metadata`\n",
|
||||
"- `Vertex ML Metadata`\n",
|
||||
"- `Vertex AI Pipelines`\n",
|
||||
"\n",
|
||||
"The steps performed include:\n",
|
||||
@@ -657,7 +657,7 @@
|
||||
"source": [
|
||||
"## Introduction to Vertex AI Metadata\n",
|
||||
"\n",
|
||||
"The `Vertex AI ML Metadata` service provides you with the ability to record, and subsequently search and analyze, the artifacts and corresponding metadata produced by your ML workflows. For example, during experimentation one might desire to record the location of the model artifacts, as artifacts, and the training hyperparameters and evaluation metrics as the corresponding metadata.\n",
|
||||
"The `Vertex ML Metadata` service provides you with the ability to record, and subsequently search and analyze, the artifacts and corresponding metadata produced by your ML workflows. For example, during experimentation one might desire to record the location of the model artifacts, as artifacts, and the training hyperparameters and evaluation metrics as the corresponding metadata.\n",
|
||||
"\n",
|
||||
"The service supports recording ML metadata both manually and automatically, with the later occurring when you use Vertex AI Pipelines.\n",
|
||||
"\n",
|
||||
@@ -675,9 +675,9 @@
|
||||
"\n",
|
||||
"### ML artifact lineage\n",
|
||||
"\n",
|
||||
"Vertex AI ML Metadata provides the ability to understand changes in the performance of your machine ML system, and analyze the metadata produced by your ML workflow and the lineage of its artifacts. An artifact's lineage includes all the factors that contributed to its creation, as well as artifacts and metadata that descend from this artifact.\n",
|
||||
"Vertex ML Metadata provides the ability to understand changes in the performance of your machine ML system, and analyze the metadata produced by your ML workflow and the lineage of its artifacts. An artifact's lineage includes all the factors that contributed to its creation, as well as artifacts and metadata that descend from this artifact.\n",
|
||||
"\n",
|
||||
"Learn more about [Introduction to Vertex AI ML Metadata ](https://cloud.google.com/vertex-ai/docs/ml-metadata/introduction)"
|
||||
"Learn more about [Introduction to Vertex ML Metadata ](https://cloud.google.com/vertex-ai/docs/ml-metadata/introduction)"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
+1139
-1150
File diff suppressed because it is too large
Load Diff
+876
-895
File diff suppressed because it is too large
Load Diff
+1848
-1860
File diff suppressed because it is too large
Load Diff
+1399
-1382
File diff suppressed because it is too large
Load Diff
+1110
-1122
File diff suppressed because it is too large
Load Diff
+1072
-1080
File diff suppressed because it is too large
Load Diff
@@ -1054,36 +1054,17 @@
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"colab": {
|
||||
"collapsed_sections": [],
|
||||
"name": "get_started_with_tf_serving_function.ipynb",
|
||||
"toc_visible": true
|
||||
"metadata": {
|
||||
"colab": {
|
||||
"collapsed_sections": [],
|
||||
"name": "get_started_with_tf_serving_function.ipynb",
|
||||
"toc_visible": true
|
||||
},
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3",
|
||||
"name": "python3"
|
||||
}
|
||||
},
|
||||
"environment": {
|
||||
"kernel": "python3",
|
||||
"name": "tf2-gpu.2-6.m91",
|
||||
"type": "gcloud",
|
||||
"uri": "gcr.io/deeplearning-platform-release/tf2-gpu.2-6:m91"
|
||||
},
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.7.12"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 4
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 0
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@
|
||||
"\n",
|
||||
"The steps performed include:\n",
|
||||
"\n",
|
||||
"- Locally train a Pytorch tabular classifier.\n",
|
||||
"- Locally train a PyTorch tabular classifier.\n",
|
||||
"- Locally test the trained model.\n",
|
||||
"- Build a HTTP server using FastAPI.\n",
|
||||
"- Create a custom serving container with the trained model and FastAPI server.\n",
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
+1533
-1552
File diff suppressed because it is too large
Load Diff
+1655
-1674
File diff suppressed because it is too large
Load Diff
+1871
-1890
File diff suppressed because it is too large
Load Diff
+1710
-1729
File diff suppressed because it is too large
Load Diff
+1
-1
@@ -53,7 +53,7 @@
|
||||
"source": [
|
||||
"## Overview\n",
|
||||
"\n",
|
||||
"This tutorial demonstrates how to use Vertex AI SDK to build a custom container that uses the Custom Prediction Routine model server to serve a scikit-learn model on Vertex AI Predictions. This is currently a **preview** feature. Pre-GA products and features might have limited support, and changes to pre-GA products and features might not be compatible with other pre-GA versions. For more information, see the [launch stage descriptions](https://cloud.google.com/products#product-launch-stages).\n",
|
||||
"This tutorial demonstrates how to use Vertex AI SDK to build a custom container that uses the Custom Prediction Routine model server to serve a scikit-learn model on Vertex AI Predictions.\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"\n",
|
||||
|
||||
+1
-1
@@ -53,7 +53,7 @@
|
||||
"source": [
|
||||
"## Overview\n",
|
||||
"\n",
|
||||
"This tutorial demonstrates how to use Vertex AI SDK to build a custom container that uses the Custom Prediction Routine model server to serve a scikit-learn model on Vertex AI Predictions. This is currently a **preview** feature. Pre-GA products and features might have limited support, and changes to pre-GA products and features might not be compatible with other pre-GA versions. For more information, see the [launch stage descriptions](https://cloud.google.com/products#product-launch-stages).\n",
|
||||
"This tutorial demonstrates how to use Vertex AI SDK to build a custom container that uses the Custom Prediction Routine model server to serve a scikit-learn model on Vertex AI Predictions.\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"\n",
|
||||
|
||||
+1
-1
@@ -53,7 +53,7 @@
|
||||
"source": [
|
||||
"## Overview\n",
|
||||
"\n",
|
||||
"This tutorial demonstrates how to use Vertex AI SDK to build a custom container that uses the Custom Prediction Routine model server to serve a scikit-learn model on Vertex AI Predictions. This is currently a **preview** feature. Pre-GA products and features might have limited support, and changes to pre-GA products and features might not be compatible with other pre-GA versions. For more information, see the [launch stage descriptions](https://cloud.google.com/products#product-launch-stages).\n",
|
||||
"This tutorial demonstrates how to use Vertex AI SDK to build a custom container that uses the Custom Prediction Routine model server to serve a scikit-learn model on Vertex AI Predictions.\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"\n",
|
||||
|
||||
+1
-1
@@ -53,7 +53,7 @@
|
||||
"source": [
|
||||
"## Overview\n",
|
||||
"\n",
|
||||
"This tutorial demonstrates how to use Vertex AI SDK to build a custom container that uses the Custom Prediction Routine model server to serve a PyTorch model on Vertex AI Predictions. This is currently a **preview** feature. Pre-GA products and features might have limited support, and changes to pre-GA products and features might not be compatible with other pre-GA versions. For more information, see the [launch stage descriptions](https://cloud.google.com/products#product-launch-stages).\n",
|
||||
"This tutorial demonstrates how to use Vertex AI SDK to build a custom container that uses the Custom Prediction Routine model server to serve a PyTorch model on Vertex AI Predictions.\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"\n",
|
||||
|
||||
+1
-1
@@ -53,7 +53,7 @@
|
||||
"source": [
|
||||
"## Overview\n",
|
||||
"\n",
|
||||
"This tutorial demonstrates how to use Vertex AI SDK to locally test [NVIDIA Triton inference server](https://developer.nvidia.com/nvidia-triton-inference-server) to serve a PyTorch model and deploy it to Vertex AI Predictions. This is currently a **preview** feature. Pre-GA products and features might have limited support, and changes to pre-GA products and features might not be compatible with other pre-GA versions. For more information, see the [launch stage descriptions](https://cloud.google.com/products#product-launch-stages).\n",
|
||||
"This tutorial demonstrates how to use Vertex AI SDK to locally test [NVIDIA Triton inference server](https://developer.nvidia.com/nvidia-triton-inference-server) to serve a PyTorch model and deploy it to Vertex AI Predictions.\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"### Dataset\n",
|
||||
|
||||
@@ -0,0 +1,619 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "7fPc-KWUi2Xd"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# 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",
|
||||
"# You may obtain a copy of the License at\n",
|
||||
"#\n",
|
||||
"# https://www.apache.org/licenses/LICENSE-2.0\n",
|
||||
"#\n",
|
||||
"# Unless required by applicable law or agreed to in writing, software\n",
|
||||
"# distributed under the License is distributed on an \"AS IS\" BASIS,\n",
|
||||
"# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n",
|
||||
"# See the License for the specific language governing permissions and\n",
|
||||
"# limitations under the License."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "eoXf8TfQoVth"
|
||||
},
|
||||
"source": [
|
||||
"# Convert between Vertex AI Vizier and Open Source Vizier\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/vizier/conversions_vertex_vizier_and_open_source_vizier.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/vizier/conversions_vertex_vizier_and_open_source_vizier.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/main/notebooks/community/vizier/conversions_vertex_vizier_and_open_source_vizier.ipynb\">\n",
|
||||
" <img src=\"https://lh3.googleusercontent.com/UiNooY4LUgW_oTvpsNhPpQzsstV5W8F7rYgxgGBD85cWJoLmrOzhVs_ksK_vgx40SHs7jCqkTkCk=e14-rj-sc0xffffff-h130-w32\" alt=\"Vertex AI logo\">\n",
|
||||
" Open in Vertex AI Workbench\n",
|
||||
" </a>\n",
|
||||
" </td>\n",
|
||||
"</table>"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "b397c59391b1"
|
||||
},
|
||||
"source": [
|
||||
"## Overview\n",
|
||||
"\n",
|
||||
"This tutorial demonstrates how to migrate code between [Vertex AI Vizier](https://cloud.google.com/vertex-ai/docs/vizier/overview) and [Open Source(OSS) Vizier](https://oss-vizier.readthedocs.io/). OSS Vizier is a Python-based service for blackbox optimization and research. It allows you to setup an OSS Vizier Server that can host blackbox optimization algorithms for tuning objective functions and defining abstractions and utilities for implementing new optimization algorithms.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "AksIKBzZ-nre"
|
||||
},
|
||||
"source": [
|
||||
"### Objective\n",
|
||||
"\n",
|
||||
"In this tutorial, you learn how to use `Vertex AI Vizier` to optimize a multi-objective study and convert the code to OSS Vizier.\n",
|
||||
"\n",
|
||||
"The goal is to __`minimize`__ the objective metric:\n",
|
||||
" ```\n",
|
||||
" y1 = r*sin(theta)\n",
|
||||
" ```\n",
|
||||
"\n",
|
||||
"and simultaneously __`maximize`__ the objective metric:\n",
|
||||
" ```\n",
|
||||
" y2 = r*cos(theta)\n",
|
||||
" ```\n",
|
||||
"\n",
|
||||
"so that you will evaluate over the parameter space:\n",
|
||||
"\n",
|
||||
" - __`r`__ in [0,1],\n",
|
||||
"\n",
|
||||
" - __`theta`__ in [0, pi/2]\n",
|
||||
"\n",
|
||||
"### Costs\n",
|
||||
"\n",
|
||||
"This tutorial uses billable components of Google Cloud:\n",
|
||||
"\n",
|
||||
"* Vertex AI\n",
|
||||
"\n",
|
||||
"Learn about [Vertex AI\n",
|
||||
"pricing](https://cloud.google.com/vertex-ai/pricing) and use the [Pricing\n",
|
||||
"Calculator](https://cloud.google.com/products/calculator/)\n",
|
||||
"to generate a cost estimate based on your projected usage.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "iMHz63rPbq6P"
|
||||
},
|
||||
"source": [
|
||||
"## Installation\n",
|
||||
"\n",
|
||||
"Install the packages required for executing this notebook."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "b6f3dc43494b"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import os\n",
|
||||
"\n",
|
||||
"# Configure the environment for the Vertex AI Workbench notebook.\n",
|
||||
"IS_WORKBENCH_NOTEBOOK = os.getenv(\"DL_ANACONDA_HOME\") and not os.getenv(\"VIRTUAL_ENV\")\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",
|
||||
"! pip3 install google-vizier==0.0.4\n",
|
||||
"! pip3 install --upgrade google-cloud-aiplatform {USER_FLAG} -q"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "64d24b4fab2c"
|
||||
},
|
||||
"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."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "O8AIwN0abq6U"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import os\n",
|
||||
"\n",
|
||||
"if not os.getenv(\"IS_TESTING\"):\n",
|
||||
" # Restart the kernel after pip installs\n",
|
||||
" import IPython\n",
|
||||
"\n",
|
||||
" app = IPython.Application.instance()\n",
|
||||
" app.kernel.do_shutdown(True)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"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",
|
||||
"\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",
|
||||
"\n",
|
||||
"4. [The Google Cloud SDK](https://cloud.google.com/sdk) is already installed in Google Cloud Notebook.\n",
|
||||
"\n",
|
||||
"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",
|
||||
"**Note**: Jupyter runs lines prefixed with `!` as shell commands, and it interpolates Python variables prefixed with `$`."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "set_project_id"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"PROJECT_ID = \"[your-project-id]\" # @param {type:\"string\"}"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "autoset_project_id"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"if PROJECT_ID == \"\" or PROJECT_ID is None or PROJECT_ID == \"[your-project-id]\":\n",
|
||||
" # Get your Google Cloud 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,
|
||||
"metadata": {
|
||||
"id": "set_gcloud_project_id"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"! gcloud config set project $PROJECT_ID"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "region"
|
||||
},
|
||||
"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. We recommend 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": "04933ed28eef"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"REGION = \"[your-region]\" # @param {type:\"string\"}"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "jvNx3KyF2Ou0"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"if REGION == \"[your-region]\":\n",
|
||||
" REGION = \"us-central1\""
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "h0SMyUsC-mzi"
|
||||
},
|
||||
"source": [
|
||||
"### Authenticate your Google Cloud account\n",
|
||||
"\n",
|
||||
"**If you are using Vertex AI Workbench Notebook**, your environment is already authenticated. Skip this step.\n",
|
||||
"\n",
|
||||
"**If you are using Colab**, run the cell below and follow the instructions\n",
|
||||
"when prompted to authenticate your account via oAuth.\n",
|
||||
"\n",
|
||||
"**Otherwise**, follow these steps:\n",
|
||||
"\n",
|
||||
"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,
|
||||
"metadata": {
|
||||
"id": "iTQY9g4mRo6r"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# If you are running this notebook in Colab, run this cell and follow the\n",
|
||||
"# instructions to authenticate your Google Cloud account. This provides access to your\n",
|
||||
"# Cloud Storage bucket and lets you submit training jobs and prediction\n",
|
||||
"# requests.\n",
|
||||
"\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",
|
||||
" google_auth.authenticate_user()\n",
|
||||
"\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 Google Cloud\n",
|
||||
" # account.\n",
|
||||
" elif not os.getenv(\"IS_TESTING\"):\n",
|
||||
" %env GOOGLE_APPLICATION_CREDENTIALS ''"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "Dax2zrpTi2Xy"
|
||||
},
|
||||
"source": [
|
||||
"### Import libraries and define constants"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "xD60d6Q0i2X0"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import datetime\n",
|
||||
"import math"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "CWuu4wmki2X3"
|
||||
},
|
||||
"source": [
|
||||
"## Tutorial\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "KyEjqIdnad0w"
|
||||
},
|
||||
"source": [
|
||||
"This section defines some parameters to create the study and optimize the objective function.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "8HCgeF8had77"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# These will be automatically filled in.\n",
|
||||
"STUDY_DISPLAY_NAME = \"{}_study_{}\".format(\n",
|
||||
" PROJECT_ID.replace(\"-\", \"\"), datetime.datetime.now().strftime(\"%Y%m%d_%H%M%S\")\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"print(\"REGION: {}\".format(REGION))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "8NBduXsEaRKr"
|
||||
},
|
||||
"source": [
|
||||
"### Define the parameters\n",
|
||||
"\n",
|
||||
"The following is a sample study configuration, built as a hierarchical python dictionary. It is already filled out. Run the cell to configure the study.\n",
|
||||
"\n",
|
||||
"__`USE_VERTEX_VIZIER`__: Uses Vertex Vizier SDK to do the optimization if True. Use OSS Vizier otherwise.\n",
|
||||
"\n",
|
||||
"__`SUGGESTION_COUNT`__: The number of suggestions (trials) requested in a single request.\n",
|
||||
"\n",
|
||||
"__`MAX_NUM_ITERATIONS`__: The number of iterations to explore before stopping. It is set to 4 to shorten the time to run the code, so don't expect convergence. For convergence, it would likely need to be about 20.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "E1VNJ4YBznhR"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"USE_VERTEX_VIZIER = True # @param {type:\"boolean\"}\n",
|
||||
"\n",
|
||||
"MAX_NUM_ITERATIONS = 4 # @param {type:\"integer\"}\n",
|
||||
"\n",
|
||||
"SUGGESTION_COUNT = 2 # @param {type:\"integer\"}\n",
|
||||
"\n",
|
||||
"OWNER = \"owner\" # @param {type:\"string\"}\n",
|
||||
"\n",
|
||||
"SERVICE_ENDPOINT = \"127.0.0.1:8888\" # @param {type:\"string\"}"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "4_Yvt-7Z8_re"
|
||||
},
|
||||
"source": [
|
||||
"### Import the package and define `create_study` for different sources\n",
|
||||
"\n",
|
||||
"In Vertex Vizier, `project` and `location` are already specified and `Study.create_or_load` is called to create a study. You need to input the owner of your study and the server address in the format [ip:port]. To bring up the OSS Vizier server, please follow the [instructions](https://oss-vizier.readthedocs.io/) on the OSS Vizier website."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "0sAHZn1406VR"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"if USE_VERTEX_VIZIER:\n",
|
||||
" from google.cloud import aiplatform\n",
|
||||
" from google.cloud.aiplatform.vizier import Study, pyvizier\n",
|
||||
"\n",
|
||||
" def create_study(project, location, display_name, problem):\n",
|
||||
" aiplatform.init(project=project, location=location)\n",
|
||||
" study = Study.create_or_load(display_name=display_name, problem=problem)\n",
|
||||
" return study\n",
|
||||
"\n",
|
||||
"else:\n",
|
||||
" from vizier.service import clients, pyvizier\n",
|
||||
"\n",
|
||||
" def create_study(project, location, display_name, problem):\n",
|
||||
" clients.environment_variables.service_endpoint = SERVICE_ENDPOINT\n",
|
||||
" study = clients.Study.from_study_config(\n",
|
||||
" problem, owner=OWNER, study_id=STUDY_DISPLAY_NAME\n",
|
||||
" )\n",
|
||||
" return study"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "guvkcQe_-zQf"
|
||||
},
|
||||
"source": [
|
||||
"### Metric evaluation functions\n",
|
||||
"\n",
|
||||
"Next, define some functions to evaluate the two objective metrics.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "Fjfk5_c900Oz"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# r * sin(theta)\n",
|
||||
"def Metric1Evaluation(r, theta):\n",
|
||||
" \"\"\"Evaluate the first metric on the trial.\"\"\"\n",
|
||||
" return r * math.sin(theta)\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# r * cos(theta)\n",
|
||||
"def Metric2Evaluation(r, theta):\n",
|
||||
" \"\"\"Evaluate the second metric on the trial.\"\"\"\n",
|
||||
" return r * math.cos(theta)\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def CreateMetrics(r, theta):\n",
|
||||
" # Evaluate both objective metrics for this trial\n",
|
||||
" y1 = Metric1Evaluation(r, theta)\n",
|
||||
" y2 = Metric2Evaluation(r, theta)\n",
|
||||
" print(\n",
|
||||
" \"[r = {}, theta = {}] => y1 = r*sin(theta) = {}, y2 = r*cos(theta) = {}\".format(\n",
|
||||
" r, theta, y1, y2\n",
|
||||
" )\n",
|
||||
" )\n",
|
||||
" measurement = pyvizier.Measurement()\n",
|
||||
" measurement.metrics[\"y1\"] = y1\n",
|
||||
" measurement.metrics[\"y2\"] = y2\n",
|
||||
"\n",
|
||||
" # Return the results for this trial\n",
|
||||
" return measurement"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "2DgUIEpZ-_fJ"
|
||||
},
|
||||
"source": [
|
||||
"### Optimization\n",
|
||||
"\n",
|
||||
"The following code defines a study with parameters and metrics, evaluates the metric information based on the suggestions from Vizier, and reports the metrics value back. After a few rounds of iteration, you can get optimal trials by calling `optimal_trials()`. The code is adapt to both Vertex Vizier and OSS Vizier."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "s-AHfPOASXXW"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"problem = pyvizier.StudyConfig()\n",
|
||||
"problem.algorithm = pyvizier.Algorithm.RANDOM_SEARCH\n",
|
||||
"\n",
|
||||
"# Objective Metrics\n",
|
||||
"problem.metric_information.append(\n",
|
||||
" pyvizier.MetricInformation(name=\"y1\", goal=pyvizier.ObjectiveMetricGoal.MINIMIZE)\n",
|
||||
")\n",
|
||||
"problem.metric_information.append(\n",
|
||||
" pyvizier.MetricInformation(name=\"y2\", goal=pyvizier.ObjectiveMetricGoal.MAXIMIZE)\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"# Defines the parameters configuration.\n",
|
||||
"root = problem.search_space.select_root()\n",
|
||||
"root.add_float_param(\"r\", 0, 1.0, scale_type=pyvizier.ScaleType.LINEAR)\n",
|
||||
"root.add_float_param(\"theta\", 0, 1.57, scale_type=pyvizier.ScaleType.LINEAR)\n",
|
||||
"\n",
|
||||
"study = create_study(\n",
|
||||
" project=PROJECT_ID,\n",
|
||||
" location=REGION,\n",
|
||||
" display_name=STUDY_DISPLAY_NAME,\n",
|
||||
" problem=problem,\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"for _ in range(MAX_NUM_ITERATIONS):\n",
|
||||
" trials = study.suggest(count=SUGGESTION_COUNT)\n",
|
||||
" for trial in trials:\n",
|
||||
" materialize_trial = trial.materialize()\n",
|
||||
" measurement = CreateMetrics(\n",
|
||||
" materialize_trial.parameters.get_value(\"r\"),\n",
|
||||
" materialize_trial.parameters.get_value(\"theta\"),\n",
|
||||
" )\n",
|
||||
" trial.add_measurement(measurement=measurement)\n",
|
||||
" trial.complete(measurement=measurement)\n",
|
||||
"\n",
|
||||
"optimal_trials = study.optimal_trials()\n",
|
||||
"print(\"optimal_trials: {}\".format(optimal_trials))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "KAxfq9Fri2YV"
|
||||
},
|
||||
"source": [
|
||||
"## 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. You can also manually delete resources that you created by running the following code."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "zQlLDfvlzYde"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"study.delete()"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"colab": {
|
||||
"collapsed_sections": [],
|
||||
"name": "conversions_vertex_vizier_and_open_source_vizier.ipynb",
|
||||
"toc_visible": true
|
||||
},
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3",
|
||||
"name": "python3"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 0
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -17,11 +17,12 @@
|
||||
/tensorboard @zbl94
|
||||
|
||||
/bigquery_ml/bqml-online-prediction.ipynb @polong-lin
|
||||
/model_monitoring/model_monitoring.ipynb @mco-gh
|
||||
/model_monitoring/model_monitoring.ipynb @andrewferlitsch
|
||||
/ml_metadata/sdk-metric-parameter-tracking-for-custom-jobs.ipynb @jialuzh
|
||||
/ml_metadata/sdk-metric-parameter-tracking-for-locally-trained-models.ipynb @jialuzh
|
||||
/ml_metadata/vertex-pipelines-ml-metadata.ipynb @sararob
|
||||
/vizier/gapic-vizier-multi-objective-optimization.ipynb @halio-g
|
||||
/training/xgboost_data_parallel_training_on_cpu_using_dask.ipynb @halio-g
|
||||
/feature_store/gapic-feature-store.ipynb @diemtvu
|
||||
/managed_notebooks @GoogleCloudPlatform/notebooks-team
|
||||
/pipelines/google_cloud_pipeline_components_bqml_text.ipynb @inardini
|
||||
@@ -31,7 +32,7 @@
|
||||
/custom/custom_training_tensorboard_profiler.ipynb @itseric
|
||||
/workbench/spark/spark_sample_notebook.ipynb @bradmiro
|
||||
/workbench/spark/spark_ml.ipynb @bradmiro
|
||||
/model-registry/bqml-vertexai-model-registry.ipynb @soheilazangeneh
|
||||
/model_registry/bqml_vertexai_model_registry.ipynb @soheilazangeneh
|
||||
/workbench/exploratory_data_analysis/explore_data_in_bigquery_with_workbench.ipynb @alokpattani
|
||||
/model_evaluation/automl_tabular_classification_model_evaluation.ipynb @soheilazangeneh
|
||||
/model_evaluation/automl_tabular_regression_model_evaluation.ipynb @soheilazangeneh
|
||||
|
||||
+127
-23
@@ -9,7 +9,7 @@ The official notebooks are organized by Google Cloud Vertex AI services.
|
||||
### AutoML Text data
|
||||
|
||||
|
||||
[Create, train, and deploy an AutoML text classification model](official/automl/automl-text-classification.ipynb)
|
||||
[Create, train, and deploy an AutoML text classification model](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/automl/automl-text-classification.ipynb)
|
||||
|
||||
Learn how to use `AutoML` to train a text classification model.
|
||||
|
||||
@@ -26,7 +26,7 @@ The steps performed include:
|
||||
### AutoML Tabular data
|
||||
|
||||
|
||||
[AutoML tabular forecasting model for batch prediction](official/automl/sdk_automl_tabular_forecasting_batch.ipynb)
|
||||
[AutoML tabular forecasting model for batch prediction](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/automl/sdk_automl_tabular_forecasting_batch.ipynb)
|
||||
|
||||
Learn how to create an `AutoML` tabular forecasting model from a Python script, and then do a batch prediction using the Vertex AI SDK.
|
||||
|
||||
@@ -40,7 +40,7 @@ The steps performed include:
|
||||
### BigQuery ML Vertex AI Model Registry Batch prediction
|
||||
|
||||
|
||||
[Deploy BiqQuery ML Model on Vertex AI Model Registry and make predictions](official/model-registry/bqml-vertexai-model-registry.ipynb)
|
||||
[Deploy BiqQuery ML Model on Vertex AI Model Registry and make predictions](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/model-registry/bqml-vertexai-model-registry.ipynb)
|
||||
|
||||
Learn how to use `Vertex AI Model Registry` with `BigQuery ML` and make batch predictions:
|
||||
|
||||
@@ -57,7 +57,7 @@ The steps performed include:
|
||||
### BigQuery ML Vertex AI Model Registry Online prediction
|
||||
|
||||
|
||||
[Online prediction with BigQuery ML](official/bigquery_ml/bqml-online-prediction.ipynb)
|
||||
[Online prediction with BigQuery ML](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/bigquery_ml/bqml-online-prediction.ipynb)
|
||||
|
||||
Learn how to train and deploy a churn prediction model for real-time inference, with the data in BigQuery and model trained using BigQuery ML, registered to Vertex AI Model Registry, and deployed to an endpoint on Vertex AI for online predictions.
|
||||
|
||||
@@ -74,7 +74,7 @@ The steps performed include:
|
||||
### Custom Training
|
||||
|
||||
|
||||
[Custom training and batch prediction](official/custom/sdk-custom-image-classification-batch.ipynb)
|
||||
[Custom training and batch prediction](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/custom/sdk-custom-image-classification-batch.ipynb)
|
||||
|
||||
Learn to use `Vertex AI Training` to create a custom trained model and use `Vertex AI Batch Prediction` to do a batch prediction on the trained model.
|
||||
|
||||
@@ -84,7 +84,7 @@ The steps performed include:
|
||||
- Upload the trained model artifacts as a `Model` resource.
|
||||
- Make a batch prediction.
|
||||
|
||||
[Custom training and online prediction](official/custom/sdk-custom-image-classification-online.ipynb)
|
||||
[Custom training and online prediction](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/custom/sdk-custom-image-classification-online.ipynb)
|
||||
|
||||
Learn to use `Vertex AI Training` to create a custom-trained model from a Python script in a Docker container, and learn to use `Vertex AI Prediction` to do a prediction on the deployed model by sending data.
|
||||
|
||||
@@ -100,7 +100,7 @@ The steps performed include:
|
||||
### Tabular Data
|
||||
|
||||
|
||||
[Compare Vertex AI Forecasting and BigQuery ML ARIMA_PLUS](official/automl/automl_forecasting_bqml_arima_plus_comparison.ipynb)
|
||||
[Compare Vertex AI Forecasting and BigQuery ML ARIMA_PLUS](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/automl/automl_forecasting_bqml_arima_plus_comparison.ipynb)
|
||||
|
||||
Learn how to create an BQML ARIMA_PLUS model using a training [Vertex AI Pipeline](https://cloud.
|
||||
|
||||
@@ -115,22 +115,34 @@ The steps performed are:
|
||||
- Make a batch prediction with the Model.
|
||||
|
||||
|
||||
### AutoML Tabular Data
|
||||
|
||||
|
||||
[AutoML Tabular Pipeline](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/automl/automl_tabular_on_vertex_pipelines.ipynb)
|
||||
|
||||
Learn how to create two regression models using [Vertex Pipelines](https://cloud.
|
||||
|
||||
The steps performed are:
|
||||
|
||||
- Create a training pipeline that reduces the search space from the default to save time.
|
||||
- Create a training pipeline that reuses the architecture search results from the previous pipeline to save time.
|
||||
|
||||
### Vertex AI Experiments
|
||||
|
||||
|
||||
[Compare pipeline runs with Vertex AI Experiments](official/experiments/comparing_pipeline_runs.ipynb)
|
||||
[Compare pipeline runs with Vertex AI Experiments](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/experiments/comparing_pipeline_runs.ipynb)
|
||||
|
||||
Learn how to use `Vertex AI Experiments` to log a pipeline job and compare different pipeline jobs.
|
||||
|
||||
|
||||
|
||||
[Build Vertex AI Experiment lineage for custom training](official/experiments/build_model_experimentation_lineage_with_prebuild_code.ipynb)
|
||||
[Build Vertex AI Experiment lineage for custom training](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/experiments/build_model_experimentation_lineage_with_prebuild_code.ipynb)
|
||||
|
||||
Learn how to integrate preprocessing code in a Vertex AI experiments.
|
||||
|
||||
|
||||
|
||||
[Track parameters and metrics for locally trained models](official/experiments/comparing_local_trained_models.ipynb)
|
||||
[Track parameters and metrics for locally trained models](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/experiments/comparing_local_trained_models.ipynb)
|
||||
|
||||
Learn how to use Vertex AI Experiments to compare and evaluate model experiments.
|
||||
|
||||
@@ -144,7 +156,7 @@ The steps performed include:
|
||||
### Vertex AI Feature Store
|
||||
|
||||
|
||||
[Online and Batch predictions using Vertex AI Feature Store](official/feature_store/sdk-feature-store.ipynb)
|
||||
[Online and Batch predictions using Vertex AI Feature Store](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/feature_store/sdk-feature-store.ipynb)
|
||||
|
||||
Learn how to use `Vertex AI Feature Store` to import feature data, and to access the feature data for both online serving and offline tasks, such as training.
|
||||
|
||||
@@ -158,7 +170,7 @@ The steps performed include:
|
||||
### Matching Engine
|
||||
|
||||
|
||||
[Create Vertex AI Matching Engine index](official/matching_engine/sdk_matching_engine_for_indexing.ipynb)
|
||||
[Create Vertex AI Matching Engine index](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/matching_engine/sdk_matching_engine_for_indexing.ipynb)
|
||||
|
||||
Learn how to create Approximate Nearest Neighbor (ANN) Index, query against indexes, and validate the performance of the index.
|
||||
|
||||
@@ -174,7 +186,7 @@ The steps performed include:
|
||||
### Model Monitoring
|
||||
|
||||
|
||||
[Vertex AI Model Monitoring with Explainable AI Feature Attributions](official/model_monitoring/model_monitoring.ipynb)
|
||||
[Vertex AI Model Monitoring with Explainable AI Feature Attributions](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/model_monitoring/model_monitoring.ipynb)
|
||||
|
||||
Learn to use the `Vertex AI Model Monitoring` service to detect drift and anomalies in prediction requests from a deployed `Vertex AI Model` resource.
|
||||
|
||||
@@ -191,7 +203,7 @@ The steps performed include:
|
||||
### Vertex AI Pipelines
|
||||
|
||||
|
||||
[Lightweight Python function-based components, and component I/O](official/pipelines/lightweight_functions_component_io_kfp.ipynb)
|
||||
[Lightweight Python function-based components, and component I/O](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/pipelines/lightweight_functions_component_io_kfp.ipynb)
|
||||
|
||||
Learn to use the KFP SDK to build lightweight Python function-based components, and then you learn to use `Vertex AI Pipelines` to execute the pipeline.
|
||||
|
||||
@@ -204,10 +216,29 @@ The steps performed include:
|
||||
- Compile the KFP pipeline.
|
||||
- Execute the KFP pipeline using `Vertex AI Pipelines`
|
||||
|
||||
### Vertex AI Pipelines Image data
|
||||
|
||||
|
||||
[AutoML image classification pipelines using google-cloud-pipeline-components](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/pipelines/google_cloud_pipeline_components_automl_images.ipynb)
|
||||
|
||||
Learn how to use `Vertex AI Pipelines` and `Google Cloud Pipeline Components` to build an `AutoML` image classification model.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Create a KFP pipeline:
|
||||
- Create a `Dataset` resource.
|
||||
- Train an AutoML image classification `Model` resource.
|
||||
- Create an `Endpoint` resource.
|
||||
- Deploys the `Model` resource to the `Endpoint` resource.
|
||||
- Compile the KFP pipeline.
|
||||
- Execute the KFP pipeline using `Vertex AI Pipelines`
|
||||
|
||||
|
||||
|
||||
### Vertex AI Pipelines Tabular data
|
||||
|
||||
|
||||
[AutoML Tabular pipelines using google-cloud-pipeline-components](official/pipelines/automl_tabular_classification_beans.ipynb)
|
||||
[AutoML Tabular pipelines using google-cloud-pipeline-components](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/pipelines/automl_tabular_classification_beans.ipynb)
|
||||
|
||||
Learn to use `Vertex AI Pipelines` and `Google Cloud Pipeline Components` to build an `AutoML` tabular classification model.
|
||||
|
||||
@@ -223,7 +254,7 @@ The steps performed include:
|
||||
|
||||
|
||||
|
||||
[AutoML tabular regression pipelines using google-cloud-pipeline-components](official/pipelines/google_cloud_pipeline_components_automl_tabular.ipynb)
|
||||
[AutoML tabular regression pipelines using google-cloud-pipeline-components](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/pipelines/google_cloud_pipeline_components_automl_tabular.ipynb)
|
||||
|
||||
Learn to use `Vertex AI Pipelines` and `Google Cloud Pipeline Components` to build an `AutoML` tabular regression model.
|
||||
|
||||
@@ -239,10 +270,29 @@ The steps performed include:
|
||||
|
||||
|
||||
|
||||
### Vertex AI Pipelines Text data
|
||||
|
||||
|
||||
[AutoML text classification pipelines using google-cloud-pipeline-components](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/pipelines/google_cloud_pipeline_components_automl_text.ipynb)
|
||||
|
||||
Learn to use `Vertex AI Pipelines` and `Google Cloud Pipeline Components` to build an `AutoML` text classification model.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Create a KFP pipeline:
|
||||
- Create a `Dataset` resource.
|
||||
- Train an AutoML text classification `Model` resource.
|
||||
- Create an `Endpoint` resource.
|
||||
- Deploys the `Model` resource to the `Endpoint` resource.
|
||||
- Compile the KFP pipeline.
|
||||
- Execute the KFP pipeline using `Vertex AI Pipelines`
|
||||
|
||||
|
||||
|
||||
### Vertex AI Pipelines
|
||||
|
||||
|
||||
[Custom training with pre-built Google Cloud Pipeline Components](official/pipelines/custom_model_training_and_batch_prediction.ipynb)
|
||||
[Custom training with pre-built Google Cloud Pipeline Components](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/pipelines/custom_model_training_and_batch_prediction.ipynb)
|
||||
|
||||
Learn to use `Vertex AI Pipelines` and `Google Cloud Pipeline Components` to build a custom model.
|
||||
|
||||
@@ -257,7 +307,7 @@ The steps performed include:
|
||||
|
||||
|
||||
|
||||
[Pipeline control structures using the KFP SDK](official/pipelines/control_flow_kfp.ipynb)
|
||||
[Pipeline control structures using the KFP SDK](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/pipelines/control_flow_kfp.ipynb)
|
||||
|
||||
Learn how to use the KFP SDK to build pipelines that use loops and conditionals, including nested examples.
|
||||
|
||||
@@ -268,7 +318,7 @@ The steps performed include:
|
||||
- Compile the KFP pipeline.
|
||||
- Execute the KFP pipeline using `Vertex AI Pipelines`
|
||||
|
||||
[Metrics visualization and run comparison using the KFP SDK](official/pipelines/metrics_viz_run_compare_kfp.ipynb)
|
||||
[Metrics visualization and run comparison using the KFP SDK](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/pipelines/metrics_viz_run_compare_kfp.ipynb)
|
||||
|
||||
Learn how to use the KFP SDK to build pipelines that generate evaluation metrics.
|
||||
|
||||
@@ -281,7 +331,7 @@ The steps performed include:
|
||||
- Execute KFP pipelines
|
||||
- Compare metrics across pipeline runs
|
||||
|
||||
[Pipelines introduction for KFP](official/pipelines/pipelines_intro_kfp.ipynb)
|
||||
[Pipelines introduction for KFP](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/pipelines/pipelines_intro_kfp.ipynb)
|
||||
|
||||
Learn how to use the KFP SDK to build pipelines that generate evaluation metrics.
|
||||
|
||||
@@ -290,10 +340,19 @@ The steps performed include:
|
||||
- Define and compile a `Vertex AI` pipeline.
|
||||
- Specify which service account to use for a pipeline run.
|
||||
|
||||
### Vertex AI Vizier
|
||||
|
||||
|
||||
[Optimizing multiple objectives with Vertex AI Vizier](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/vizier/gapic-vizier-multi-objective-optimization.ipynb)
|
||||
|
||||
Learn how to use `Vertex AI Vizier` to optimize a multi-objective study.
|
||||
|
||||
|
||||
|
||||
### Vertex Explainable AI Tabular data
|
||||
|
||||
|
||||
[AutoML training tabular binary classification model for batch explanation](official/explainable_ai/sdk_automl_tabular_binary_classification_batch_explain.ipynb)
|
||||
[AutoML training tabular binary classification model for batch explanation](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/explainable_ai/sdk_automl_tabular_binary_classification_batch_explain.ipynb)
|
||||
|
||||
Learn to use `AutoML` to create a tabular binary classification model from a Python script, and then learn to use `Vertex AI Batch Prediction` to make predictions with explanations.
|
||||
|
||||
@@ -309,10 +368,24 @@ The steps performed include:
|
||||
|
||||
* Batch Prediction Service: Does a queued (batch) prediction for the entire set of instances in the background and stores the results in a Cloud Storage bucket when ready.
|
||||
|
||||
[AutoML training tabular classification model for online explanation](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/explainable_ai/sdk_automl_tabular_classification_online_explain.ipynb)
|
||||
|
||||
Learn how to use `AutoML` to create a tabular binary classification model from a Python script, and then learn to use `Vertex AI Online Prediction` to make online predictions with explanations.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Create a `Vertex Dataset` resource.
|
||||
- Train an `AutoML` tabular binary classification model.
|
||||
- View the model evaluation metrics for the trained model.
|
||||
- Create a serving `Endpoint` resource.
|
||||
- Deploy the `Model` resource to a serving `Endpoint` resource.
|
||||
- Make an online prediction request with explainability.
|
||||
- Undeploy the `Model` resource.
|
||||
|
||||
### Vertex Explainable AI Image data
|
||||
|
||||
|
||||
[Custom training image classification model for batch prediction with explainabilty](official/explainable_ai/sdk_custom_image_classification_batch_explain.ipynb)
|
||||
[Custom training image classification model for batch prediction with explainabilty](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/explainable_ai/sdk_custom_image_classification_batch_explain.ipynb)
|
||||
|
||||
Learn to use `Vertex AI Training and Explainable AI` to create a custom image classification model with explanations, and then you learn to use `Vertex AI Batch Prediction` to make a batch prediction request with explanations.
|
||||
|
||||
@@ -324,10 +397,40 @@ The steps performed include:
|
||||
- Upload the trained model artifacts and explanation parameters as a `Model` resource.
|
||||
- Make a batch prediction with explanations.
|
||||
|
||||
[Custom training image classification model for online prediction with explainabilty](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/explainable_ai/sdk_custom_image_classification_online_explain.ipynb)
|
||||
|
||||
Learn how to use `Vertex AI Training and Explainable AI` to create a custom image classification model with explanations, and then you learn to use `Vertex AI Prediction` to make an online prediction request with explanations.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Create a `Vertex AI` custom job for training a TensorFlow model.
|
||||
- View the model evaluation for the trained model.
|
||||
- Set explanation parameters for when the model is deployed.
|
||||
- Upload the trained model artifacts and explanations as a `Model` resource.
|
||||
- Create a serving `Endpoint` resource.
|
||||
- Deploy the `Model` resource to a serving `Endpoint` resource.
|
||||
- Make a prediction with explanation.
|
||||
- Undeploy the `Model` resource.
|
||||
|
||||
### Vertex Explainable AI Tabular data
|
||||
|
||||
|
||||
[Custom training tabular regression model for batch prediction with explainabilty](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/explainable_ai/sdk_custom_tabular_regression_batch_explain.ipynb)
|
||||
|
||||
Learn how to use `Vertex AI Training and Explainable AI` to create a custom image classification model with explanations, and then you learn to use `Vertex AI Batch Prediction` to make a batch prediction request with explanations.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Create a `Vertex AI` custom job for training a TensorFlow model.
|
||||
- View the model evaluation for the trained model.
|
||||
- Set explanation parameters for when the model is deployed.
|
||||
- Upload the trained model artifacts and explanations as a `Model` resource.
|
||||
- Make a batch prediction with explanations.
|
||||
|
||||
### Vertex ML Metadata
|
||||
|
||||
|
||||
[Track parameters and metrics for custom training jobs](official/ml_metadata/sdk-metric-parameter-tracking-for-custom-jobs.ipynb)
|
||||
[Track parameters and metrics for custom training jobs](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/ml_metadata/sdk-metric-parameter-tracking-for-custom-jobs.ipynb)
|
||||
|
||||
Learn how to use Vertex AI SDK for Python to:
|
||||
|
||||
@@ -337,4 +440,5 @@ The steps performed include:
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
|
||||
[AutoML Tabular Training and Prediction](official/automl/automl-tabular-classification.ipynb)
|
||||
[AutoML Tabular Training and Prediction](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/automl/automl-tabular-classification.ipynb)
|
||||
|
||||
Learn how to train and make predictions on an AutoML model based on a tabular dataset.
|
||||
|
||||
@@ -11,7 +11,7 @@ The steps performed include the following:
|
||||
- Make a prediction by sending data.
|
||||
- Undeploy the `Model` resource.
|
||||
|
||||
[Create, train, and deploy an AutoML text classification model](official/automl/automl-text-classification.ipynb)
|
||||
[Create, train, and deploy an AutoML text classification model](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/automl/automl-text-classification.ipynb)
|
||||
|
||||
Learn how to use `AutoML` to train a text classification model.
|
||||
|
||||
@@ -25,7 +25,7 @@ The steps performed include:
|
||||
* Make an online prediction
|
||||
* Make a batch prediction
|
||||
|
||||
[AutoML training video classification model for batch prediction](official/automl/sdk_automl_video_classification_batch.ipynb)
|
||||
[AutoML training video classification model for batch prediction](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/automl/sdk_automl_video_classification_batch.ipynb)
|
||||
|
||||
Learn how to create an AutoML video classification model from a Python script, and then do a batch prediction using the Vertex AI SDK.
|
||||
|
||||
@@ -41,7 +41,20 @@ The steps performed include:
|
||||
|
||||
* Batch Prediction Service: Does a queued (batch) prediction for the entire set of instances in the background and stores the results in a Cloud Storage bucket when ready.
|
||||
|
||||
[AutoML tabular forecasting model for batch prediction](official/automl/sdk_automl_tabular_forecasting_batch.ipynb)
|
||||
[AutoML training text entity extraction model for online prediction](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/automl/sdk_automl_text_entity_extraction_online.ipynb)
|
||||
|
||||
Learn how to create an AutoML text entity extraction model and deploy for online prediction from a Python script using the Vertex SDK.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Create a Vertex `Dataset` resource.
|
||||
- Train the model.
|
||||
- View the model evaluation.
|
||||
- Deploy the `Model` resource to a serving `Endpoint` resource.
|
||||
- Make a prediction.
|
||||
- Undeploy the `Model`.
|
||||
|
||||
[AutoML tabular forecasting model for batch prediction](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/automl/sdk_automl_tabular_forecasting_batch.ipynb)
|
||||
|
||||
Learn how to create an `AutoML` tabular forecasting model from a Python script, and then do a batch prediction using the Vertex AI SDK.
|
||||
|
||||
@@ -52,7 +65,7 @@ The steps performed include:
|
||||
- Obtain the evaluation metrics for the `Model` resource.
|
||||
- Make a batch prediction.
|
||||
|
||||
[AutoML training image object detection model for batch prediction](official/automl/sdk_automl_image_object_detection_batch.ipynb)
|
||||
[AutoML training image object detection model for batch prediction](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/automl/sdk_automl_image_object_detection_batch.ipynb)
|
||||
|
||||
Learn how to create an AutoML image object detection model from a Python script, and then do a batch prediction using the Vertex AI SDK.
|
||||
|
||||
@@ -68,7 +81,7 @@ The steps performed include:
|
||||
|
||||
* Batch Prediction Service: Does a queued (batch) prediction for the entire set of instances in the background and stores the results in a Cloud Storage bucket when ready.
|
||||
|
||||
[AutoML training video action recognition model for batch prediction](official/automl/sdk_automl_video_action_recognition_batch.ipynb)
|
||||
[AutoML training video action recognition model for batch prediction](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/automl/sdk_automl_video_action_recognition_batch.ipynb)
|
||||
|
||||
Learn how to create an AutoML video action recognition model from a Python script, and then do a batch prediction using the Vertex AI SDK.
|
||||
|
||||
@@ -84,7 +97,16 @@ The steps performed include:
|
||||
|
||||
* Batch Prediction Service: Does a queued (batch) prediction for the entire set of instances in the background and stores the results in a Cloud Storage bucket when ready.
|
||||
|
||||
[AutoML training text sentiment analysis model for online prediction](official/automl/sdk_automl_text_sentiment_analysis_online.ipynb)
|
||||
[AutoML Tabular Pipeline](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/automl/automl_tabular_on_vertex_pipelines.ipynb)
|
||||
|
||||
Learn how to create two regression models using [Vertex Pipelines](https://cloud.
|
||||
|
||||
The steps performed are:
|
||||
|
||||
- Create a training pipeline that reduces the search space from the default to save time.
|
||||
- Create a training pipeline that reuses the architecture search results from the previous pipeline to save time.
|
||||
|
||||
[AutoML training text sentiment analysis model for online prediction](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/automl/sdk_automl_text_sentiment_analysis_online.ipynb)
|
||||
|
||||
Learn how to create an AutoML text sentiment analysis model and deploy for online prediction from a Python script using the Vertex SDK.
|
||||
|
||||
@@ -97,7 +119,7 @@ The steps performed include:
|
||||
- Make a prediction.
|
||||
- Undeploy the `Model`.
|
||||
|
||||
[Compare Vertex AI Forecasting and BigQuery ML ARIMA_PLUS](official/automl/automl_forecasting_bqml_arima_plus_comparison.ipynb)
|
||||
[Compare Vertex AI Forecasting and BigQuery ML ARIMA_PLUS](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/automl/automl_forecasting_bqml_arima_plus_comparison.ipynb)
|
||||
|
||||
Learn how to create an BQML ARIMA_PLUS model using a training [Vertex AI Pipeline](https://cloud.
|
||||
|
||||
@@ -112,7 +134,7 @@ The steps performed are:
|
||||
- Make a batch prediction with the Model.
|
||||
|
||||
|
||||
[AutoML training tabular regression model for online prediction using BigQuery](official/automl/sdk_automl_tabular_regression_online_bq.ipynb)
|
||||
[AutoML training tabular regression model for online prediction using BigQuery](https://github.com/GoogleCloudPlatform/vertex-ai-samples/tree/master/notebooks/official/automl/sdk_automl_tabular_regression_online_bq.ipynb)
|
||||
|
||||
Learn how to create an AutoML tabular regression model and deploy for online prediction from a Python script using the Vertex AI SDK.
|
||||
|
||||
@@ -124,3 +146,32 @@ The steps performed include:
|
||||
- Deploy the `Model` resource to a serving `Endpoint` resource.
|
||||
- Make a prediction.
|
||||
- Undeploy the `Model`.
|
||||
|
||||
[AutoML training video object tracking model for batch prediction](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/automl/sdk_automl_video_object_tracking_batch.ipynb)
|
||||
|
||||
Learn how to create an AutoML video object tracking model from a Python script, and then do a batch prediction using the Vertex SDK.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Create a Vertex `Dataset` resource.
|
||||
- Train the model.
|
||||
- View the model evaluation.
|
||||
- Make a batch prediction.
|
||||
|
||||
|
||||
* Prediction Service: Does an on-demand prediction for the entire set of instances (i.e., one or more data items) and returns the results in real-time.
|
||||
|
||||
* Batch Prediction Service: Does a queued (batch) prediction for the entire set of instances in the background and stores the results in a Cloud Storage bucket when ready.
|
||||
|
||||
[AutoML training tabular regression model for batch prediction using BigQuery](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/automl/sdk_automl_tabular_regression_batch_bq.ipynb)
|
||||
|
||||
Learn how to create an AutoML tabular regression model and deploy it for batch prediction using the Vertex AI SDK for Python.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Create a Vertex AI `Dataset` resource.
|
||||
- Train the model.
|
||||
- View the model evaluation.
|
||||
- Deploy the `Model` resource to a serving `Endpoint` resource.
|
||||
- Make a prediction.
|
||||
- Undeploy the `Model`.
|
||||
|
||||
@@ -61,7 +61,7 @@
|
||||
"source": [
|
||||
"## Overview\n",
|
||||
"\n",
|
||||
"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."
|
||||
"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 accomplish this by training forecasting models using historical sales data. You 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."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -72,13 +72,18 @@
|
||||
"source": [
|
||||
"### Objective\n",
|
||||
"\n",
|
||||
"In this tutorial, you learn how to 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",
|
||||
"In this tutorial, you learn how to create an BigQuery ML 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",
|
||||
"This tutorial uses the following Google Cloud ML services and resources:\n",
|
||||
"\n",
|
||||
"- BigQuery\n",
|
||||
"- Vertex AI\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",
|
||||
"- Train the BigQuery ML ARIMA_PLUS model.\n",
|
||||
"- View BigQuery ML model evaluation.\n",
|
||||
"- Make a batch prediction with the BigQuery ML model.\n",
|
||||
"- Create a Vertex AI `Dataset` resource.\n",
|
||||
"- Train the Vertex AI Forecasting model.\n",
|
||||
"- View the Model evaluation.\n",
|
||||
@@ -93,7 +98,7 @@
|
||||
"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."
|
||||
"To demonstrate the tradeoffs between using BigQuery ML 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 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."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -108,7 +113,7 @@
|
||||
"\n",
|
||||
"* Vertex AI\n",
|
||||
"* Cloud Storage\n",
|
||||
"* BigQuery / BQML\n",
|
||||
"* BigQuery / BigQuery ML\n",
|
||||
"\n",
|
||||
"Learn about [Vertex AI\n",
|
||||
"pricing](https://cloud.google.com/vertex-ai/pricing), [Cloud Storage\n",
|
||||
@@ -241,7 +246,7 @@
|
||||
"\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",
|
||||
"\n",
|
||||
"4. If you are running this notebook locally, you will need to install the [Cloud SDK]((https://cloud.google.com/sdk)).\n",
|
||||
"4. 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",
|
||||
"Cloud SDK uses the right project for all the commands in this notebook.\n",
|
||||
@@ -270,8 +275,7 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"PROJECT_ID = \"[your-project-id]\" # @param {type:\"string\"}\n",
|
||||
"SERVICE_ACCOUNT = \"\" # @param {type:\"string\"}"
|
||||
"PROJECT_ID = \"[your-project-id]\" # @param {type:\"string\"}"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -286,8 +290,7 @@
|
||||
" # 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)\n",
|
||||
"SERVICE_ACCOUNT = SERVICE_ACCOUNT or None"
|
||||
" print(\"Project ID:\", PROJECT_ID)"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -308,7 +311,7 @@
|
||||
},
|
||||
"source": [
|
||||
"#### 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",
|
||||
"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 use 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 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",
|
||||
@@ -451,30 +454,41 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"BUCKET_URI = \"gs://[your-bucket-name]\" # @param {type:\"string\"}"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "4FxNxXwW3inJ"
|
||||
},
|
||||
"source": [
|
||||
"Create the bucket if it doesn't already exist."
|
||||
"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"
|
||||
"id": "4FxNxXwW3inJ"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"if BUCKET_URI == \"\" or BUCKET_URI is None or BUCKET_URI == \"gs://[your-bucket-name]\":\n",
|
||||
" BUCKET_URI = \"gs://\" + PROJECT_ID + \"aip-\" + UUID\n",
|
||||
"\n",
|
||||
"! gsutil ls -b $BUCKET_URI || gsutil mb -l $REGION $BUCKET_URI"
|
||||
"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": "autoset_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": "91c46850b49b"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"! gsutil mb -l $REGION -p $PROJECT_ID $BUCKET_URI"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -497,15 +511,84 @@
|
||||
"! gsutil ls -al $BUCKET_URI"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "85c4ecfd133a"
|
||||
},
|
||||
"source": [
|
||||
"#### Service Account \n",
|
||||
"\n",
|
||||
"You use a service account to create Vertex AI Pipeline jobs."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "77b01a1fdbb4"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"SERVICE_ACCOUNT = \"[your-service-account]\" # @param {type:\"string\"}"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "f936bebda2d4"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"if (\n",
|
||||
" SERVICE_ACCOUNT == \"\"\n",
|
||||
" or SERVICE_ACCOUNT is None\n",
|
||||
" or SERVICE_ACCOUNT == \"[your-service-account]\"\n",
|
||||
"):\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": "markdown",
|
||||
"metadata": {
|
||||
"id": "40ef6967cad3"
|
||||
},
|
||||
"source": [
|
||||
"#### Set service account access for Vertex AI Pipelines\n",
|
||||
"\n",
|
||||
"Run the following commands to grant your service account access to read and write pipeline artifacts in the bucket that you created in the previous step. You only need to run this step once per service account."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "f88cb0488c08"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"! gsutil iam ch serviceAccount:{SERVICE_ACCOUNT}:roles/storage.objectCreator $BUCKET_URI\n",
|
||||
"\n",
|
||||
"! gsutil iam ch serviceAccount:{SERVICE_ACCOUNT}:roles/storage.objectViewer $BUCKET_URI"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "setup_vars"
|
||||
},
|
||||
"source": [
|
||||
"### Set up variables\n",
|
||||
"\n",
|
||||
"Next, set up some variables used throughout the tutorial.\n",
|
||||
"### Import libraries and define constants"
|
||||
]
|
||||
},
|
||||
@@ -565,7 +648,7 @@
|
||||
"source": [
|
||||
"### Location of BigQuery destination table.\n",
|
||||
"\n",
|
||||
"Create two datasets, one for each model you will train. To make things simpler, create the datasets in the same region as the training data."
|
||||
"#### Create two datasets, one for each model you train. To make things simpler, create the datasets in the same region as the training data."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -606,7 +689,7 @@
|
||||
"\n",
|
||||
"Before training a model, you must first generate our dataset of store sales. This dataset will include multiple products and stores, and it will also simulate factors such as advertisements and holiday effects. The data will be split into `TRAIN`, `VALIDATE`, `TEST`, and `PREDICT` sets, where the last three sets are all 1 month in duration.\n",
|
||||
"\n",
|
||||
"Begin by defining the subqueries that will create this base sales data."
|
||||
"#### Begin by defining the subqueries that will create this base sales data."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -715,7 +798,7 @@
|
||||
"id": "IdWrtxYtqdsh"
|
||||
},
|
||||
"source": [
|
||||
"Next, convert this base sales data into a dataset you will use to train a model, and a dataset you will pass to a trained model at serving time. The training dataset will include the `TRAIN`, `VALIDATE`, and `TEST` splits, while the prediction dataset will include the `PREDICT` split and also the `TEST` split to provide context information."
|
||||
"#### Next, convert this base sales data into a dataset you use to train a model, and a dataset you pass to a trained model at serving time. The training dataset will include the `TRAIN`, `VALIDATE`, and `TEST` splits, while the prediction dataset will include the `PREDICT` split and also the `TEST` split to provide context information."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -764,7 +847,9 @@
|
||||
"source": [
|
||||
"You can take a look at the sales data that was generated. Later in this tutorial, we will visualize the time series along with our forecast.\n",
|
||||
"\n",
|
||||
"The model is trained with data from January 2017 to October 2019 inclusive."
|
||||
"The model is trained with data from January 2017 to October 2019 inclusive.\n",
|
||||
"\n",
|
||||
"#### Look at the training data"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -785,7 +870,9 @@
|
||||
"id": "F00dL8oEqqVb"
|
||||
},
|
||||
"source": [
|
||||
"The table used for prediction contains data from November 2019. It also includes actuals from October 2019 as context information."
|
||||
"The table used for prediction contains data from November 2019. It also includes actuals from October 2019 as context information.\n",
|
||||
"\n",
|
||||
"#### Look at the prediction data"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -806,17 +893,17 @@
|
||||
"id": "tutorial_start:automl"
|
||||
},
|
||||
"source": [
|
||||
"# Create a BQML ARIMA_PLUS model\n",
|
||||
"# Create a BigQuery ML ARIMA_PLUS model\n",
|
||||
"\n",
|
||||
"Now you are ready to start creating your own BQML ARIMA_PLUS model.\n",
|
||||
"Now you are ready to start creating your own BigQuery ML ARIMA_PLUS model.\n",
|
||||
"\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",
|
||||
"Like with Vertex AI Forecasting, the pipeline you 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 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",
|
||||
"Backtesting involves training a single BigQuery ML 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. We window with a stride length of 1, so all periods are used for evaluation.\n",
|
||||
"According to [BQ pricing](https://cloud.google.com/bigquery-ml/pricing), BigQuery ML 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 / 1) periods * 20 candidates = $0.44`."
|
||||
]
|
||||
@@ -827,7 +914,7 @@
|
||||
"id": "t04OJzrORmJ4"
|
||||
},
|
||||
"source": [
|
||||
"## Create and run training job\n",
|
||||
"## Create and run the training job\n",
|
||||
"To train a model using the ARIMA pipeline, you perform two steps: \n",
|
||||
"\n",
|
||||
"1. download the training pipeline from GCPC.\n",
|
||||
@@ -904,7 +991,7 @@
|
||||
"source": [
|
||||
"### Run the training pipeline\n",
|
||||
"\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",
|
||||
"Use the Vertex AI Python SDK to kick off a training pipeline run. Once the run has started, the following cell outputs 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/[REGION]/pipelines/runs/[DISPLAY_NAME]`"
|
||||
]
|
||||
@@ -939,7 +1026,7 @@
|
||||
"## Review model evaluation scores\n",
|
||||
"After your model has finished training, you can review the evaluation scores for it.\n",
|
||||
"\n",
|
||||
"Metrics are always reported via the `metrics` table in the destination dataset."
|
||||
"#### Metrics are always reported via the `metrics` table in the destination dataset."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -961,7 +1048,11 @@
|
||||
"id": "jsRVi6AoiUIE"
|
||||
},
|
||||
"source": [
|
||||
"You can also view the predictions used to calculate the evaluation metrics if you want to calculate your own. This table containing all these predictions is called `evaluated_examples`. In this table, each distinct `predicted_on_date` represents the starting period of a window of predictions. The backtesting metrics make use of all these windows."
|
||||
"You can view the predictions used to calculate the evaluation metrics if you want to calculate your own. \n",
|
||||
"\n",
|
||||
"#### View predictions used to calculate the evaluation metrics\n",
|
||||
"\n",
|
||||
"This table containing all these predictions is called `evaluated_examples`. In this table, each distinct `predicted_on_date` represents the starting period of a window of predictions. The backtesting metrics make use of all these windows."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -991,7 +1082,7 @@
|
||||
"- `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_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",
|
||||
"- `model_name`: Name of an existing BigQuery ML ARIMA_PLUS model to use for predictions.\n",
|
||||
"\n",
|
||||
"The execution of the prediction pipeline may take around **5 minutes**."
|
||||
]
|
||||
@@ -1004,7 +1095,7 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Get the model name programmatically, you can also find this by looking at the\n",
|
||||
"# Get the model name programmatically, you can find this by looking at the\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",
|
||||
@@ -1034,7 +1125,7 @@
|
||||
"source": [
|
||||
"### Run the prediction pipeline\n",
|
||||
"\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",
|
||||
"Use the Vertex AI Python SDK to kick off a prediction pipeline run. Once the run has started, the following cell outputs 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/[REGION]/pipelines/runs/[DISPLAY_NAME]`"
|
||||
]
|
||||
@@ -1079,7 +1170,7 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Get the prediction table programmatically, you can also find this by looking at the\n",
|
||||
"# Get the prediction table programmatically, you can find this by looking at the\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",
|
||||
@@ -1246,7 +1337,7 @@
|
||||
"id": "create_automl_pipeline:tabular,forecast"
|
||||
},
|
||||
"source": [
|
||||
"### Create and run training job\n",
|
||||
"### Create and run the training job\n",
|
||||
"\n",
|
||||
"To train an AutoML model, you perform two steps: 1) create a training job, and 2) run the job.\n",
|
||||
"\n",
|
||||
@@ -1327,7 +1418,7 @@
|
||||
"- `time_column`: Name of the column that identifies time order in the time series. This column must be available at forecast.\n",
|
||||
"- `time_series_identifier_column`: Name of the column that identifies the time series.\n",
|
||||
"\n",
|
||||
"You can also specify the split with either\n",
|
||||
"You can specify the split with either\n",
|
||||
"- `training_fraction_split`: The percentage of the dataset to use for training.\n",
|
||||
"- `validation_fraction_split`: The percentage of the dataset to use for validation.\n",
|
||||
"- `test_fraction_split`: The percentage of the dataset to use for test (holdout data).\n",
|
||||
@@ -1421,7 +1512,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 AI 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 BigQuery ML ARIMA_PLUS evaluation metrics show the relative impact of including these additional features in a model."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -1620,8 +1711,9 @@
|
||||
"for dataset_id in [arima_dataset_path, vertex_dataset_path]:\n",
|
||||
" client.delete_dataset(dataset_id, delete_contents=True, not_found_ok=True)\n",
|
||||
"\n",
|
||||
"if os.getenv(\"IS_TESTING\"):\n",
|
||||
" ! gsutil rm -r $BUCKET_URI"
|
||||
"delete_bucket = False\n",
|
||||
"if delete_bucket or os.getenv(\"IS_TESTING\"):\n",
|
||||
" ! gsutil -m rm -r $BUCKET_URI"
|
||||
]
|
||||
}
|
||||
],
|
||||
|
||||
@@ -88,7 +88,8 @@
|
||||
"source": [
|
||||
"### Dataset\n",
|
||||
"\n",
|
||||
"The dataset you will be using is the [Safe Driver Prediction](https://www.kaggle.com/competitions/porto-seguro-safe-driver-prediction/data?select=train.csv) dataset for predicting the probability of an auto insurance policy holder filing a claim for a given incident."
|
||||
"The dataset you will be using is [Bank Marketing](https://archive.ics.uci.edu/ml/datasets/bank+marketing).\n",
|
||||
"The data is for direct marketing campaigns (phone calls) of a Portuguese banking institution. The binary classification goal is to predict if a client will subscribe a term deposit. For this notebook, we randomly selected 90% of the rows in the original dataset and saved them in a train.csv file hosted on Cloud Storage. To download the file, click [here](https://storage.googleapis.com/cloud-samples-data/vertex-ai/tabular-workflows/datasets/bank-marketing/train.csv)."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -638,9 +639,9 @@
|
||||
"root_dir = os.path.join(BUCKET_URI, \"automl_tabular_pipeline\")\n",
|
||||
"prediction_type = \"classification\"\n",
|
||||
"optimization_objective = \"minimize-log-loss\"\n",
|
||||
"target_column = \"target\"\n",
|
||||
"target_column = \"deposit\"\n",
|
||||
"data_source_csv_filenames = (\n",
|
||||
" \"gs://cloud-samples-data/vertex-ai/tabular-workflows/datasets/safe-driver/train.csv\"\n",
|
||||
" \"gs://cloud-samples-data/vertex-ai/tabular-workflows/datasets/bank-marketing/train.csv\"\n",
|
||||
")\n",
|
||||
"data_source_bigquery_table_path = None # format: bq://bq_project.bq_dataset.bq_table\n",
|
||||
"\n",
|
||||
@@ -659,63 +660,22 @@
|
||||
"weight_column = None\n",
|
||||
"\n",
|
||||
"features = [\n",
|
||||
" \"ps_ind_01\",\n",
|
||||
" \"ps_ind_02_cat\",\n",
|
||||
" \"ps_ind_03\",\n",
|
||||
" \"ps_ind_04_cat\",\n",
|
||||
" \"ps_ind_05_cat\",\n",
|
||||
" \"ps_ind_06_bin\",\n",
|
||||
" \"ps_ind_07_bin\",\n",
|
||||
" \"ps_ind_08_bin\",\n",
|
||||
" \"ps_ind_09_bin\",\n",
|
||||
" \"ps_ind_10_bin\",\n",
|
||||
" \"ps_ind_11_bin\",\n",
|
||||
" \"ps_ind_12_bin\",\n",
|
||||
" \"ps_ind_13_bin\",\n",
|
||||
" \"ps_ind_14\",\n",
|
||||
" \"ps_ind_15\",\n",
|
||||
" \"ps_ind_16_bin\",\n",
|
||||
" \"ps_ind_17_bin\",\n",
|
||||
" \"ps_ind_18_bin\",\n",
|
||||
" \"ps_reg_01\",\n",
|
||||
" \"ps_reg_02\",\n",
|
||||
" \"ps_reg_03\",\n",
|
||||
" \"ps_car_01_cat\",\n",
|
||||
" \"ps_car_02_cat\",\n",
|
||||
" \"ps_car_03_cat\",\n",
|
||||
" \"ps_car_04_cat\",\n",
|
||||
" \"ps_car_05_cat\",\n",
|
||||
" \"ps_car_06_cat\",\n",
|
||||
" \"ps_car_07_cat\",\n",
|
||||
" \"ps_car_08_cat\",\n",
|
||||
" \"ps_car_09_cat\",\n",
|
||||
" \"ps_car_10_cat\",\n",
|
||||
" \"ps_car_11_cat\",\n",
|
||||
" \"ps_car_11\",\n",
|
||||
" \"ps_car_12\",\n",
|
||||
" \"ps_car_13\",\n",
|
||||
" \"ps_car_14\",\n",
|
||||
" \"ps_car_15\",\n",
|
||||
" \"ps_calc_01\",\n",
|
||||
" \"ps_calc_02\",\n",
|
||||
" \"ps_calc_03\",\n",
|
||||
" \"ps_calc_04\",\n",
|
||||
" \"ps_calc_05\",\n",
|
||||
" \"ps_calc_06\",\n",
|
||||
" \"ps_calc_07\",\n",
|
||||
" \"ps_calc_08\",\n",
|
||||
" \"ps_calc_09\",\n",
|
||||
" \"ps_calc_10\",\n",
|
||||
" \"ps_calc_11\",\n",
|
||||
" \"ps_calc_12\",\n",
|
||||
" \"ps_calc_13\",\n",
|
||||
" \"ps_calc_14\",\n",
|
||||
" \"ps_calc_15_bin\",\n",
|
||||
" \"ps_calc_16_bin\",\n",
|
||||
" \"ps_calc_17_bin\",\n",
|
||||
" \"ps_calc_18_bin\",\n",
|
||||
" \"ps_calc_19_bin\",\n",
|
||||
" \"ps_calc_20_bin\",\n",
|
||||
" \"age\",\n",
|
||||
" \"job\",\n",
|
||||
" \"marital\",\n",
|
||||
" \"education\",\n",
|
||||
" \"default\",\n",
|
||||
" \"balance\",\n",
|
||||
" \"housing\",\n",
|
||||
" \"loan\",\n",
|
||||
" \"contact\",\n",
|
||||
" \"day\",\n",
|
||||
" \"month\",\n",
|
||||
" \"duration\",\n",
|
||||
" \"campaign\",\n",
|
||||
" \"pdays\",\n",
|
||||
" \"previous\",\n",
|
||||
" \"poutcome\",\n",
|
||||
"]\n",
|
||||
"transformations = generate_auto_transformation(features)\n",
|
||||
"transform_config_path = os.path.join(root_dir, f\"transform_config_{uuid.uuid4()}.json\")\n",
|
||||
|
||||
@@ -73,7 +73,7 @@
|
||||
"source": [
|
||||
"### Objective\n",
|
||||
"\n",
|
||||
"In this tutorial, you how to create an AutoML text entity extraction model and deploy for online prediction from a Python script using the Vertex SDK. You can alternatively create and deploy models using the `gcloud` command-line tool or online using the Cloud Console.\n",
|
||||
"In this tutorial, you learn how to create an AutoML text entity extraction model and deploy for online prediction from a Python script using the Vertex SDK. You can alternatively create and deploy models using the `gcloud` command-line tool or online using the Cloud Console.\n",
|
||||
"\n",
|
||||
"The steps performed include:\n",
|
||||
"\n",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
|
||||
[Online prediction with BigQuery ML](official/bigquery_ml/bqml-online-prediction.ipynb)
|
||||
[Online prediction with BigQuery ML](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/bigquery_ml/bqml-online-prediction.ipynb)
|
||||
|
||||
Learn how to train and deploy a churn prediction model for real-time inference, with the data in BigQuery and model trained using BigQuery ML, registered to Vertex AI Model Registry, and deployed to an endpoint on Vertex AI for online predictions.
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
|
||||
[Custom training and batch prediction](official/custom/sdk-custom-image-classification-batch.ipynb)
|
||||
[Custom training and batch prediction](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/custom/sdk-custom-image-classification-batch.ipynb)
|
||||
|
||||
Learn to use `Vertex AI Training` to create a custom trained model and use `Vertex AI Batch Prediction` to do a batch prediction on the trained model.
|
||||
|
||||
@@ -9,7 +9,7 @@ The steps performed include:
|
||||
- Upload the trained model artifacts as a `Model` resource.
|
||||
- Make a batch prediction.
|
||||
|
||||
[Profile model training performance using Profiler](official/custom/custom_training_tensorboard_profiler.ipynb)
|
||||
[Profile model training performance using Profiler](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/custom/custom_training_tensorboard_profiler.ipynb)
|
||||
|
||||
Learn how to enable Vertex AI TensorBoard Profiler for custom training jobs.
|
||||
|
||||
@@ -21,7 +21,7 @@ The steps performed include:
|
||||
- View the TensorBoard Profiler dashboard
|
||||
|
||||
|
||||
[Training a TensorFlow model on BigQuery data](official/custom/custom-tabular-bq-managed-dataset.ipynb)
|
||||
[Training a TensorFlow model on BigQuery data](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/custom/custom-tabular-bq-managed-dataset.ipynb)
|
||||
|
||||
Learn how to create a custom-trained model from a Python script in a Docker container using the Vertex AI SDK for Python, and then get a prediction from the deployed model by sending data.
|
||||
|
||||
@@ -33,7 +33,7 @@ The steps performed include:
|
||||
- Make a prediction.
|
||||
- Undeploy the `Model` resource.
|
||||
|
||||
[Custom training and online prediction](official/custom/sdk-custom-image-classification-online.ipynb)
|
||||
[Custom training and online prediction](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/custom/sdk-custom-image-classification-online.ipynb)
|
||||
|
||||
Learn to use `Vertex AI Training` to create a custom-trained model from a Python script in a Docker container, and learn to use `Vertex AI Prediction` to do a prediction on the deployed model by sending data.
|
||||
|
||||
@@ -46,7 +46,7 @@ The steps performed include:
|
||||
- Make a prediction.
|
||||
- Undeploy the `Model` resource.
|
||||
|
||||
[Deploying Iris-detection model using FastAPI and Vertex AI custom container serving](official/custom/SDK_Custom_Container_Prediction.ipynb)
|
||||
[Deploying Iris-detection model using FastAPI and Vertex AI custom container serving](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/custom/SDK_Custom_Container_Prediction.ipynb)
|
||||
|
||||
Learn how to create, deploy and serve a custom classification model on Vertex AI.
|
||||
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
|
||||
[Compare pipeline runs with Vertex AI Experiments](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/experiments/comparing_pipeline_runs.ipynb)
|
||||
|
||||
Learn how to use `Vertex AI Experiments` to log a pipeline job and compare different pipeline jobs.
|
||||
|
||||
|
||||
|
||||
[Track parameters and metrics for locally trained models](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/experiments/comparing_local_trained_models.ipynb)
|
||||
|
||||
Learn how to use Vertex AI Experiments to compare and evaluate model experiments.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- log the model parameters
|
||||
- log the loss and metrics on every epoch to TensorBoard
|
||||
- log the evaluation metrics
|
||||
|
||||
|
||||
[Build Vertex AI Experiment lineage for custom training](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/experiments/build_model_experimentation_lineage_with_prebuild_code.ipynb)
|
||||
|
||||
Learn how to integrate preprocessing code in a Vertex AI experiments.
|
||||
|
||||
|
||||
+19
-6
@@ -689,6 +689,7 @@
|
||||
"# Training\n",
|
||||
"TRAIN_EXECUTION_NAME = \"train\"\n",
|
||||
"TARGET = \"category\"\n",
|
||||
"TARGET_LABELS = [\"b\", \"t\", \"e\", \"m\"]\n",
|
||||
"FEATURES = \"title\"\n",
|
||||
"TEST_SIZE = 0.2\n",
|
||||
"SEED = 8\n",
|
||||
@@ -974,7 +975,8 @@
|
||||
"import joblib\n",
|
||||
"import pandas as pd\n",
|
||||
"from sklearn.feature_extraction.text import CountVectorizer, TfidfTransformer\n",
|
||||
"from sklearn.metrics import accuracy_score, precision_score, recall_score\n",
|
||||
"from sklearn.metrics import (accuracy_score, confusion_matrix, precision_score,\n",
|
||||
" recall_score)\n",
|
||||
"from sklearn.model_selection import train_test_split\n",
|
||||
"from sklearn.naive_bayes import MultinomialNB\n",
|
||||
"from sklearn.pipeline import Pipeline\n",
|
||||
@@ -1049,13 +1051,17 @@
|
||||
" y_pred = model.predict(X_test)\n",
|
||||
"\n",
|
||||
" # Store evaluation metrics\n",
|
||||
" # Store evaluation metrics\n",
|
||||
" metrics = {\n",
|
||||
" summary_metrics = {\n",
|
||||
" \"accuracy\": round(accuracy_score(y_test, y_pred), 5),\n",
|
||||
" \"precision\": round(precision_score(y_test, y_pred, average=\"weighted\"), 5),\n",
|
||||
" \"recall\": round(recall_score(y_test, y_pred, average=\"weighted\"), 5),\n",
|
||||
" }\n",
|
||||
" return metrics\n",
|
||||
" classification_metrics = {\n",
|
||||
" \"matrix\": confusion_matrix(y_test, y_pred, labels=TARGET_LABELS).tolist(),\n",
|
||||
" \"labels\": TARGET_LABELS,\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" return summary_metrics, classification_metrics\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def save_model(model: Pipeline, save_path: str) -> int:\n",
|
||||
@@ -1138,13 +1144,20 @@
|
||||
"\n",
|
||||
" # Evaluate model\n",
|
||||
" logging.info(\"Evaluate model.\")\n",
|
||||
" model_metrics = evaluate_model(trained_pipeline, x_val, y_val)\n",
|
||||
" summary_metrics, classification_metrics = evaluate_model(\n",
|
||||
" trained_pipeline, x_val, y_val\n",
|
||||
" )\n",
|
||||
"\n",
|
||||
" # Log training metrics and store model artifact ----------------------------\n",
|
||||
"\n",
|
||||
" # Log training metrics\n",
|
||||
" logging.info(\"Log training metrics.\")\n",
|
||||
" vertex_ai.log_metrics(model_metrics)\n",
|
||||
" vertex_ai.log_metrics(summary_metrics)\n",
|
||||
" vertex_ai.log_classification_metrics(\n",
|
||||
" labels=classification_metrics[\"labels\"],\n",
|
||||
" matrix=classification_metrics[\"matrix\"],\n",
|
||||
" display_name=\"my-confusion-matrix\",\n",
|
||||
" )\n",
|
||||
"\n",
|
||||
" # Generate first ten predictions\n",
|
||||
" logging.info(\"Generate prediction sample.\")\n",
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
|
||||
[Custom training tabular regression model for batch prediction with explainabilty](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/explainable_ai/sdk_custom_tabular_regression_batch_explain.ipynb)
|
||||
|
||||
Learn how to use `Vertex AI Training and Explainable AI` to create a custom image classification model with explanations, and then you learn to use `Vertex AI Batch Prediction` to make a batch prediction request with explanations.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Create a `Vertex AI` custom job for training a TensorFlow model.
|
||||
- View the model evaluation for the trained model.
|
||||
- Set explanation parameters for when the model is deployed.
|
||||
- Upload the trained model artifacts and explanations as a `Model` resource.
|
||||
- Make a batch prediction with explanations.
|
||||
|
||||
[AutoML training tabular binary classification model for batch explanation](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/explainable_ai/sdk_automl_tabular_binary_classification_batch_explain.ipynb)
|
||||
|
||||
Learn to use `AutoML` to create a tabular binary classification model from a Python script, and then learn to use `Vertex AI Batch Prediction` to make predictions with explanations.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Create a `Vertex Dataset` resource.
|
||||
- Train an `AutoML` tabular binary classification model.
|
||||
- View the model evaluation metrics for the trained model.
|
||||
- Make a batch prediction request with explainability.
|
||||
|
||||
|
||||
* Prediction Service: Does an on-demand prediction for the entire set of instances (i.e., one or more data items) and returns the results in real-time.
|
||||
|
||||
* Batch Prediction Service: Does a queued (batch) prediction for the entire set of instances in the background and stores the results in a Cloud Storage bucket when ready.
|
||||
|
||||
[AutoML training tabular classification model for online explanation](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/explainable_ai/sdk_automl_tabular_classification_online_explain.ipynb)
|
||||
|
||||
Learn how to use `AutoML` to create a tabular binary classification model from a Python script, and then learn to use `Vertex AI Online Prediction` to make online predictions with explanations.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Create a `Vertex Dataset` resource.
|
||||
- Train an `AutoML` tabular binary classification model.
|
||||
- View the model evaluation metrics for the trained model.
|
||||
- Create a serving `Endpoint` resource.
|
||||
- Deploy the `Model` resource to a serving `Endpoint` resource.
|
||||
- Make an online prediction request with explainability.
|
||||
- Undeploy the `Model` resource.
|
||||
|
||||
[Custom training image classification model for online prediction with explainabilty](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/explainable_ai/sdk_custom_image_classification_online_explain.ipynb)
|
||||
|
||||
Learn how to use `Vertex AI Training and Explainable AI` to create a custom image classification model with explanations, and then you learn to use `Vertex AI Prediction` to make an online prediction request with explanations.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Create a `Vertex AI` custom job for training a TensorFlow model.
|
||||
- View the model evaluation for the trained model.
|
||||
- Set explanation parameters for when the model is deployed.
|
||||
- Upload the trained model artifacts and explanations as a `Model` resource.
|
||||
- Create a serving `Endpoint` resource.
|
||||
- Deploy the `Model` resource to a serving `Endpoint` resource.
|
||||
- Make a prediction with explanation.
|
||||
- Undeploy the `Model` resource.
|
||||
|
||||
[Custom training tabular regression model for online prediction with explainabilty using get_metadata](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/explainable_ai/sdk_custom_tabular_regression_online_explain_get_metadata.ipynb)
|
||||
|
||||
Learn how to create a custom model from a Python script in a Google prebuilt Docker container using the Vertex SDK, and then do a prediction with explanations on the deployed model by sending data.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Create a Vertex custom job for training a model.
|
||||
- Train a TensorFlow model.
|
||||
- Retrieve and load the model artifacts.
|
||||
- View the model evaluation.
|
||||
- Set explanation parameters.
|
||||
- Upload the model as a Vertex `Model` resource.
|
||||
- Deploy the `Model` resource to a serving `Endpoint` resource.
|
||||
- Make a prediction with explanation.
|
||||
- Undeploy the `Model` resource.
|
||||
|
||||
[Custom training image classification model for batch prediction with explainabilty](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/explainable_ai/sdk_custom_image_classification_batch_explain.ipynb)
|
||||
|
||||
Learn to use `Vertex AI Training and Explainable AI` to create a custom image classification model with explanations, and then you learn to use `Vertex AI Batch Prediction` to make a batch prediction request with explanations.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Create a `Vertex AI` custom job for training a TensorFlow model.
|
||||
- View the model evaluation for the trained model.
|
||||
- Set explanation parameters for when the model is deployed.
|
||||
- Upload the trained model artifacts and explanation parameters as a `Model` resource.
|
||||
- Make a batch prediction with explanations.
|
||||
+1
-1
@@ -73,7 +73,7 @@
|
||||
"source": [
|
||||
"### Objective\n",
|
||||
"\n",
|
||||
"In this tutorial, you how to learn to use `AutoML` to create a tabular binary classification model from a Python script, and then learn to use `Vertex AI Online Prediction` to make online predictions with explanations. You can alternatively create and deploy models using the `gcloud` command-line tool or online using the Cloud Console.\n",
|
||||
"In this tutorial, you learn how to use `AutoML` to create a tabular binary classification model from a Python script, and then learn to use `Vertex AI Online Prediction` to make online predictions with explanations. You can alternatively create and deploy models using the `gcloud` command-line tool or online using the Cloud Console.\n",
|
||||
"\n",
|
||||
"This tutorial uses the following Google Cloud ML services:\n",
|
||||
"\n",
|
||||
|
||||
+48
-38
@@ -73,7 +73,7 @@
|
||||
"source": [
|
||||
"### Objective\n",
|
||||
"\n",
|
||||
"In this tutorial, you how learn to use `Vertex AI Training and Explainable AI` to create a custom image classification model with explanations, and then you learn to use `Vertex AI Batch Prediction` to make a batch prediction request with explanations. You can alternatively create custom models using `gcloud` command-line tool or online using Cloud Console.\n",
|
||||
"In this tutorial, you learn how to use `Vertex AI Training and Explainable AI` to create a custom image classification model with explanations, and then you learn to use `Vertex AI Batch Prediction` to make a batch prediction request with explanations. You can alternatively create custom models using `gcloud` command-line tool or online using Cloud Console.\n",
|
||||
"\n",
|
||||
"This tutorial uses the following Google Cloud ML services:\n",
|
||||
"\n",
|
||||
@@ -188,9 +188,9 @@
|
||||
"if IS_WORKBENCH_NOTEBOOK:\n",
|
||||
" USER_FLAG = \"--user\"\n",
|
||||
"\n",
|
||||
"! pip3 install --upgrade google-cloud-aiplatform $USER_FLAG -q\n",
|
||||
"! pip3 install {USER_FLAG} --upgrade google-cloud-storage -q\n",
|
||||
"! pip3 install --upgrade tensorflow $USER_FLAG -q"
|
||||
"! pip3 install --upgrade --quiet {USER_FLAG} google-cloud-aiplatform \\\n",
|
||||
" google-cloud-storage \\\n",
|
||||
" tensorflow==2.5"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -317,7 +317,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\""
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -326,9 +329,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."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -339,9 +342,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 length 8\n",
|
||||
"def generate_uuid():\n",
|
||||
" return \"\".join(random.choices(string.ascii_lowercase + string.digits, k=8))\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"UUID = generate_uuid()"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -353,7 +363,7 @@
|
||||
"### Authenticate your Google Cloud account\n",
|
||||
"\n",
|
||||
"**If you are using Workbench AI 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",
|
||||
@@ -448,7 +458,7 @@
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"if BUCKET_NAME == \"\" or BUCKET_NAME is None or BUCKET_NAME == \"[your-bucket-name]\":\n",
|
||||
" BUCKET_NAME = PROJECT_ID + \"aip-\" + TIMESTAMP\n",
|
||||
" BUCKET_NAME = PROJECT_ID + \"aip-\" + UUID\n",
|
||||
" BUCKET_URI = \"gs://\" + BUCKET_NAME"
|
||||
]
|
||||
},
|
||||
@@ -948,7 +958,7 @@
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"job = aip.CustomTrainingJob(\n",
|
||||
" display_name=\"boston_\" + TIMESTAMP,\n",
|
||||
" display_name=\"boston_\" + UUID,\n",
|
||||
" script_path=\"custom/trainer/task.py\",\n",
|
||||
" container_uri=TRAIN_IMAGE,\n",
|
||||
" requirements=[\"gcsfs==0.7.1\", \"tensorflow-datasets==4.4\"],\n",
|
||||
@@ -983,7 +993,7 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"MODEL_DIR = \"{}/{}\".format(BUCKET_URI, TIMESTAMP)\n",
|
||||
"MODEL_DIR = \"{}/{}\".format(BUCKET_URI, UUID)\n",
|
||||
"\n",
|
||||
"EPOCHS = 20\n",
|
||||
"STEPS = 100\n",
|
||||
@@ -1404,7 +1414,7 @@
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"model = aip.Model.upload(\n",
|
||||
" display_name=\"boston_\" + TIMESTAMP,\n",
|
||||
" display_name=\"boston_\" + UUID,\n",
|
||||
" artifact_uri=MODEL_DIR,\n",
|
||||
" serving_container_image_uri=DEPLOY_IMAGE,\n",
|
||||
" explanation_parameters=parameters,\n",
|
||||
@@ -1434,7 +1444,7 @@
|
||||
"source": [
|
||||
"### Make test items\n",
|
||||
"\n",
|
||||
"You will use synthetic data as a test data items. Don't be concerned that we are using synthetic data -- we just want to demonstrate how to make a prediction."
|
||||
"You use a portion of the preprocessed evaluation data (x_test) for your batch request."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -1460,14 +1470,16 @@
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "make_batch_file:automl,tabular,alt"
|
||||
"id": "622926573681"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"! gsutil cat $IMPORT_FILE | head -n 1 > tmp.csv\n",
|
||||
"! gsutil cat $IMPORT_FILE | tail -n 10 >> tmp.csv\n",
|
||||
"\n",
|
||||
"! cut -d, -f1-16 tmp.csv > batch.csv\n",
|
||||
"with open(\"batch.csv\", \"w\") as f:\n",
|
||||
" f.write(\"crim, zn, indus, chas, nox, rm, age, dis, rad, tax, ptratio, b, lstat\\n\")\n",
|
||||
" f.write(str(x_test[0].tolist()).replace(\"[\", \"\").replace(\"]\", \"\"))\n",
|
||||
" f.write(\"\\n\")\n",
|
||||
" f.write(str(x_test[1].tolist()))\n",
|
||||
" f.write(\"\\n\")\n",
|
||||
"\n",
|
||||
"gcs_input_uri = BUCKET_URI + \"/test.csv\"\n",
|
||||
"\n",
|
||||
@@ -1505,7 +1517,7 @@
|
||||
"MAX_NODES = 1\n",
|
||||
"\n",
|
||||
"batch_predict_job = model.batch_predict(\n",
|
||||
" job_display_name=\"boston_\" + TIMESTAMP,\n",
|
||||
" job_display_name=\"boston_\" + UUID,\n",
|
||||
" gcs_source=gcs_input_uri,\n",
|
||||
" gcs_destination_prefix=BUCKET_URI,\n",
|
||||
" instances_format=\"csv\",\n",
|
||||
@@ -1539,8 +1551,7 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"if not os.getenv(\"IS_TESTING\"):\n",
|
||||
" batch_predict_job.wait()"
|
||||
"batch_predict_job.wait()"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -1567,22 +1578,19 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"if not os.getenv(\"IS_TESTING\"):\n",
|
||||
" import tensorflow as tf\n",
|
||||
"bp_iter_outputs = batch_predict_job.iter_outputs()\n",
|
||||
"\n",
|
||||
" bp_iter_outputs = batch_predict_job.iter_outputs()\n",
|
||||
"explanation_results = list()\n",
|
||||
"for blob in bp_iter_outputs:\n",
|
||||
" if blob.name.split(\"/\")[-1].startswith(\"explanation\"):\n",
|
||||
" explanation_results.append(blob.name)\n",
|
||||
"\n",
|
||||
" explanation_results = list()\n",
|
||||
" for blob in bp_iter_outputs:\n",
|
||||
" if blob.name.split(\"/\")[-1].startswith(\"explanation\"):\n",
|
||||
" explanation_results.append(blob.name)\n",
|
||||
"\n",
|
||||
" tags = list()\n",
|
||||
" for explanation_result in explanation_results:\n",
|
||||
" gfile_name = f\"gs://{bp_iter_outputs.bucket.name}/{explanation_result}\"\n",
|
||||
" with tf.io.gfile.GFile(name=gfile_name, mode=\"r\") as gfile:\n",
|
||||
" for line in gfile.readlines():\n",
|
||||
" print(line)"
|
||||
"tags = list()\n",
|
||||
"for explanation_result in explanation_results:\n",
|
||||
" gfile_name = f\"gs://{bp_iter_outputs.bucket.name}/{explanation_result}\"\n",
|
||||
" with tf.io.gfile.GFile(name=gfile_name, mode=\"r\") as gfile:\n",
|
||||
" for line in gfile.readlines():\n",
|
||||
" print(line)"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -1616,7 +1624,9 @@
|
||||
" print(e)\n",
|
||||
"\n",
|
||||
"if delete_bucket or os.getenv(\"IS_TESTING\"):\n",
|
||||
" ! gsutil rm -r $BUCKET_URI"
|
||||
" ! gsutil rm -r $BUCKET_URI\n",
|
||||
"\n",
|
||||
"! rm -rf batch.csv custom.tar.gz custom"
|
||||
]
|
||||
}
|
||||
],
|
||||
|
||||
+12
-12
@@ -65,17 +65,6 @@
|
||||
"This tutorial demonstrates how to use the Vertex AI SDK to train and deploy a custom tabular regression model for online prediction with explanation."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "dataset:custom,boston,lrg"
|
||||
},
|
||||
"source": [
|
||||
"### Dataset\n",
|
||||
"\n",
|
||||
"The dataset used for this tutorial is the [Boston Housing Prices dataset](https://www.cs.toronto.edu/~delve/data/boston/bostonDetail.html). The version of the dataset you will use in this tutorial is built into TensorFlow. The trained model predicts the median price of a house in units of 1K USD."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
@@ -84,7 +73,7 @@
|
||||
"source": [
|
||||
"### Objective\n",
|
||||
"\n",
|
||||
"In this tutorial, you learn to use `Vertex AI Training and Explainable AI` to create a custom image classification model with explanations, and then you learn to use `Vertex AI Prediction` to make an online prediction request with explanations. You can alternatively create custom models using `gcloud` command-line tool or online using Cloud Console.\n",
|
||||
"In this tutorial, you learn how to use `Vertex AI Training and Explainable AI` to create a custom image classification model with explanations, and then you learn to use `Vertex AI Prediction` to make an online prediction request with explanations. You can alternatively create custom models using `gcloud` command-line tool or online using Cloud Console.\n",
|
||||
"\n",
|
||||
"This tutorial uses the following Google Cloud ML services:\n",
|
||||
"\n",
|
||||
@@ -106,6 +95,17 @@
|
||||
"- Undeploy the `Model` resource."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "dataset:custom,boston,lrg"
|
||||
},
|
||||
"source": [
|
||||
"### Dataset\n",
|
||||
"\n",
|
||||
"The dataset used for this tutorial is the [Boston Housing Prices dataset](https://www.cs.toronto.edu/~delve/data/boston/bostonDetail.html). The version of the dataset you will use in this tutorial is built into TensorFlow. The trained model predicts the median price of a house in units of 1K USD."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
|
||||
[Using Vertex AI Feature Store with pandas DataFrame](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/feature_store/sdk-feature-store-pandas.ipynb)
|
||||
|
||||
Learn how to use `Vertex AI Feature Store` with pandas DataFrame.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Ingest Feature values from Pandas DataFrame into Feature Store's Entity types.
|
||||
- Read Entity Feature values from Online Feature Store into Pandas DataFrame.
|
||||
- Batch serve Feature values from your Feature Store into Pandas DataFrame.
|
||||
|
||||
|
||||
- Online serving with updated feature values.
|
||||
- Point-in-time correctness to fetch feature values for training.
|
||||
|
||||
[Online and Batch predictions using Vertex AI Feature Store](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/feature_store/sdk-feature-store.ipynb)
|
||||
|
||||
Learn how to use `Vertex AI Feature Store` to import feature data, and to access the feature data for both online serving and offline tasks, such as training.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Create featurestore, entity type, and feature resources.
|
||||
- Import feature data into `Vertex AI Feature Store` resource.
|
||||
- Serve online prediction requests using the imported features.
|
||||
- Access imported features in offline jobs, such as training jobs.
|
||||
@@ -29,6 +29,8 @@
|
||||
"id": "JAPoU8Sm5E6e"
|
||||
},
|
||||
"source": [
|
||||
"# Using Vertex AI Feature Store with pandas DataFrame\n",
|
||||
"\n",
|
||||
"<table align=\"left\">\n",
|
||||
" <td>\n",
|
||||
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/feature_store/sdk-feature-store-pandas.ipynb\">\n",
|
||||
@@ -44,7 +46,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/feature_store/sdk-feature-store-pandas.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/feature_store/sdk-feature-store-pandas.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://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/feature_store/sdk-feature-store.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/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",
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
|
||||
[Create Vertex AI Matching Engine index](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/matching_engine/sdk_matching_engine_for_indexing.ipynb)
|
||||
|
||||
Learn how to create Approximate Nearest Neighbor (ANN) Index, query against indexes, and validate the performance of the index.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
* Create ANN Index and Brute Force Index
|
||||
* Create an IndexEndpoint with VPC Network
|
||||
* Deploy ANN Index and Brute Force Index
|
||||
* Perform online query
|
||||
* Compute recall
|
||||
|
||||
|
||||
[Introduction to builtin Swivel embedding algorithm](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/matching_engine/intro-swivel.ipynb)
|
||||
|
||||
Learn how to train custom embeddings using Vertex AI Pipelines and deploy the model for serving.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
1. **Setup**: Importing the required libraries and setting your global variables.
|
||||
2. **Configure parameters**: Setting the appropriate parameter values for the pipeline job.
|
||||
3. **Train on Vertex AI Pipelines**: Create a Swivel job to Vertex Pipelines using pipeline template.
|
||||
4. **Deploy on Vertex AI Prediction**: Importing and deploying the trained model to a callable endpoint.
|
||||
5. **Predict**: Calling the deployed endpoint using online prediction.
|
||||
6. **Cleaning up**: Deleting resources created by this tutorial.
|
||||
|
||||
[Introduction to builtin Two-towers embedding algorithm](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/matching_engine/two-tower-model-introduction.ipynb)
|
||||
|
||||
Learn how to run the two-tower model.
|
||||
|
||||
The steps performed include:
|
||||
1. **Setup**: Importing the required libraries and setting your global variables.
|
||||
2. **Configure parameters**: Setting the appropriate parameter values for the training job.
|
||||
3. **Train on Vertex AI Training**: Submitting a training job.
|
||||
4. **Deploy on Vertex AI Prediction**: Importing and deploying the trained model to a callable endpoint.
|
||||
5. **Predict**: Calling the deployed endpoint using online or batch prediction.
|
||||
6. **Hyperparameter tuning**: Running a hyperparameter tuning job.
|
||||
7. **Cleaning up**: Deleting resources created by this tutorial.
|
||||
@@ -79,7 +79,9 @@
|
||||
"source": [
|
||||
"### Objective\n",
|
||||
"\n",
|
||||
"In this notebook, you learn how to train custom embeddings using Vertex AI Pipelines and deploy the model for serving. The steps performed include:\n",
|
||||
"In this notebook, you learn how to train custom embeddings using Vertex AI Pipelines and deploy the model for serving. \n",
|
||||
"\n",
|
||||
"The steps performed include:\n",
|
||||
"\n",
|
||||
"1. **Setup**: Importing the required libraries and setting your global variables.\n",
|
||||
"2. **Configure parameters**: Setting the appropriate parameter values for the pipeline job.\n",
|
||||
|
||||
@@ -74,7 +74,8 @@
|
||||
"### Objective\n",
|
||||
"\n",
|
||||
"In this notebook, you learn how to run the two-tower model.\n",
|
||||
"The tutorial covers the following steps:\n",
|
||||
"\n",
|
||||
"The steps performed include:\n",
|
||||
"1. **Setup**: Importing the required libraries and setting your global variables.\n",
|
||||
"2. **Configure parameters**: Setting the appropriate parameter values for the training job.\n",
|
||||
"3. **Train on Vertex AI Training**: Submitting a training job.\n",
|
||||
|
||||
@@ -32,17 +32,24 @@
|
||||
"# Vertex AI: Vertex AI Migration: AutoML Image Classification\n",
|
||||
"\n",
|
||||
"<table align=\"left\">\n",
|
||||
"\n",
|
||||
" <td>\n",
|
||||
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/ai-platform-samples/blob/master/vertex-ai-samples/tree/master/notebooks/official/migration/UJ1%20Vertex%20SDK%20AutoML%20Image%20Classification.ipynb\">\n",
|
||||
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/migration/UJ1 Vertex SDK AutoML Image Classification.ipynb\">\n",
|
||||
" <img src=\"https://cloud.google.com/ml-engine/images/colab-logo-32px.png\" alt=\"Colab logo\"> Run in Colab\n",
|
||||
" </a>\n",
|
||||
" </td>\n",
|
||||
" <td>\n",
|
||||
" <a href=\"https://github.com/GoogleCloudPlatform/ai-platform-samples/blob/master/vertex-ai-samples/tree/master/notebooks/official/migration/UJ1%20Vertex%20SDK%20AutoML%20Image%20Classification.ipynb\">\n",
|
||||
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/migration/UJ1 Vertex SDK AutoML Image Classification.ipynb\">\n",
|
||||
" <img src=\"https://cloud.google.com/ml-engine/images/github-logo-32px.png\" alt=\"GitHub logo\">\n",
|
||||
" View on GitHub\n",
|
||||
" </a>\n",
|
||||
" </td>\n",
|
||||
" <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/UJ1 Vertex SDK AutoML Image Classification.ipynb\">\n",
|
||||
" <img src=\"https://lh3.googleusercontent.com/UiNooY4LUgW_oTvpsNhPpQzsstV5W8F7rYgxgGBD85cWJoLmrOzhVs_ksK_vgx40SHs7jCqkTkCk=e14-rj-sc0xffffff-h130-w32\" alt=\"Vertex AI logo\">\n",
|
||||
" Open in Vertex AI Workbench\n",
|
||||
" </a>\n",
|
||||
" </td> \n",
|
||||
"</table>\n",
|
||||
"<br/><br/><br/>"
|
||||
]
|
||||
@@ -55,7 +62,7 @@
|
||||
"source": [
|
||||
"### Dataset\n",
|
||||
"\n",
|
||||
"The dataset used for this tutorial is the [Flowers dataset](https://www.tensorflow.org/datasets/catalog/tf_flowers) from [TensorFlow Datasets](https://www.tensorflow.org/datasets/catalog/overview). The version of the dataset you will use in this tutorial is stored in a public Cloud Storage bucket. The trained model predicts the type of flower an image is from a class of five flowers: daisy, dandelion, rose, sunflower, or tulip."
|
||||
"The dataset used for this tutorial is the [Flowers dataset](https://www.tensorflow.org/datasets/catalog/tf_flowers) from [TensorFlow Datasets](https://www.tensorflow.org/datasets/catalog/overview). The version of the dataset you use in this tutorial is stored in a public Cloud Storage bucket. The trained model predicts the type of flower an image is from a class of five flowers: daisy, dandelion, rose, sunflower, or tulip."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -119,7 +126,7 @@
|
||||
"source": [
|
||||
"## Installation\n",
|
||||
"\n",
|
||||
"Install the latest version of Vertex SDK for Python."
|
||||
"Install the packages required for executing this notebook."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -138,39 +145,7 @@
|
||||
"else:\n",
|
||||
" USER_FLAG = \"\"\n",
|
||||
"\n",
|
||||
"! pip3 install --upgrade google-cloud-aiplatform $USER_FLAG"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "install_storage"
|
||||
},
|
||||
"source": [
|
||||
"Install the latest GA version of *google-cloud-storage* library as well."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "install_storage"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"! pip3 install -U google-cloud-storage $USER_FLAG"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "install_tensorflow"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"if os.getenv(\"IS_TESTING\"):\n",
|
||||
" ! pip3 install --upgrade tensorflow $USER_FLAG"
|
||||
"! pip3 install --upgrade google-cloud-aiplatform google-cloud-storage tensorflow $USER_FLAG -q"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -224,7 +199,7 @@
|
||||
"\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",
|
||||
"\n",
|
||||
"4. If you are running this notebook locally, you will need to install the [Cloud SDK]((https://cloud.google.com/sdk)).\n",
|
||||
"4. 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",
|
||||
"Cloud SDK uses the right project for all the commands in this notebook.\n",
|
||||
@@ -297,7 +272,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\""
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -306,9 +284,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."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -319,9 +297,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()"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -332,7 +317,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",
|
||||
@@ -367,8 +352,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",
|
||||
@@ -378,7 +366,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]'"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -391,7 +379,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."
|
||||
]
|
||||
@@ -404,7 +392,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}\""
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -415,8 +404,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}\""
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -436,7 +426,7 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"! gsutil mb -l $REGION $BUCKET_NAME"
|
||||
"! gsutil mb -l $REGION -p $PROJECT_ID $BUCKET_URI"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -456,7 +446,7 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"! gsutil ls -al $BUCKET_NAME"
|
||||
"! gsutil ls -al $BUCKET_URI"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -488,9 +478,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."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -501,7 +491,7 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"aip.init(project=PROJECT_ID, staging_bucket=BUCKET_NAME)"
|
||||
"aip.init(project=PROJECT_ID, staging_bucket=BUCKET_URI)"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -605,7 +595,7 @@
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"dataset = aip.ImageDataset.create(\n",
|
||||
" display_name=\"Flowers\" + \"_\" + TIMESTAMP,\n",
|
||||
" display_name=\"Flowers\" + \"_\" + UUID,\n",
|
||||
" gcs_source=[IMPORT_FILE],\n",
|
||||
" import_schema_uri=aip.schema.dataset.ioformat.image.single_label_classification,\n",
|
||||
")\n",
|
||||
@@ -690,7 +680,7 @@
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"dag = aip.AutoMLImageTrainingJob(\n",
|
||||
" display_name=\"flowers_\" + TIMESTAMP,\n",
|
||||
" display_name=\"flowers_\" + UUID,\n",
|
||||
" prediction_type=\"classification\",\n",
|
||||
" multi_label=False,\n",
|
||||
" model_type=\"CLOUD\",\n",
|
||||
@@ -731,7 +721,7 @@
|
||||
"\n",
|
||||
"The `run` method when completed returns the `Model` resource.\n",
|
||||
"\n",
|
||||
"The execution of the training pipeline will take upto 20 minutes."
|
||||
"The execution of the training pipeline take upto 20 minutes."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -744,7 +734,7 @@
|
||||
"source": [
|
||||
"model = dag.run(\n",
|
||||
" dataset=dataset,\n",
|
||||
" model_display_name=\"flowers_\" + TIMESTAMP,\n",
|
||||
" model_display_name=\"flowers_\" + UUID,\n",
|
||||
" training_fraction_split=0.8,\n",
|
||||
" validation_fraction_split=0.1,\n",
|
||||
" test_fraction_split=0.1,\n",
|
||||
@@ -817,7 +807,7 @@
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Get model resource ID\n",
|
||||
"models = aip.Model.list(filter=\"display_name=flowers_\" + TIMESTAMP)\n",
|
||||
"models = aip.Model.list(filter=\"display_name=flowers_\" + UUID)\n",
|
||||
"\n",
|
||||
"# Get a reference to the Model Service client\n",
|
||||
"client_options = {\"api_endpoint\": f\"{REGION}-aiplatform.googleapis.com\"}\n",
|
||||
@@ -896,7 +886,7 @@
|
||||
"source": [
|
||||
"### Get test item(s)\n",
|
||||
"\n",
|
||||
"Now do a batch prediction to your Vertex model. You will use arbitrary examples out of the dataset as a test items. Don't be concerned that the examples were likely used in training the model -- we just want to demonstrate how to make a prediction."
|
||||
"Now do a batch prediction to your Vertex model. You use arbitrary examples out of the dataset as a test items. Don't be concerned that the examples were likely used in training the model -- we just want to demonstrate how to make a prediction."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -941,11 +931,11 @@
|
||||
"file_1 = test_item_1.split(\"/\")[-1]\n",
|
||||
"file_2 = test_item_2.split(\"/\")[-1]\n",
|
||||
"\n",
|
||||
"! gsutil cp $test_item_1 $BUCKET_NAME/$file_1\n",
|
||||
"! gsutil cp $test_item_2 $BUCKET_NAME/$file_2\n",
|
||||
"! gsutil cp $test_item_1 $BUCKET_URI/$file_1\n",
|
||||
"! gsutil cp $test_item_2 $BUCKET_URI/$file_2\n",
|
||||
"\n",
|
||||
"test_item_1 = BUCKET_NAME + \"/\" + file_1\n",
|
||||
"test_item_2 = BUCKET_NAME + \"/\" + file_2"
|
||||
"test_item_1 = BUCKET_URI + \"/\" + file_1\n",
|
||||
"test_item_2 = BUCKET_URI + \"/\" + file_2"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -956,7 +946,7 @@
|
||||
"source": [
|
||||
"### Make the batch input file\n",
|
||||
"\n",
|
||||
"Now make a batch input file, which you will store in your local Cloud Storage bucket. The batch input file can be either CSV or JSONL. You will use JSONL in this tutorial. For JSONL file, you make one dictionary entry per line for each data item (instance). The dictionary contains the key/value pairs:\n",
|
||||
"Now make a batch input file, which you store in your local Cloud Storage bucket. The batch input file can be either CSV or JSONL. You use JSONL in this tutorial. For JSONL file, you make one dictionary entry per line for each data item (instance). The dictionary contains the key/value pairs:\n",
|
||||
"\n",
|
||||
"- `content`: The Cloud Storage path to the image.\n",
|
||||
"- `mime_type`: The content type. In our example, it is a `jpeg` file.\n",
|
||||
@@ -978,7 +968,7 @@
|
||||
"\n",
|
||||
"import tensorflow as tf\n",
|
||||
"\n",
|
||||
"gcs_input_uri = BUCKET_NAME + \"/test.jsonl\"\n",
|
||||
"gcs_input_uri = BUCKET_URI + \"/test.jsonl\"\n",
|
||||
"with tf.io.gfile.GFile(gcs_input_uri, \"w\") as f:\n",
|
||||
" data = {\"content\": test_item_1, \"mime_type\": \"image/jpeg\"}\n",
|
||||
" f.write(json.dumps(data) + \"\\n\")\n",
|
||||
@@ -1002,7 +992,7 @@
|
||||
"- `job_display_name`: The human readable name for the batch prediction job.\n",
|
||||
"- `gcs_source`: A list of one or more batch request input files.\n",
|
||||
"- `gcs_destination_prefix`: The Cloud Storage location for storing the batch prediction resuls.\n",
|
||||
"- `sync`: If set to True, the call will block while waiting for the asynchronous batch job to complete."
|
||||
"- `sync`: If set to True, the call block while waiting for the asynchronous batch job to complete."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -1014,9 +1004,9 @@
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"batch_predict_job = model.batch_predict(\n",
|
||||
" job_display_name=\"flowers_\" + TIMESTAMP,\n",
|
||||
" job_display_name=\"flowers_\" + UUID,\n",
|
||||
" gcs_source=gcs_input_uri,\n",
|
||||
" gcs_destination_prefix=BUCKET_NAME,\n",
|
||||
" gcs_destination_prefix=BUCKET_URI,\n",
|
||||
" sync=False,\n",
|
||||
")\n",
|
||||
"\n",
|
||||
@@ -1232,7 +1222,7 @@
|
||||
"source": [
|
||||
"### Get test item\n",
|
||||
"\n",
|
||||
"You will use an arbitrary example out of the dataset as a test item. Don't be concerned that the example was likely used in training the model -- we just want to demonstrate how to make a prediction."
|
||||
"You use an arbitrary example out of the dataset as a test item. Don't be concerned that the example was likely used in training the model -- we just want to demonstrate how to make a prediction."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -1423,7 +1413,7 @@
|
||||
" print(e)\n",
|
||||
"\n",
|
||||
" if \"BUCKET_NAME\" in globals():\n",
|
||||
" ! gsutil rm -r $BUCKET_NAME"
|
||||
" ! gsutil rm -r $BUCKET_URI"
|
||||
]
|
||||
}
|
||||
],
|
||||
|
||||
+336
-499
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,30 @@
|
||||
|
||||
[Track parameters and metrics for locally trained models](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/ml_metadata/sdk-metric-parameter-tracking-for-locally-trained-models.ipynb)
|
||||
|
||||
Learn how to use `Vertex ML Metadata` to track training parameters and evaluation metrics.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Track parameters and metrics for a locally trained model.
|
||||
- Extract and perform analysis for all parameters and metrics within an Experiment.
|
||||
|
||||
[Track parameters and metrics for custom training jobs](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/ml_metadata/sdk-metric-parameter-tracking-for-custom-jobs.ipynb)
|
||||
|
||||
Learn how to use Vertex AI SDK for Python to:
|
||||
|
||||
The steps performed include:
|
||||
- Track training parameters and prediction metrics for a custom training job.
|
||||
- Extract and perform analysis for all parameters and metrics within an Experiment.
|
||||
|
||||
[Track artifacts and metrics across Vertex AI Pipelines runs using Vertex ML Metadata](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/ml_metadata/vertex-pipelines-ml-metadata.ipynb)
|
||||
|
||||
Learn how to track artifacts and metrics with `Vertex ML Metadata` in `Vertex AI Pipeline` runs.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
* Use the Kubeflow Pipelines SDK to build an ML pipeline that runs on Vertex AI
|
||||
* The pipeline will create a dataset, train a scikit-learn model, and deploy the model to an endpoint
|
||||
* Write custom pipeline components that generate artifacts and metadata
|
||||
* Compare Vertex Pipelines runs, both in the Cloud console and programmatically
|
||||
* Trace the lineage for pipeline-generated artifacts
|
||||
* Query your pipeline run metadata
|
||||
@@ -0,0 +1,71 @@
|
||||
|
||||
[Evaluating BatchPrediction results from AutoML Tabular Classification model](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/model_evaluation/automl_tabular_classification_model_evaluation.ipynb)
|
||||
|
||||
Learn how to train a Vertex AI AutoML Tabular Classification model and learn how to evaluate it through a Vertex AI pipeline job using `google_cloud_pipeline_components`:
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Create a Vertex AI `Dataset`.
|
||||
- Train a Automl Tabular Classification model on the `Dataset` resource.
|
||||
- Import the trained `AutoML model resource` into the pipeline.
|
||||
- Run a `Batch Prediction` job.
|
||||
- Evaulate the AutoML model using the `Classification Evaluation Component`.
|
||||
- Import the classification metrics to the AutoML model resource.
|
||||
|
||||
[Evaluating BatchPrediction results from AutoML Tabular Classification model](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/model_evaluation/automl_video_classification_model_evaluation.ipynb)
|
||||
|
||||
Learn how to train a Vertex AI AutoML Tabular Classification model and learn how to evaluate it through a Vertex AI pipeline job using `google_cloud_pipeline_components`:
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Create a Vertex AI `Dataset`.
|
||||
- Train a Automl Tabular Classification model on the `Dataset` resource.
|
||||
- Import the trained `AutoML model resource` into the pipeline.
|
||||
- Run a `Batch Prediction` job.
|
||||
- Evaulate the AutoML model using the `Classification Evaluation Component`.
|
||||
- Import the classification metrics to the AutoML model resource.
|
||||
|
||||
[Evaluating BatchPrediction results from AutoML Tabular regression model](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/model_evaluation/automl_tabular_regression_model_evaluation.ipynb)
|
||||
|
||||
Learn how to evaluate a Vertex AI model resource through a Vertex AI pipeline job using `google_cloud_pipeline_components`:
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Create a Vertex AI Dataset
|
||||
- Configure a `AutoMLTabularTrainingJob`
|
||||
- Run the `AutoMLTabularTrainingJob` which returns a model
|
||||
- Import a pre-trained `AutoML model resource` into the pipeline
|
||||
- Run a `batch prediction` job
|
||||
- Evaulate the AutoML model using the `regression evaluation component`
|
||||
- Import the Classification Metrics to the AutoML model resource
|
||||
|
||||
[Evaluating Batch Prediction results from Custom Tabular regression model](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/model_evaluation/custom_tabular_regression_model_evaluation.ipynb)
|
||||
|
||||
Learn how to evaluate a Vertex AI model resource through a Vertex AI pipeline job using `google_cloud_pipeline_components`:
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Create a Vertex AI `CustomTrainingJob` for training a model.
|
||||
- Run the `CustomTrainingJob`
|
||||
- Retrieve and load the model artifacts.
|
||||
- View the model evaluation.
|
||||
- Upload the model as a Vertex AI Model resource.
|
||||
- Import a pre-trained `Vertex AI model resource` into the pipeline
|
||||
- Run a `batch prediction` job
|
||||
- Evaulate the model using the `regression evaluation component`
|
||||
- Import the Classification Metrics to the Vertex AI model resource
|
||||
|
||||
[AutoML text classification pipelines using google-cloud-pipeline-components](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/model_evaluation/automl_text_classification_model_evaluation.ipynb)
|
||||
|
||||
Learn how to use `Vertex AI Pipelines` and `Google Cloud Pipeline Components` to build an `AutoML` text classification model.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Create a Vertex AI `Dataset`.
|
||||
- Train a Automl Tabular Classification model on the `Dataset` resource.
|
||||
- Import the trained `AutoML model resource` into the pipeline.
|
||||
- Run a `Batch Prediction` job.
|
||||
- Evaulate the AutoML model using the `Classification Evaluation Component`.
|
||||
- Import the classification metrics to the AutoML model resource.
|
||||
|
||||
|
||||
+1345
-1367
File diff suppressed because it is too large
Load Diff
+117
-212
@@ -29,7 +29,7 @@
|
||||
"id": "title"
|
||||
},
|
||||
"source": [
|
||||
"# Vertex AI Pipelines: Evaluating Batch Prediction results from Custom Tabular regression model\n",
|
||||
"# Vertex AI Pipelines: Evaluating batch prediction results from Custom Tabular regression model\n",
|
||||
"\n",
|
||||
"<table align=\"left\">\n",
|
||||
"\n",
|
||||
@@ -61,7 +61,7 @@
|
||||
"source": [
|
||||
"## Overview\n",
|
||||
"\n",
|
||||
"This notebook demonstrates how to use the Vertex AI regression model evaluation component to evaluate a Custom regression model. Model evaluation helps you determine your model performance based on the evaluation metrics and improve the model if necessary. "
|
||||
"This notebook demonstrates how to use the Vertex AI regression model evaluation component to evaluate a custom regression model. Model evaluation helps you determine your model performance based on the evaluation metrics and improve the model if necessary. "
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -76,10 +76,10 @@
|
||||
"\n",
|
||||
"This tutorial uses the following Google Cloud ML services and resources:\n",
|
||||
"\n",
|
||||
"- Vertex AI `CustomTrainingJob`\n",
|
||||
"- Vertex AI `BatchPrediction`\n",
|
||||
"- Vertex AI `Pipeline`\n",
|
||||
"- Vertex AI `Model Registry`\n",
|
||||
"- Vertex AI Training (Custom Training)\n",
|
||||
"- Vertex AI Batch Predictions\n",
|
||||
"- Vertex AI Pipelines\n",
|
||||
"- Vertex AI Model Registry\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"The steps performed include:\n",
|
||||
@@ -89,10 +89,10 @@
|
||||
"- Retrieve and load the model artifacts.\n",
|
||||
"- View the model evaluation.\n",
|
||||
"- Upload the model as a Vertex AI Model resource.\n",
|
||||
"- Import a pre-trained `Vertex AI model resource` into the pipeline\n",
|
||||
"- Run a `batch prediction` job\n",
|
||||
"- Evaulate the model using the `regression evaluation component`\n",
|
||||
"- Import the Classification Metrics to the Vertex AI model resource"
|
||||
"- Import a pre-trained `Vertex AI model resource` into the pipeline.\n",
|
||||
"- Run a `batch prediction` job in the pipeline.\n",
|
||||
"- Evaulate the model using the `regression evaluation component`.\n",
|
||||
"- Import the Regression Metrics to the Vertex AI model resource."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -191,13 +191,13 @@
|
||||
"USER_FLAG = \"\"\n",
|
||||
"if IS_WORKBENCH_NOTEBOOK:\n",
|
||||
" USER_FLAG = \"--user\"\n",
|
||||
"\n",
|
||||
"! pip3 install --upgrade google-cloud-aiplatform {USER_FLAG} -q\n",
|
||||
"! pip3 install -U google-cloud-storage $USER_FLAG -q\n",
|
||||
"! pip3 install --upgrade tensorflow $USER_FLAG -q\n",
|
||||
"! pip3 install google-cloud-pipeline-components==1.0.20 {USER_FLAG} -q\n",
|
||||
"! pip3 install --upgrade kfp {USER_FLAG} -q\n",
|
||||
"! pip3 install --upgrade matplotlib {USER_FLAG} -q"
|
||||
" \n",
|
||||
"! pip3 install --upgrade --quiet {USER_FLAG} google-cloud-aiplatform \\\n",
|
||||
" tensorflow \\\n",
|
||||
" google-cloud-pipeline-components \\\n",
|
||||
" kfp \\\n",
|
||||
" matplotlib \\\n",
|
||||
" google-cloud-storage "
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -624,7 +624,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."
|
||||
]
|
||||
@@ -659,7 +659,7 @@
|
||||
"\n",
|
||||
"Learn more about [hardware accelerator support for your region](https://cloud.google.com/vertex-ai/docs/general/locations#accelerators) \n",
|
||||
"\n",
|
||||
"*Note*: TF releases before 2.3 for GPU support will fail to load the custom model in this tutorial. It is a known issue and fixed in TF 2.3 -- which is caused by static graph ops that are generated in the serving function. If you encounter this issue on your own custom models, use a container image for TF 2.3 with GPU support."
|
||||
"*Note*: TF releases before 2.3 for GPU support will fail to load the custom model in this tutorial. It is a known issue and fixed in TF 2.3 which is caused by static graph ops that are generated in the serving function. If you encounter this issue on your own custom models, use a container image for TF 2.3 with GPU support."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -753,7 +753,7 @@
|
||||
"\n",
|
||||
"Next, set the machine type to use for training and prediction.\n",
|
||||
"\n",
|
||||
"- Set the variables `TRAIN_COMPUTE` and `DEPLOY_COMPUTE` to configure the compute resources for the VMs you will use for for training and prediction.\n",
|
||||
"- Set the variables `TRAIN_COMPUTE` and `DEPLOY_COMPUTE` to configure the compute resources for the VMs you use for training and prediction.\n",
|
||||
" - `machine type`\n",
|
||||
" - `n1-standard`: 3.75GB of memory per vCPU.\n",
|
||||
" - `n1-highmem`: 6.5GB of memory per vCPU\n",
|
||||
@@ -795,30 +795,23 @@
|
||||
"print(\"Deploy machine type\", DEPLOY_COMPUTE)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "tutorial_start:custom"
|
||||
},
|
||||
"source": [
|
||||
"# Training a custom model\n",
|
||||
"\n",
|
||||
"Now you are ready to start creating your own custom model and training for Boston Housing. \n",
|
||||
"\n",
|
||||
"[Learn more about custom model training on Vertex AI](https://cloud.google.com/vertex-ai/docs/training/custom-training)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "examine_training_package"
|
||||
},
|
||||
"source": [
|
||||
"## Training a custom model\n",
|
||||
"\n",
|
||||
"Now you are ready to start creating your own custom model and training for Boston Housing. \n",
|
||||
"\n",
|
||||
"[Learn more about custom model training on Vertex AI](https://cloud.google.com/vertex-ai/docs/training/custom-training)\n",
|
||||
"\n",
|
||||
"### Examine the training package\n",
|
||||
"\n",
|
||||
"#### Package layout\n",
|
||||
"\n",
|
||||
"Before you start the training, you will look at how a Python package is assembled for a custom training job. When unarchived, the package contains the following directory/file layout.\n",
|
||||
"Before you start the training, you look at how a Python package is assembled for a custom training job. When unarchived, the package contains the following directory/file layout.\n",
|
||||
"\n",
|
||||
"- PKG-INFO\n",
|
||||
"- README.md\n",
|
||||
@@ -830,11 +823,13 @@
|
||||
"\n",
|
||||
"The files `setup.cfg` and `setup.py` are the instructions for installing the package into the operating environment of the Docker image.\n",
|
||||
"\n",
|
||||
"The file `trainer/task.py` is the Python script for executing the custom training job. *Note*, when we referred to it in the worker pool specification, we replaced the directory slash with a dot (`trainer.task`) and dropped the file suffix (`.py`).\n",
|
||||
"The file `trainer/task.py` is the Python script for executing the custom training job. \n",
|
||||
"\n",
|
||||
"**Note:** When you refer to it in the worker pool specification, you replace the directory slash with a dot (`trainer.task`) and dropped the file suffix (`.py`).\n",
|
||||
"\n",
|
||||
"#### Package Assembly\n",
|
||||
"\n",
|
||||
"In the following cells, you will assemble the training package."
|
||||
"In the following cells, you assemble the training package."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -872,7 +867,7 @@
|
||||
"id": "taskpy_contents:boston"
|
||||
},
|
||||
"source": [
|
||||
"#### Task.py contents\n",
|
||||
"#### Create task.py\n",
|
||||
"\n",
|
||||
"In the next cell, you write the contents of the training script task.py. In summary:\n",
|
||||
"\n",
|
||||
@@ -1013,7 +1008,7 @@
|
||||
"id": "tarball_training_script"
|
||||
},
|
||||
"source": [
|
||||
"#### Store the training script on your Cloud Storage bucket\n",
|
||||
"**Store the training script on your Cloud Storage bucket.**\n",
|
||||
"\n",
|
||||
"Next, you package the training folder into a compressed tar ball, and then store it in your Cloud Storage bucket."
|
||||
]
|
||||
@@ -1045,16 +1040,16 @@
|
||||
"\n",
|
||||
"1) Create a custom training job\n",
|
||||
"\n",
|
||||
"2) Run the job.\n",
|
||||
"2) Run the job\n",
|
||||
"\n",
|
||||
"#### Create custom training job\n",
|
||||
"#### Create a custom training job\n",
|
||||
"\n",
|
||||
"A custom training job is created with the `CustomTrainingJob` class, with the following parameters:\n",
|
||||
"\n",
|
||||
"- `display_name`: The human readable name for the custom training job.\n",
|
||||
"- `container_uri`: The training container image.\n",
|
||||
"- `requirements`: Package requirements for the training container image (e.g., pandas).\n",
|
||||
"- `script_path`: The relative path to the training script."
|
||||
"- `display_name`: The human readable name for the custom training job\n",
|
||||
"- `container_uri`: The training container image\n",
|
||||
"- `requirements`: Package requirements for the training container image (e.g., pandas)\n",
|
||||
"- `script_path`: The relative path to the training script"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -1081,7 +1076,7 @@
|
||||
"id": "prepare_custom_cmdargs"
|
||||
},
|
||||
"source": [
|
||||
"### Prepare your command-line arguments\n",
|
||||
"#### Prepare your command-line arguments\n",
|
||||
"\n",
|
||||
"Now define the command-line arguments for your custom training container:\n",
|
||||
"\n",
|
||||
@@ -1128,7 +1123,7 @@
|
||||
"source": [
|
||||
"#### Run the custom training job\n",
|
||||
"\n",
|
||||
"Next, you run the custom job to start the training job by invoking the method `run`, with the following parameters:\n",
|
||||
"Next, you run the custom job to start the training job by invoking the `run()` method, with the following parameters:\n",
|
||||
"\n",
|
||||
"- `args`: The command-line arguments to pass to the training script.\n",
|
||||
"- `replica_count`: The number of compute instances for training (replica_count = 1 is single node training).\n",
|
||||
@@ -1136,7 +1131,7 @@
|
||||
"- `accelerator_type`: The hardware accelerator type.\n",
|
||||
"- `accelerator_count`: The number of accelerators to attach to a worker replica.\n",
|
||||
"- `base_output_dir`: The Cloud Storage location to write the model artifacts to.\n",
|
||||
"- `sync`: Whether to block until completion of the job."
|
||||
"- `sync`: Whether to execute this method synchronously. If False, this method will be executed in concurrent Future and any downstream object will be immediately returned and synced when the Future has completed."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -1175,11 +1170,11 @@
|
||||
"id": "ab954a846b61"
|
||||
},
|
||||
"source": [
|
||||
"## Load the saved model\n",
|
||||
"#### Load the saved model\n",
|
||||
"\n",
|
||||
"Your model is stored in a TensorFlow SavedModel format in a Cloud Storage bucket. Now load it from the Cloud Storage bucket, and then you can perform tasks such as model evaluation and make prediction requests.\n",
|
||||
"\n",
|
||||
"To load, you use the `tf.saved_model.load()` method passing it the Cloud Storage path where the model is saved -- specified by `MODEL_DIR`."
|
||||
"To load the model, you pass the Cloud Storage path \"MODEL_DIR\" to the `tf.saved_model.load()` method."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -1199,11 +1194,11 @@
|
||||
"id": "serving_function_signature"
|
||||
},
|
||||
"source": [
|
||||
"## Get the serving function signature\n",
|
||||
"#### Get the serving function signature\n",
|
||||
"\n",
|
||||
"You can get the signatures of your model's input and output layers by reloading the model into memory, and querying it for the signatures corresponding to each layer.\n",
|
||||
"\n",
|
||||
"When making a prediction request, you need to route the request to the serving function instead of the model, so you need to know the input layer name of the serving function -- which you use later when you make a prediction request.\n",
|
||||
"When making a prediction request, you need to route the request to the serving function instead of the model, so you need to know the input layer name of the serving function which you use later when you make a prediction request.\n",
|
||||
"\n",
|
||||
"You also need to know the name of the serving function's input and output layer for constructing the explanation metadata **during a later step**."
|
||||
]
|
||||
@@ -1224,52 +1219,31 @@
|
||||
"print(\"Serving function output:\", serving_output)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "e9926f55a85d"
|
||||
},
|
||||
"source": [
|
||||
"## Configure feature-based explanations (Optional) "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "3276368bae14"
|
||||
},
|
||||
"source": [
|
||||
"**If you want to configure explanations for the model, follow this step else skip this step.**"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "c67a1509f62d"
|
||||
},
|
||||
"source": [
|
||||
"**To use Vertex Explainable AI with a custom-trained model, you must configure certain options when you create the Model resource that you plan to request explanations from, when you deploy the model, or when you submit a batch explanation job.** \n",
|
||||
"\n",
|
||||
"**If you want to use Vertex Explainable AI with an AutoML tabular model, then you don't need to perform any configuration; Vertex AI automatically configures the model for Vertex Explainable AI.**"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "69d4859c7196"
|
||||
},
|
||||
"source": [
|
||||
"## Configure feature-based explanations (Optional) \n",
|
||||
"\n",
|
||||
"**For configuring explanations to the model, follow this step. This step is optional.**\n",
|
||||
"\n",
|
||||
"To use Vertex Explainable AI with a custom-trained model, you must configure certain options when you create the Model resource that you plan to request explanations from, or when you deploy the model, or when you submit a batch explanation job.\n",
|
||||
"\n",
|
||||
"If you want to use Vertex Explainable AI with an AutoML tabular model, then you don't need to perform any configuration. Vertex AI automatically configures the model for Vertex Explainable AI.\n",
|
||||
"\n",
|
||||
"### Explanation Specification\n",
|
||||
"\n",
|
||||
"To get explanations when doing a prediction, you must enable the explanation capability and set corresponding settings when you upload your custom model to an Vertex `Model` resource. These settings are referred to as the explanation metadata, which consists of:\n",
|
||||
"To get explanations when doing a prediction, you must enable the explanation feature and set corresponding settings when you upload your custom model to Vertex AI Model registry. These settings are referred to as the explanation metadata, which consists of:\n",
|
||||
"\n",
|
||||
"- `parameters`: This is the specification for the explainability algorithm to use for explanations on your model. You can choose between:\n",
|
||||
" - Shapley - *Note*, not recommended for image data -- can be very long running\n",
|
||||
"- `parameters`: Specification for the explainability algorithm to use for explanations on your model. You can choose between:\n",
|
||||
" - Shapley (not recommended for image data as the computation can take long)\n",
|
||||
" - XRAI\n",
|
||||
" - Integrated Gradients\n",
|
||||
"- `metadata`: This is the specification for how the algoithm is applied on your custom model.\n",
|
||||
"- `metadata`: Specification for how the algoithm is applied on your custom model\n",
|
||||
"\n",
|
||||
"[Learn more about explanation specification here](https://cloud.google.com/vertex-ai/docs/explainable-ai/configuring-explanations-feature-based#when-creating-or-importing-model)\n",
|
||||
"Learn more about [explanation specification](https://cloud.google.com/vertex-ai/docs/explainable-ai/configuring-explanations-feature-based#when-creating-or-importing-model).\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"\n",
|
||||
@@ -1344,24 +1318,20 @@
|
||||
")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "beec0356d7b8"
|
||||
},
|
||||
"source": [
|
||||
"## Make instance schema and prediction schema yaml files"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "ed414a2f945a"
|
||||
},
|
||||
"source": [
|
||||
"#### instance_schema.yaml and prediction_schema.yaml contents\n",
|
||||
"### Make instance schema and prediction schema yaml files\n",
|
||||
"\n",
|
||||
"In the next cell, you write the contents of the instance_schema.yaml . You write the information about the prediction instances you give to your batch prediction .\n",
|
||||
"In next cells, you write the contents of **instance_schema.yaml** and **prediction_schema.yaml** files. Content structure is same for both files.\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"#### Make instance schema yaml file\n",
|
||||
"\n",
|
||||
"In the next cell, you write the contents of the instance_schema.yaml . You write the structure about the prediction instances you give to your batch prediction .\n",
|
||||
"\n",
|
||||
"- Give the title and description.\n",
|
||||
"- Give type of the input. In our case input to batch predictin is \n",
|
||||
@@ -1381,10 +1351,9 @@
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"%%writefile instance_schema.yaml\n",
|
||||
"title: TabularClassification\n",
|
||||
"description: 'Classification Instances.\n",
|
||||
"title: TabularRegression\n",
|
||||
"description: 'Regression Instances.'\n",
|
||||
"\n",
|
||||
" '\n",
|
||||
"type: object\n",
|
||||
"properties:\n",
|
||||
" dense_input:\n",
|
||||
@@ -1393,9 +1362,7 @@
|
||||
" type: float\n",
|
||||
" minimum: 0.0\n",
|
||||
" maximum: 1.0\n",
|
||||
" description: 'Input values to model\n",
|
||||
"\n",
|
||||
" '\n"
|
||||
" description: 'Input values to model'\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -1404,7 +1371,7 @@
|
||||
"id": "ef75c6f86088"
|
||||
},
|
||||
"source": [
|
||||
"### Make prediction schema yaml file"
|
||||
"#### Make prediction schema yaml file"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -1413,15 +1380,13 @@
|
||||
"id": "53f324aaf19a"
|
||||
},
|
||||
"source": [
|
||||
"In the next cell, you write the contents of the prediction_schema.yaml . You write the information about the prediction output you get from your batch prediction job.\n",
|
||||
"In the next cell, you write the contents of the prediction_schema.yaml . You write the structure about the prediction output you get from your batch prediction job.\n",
|
||||
"\n",
|
||||
"Contents are same as instance_schema.yaml file\n",
|
||||
"\n",
|
||||
"In our case output from batch prediction job is \n",
|
||||
"In your case, output from batch prediction job is \n",
|
||||
"\n",
|
||||
"**{\"instance\": {\"dense_input\": [0.02715405449271202, 0.0, 0.027177177369594574, 0.0, 0.0010195195209234953, 0.009660660289227962, 0.1501501500606537, 0.0027548049110919237, 0.036036036908626556, 1.0, 0.03033033013343811, 0.04091591760516167, 0.043618619441986084]}, \"prediction\": [0.522156954]}**\n",
|
||||
"\n",
|
||||
"Prediction, you get is **\"prediction\": [0.522156954]**, which is of type array."
|
||||
"Prediction output of batch prediction job is **\"prediction\": [0.522156954]**, which is of type array."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -1434,8 +1399,8 @@
|
||||
"source": [
|
||||
"%%writefile prediction_schema.yaml\n",
|
||||
"title: TabularRegression\n",
|
||||
"description: 'Regression results.\n",
|
||||
" '\n",
|
||||
"description: 'Regression results.'\n",
|
||||
"\n",
|
||||
"type: array"
|
||||
]
|
||||
},
|
||||
@@ -1445,7 +1410,7 @@
|
||||
"id": "ff29b80d8b9c"
|
||||
},
|
||||
"source": [
|
||||
"Upload both files to your Cloud Storage bucket."
|
||||
"Upload both the files to your Cloud Storage bucket."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -1466,7 +1431,7 @@
|
||||
"id": "upload_model:mbsdk"
|
||||
},
|
||||
"source": [
|
||||
"## Upload the model\n",
|
||||
"### Upload the model\n",
|
||||
"\n",
|
||||
"Next, upload your model to a `Model` resource using `Model.upload()` method, with the following parameters:\n",
|
||||
"\n",
|
||||
@@ -1479,16 +1444,9 @@
|
||||
"- `explanation_parameters`: Parameters to configure explaining for `Model`'s predictions.\n",
|
||||
"- `explanation_metadata`: Metadata describing the `Model`'s input and output for explanation.\n",
|
||||
"\n",
|
||||
"If the `upload()` method is run asynchronously, you can subsequently block until completion with the `wait()` method."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "01fca26f26c3"
|
||||
},
|
||||
"source": [
|
||||
"**If you want to configure explanations for the model, set `explanation_parameters`, `explanation_metadata` parameters. Else do not set them.**"
|
||||
"If the `upload()` method is run asynchronously, you can subsequently block until completion with the `wait()` method.\n",
|
||||
"\n",
|
||||
"**Note:** If you want to configure explanations for the model, set `explanation_parameters`, `explanation_metadata` parameters. Else do not set them."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -1523,7 +1481,7 @@
|
||||
"\n",
|
||||
"You load the Boston Housing test (holdout) data from `tf.keras.datasets`, using the method `load_data()`. This returns the dataset as a tuple of two elements. The first element is the training data and the second is the test data. Each element is also a tuple of two elements: the feature data, and the corresponding labels (median value of owner-occupied home).\n",
|
||||
"\n",
|
||||
"You don't need the training data, and hence why we loaded it as `(_, _)`.\n",
|
||||
"You don't need the training data, and hence you load it as `(_, _)`.\n",
|
||||
"\n",
|
||||
"Before you can run the data through the pipeline, you need to preprocess it:\n",
|
||||
"\n",
|
||||
@@ -1591,35 +1549,21 @@
|
||||
" f.write(json.dumps(data) + \"\\n\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "6d554697ccba"
|
||||
},
|
||||
"source": [
|
||||
"## Model Evaluation"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "dAYyBa_qw0aT"
|
||||
},
|
||||
"source": [
|
||||
"## Model Evaluation\n",
|
||||
"\n",
|
||||
"Now you create a pipeline for performing model evaluation.\n",
|
||||
"\n",
|
||||
"### Create Pipeline for evaluations\n",
|
||||
"\n",
|
||||
"Now, you run a Vertex AI Batch Prediction job and generate evaluations and feature-attributions on its results. \n",
|
||||
"Now, you run a Vertex AI BatchPrediction job and generate evaluations and feature-attributions on its results by creating a Vertex AI pipeline using the components available from the [google-cloud-pipeline-components](https://google-cloud-pipeline-components.readthedocs.io/en/google-cloud-pipeline-components-1.0.17/index.html) python package. \n",
|
||||
"\n",
|
||||
"To do so, you create a Vertex AI pipeline using the components available from the [`google-cloud-pipeline-components`](https://google-cloud-pipeline-components.readthedocs.io/en/google-cloud-pipeline-components-1.0.17/index.html) python package.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "edb8612865ce"
|
||||
},
|
||||
"source": [
|
||||
"Set a display name for your pipeline."
|
||||
"**Set a display name for your pipeline.**"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -1658,7 +1602,7 @@
|
||||
"id": "51f9c8d3e4ab"
|
||||
},
|
||||
"source": [
|
||||
"### Define the Pipeline\n",
|
||||
"#### Define the Pipeline\n",
|
||||
"\n",
|
||||
"While defining the flow of the pipeline, you get the model resource first. Then, you sample the provided source dataset for batch predictions and create a batch prediction. The explanations are enabled while creating the batch prediction job to generate feature attributions. Once the batch prediction job is completed, you get the regression evaluation metrics and the feature attributions from the results.\n",
|
||||
"\n",
|
||||
@@ -1672,28 +1616,17 @@
|
||||
"- `ModelEvaluationFeatureAttributionOp`: Compute feature attribution on a trained model’s batch explanation results. Creates a Dataflow job with Apache Beam and TFMA to compute feature attributions. \n",
|
||||
"- `ModelImportEvaluationOp`: Imports a model evaluation artifact to an existing Vertex AI Model resource with ModelService.ImportModelEvaluation. \n",
|
||||
"\n",
|
||||
"**The pipeline takes about 1 hour to complete.**\n",
|
||||
"\n",
|
||||
"Learn more about [Google Cloud Pipeline Model Evaluation components](https://google-cloud-pipeline-components.readthedocs.io/en/google-cloud-pipeline-components-1.0.20/google_cloud_pipeline_components.experimental.evaluation.html)."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "9aba67b73868"
|
||||
},
|
||||
"source": [
|
||||
"#### Example workflow\n",
|
||||
"Learn more about [Google Cloud Pipeline Model Evaluation components](https://google-cloud-pipeline-components.readthedocs.io/en/google-cloud-pipeline-components-1.0.20/google_cloud_pipeline_components.experimental.evaluation.html).\n",
|
||||
"\n",
|
||||
"##### Example workflow\n",
|
||||
"\n",
|
||||
"1.If this\n",
|
||||
"\n",
|
||||
"({\"dense_input\": [0.7220525145530701, 0.0, 0.6524873971939087], \"MEDV\": 7.2}\n",
|
||||
"{\"dense_input\": [0.004922522697597742, 0.0, 0.3608507513999939], \"MEDV\": 18.8})\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"is the input to data sampler and if sample size is 1,\n",
|
||||
"\n",
|
||||
"output is \n",
|
||||
"\n",
|
||||
"{\"dense_input\": [0.004922522697597742, 0.0, 0.3608507513999939], \"MEDV\": 18.8}\n",
|
||||
@@ -1708,7 +1641,7 @@
|
||||
"\n",
|
||||
"4.The output of the batch prediction is given as input for the `ModelEvaluationRegressionOp` component. For a custom model, the ground truth cannot be part of the batch prediction instance, so we provide the output of the data sampler with ground truths to `ModelEvaluationRegressionOp`'s `ground_truth_gcs_source` parameter.\n",
|
||||
"\n",
|
||||
"5.In `ModelImportEvaluationOp` We import evaluation metrics and feature attributions to the model.\n"
|
||||
"5.In `ModelImportEvaluationOp`, we import evaluation metrics and feature attributions to the model.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -1729,14 +1662,9 @@
|
||||
" batch_predict_gcs_source_uris: list,\n",
|
||||
" key_columns: list,\n",
|
||||
" batch_predict_instances_format: str,\n",
|
||||
" batch_predict_sample_size: int,\n",
|
||||
" batch_predict_predictions_format: str = \"jsonl\",\n",
|
||||
" batch_predict_machine_type: str = \"n1-standard-4\",\n",
|
||||
" batch_predict_explanation_metadata: dict = {},\n",
|
||||
" batch_predict_explanation_parameters: dict = {},\n",
|
||||
" batch_predict_explanation_data_sample_size: int = 10000,\n",
|
||||
" dataflow_max_num_workers: int = 5,\n",
|
||||
" dataflow_use_public_ips: bool = True,\n",
|
||||
" encryption_spec_key_name: str = \"\",\n",
|
||||
"):\n",
|
||||
"\n",
|
||||
" from google_cloud_pipeline_components.aiplatform import ModelBatchPredictOp\n",
|
||||
@@ -1755,7 +1683,7 @@
|
||||
" root_dir=root_dir,\n",
|
||||
" gcs_source_uris=batch_predict_gcs_source_uris,\n",
|
||||
" instances_format=batch_predict_instances_format,\n",
|
||||
" sample_size=batch_predict_explanation_data_sample_size,\n",
|
||||
" sample_size=batch_predict_sample_size,\n",
|
||||
" )\n",
|
||||
"\n",
|
||||
" # Run Data-splitter task\n",
|
||||
@@ -1779,11 +1707,8 @@
|
||||
" predictions_format=batch_predict_predictions_format,\n",
|
||||
" gcs_destination_output_uri_prefix=root_dir,\n",
|
||||
" machine_type=batch_predict_machine_type,\n",
|
||||
" encryption_spec_key_name=encryption_spec_key_name,\n",
|
||||
" # Set the explanation parameters\n",
|
||||
" generate_explanation=True,\n",
|
||||
" explanation_parameters=batch_predict_explanation_parameters,\n",
|
||||
" explanation_metadata=batch_predict_explanation_metadata,\n",
|
||||
" )\n",
|
||||
"\n",
|
||||
" # Run evaluation based on prediction type and feature attribution component.\n",
|
||||
@@ -1799,9 +1724,6 @@
|
||||
" predictions_format=batch_predict_predictions_format,\n",
|
||||
" prediction_score_column=\"prediction\",\n",
|
||||
" ground_truth_column=target_column_name,\n",
|
||||
" dataflow_max_workers_num=dataflow_max_num_workers,\n",
|
||||
" dataflow_use_public_ips=dataflow_use_public_ips,\n",
|
||||
" encryption_spec_key_name=encryption_spec_key_name,\n",
|
||||
" )\n",
|
||||
"\n",
|
||||
" # Get Feature Attributions\n",
|
||||
@@ -1811,9 +1733,6 @@
|
||||
" root_dir=root_dir,\n",
|
||||
" predictions_format=\"jsonl\",\n",
|
||||
" predictions_gcs_source=batch_explain_task.outputs[\"gcs_output_directory\"],\n",
|
||||
" dataflow_max_workers_num=dataflow_max_num_workers,\n",
|
||||
" dataflow_use_public_ips=dataflow_use_public_ips,\n",
|
||||
" encryption_spec_key_name=encryption_spec_key_name,\n",
|
||||
" )\n",
|
||||
"\n",
|
||||
" ModelImportEvaluationOp(\n",
|
||||
@@ -1830,7 +1749,7 @@
|
||||
"id": "RqcRr7USbseH"
|
||||
},
|
||||
"source": [
|
||||
"### Compile the pipeline\n",
|
||||
"##### Compile the pipeline\n",
|
||||
"\n",
|
||||
"Next, compile the pipline to the `tabular_regression_pipline.json` file."
|
||||
]
|
||||
@@ -1849,23 +1768,17 @@
|
||||
")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "UCn7EORsbseH"
|
||||
},
|
||||
"source": [
|
||||
"### Define the parameters to run the pipeline\n",
|
||||
"\n",
|
||||
"Specify the required parameters to run the pipeline.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "zwrhHGm7bseH"
|
||||
},
|
||||
"source": [
|
||||
"##### Define the parameters to run the pipeline\n",
|
||||
"\n",
|
||||
"Specify the required parameters to run the pipeline.\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"To pass the required arguments to the pipeline, you define the following paramters below:\n",
|
||||
"\n",
|
||||
"- `project`: Project ID.\n",
|
||||
@@ -1888,6 +1801,7 @@
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"PIPELINE_ROOT = f\"{BUCKET_URI}/pipeline_root/boston_{UUID}\"\n",
|
||||
"batch_predict_sample_size = 5\n",
|
||||
"parameters = {\n",
|
||||
" \"project\": PROJECT_ID,\n",
|
||||
" \"location\": REGION,\n",
|
||||
@@ -1898,7 +1812,7 @@
|
||||
" BUCKET_URI + \"/\" + \"test_file_with_ground_truth.jsonl\"\n",
|
||||
" ],\n",
|
||||
" \"batch_predict_instances_format\": \"jsonl\",\n",
|
||||
" \"batch_predict_explanation_data_sample_size\": 5,\n",
|
||||
" \"batch_predict_sample_size\": batch_predict_sample_size,\n",
|
||||
" \"key_columns\": [\"dense_input\"],\n",
|
||||
"}"
|
||||
]
|
||||
@@ -1914,7 +1828,11 @@
|
||||
"- `display_name`: The user-defined name of this Pipeline.\n",
|
||||
"- `template_path`: The path of PipelineJob or PipelineSpec JSON or YAML file. It can be a local path, a Google Cloud Storage URI (e.g. \"gs://project.name\"), or an Artifact Registry URI (e.g. \"https://us-central1-kfp.pkg.dev/proj/repo/pack/latest\").\n",
|
||||
"- `parameter_values`: The mapping from runtime parameter names to its values that control the pipeline run.\n",
|
||||
"- `enable_caching`: Whether to turn on caching for the run. If this is not set, defaults to the compile time settings, which are True for all tasks by default, while users may specify different caching options for individual tasks. If this is set, the setting applies to all tasks in the pipeline. Overrides the compile time settings.\n"
|
||||
"- `enable_caching`: Whether to turn on caching for the run. If this is not set, defaults to the compile time settings, which are True for all tasks by default, while users may specify different caching options for individual tasks. If this is set, the setting applies to all tasks in the pipeline. Overrides the compile time settings.\n",
|
||||
"\n",
|
||||
"Run the pipeline using the configured `SERVICE_ACCOUNT`\n",
|
||||
"\n",
|
||||
"**The pipeline takes about 1 hour to complete.**\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -1950,27 +1868,13 @@
|
||||
"id": "l7DHzescbseI"
|
||||
},
|
||||
"source": [
|
||||
"### Runtime Graph of Model Evaluation pipeline \n",
|
||||
"##### Runtime Graph of Model Evaluation pipeline\n",
|
||||
"\n",
|
||||
"In the UI, many of the pipeline DAG nodes will expand or collapse when you click on them. Here is a partially-expanded view of the DAG (click image to see larger version)."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "WSyD50YgbseJ"
|
||||
},
|
||||
"source": [
|
||||
"<img src=\"images/custom_tabular_regression_evaluation_pipeline.PNG\" style=\"height:622px;width:726px\"></img>"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "EJGzb54mbseJ"
|
||||
},
|
||||
"source": [
|
||||
"### Get the Model Evaluation Results\n",
|
||||
"In the UI, many of the pipeline DAG nodes will expand or collapse when you click on them. Here is a partially-expanded view of the DAG (click image to see larger version).\n",
|
||||
"\n",
|
||||
"<img src=\"images/custom_tabular_regression_evaluation_pipeline.PNG\" style=\"height:622px;width:726px\"></img>\n",
|
||||
"\n",
|
||||
"### Get the model evaluation results\n",
|
||||
"\n",
|
||||
"After the evalution pipeline is finished, run the below cell to print the evaluation metrics."
|
||||
]
|
||||
@@ -2009,7 +1913,9 @@
|
||||
"id": "1-oX7xI6bseJ"
|
||||
},
|
||||
"source": [
|
||||
"### Visualize the metrics\n"
|
||||
"### Visualize the metrics\n",
|
||||
"\n",
|
||||
"After the evalution pipeline is finished, run the below cell to visualize the evaluation metrics."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -2049,7 +1955,7 @@
|
||||
"\n",
|
||||
"Feature attributions indicate how much each feature in your model contributed to the predictions for each given instance.\n",
|
||||
"\n",
|
||||
"Learn more about [Feature Attributions](https://cloud.google.com/vertex-ai/docs/explainable-ai/overview#feature_attributions)\n",
|
||||
"Learn more about [Feature attributions](https://cloud.google.com/vertex-ai/docs/explainable-ai/overview#feature_attributions).\n",
|
||||
"\n",
|
||||
"Run the below cell to get the feature attributions. "
|
||||
]
|
||||
@@ -2162,7 +2068,6 @@
|
||||
"# Delete model resource\n",
|
||||
"model.delete()\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# Delete the training job\n",
|
||||
"train_job.delete()\n",
|
||||
"\n",
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
|
||||
[Vertex AI Model Monitoring with Explainable AI Feature Attributions](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/model_monitoring/model_monitoring.ipynb)
|
||||
|
||||
Learn to use the `Vertex AI Model Monitoring` service to detect drift and anomalies in prediction requests from a deployed `Vertex AI Model` resource.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Upload a pre-trained model as a `Vertex AI Model` resource.
|
||||
- Create an `Vertex AI Endpoint` resource.
|
||||
- Deploy the `Model` resource to the `Endpoint` resource.
|
||||
- Configure the `Endpoint` resource for model monitoring.
|
||||
- Initialize the baseline distribution for model monitoring.
|
||||
- Generate synthetic prediction requests.
|
||||
- Understand how to interpret the statistics, visualizations, other data reported by the model monitoring feature.
|
||||
@@ -975,7 +975,7 @@
|
||||
"# Sampling rate (optional, default=.8)\n",
|
||||
"LOG_SAMPLE_RATE = 0.8 # @param {type:\"number\"}\n",
|
||||
"\n",
|
||||
"# Monitoring Interval in seconds (optional, default=1).\n",
|
||||
"# Monitoring Interval in hours (optional, default=1).\n",
|
||||
"MONITOR_INTERVAL = 1 # @param {type:\"number\"}\n",
|
||||
"\n",
|
||||
"# URI to training dataset.\n",
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
|
||||
[Deploy BiqQuery ML Model on Vertex AI Model Registry and make predictions](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/model_registry/bqml_vertexai_model_registry.ipynb)
|
||||
|
||||
Learn how to use `Vertex AI Model Registry` with `BigQuery ML` and make batch predictions:
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Train a model with `BigQuery ML`
|
||||
- Upload the model to `Vertex AI Model Registry`
|
||||
- Create a `Vertex AI Endpoint` resource
|
||||
- Deploy the `Model` resource to the `Endpoint` resource
|
||||
- Make `prediction` requests to the model endpoint
|
||||
- Run `batch prediction` job on the `Model` resource
|
||||
|
||||
+4
-4
@@ -34,18 +34,18 @@
|
||||
"<table align=\"left\">\n",
|
||||
"\n",
|
||||
" <td>\n",
|
||||
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/model-registry/bqml-vertexai-model-registry.ipynb\" target=\"_blank\">\n",
|
||||
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/model_registry/bqml_vertexai_model_registry.ipynb\" target=\"_blank\">\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/model-registry/bqml-vertexai-model-registry.ipynb\" target=\"_blank\">\n",
|
||||
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/model_registry/bqml_vertexai_model_registry.ipynb\" target=\"_blank\">\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/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",
|
||||
@@ -864,7 +864,7 @@
|
||||
"metadata": {
|
||||
"colab": {
|
||||
"collapsed_sections": [],
|
||||
"name": "bqml-vertexai-model-registry.ipynb",
|
||||
"name": "bqml_vertexai_model_registry.ipynb",
|
||||
"toc_visible": true
|
||||
},
|
||||
"kernelspec": {
|
||||
@@ -1,21 +1,162 @@
|
||||
# Vertex Pipeline examples
|
||||
|
||||
This directory holds [Vertex Pipelines](https://cloud.google.com/vertex-ai/docs/pipelines) example notebooks.
|
||||
[AutoML image classification pipelines using google-cloud-pipeline-components](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/pipelines/google_cloud_pipeline_components_automl_images.ipynb)
|
||||
|
||||
- [pipelines_intro_kfp.ipynb](./pipelines_intro_kfp.ipynb) introduces some of the Vertex Pipelines features, using the [Kubeflow Pipelines (KFP) SDK](https://www.kubeflow.org/docs/components/pipelines/).
|
||||
Learn how to use `Vertex AI Pipelines` and `Google Cloud Pipeline Components` to build an `AutoML` image classification model.
|
||||
|
||||
- [control_flow_kfp.ipynb](./control_flow_kfp.ipynb) shows how you can build pipelines that include conditionals and parallel 'for' loops using the KFP SDK.
|
||||
- [lightweight_functions_component_io_kfp.ipynb](./lightweight_functions_component_io_kfp.ipynb) shows how to build lightweight Python function-based components, and in particular how to support component I/O using the KFP SDK.
|
||||
- [metrics_viz_run_compare_kfp.ipynb](./metrics_viz_run_compare_kfp.ipynb) shows how to use the KFP SDK to build Vertex Pipelines that generate model metrics and metrics visualizations; and how to compare pipeline runs.
|
||||
The steps performed include:
|
||||
|
||||
The following examples show how to use the components defined in [google_cloud_pipeline_components](https://github.com/kubeflow/pipelines/tree/master/components/google-cloud) to build pipelines that access [Vertex AI](https://cloud.google.com/vertex-ai/) services.
|
||||
- Create a KFP pipeline:
|
||||
- Create a `Dataset` resource.
|
||||
- Train an AutoML image classification `Model` resource.
|
||||
- Create an `Endpoint` resource.
|
||||
- Deploys the `Model` resource to the `Endpoint` resource.
|
||||
- Compile the KFP pipeline.
|
||||
- Execute the KFP pipeline using `Vertex AI Pipelines`
|
||||
|
||||
|
||||
|
||||
[Metrics visualization and run comparison using the KFP SDK](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/pipelines/metrics_viz_run_compare_kfp.ipynb)
|
||||
|
||||
Learn how to use the KFP SDK to build pipelines that generate evaluation metrics.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Create KFP components:
|
||||
- Generate ROC curve and confusion matrix visualizations for classification results
|
||||
- Write metrics
|
||||
- Create KFP pipelines.
|
||||
- Execute KFP pipelines
|
||||
- Compare metrics across pipeline runs
|
||||
|
||||
[Lightweight Python function-based components, and component I/O](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/pipelines/lightweight_functions_component_io_kfp.ipynb)
|
||||
|
||||
Learn to use the KFP SDK to build lightweight Python function-based components, and then you learn to use `Vertex AI Pipelines` to execute the pipeline.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Build Python function-based KFP components.
|
||||
- Construct a KFP pipeline.
|
||||
- Pass *Artifacts* and *parameters* between components, both by path reference and by value.
|
||||
- Use the `kfp.dsl.importer` method.
|
||||
- Compile the KFP pipeline.
|
||||
- Execute the KFP pipeline using `Vertex AI Pipelines`
|
||||
|
||||
[Custom training with pre-built Google Cloud Pipeline Components](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/pipelines/custom_model_training_and_batch_prediction.ipynb)
|
||||
|
||||
Learn to use `Vertex AI Pipelines` and `Google Cloud Pipeline Components` to build a custom model.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Create a KFP pipeline:
|
||||
- Train a custom model.
|
||||
- Upload the trained model as a `Model` resource.
|
||||
- Create an `Endpoint` resource.
|
||||
- Deploy the `Model` resource to the `Endpoint` resource.
|
||||
- Make a batch prediction request.
|
||||
|
||||
|
||||
|
||||
[AutoML Tabular pipelines using google-cloud-pipeline-components](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/pipelines/automl_tabular_classification_beans.ipynb)
|
||||
|
||||
Learn to use `Vertex AI Pipelines` and `Google Cloud Pipeline Components` to build an `AutoML` tabular classification model.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Create a KFP pipeline:
|
||||
- Create a `Dataset` resource.
|
||||
- Train an AutoML tabular classification `Model` resource.
|
||||
- Create an `Endpoint` resource.
|
||||
- Deploys the `Model` resource to the `Endpoint` resource.
|
||||
- Compile the KFP pipeline.
|
||||
- Execute the KFP pipeline using `Vertex AI Pipelines`
|
||||
|
||||
|
||||
|
||||
[Training an acquisition-prediction model using Swivel, BigQuery ML and Vertex AI Pipelines](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/pipelines/google_cloud_pipeline_components_bqml_text.ipynb)
|
||||
|
||||
Learn how to build a simple BigQuery ML pipeline using Vertex AI pipelines in order to calculate text embeddings of content from articles and classify them
|
||||
into the *corporate acquisitions* category.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Creating a component for Dataflow job that ingests data to BigQuery.
|
||||
- Creating a component for preprocessing steps to run on the data in BigQuery.
|
||||
- Creating a component for training a logistic regression model using BigQuery ML.
|
||||
- Building and configuring a Kubeflow DSL pipeline with all the created components.
|
||||
- Compiling and running the pipeline in Vertex AI Pipelines.
|
||||
|
||||
[Pipelines introduction for KFP](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/pipelines/pipelines_intro_kfp.ipynb)
|
||||
|
||||
Learn how to use the KFP SDK to build pipelines that generate evaluation metrics.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Define and compile a `Vertex AI` pipeline.
|
||||
- Specify which service account to use for a pipeline run.
|
||||
|
||||
[AutoML tabular regression pipelines using google-cloud-pipeline-components](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/pipelines/google_cloud_pipeline_components_automl_tabular.ipynb)
|
||||
|
||||
Learn to use `Vertex AI Pipelines` and `Google Cloud Pipeline Components` to build an `AutoML` tabular regression model.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Create a KFP pipeline:
|
||||
- Create a `Dataset` resource.
|
||||
- Train an AutoML tabular regression `Model` resource.
|
||||
- Create an `Endpoint` resource.
|
||||
- Deploys the `Model` resource to the `Endpoint` resource.
|
||||
- Compile the KFP pipeline.
|
||||
- Execute the KFP pipeline using `Vertex AI Pipelines`
|
||||
|
||||
|
||||
|
||||
[Model upload, predict, and evaluate using google-cloud-pipeline-components](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/pipelines/google_cloud_pipeline_components_model_upload_predict_evaluate.ipynb)
|
||||
|
||||
Learn how to evaluate a custom model using a pipeline with components from `google_cloud_pipeline_components` and a custom pipeline component you build.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Upload a pre-trained model as a `Model` resource.
|
||||
- Run a `BatchPredictionJob` on the `Model` resource with ground truth data.
|
||||
- Generate evaluation `Metrics` artifact about the `Model` resource.
|
||||
- Compare the evaluation metrics to a threshold.
|
||||
|
||||
|
||||
[Pipeline control structures using the KFP SDK](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/pipelines/control_flow_kfp.ipynb)
|
||||
|
||||
Learn how to use the KFP SDK to build pipelines that use loops and conditionals, including nested examples.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Create a KFP pipeline:
|
||||
- Use control flow components
|
||||
- Compile the KFP pipeline.
|
||||
- Execute the KFP pipeline using `Vertex AI Pipelines`
|
||||
|
||||
[Loan eligibility prediction using `google-cloud-pipeline-components` and Spark ML](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/pipelines/google_cloud_pipeline_components_dataproc_tabular.ipynb)
|
||||
|
||||
Learn how to build a Vertex AI pipeline and train a Random-forest model using Spark ML for loan-eligibility classification problem.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
* Use the `DataprocPySparkBatchOp` to preprocess data.
|
||||
* Create a Vertex AI dataset resource on the training data.
|
||||
* Train a random forest model using Pyspark.
|
||||
* Build a Vertex AI pipeline and run the training job.
|
||||
* Use the Spark serving image in order to deploy a Spark model on Vertex AI Endpoint.
|
||||
|
||||
[AutoML text classification pipelines using google-cloud-pipeline-components](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/pipelines/google_cloud_pipeline_components_automl_text.ipynb)
|
||||
|
||||
Learn to use `Vertex AI Pipelines` and `Google Cloud Pipeline Components` to build an `AutoML` text classification model.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Create a KFP pipeline:
|
||||
- Create a `Dataset` resource.
|
||||
- Train an AutoML text classification `Model` resource.
|
||||
- Create an `Endpoint` resource.
|
||||
- Deploys the `Model` resource to the `Endpoint` resource.
|
||||
- Compile the KFP pipeline.
|
||||
- Execute the KFP pipeline using `Vertex AI Pipelines`
|
||||
|
||||
- [google-cloud-pipeline-components_automl_images.ipynb](./google-cloud-pipeline-components_automl_images.ipynb)
|
||||
- [google-cloud-pipeline-components_automl_tabular.ipynb](./google-cloud-pipeline-components_automl_tabular.ipynb) (tabular regression model)
|
||||
- [automl_tabular_classification_beans.ipynb](./automl_tabular_classification_beans.ipynb) (tabular classification model)
|
||||
- [google-cloud-pipeline-components_automl_text.ipynb](.google-cloud-pipeline-components_automl_text.ipynb)
|
||||
- (Experimental) [google_cloud_pipeline_components_model_train_upload_deploy.ipynb](./google_cloud_pipeline_components_model_train_upload_deploy.ipynb): includes an experimental component to run a custom training job directly by defining its worker specs
|
||||
- (Experimental) [google_cloud_pipeline_components_model_upload_predict_evaluate.ipynb](./google_cloud_pipeline_components_model_upload_predict_evaluate.ipynb): includes an experimental evaluation component to generate evaluation metrics for a model given ground truth and predictions
|
||||
|
||||
**Note**: Currently, pipelines built using `kfp.v2`, such as these examples, will work only with Vertex Pipelines.
|
||||
A 'compatibility mode', which will allow these pipelines to be run on OSS KFP as well, is coming soon.
|
||||
|
||||
+96
-25
@@ -72,7 +72,7 @@
|
||||
"source": [
|
||||
"### Objective\n",
|
||||
"\n",
|
||||
"In this notebook, you build a Vertex AI pipeline and train a Random-forest model using Spark ML for loan-eligibility classification problem. \n",
|
||||
"In this notebook, you learn how to build a Vertex AI pipeline and train a Random-forest model using Spark ML for loan-eligibility classification problem. \n",
|
||||
"\n",
|
||||
"This tutorial uses the following Google Cloud ML services and resources:\n",
|
||||
"\n",
|
||||
@@ -204,9 +204,9 @@
|
||||
"if IS_WORKBENCH_NOTEBOOK:\n",
|
||||
" USER_FLAG = \"--user\"\n",
|
||||
" \n",
|
||||
"!pip3 install {USER_FLAG} --upgrade google-cloud-aiplatform==1.11.0 \\\n",
|
||||
" kfp==1.8.11 \\\n",
|
||||
" google-cloud-pipeline-components==1.0.18 --quiet --no-warn-conflicts"
|
||||
"! pip3 install {USER_FLAG} --upgrade google-cloud-aiplatform==1.18.1 \\\n",
|
||||
" kfp==1.8.14 \\\n",
|
||||
" google-cloud-pipeline-components==1.0.24 --quiet --no-warn-conflicts"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -317,7 +317,7 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"! gcloud config set project $PROJECT_ID"
|
||||
"! gcloud config set project $PROJECT_ID --quiet"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -479,6 +479,39 @@
|
||||
" %env GOOGLE_APPLICATION_CREDENTIALS ''"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "b109ba134099"
|
||||
},
|
||||
"source": [
|
||||
"### Enable Google Cloud services\n",
|
||||
"\n",
|
||||
"Enable the following services in your project:\n",
|
||||
"\n",
|
||||
"* Artifact Registry\n",
|
||||
"* Cloud Build\n",
|
||||
"* Container Registry\n",
|
||||
"* Dataproc\n",
|
||||
"* Vertex AI\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "1faa3afe3686"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"! gcloud services enable \\\n",
|
||||
" artifactregistry.googleapis.com \\\n",
|
||||
" cloudbuild.googleapis.com \\\n",
|
||||
" containerregistry.googleapis.com \\\n",
|
||||
" dataproc.googleapis.com \\\n",
|
||||
" aiplatform.googleapis.com"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
@@ -709,6 +742,7 @@
|
||||
"!gcloud artifacts repositories create $REPO_NAME \\\n",
|
||||
" --repository-format=docker \\\n",
|
||||
" --location=$REGION \\\n",
|
||||
" --quiet \\\n",
|
||||
" --description=\"loan eligibility spark docker repository\""
|
||||
]
|
||||
},
|
||||
@@ -761,6 +795,7 @@
|
||||
"PIPELINE_ROOT = f\"{BUCKET_URI}/pipelines\"\n",
|
||||
"PIPELINE_PACKAGE_PATH = str(BUILD_PATH / f\"pipeline_{UUID}.json\")\n",
|
||||
"RUNTIME_CONTAINER_IMAGE = f\"gcr.io/{PROJECT_ID}/{RUNTIME_IMAGE}:{IMAGE_TAG}\"\n",
|
||||
"SUBNETWORK_URI = f\"projects/{PROJECT_ID}/regions/{REGION}/subnetworks/{SUBNETWORK}\"\n",
|
||||
"ML_APPLICATION = \"loan-eligibility\"\n",
|
||||
"TASK = \"sparkml\"\n",
|
||||
"MODEL_TYPE = \"rfor\"\n",
|
||||
@@ -1840,10 +1875,10 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"!gsutil cp $SRC/__init__.py $BUCKET_URI/src/__init__.py\n",
|
||||
"!gsutil cp $SRC/data_preprocessing.py $BUCKET_URI/src/data_preprocessing.py\n",
|
||||
"!gsutil cp $SRC/model_training.py $BUCKET_URI/src/model_training.py\n",
|
||||
"!gsutil cp $SRC/hp_tuning.py $BUCKET_URI/src/hp_tuning.py"
|
||||
"! gsutil cp $SRC/__init__.py $BUCKET_URI/src/__init__.py\n",
|
||||
"! gsutil cp $SRC/data_preprocessing.py $BUCKET_URI/src/data_preprocessing.py\n",
|
||||
"! gsutil cp $SRC/model_training.py $BUCKET_URI/src/model_training.py\n",
|
||||
"! gsutil cp $SRC/hp_tuning.py $BUCKET_URI/src/hp_tuning.py"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -2117,7 +2152,7 @@
|
||||
" return c_matrix\n",
|
||||
"\n",
|
||||
" # Main -------------------------------------------------------------------------------------------------------------------------------\n",
|
||||
" with open(metrics_path, mode=\"r\") as json_file:\n",
|
||||
" with open(metrics_path) as json_file:\n",
|
||||
" metrics_dict = json.load(json_file)\n",
|
||||
"\n",
|
||||
" area_roc = metrics_dict[\"test_area_roc\"]\n",
|
||||
@@ -2210,7 +2245,7 @@
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Set DEPLOY_MODEL to True\n",
|
||||
"DEPLOY_MODEL = False"
|
||||
"DEPLOY_MODEL = True"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -2244,7 +2279,7 @@
|
||||
"\n",
|
||||
" # Clone and build the scala-sbt cloud builder\n",
|
||||
" ! git clone https://github.com/GoogleCloudPlatform/cloud-builders-community.git\n",
|
||||
" ! cd ${CWD}/cloud-builders-community/scala-sbt && \\\n",
|
||||
" ! cd {CWD}/cloud-builders-community/scala-sbt && \\\n",
|
||||
" gcloud builds submit .\n",
|
||||
"\n",
|
||||
" # Clone and build the serving container code\n",
|
||||
@@ -2433,6 +2468,7 @@
|
||||
" model_name: str = MODEL_NAME,\n",
|
||||
" project_id: str = PROJECT_ID,\n",
|
||||
" location: str = REGION,\n",
|
||||
" subnetwork_uri: str = SUBNETWORK_URI,\n",
|
||||
" deploy_model: bool = DEPLOY_MODEL,\n",
|
||||
" artifact_uri: str = ARTIFACT_URI,\n",
|
||||
" serving_image_uri: str = SERVING_IMAGE_URI,\n",
|
||||
@@ -2457,6 +2493,7 @@
|
||||
" container_image=custom_container_image,\n",
|
||||
" main_python_file_uri=preprocessing_main_python_file_uri,\n",
|
||||
" args=build_preprocessing_args_op.output,\n",
|
||||
" subnetwork_uri=subnetwork_uri,\n",
|
||||
" ).after(build_preprocessing_args_op)\n",
|
||||
"\n",
|
||||
" # create dataset\n",
|
||||
@@ -2476,15 +2513,18 @@
|
||||
" ).after(create_dataset_op)\n",
|
||||
"\n",
|
||||
" # training model\n",
|
||||
" model_traning_op = DataprocPySparkBatchOp(\n",
|
||||
" model_training_op = DataprocPySparkBatchOp(\n",
|
||||
" project=project_id,\n",
|
||||
" location=location,\n",
|
||||
" container_image=custom_container_image,\n",
|
||||
" main_python_file_uri=training_main_python_file_uri,\n",
|
||||
" args=build_training_args_op.output,\n",
|
||||
" subnetwork_uri=subnetwork_uri,\n",
|
||||
" ).after(build_training_args_op)\n",
|
||||
"\n",
|
||||
" evaluate_model_op = evaluate_model(metrics_uri=metrics_path).after(model_traning_op)\n",
|
||||
" evaluate_model_op = evaluate_model(metrics_uri=metrics_path).after(\n",
|
||||
" model_training_op\n",
|
||||
" )\n",
|
||||
"\n",
|
||||
" # evaluate condition\n",
|
||||
" with Condition(\n",
|
||||
@@ -2508,7 +2548,8 @@
|
||||
" main_python_file_uri=hpt_main_python_file_uri,\n",
|
||||
" args=build_hpt_args_op.output,\n",
|
||||
" runtime_config_properties=HPT_RUNTIME_PROPERTIES,\n",
|
||||
" ).after(model_traning_op)\n",
|
||||
" subnetwork_uri=subnetwork_uri,\n",
|
||||
" ).after(model_training_op)\n",
|
||||
"\n",
|
||||
" # evaluate condition to upload and deploy model to Vertex AI\n",
|
||||
" with Condition(\n",
|
||||
@@ -2628,9 +2669,44 @@
|
||||
"source": [
|
||||
"### (Optional) Get online predictions from the deployed model\n",
|
||||
"\n",
|
||||
"You can request online predictions if the model was deployed to a Vertex AI endpoint. Use the `google-cloud-aiplatform` client library to request predictions, or use `curl` as per below:\n",
|
||||
"You can request online predictions if the model was deployed to a Vertex AI endpoint. Use the `google-cloud-aiplatform` client library to request predictions, or you can use `curl`.\n",
|
||||
"\n",
|
||||
"Create the prediction request payload with the instances that you want to predict:"
|
||||
"For this model, the prediction response contains the predicted label (`0 == not eligible`, `1 == eligible`) for each prediction instance that is sent to the endpoint."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "4c311f9fc363"
|
||||
},
|
||||
"source": [
|
||||
"The following cell demonstrates how to use the `google-cloud-aiplatform` client library to request predictions from one or more instances."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "f6623204ee52"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"instances = [\n",
|
||||
" [214.0, \"360\", \"Rural\", 2.13, 2.21, 0.0, 0.0, 2.31, 2.01, 0.0, 0.0, 0.0, 0.0],\n",
|
||||
" [213.0, \"360\", \"Semiurban\", 2.03, 2.11, 0.0, 0.0, 2.13, 2.02, 0.0, 0.0, 0.0, 0.0],\n",
|
||||
"]\n",
|
||||
"\n",
|
||||
"endpoint = vertex_ai.Endpoint.list(filter=f'display_name=\"{MODEL_NAME}\"')[-1]\n",
|
||||
"endpoint.predict(instances)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "1a2104c45e21"
|
||||
},
|
||||
"source": [
|
||||
"To use `curl`, first write the prediction instances to a file:"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -2656,7 +2732,7 @@
|
||||
"id": "b7cbfec4537d"
|
||||
},
|
||||
"source": [
|
||||
"Use `curl` to send the prediction request to the Vertex AI endpoint. The response contains the predicted label (`0 == not eligible`, `1 == eligible`) for each instance sent in the request payload."
|
||||
"Use `curl` to send the prediction request to the Vertex AI endpoint:"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -2667,15 +2743,10 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"ENDPOINT_ID=!(gcloud ai endpoints list \\\n",
|
||||
" --region={REGION} \\\n",
|
||||
" --filter=display_name={MODEL_NAME} \\\n",
|
||||
" --format='value(name)')\n",
|
||||
"\n",
|
||||
"!curl -X POST \\\n",
|
||||
"! curl -X POST \\\n",
|
||||
" -H \"Authorization: Bearer $(gcloud auth print-access-token)\" \\\n",
|
||||
" -H \"Content-Type: application/json\" \\\n",
|
||||
" https://{REGION}-aiplatform.googleapis.com/v1/projects/{PROJECT_ID}/locations/us-central1/endpoints/{ENDPOINT_ID[-1]}:predict \\\n",
|
||||
" https://{REGION}-aiplatform.googleapis.com/v1/projects/{PROJECT_ID}/locations/{REGION}/endpoints/{endpoint.name}:predict \\\n",
|
||||
" -d \"@instances.json\""
|
||||
]
|
||||
},
|
||||
|
||||
+14
-14
@@ -64,19 +64,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) to build a [Vertex AI Pipelines](https://cloud.google.com/vertex-ai/docs/pipelines) workflow that trains a [custom model](https://cloud.google.com/vertex-ai/docs/training/containers-overview), uploads the model as a `Model` resource, creates an `Endpoint` resource, and deploys the `Model` resource to the `Endpoint` resource."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "dataset:bikes_weather,lrg"
|
||||
},
|
||||
"source": [
|
||||
"### Dataset\n",
|
||||
"\n",
|
||||
"The dataset used for this tutorial is [Cloud Public Dataset Program](https://cloud.google.com/bigquery/public-data/) [London Bikes Rental](https://console.cloud.google.com/bigquery?p=bigquery-public-data&d=london_bicycles&page=dataset&_ga=2.122237643.-1779725180.1624895157) combined with [NOAA weather data ](https://console.cloud.google.com/bigquery?p=bigquery-public-data&d=noaa_gsod&page=dataset&_ga=2.179861860.-1779725180.1624895157)\n",
|
||||
"\n",
|
||||
"The dataset predicts the duration of the bike rental."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
@@ -85,7 +72,7 @@
|
||||
"source": [
|
||||
"### Objective\n",
|
||||
"\n",
|
||||
"In this tutorial, you learn to use `Vertex AI Pipelines` and `Google Cloud Pipeline Components` to build and deploy a custom model.\n",
|
||||
"In this tutorial, you learn how to use `Vertex AI Pipelines` and `Google Cloud Pipeline Components` to build and deploy a custom model.\n",
|
||||
"\n",
|
||||
"This tutorial uses the following Google Cloud ML services:\n",
|
||||
"\n",
|
||||
@@ -109,6 +96,19 @@
|
||||
"(From that page, see also the `CustomPythonPackageTrainingJobRunOp` and `CustomContainerTrainingJobRunOp` components, which similarly run 'custom' training, but as with the related `google.cloud.aiplatform.CustomContainerTrainingJob` and `google.cloud.aiplatform.CustomPythonPackageTrainingJob` methods from the [Vertex AI SDK](https://googleapis.dev/python/aiplatform/latest/aiplatform.html), also upload the trained model)."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "dataset:bikes_weather,lrg"
|
||||
},
|
||||
"source": [
|
||||
"### Dataset\n",
|
||||
"\n",
|
||||
"The dataset used for this tutorial is [Cloud Public Dataset Program](https://cloud.google.com/bigquery/public-data/) [London Bikes Rental](https://console.cloud.google.com/bigquery?p=bigquery-public-data&d=london_bicycles&page=dataset&_ga=2.122237643.-1779725180.1624895157) combined with [NOAA weather data ](https://console.cloud.google.com/bigquery?p=bigquery-public-data&d=noaa_gsod&page=dataset&_ga=2.179861860.-1779725180.1624895157)\n",
|
||||
"\n",
|
||||
"The dataset predicts the duration of the bike rental."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
|
||||
[PyTorch distributed training with Vertex AI Reduction Server](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/reduction_server/pytorch_distributed_training_reduction_server.ipynb)
|
||||
|
||||
Learn how to create a PyTorch distributed training job that uses PyTorch distributed training framework and tools, and run the training job on the Vertex AI Training service with Reduction Server.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
* Create a PyTorch distributed training application
|
||||
* Package the training application with pre-built containers
|
||||
* Create a custom job on Vertex AI with Reduction Server
|
||||
* Submit and monitor the job
|
||||
+13
-11
@@ -61,7 +61,7 @@
|
||||
"source": [
|
||||
"## Overview\n",
|
||||
"\n",
|
||||
"When you train a large ML model using multiple nodes, communicating gradients between nodes can contribute significant latency. Reduction Server is an all-reduce algorithm that can increase throughput and reduce latency for distributed training. This notebook demonstrates how to run a PyTorch distributed training job with Reduction Server on Vertex AI. The training job is created to fine-tune pretrained model `bert-large-cased` from the Hugging Face Transformers library on the `imdb` dataset for sentiment classification."
|
||||
"When you run a distributed training job across multiple nodes using GPUs, communicating gradients between nodes can contribute significant latency. Reduction Server is an all-reduce algorithm that can increase throughput and reduce latency for distributed training. This notebook demonstrates how to run a PyTorch distributed training job with Reduction Server on Vertex AI. The training job is created to fine-tune pretrained model `bert-large-cased` from the Hugging Face Transformers library on the `imdb` dataset for sentiment classification."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -72,7 +72,7 @@
|
||||
"source": [
|
||||
"### Objective\n",
|
||||
"\n",
|
||||
"In this notebook, you create a Python source distribution with the training code and dependencies to use with a pre-built containers on Vertex AI. You learn how to configure, submit, and monitor a Vertex AI Training job that uses PyTorch distributed training framework and tools with Reduction Server to optimize network bandwith and latency of the gradient reduction operation in distributed training.\n",
|
||||
"In this notebook, you learn how to create a PyTorch distributed training job that uses PyTorch distributed training framework and tools, and run the training job on the Vertex AI Training service with Reduction Server.\n",
|
||||
"\n",
|
||||
"This tutorial uses the following Google Cloud ML services and resources:\n",
|
||||
"\n",
|
||||
@@ -82,8 +82,10 @@
|
||||
"\n",
|
||||
"The steps performed include:\n",
|
||||
"\n",
|
||||
"* Create a custom training job that uses Reduction Server\n",
|
||||
"* Submit and monitor the job\n"
|
||||
"* Create a PyTorch distributed training application\n",
|
||||
"* Package the training application with pre-built containers\n",
|
||||
"* Create a custom job on Vertex AI with Reduction Server\n",
|
||||
"* Submit and monitor the job \n"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -357,7 +359,7 @@
|
||||
"import string\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# Generate a uuid of a specifed length(default=8)\n",
|
||||
"# Generate a uuid of a specified 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",
|
||||
@@ -606,11 +608,11 @@
|
||||
"source": [
|
||||
"### Packaging the training application\n",
|
||||
"\n",
|
||||
"Before running the training job on Vertex AI, the training application code and any dependencies must be packaged and uploaded to Cloud Storage bucket or Container Registry or Artifact Registry that your Google Cloud project can access. This sections shows how to package and stage your application in the cloud.\n",
|
||||
"Before running the training job on Vertex AI, the training application code and any dependencies must be packaged and uploaded to Cloud Storage bucket or Container Registry or Artifact Registry that your Google Cloud project can access. This section shows how to package and stage your application in the cloud.\n",
|
||||
"\n",
|
||||
"There are two ways to package your application and dependencies and train on Vertex AI:\n",
|
||||
"\n",
|
||||
"1. [Create a Python source distribution](https://cloud.google.com/vertex-ai/docs/training/create-python-pre-built-container) with the training code and dependencies to use with a [pre-built containers](https://cloud.google.com/vertex-ai/docs/training/pre-built-containers) on Vertex AI\n",
|
||||
"1. [Create a Python source distribution](https://cloud.google.com/vertex-ai/docs/training/create-python-pre-built-container) with the training code and dependencies to use with a [pre-built container](https://cloud.google.com/vertex-ai/docs/training/pre-built-containers) on Vertex AI\n",
|
||||
"2. Use [custom containers](https://cloud.google.com/ai-platform/training/docs/custom-containers-training) to package dependencies using Docker containers\n",
|
||||
"\n",
|
||||
"**This notebook shows the Python source distribution option to run a custom training job on Vertex AI.**"
|
||||
@@ -685,7 +687,7 @@
|
||||
"id": "4NqTnsxaAdRp"
|
||||
},
|
||||
"source": [
|
||||
"#### Create file struture of the training application"
|
||||
"#### Create file structure of the training application"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -879,7 +881,7 @@
|
||||
" # For multiprocessing distributed training, rank needs to be the\n",
|
||||
" # global rank among all the processes\n",
|
||||
" rank = rank * ngpus_per_node + local_rank\n",
|
||||
" print (f\"Distributed and Multiprocesing. Setting rank for each worker. rank={rank}\")\n",
|
||||
" print (f\"Distributed and Multi-processing. Setting rank for each worker. rank={rank}\")\n",
|
||||
"\n",
|
||||
" dist.init_process_group(\n",
|
||||
" backend=\"nccl\", \n",
|
||||
@@ -969,7 +971,7 @@
|
||||
"id": "gv0PB6WhjKsA"
|
||||
},
|
||||
"source": [
|
||||
"### Run custome training job with Reduction Server on Vertex AI\n",
|
||||
"### Run custom training job with Reduction Server on Vertex AI\n",
|
||||
"\n",
|
||||
"Configure a custom job with the pre-built container image for PyTorch and training code packaged as Python source distribution."
|
||||
]
|
||||
@@ -1078,7 +1080,7 @@
|
||||
"source": [
|
||||
"#### Submit the training job\n",
|
||||
"\n",
|
||||
"After the taining experiment and worker pool configuration parameters have been defined, use the Vertex AI SDK for Python to submit and monitor a training job.\n",
|
||||
"After the training cluster configuration parameters have been defined, use the Vertex AI SDK for Python to submit and monitor a training job.\n",
|
||||
"\n",
|
||||
"*NOTE: When using Vertex AI SDK for Python for submitting a training job, it creates a Training Pipeline which launches the custom job on Vertex AI Training service.*"
|
||||
]
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
|
||||
[AutoML Video Classification Example](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/sdk/SDK_AutoML_Video_Classification.ipynb)
|
||||
|
||||
The objective of this notebook is to build a AutoML Video Classification Model.
|
||||
|
||||
The steps performed include the following:
|
||||
|
||||
- Set your task name, and GCS prefix
|
||||
- Copy AutoML video demo train data for creating managed dataset
|
||||
- Create a dataset on Vertex AI.
|
||||
- Configure a training job
|
||||
- Launch a training job and create a model on Vertex AI
|
||||
- Copy AutoML Video Demo Prediction Data for creating batch prediction job
|
||||
- Perform batch prediction job on the model
|
||||
|
||||
|
||||
[Custom training using Python package, managed text dataset, and TF Serving container](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/sdk/SDK_Custom_Training_Python_Package_Managed_Text_Dataset_Tensorflow_Serving_Container.ipynb)
|
||||
|
||||
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.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Create utility functions to download data and prepare csv files for creating Vertex AI Managed Dataset
|
||||
- Download Data
|
||||
- Prepare CSV Files for Creating Managed Dataset
|
||||
- Create Custom Training Python Package
|
||||
- Create TensorFlow Serving Container
|
||||
- Run Custom Python Package Training with Managed Text Dataset
|
||||
- Deploy a Model and Create an Endpoint on Vertex AI
|
||||
- Predict on the Endpoint
|
||||
- Create a Batch Prediction Job on the Model
|
||||
+1
-1
@@ -73,7 +73,7 @@
|
||||
"source": [
|
||||
"### Objective\n",
|
||||
"\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",
|
||||
"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",
|
||||
"This tutorial uses the following Google Cloud ML services and resources:\n",
|
||||
"\n",
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
|
||||
[BQML and AutoML - Experimenting with Vertex AI](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/master/notebooks/official/structured_data/rapid_prototyping_bqml_automl.ipynb)
|
||||
|
||||
Learn how to use `Vertex AI Predictions` for rapid prototyping a model.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Creating a BigQuery and Vertex AI training dataset.
|
||||
- Training a BigQuery ML and AutoML model.
|
||||
- Extracting evaluation metrics from the BigQueryML and AutoML models.
|
||||
- Selecting the best trained model.
|
||||
- Deploying the best trained model.
|
||||
- Testing the deployed model infrastructure.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
|
||||
[Vertex AI Explainations with TabNet models](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/tabnet/ai-explanations-tabnet-algorithm.ipynb)
|
||||
|
||||
Learn how to provide a sample plotting tool to visualize the output of TabNet, which is helpful in explaining the algorithm.
|
||||
|
||||
The steps performed are:
|
||||
* Setup the the project.
|
||||
* Download the prediction data of pretrain model onf Syn2 data.
|
||||
* Visualize and understand the feature importance based on the masks output.
|
||||
* Clean up the resource created by this tutorial.
|
||||
|
||||
[Vertex AI TabNet](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/tabnet/tabnet_vertex_tutorial.ipynb)
|
||||
|
||||
Learn how to run TabNet model on Vertex AI.
|
||||
|
||||
The steps performed are:
|
||||
1. **Setup**: Importing the required libraries and setting your global variables.
|
||||
2. **Configure parameters**: Setting the appropriate parameter values for the training job.
|
||||
3. **Train on Vertex AI Training**: Submitting a training job using csv input.
|
||||
4. **Hyperparameter tuning**: Running a hyperparameter tuning job.
|
||||
5. **Hyperparameter on Vertex AI Training with BigQuery input**: Submitting a training job using BigQuery input.
|
||||
6. **Cleaning up**: Deleting resources created by this tutorial.
|
||||
@@ -74,9 +74,9 @@
|
||||
"source": [
|
||||
"### Objective\n",
|
||||
"\n",
|
||||
"You learn how to provide a sample plotting tool to visualize the output of TabNet, which is helpful in explaining the algorithm. \n",
|
||||
"In this tutorial, you learn how to provide a sample plotting tool to visualize the output of TabNet, which is helpful in explaining the algorithm. \n",
|
||||
"\n",
|
||||
"The steps covered include:\n",
|
||||
"The steps performed are:\n",
|
||||
"* Setup the the project.\n",
|
||||
"* Download the prediction data of pretrain model onf Syn2 data.\n",
|
||||
"* Visualize and understand the feature importance based on the masks output.\n",
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
|
||||
[TabNet Pipeline](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/tabular_workflows/tabnet_on_vertex_pipelines.ipynb)
|
||||
|
||||
Learn how to create two classification models using Vertex AI TabNet Tabular Workflows.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Create a TabNet CustomJob. This is the best option if you know which hyperparameters to use for training.
|
||||
- Create a TabNet HyperparameterTuningJob. This allows you to get the best set of hyperparameters for your dataset.
|
||||
|
||||
|
||||
|
||||
[Wide & Deep Pipeline](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/tabular_workflows/wide_and_deep_on_vertex_pipelines.ipynb)
|
||||
|
||||
Learn how to create two classification models using Vertex AI Wide & Deep Tabular Workflows.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Create a Wide & Deep CustomJob. This is the best option if you know which hyperparameters to use for training.
|
||||
- Create a Wide & Deep HyperparameterTuningJob. This allows you to get the best set of hyperparameters for your dataset.
|
||||
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
|
||||
[Vertex AI TensorBoard custom training with prebuilt container](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/tensorboard/tensorboard_custom_training_with_prebuilt_container.ipynb)
|
||||
|
||||
Learn how to create a custom training job using prebuilt containers, and monitor your training process on Vertex AI TensorBoard in near real time.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
* Setup service account and Google Cloud Storage buckets.
|
||||
* Write your customized training code.
|
||||
* Package and upload your training code to Google Cloud Storage.
|
||||
* Create & launch your custom training job with Tensorboard enabled for near real time monitorning.
|
||||
|
||||
[Vertex AI TensorBoard Custom Training with Custom Container](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/tensorboard/tensorboard_custom_training_with_custom_container.ipynb)
|
||||
|
||||
Learn how to create a custom training job using custom containers, and monitor your training process on Vertex AI TensorBoard in near real time.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
* Create docker repository & config.
|
||||
* Create a custom container image with your customized training code.
|
||||
* Setup service account and Google Cloud Storage buckets.
|
||||
* Create & launch your custom training job with your custom container.
|
||||
@@ -0,0 +1,24 @@
|
||||
|
||||
[PyTorch image classification multi-node distributed data parallel training on cpu using Vertex training with custom container](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/training/multi_node_ddp_gloo_vertex_training_with_custom_container.ipynb)
|
||||
|
||||
Learn how to create a distributed PyTorch training job using Vertex AI SDK for Python and custom containers.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Setting up your GCP project : Setting up the PROJECT_ID, REGION & SERVICE_ACCOUNT
|
||||
- Creating a cloud storage bucket
|
||||
- Building Custom Container using Artifact Registry and Docker
|
||||
- Create a Vertex AI tensorboard instance to store your Vertex AI experiment
|
||||
- Run a Vertex AI SDK CustomContainerTrainingJob
|
||||
|
||||
[PyTorch Image Classification Multi-Node Distributed Data Parallel Training on GPU using Vertex AI Training with Custom Container](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/training/multi_node_ddp_nccl_vertex_training_with_custom_container.ipynb)
|
||||
|
||||
Learn how to create a distributed PyTorch training job using Vertex AI SDK for Python and custom containers.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Setting up your GCP project : Setting up the PROJECT_ID, REGION & SERVICE_ACCOUNT
|
||||
- Creating a cloud storage bucket
|
||||
- Building Custom Container using Artifact Registry and Docker
|
||||
- Create a Vertex AI Tensorboard Instance to store your Vertex AI experiment
|
||||
- Run a Vertex AI SDK CustomContainerTrainingJob
|
||||
File diff suppressed because it is too large
Load Diff
+1
-1
@@ -53,7 +53,7 @@
|
||||
" </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/main/notebooks/official/training/multi_node_ddp_nccl_vertex_training_with_custom_container.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/training/multi_node_ddp_nccl_vertex_training_with_custom_container.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",
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 200 KiB |
@@ -0,0 +1,933 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "7fPc-KWUi2Xd"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# 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",
|
||||
"# You may obtain a copy of the License at\n",
|
||||
"#\n",
|
||||
"# https://www.apache.org/licenses/LICENSE-2.0\n",
|
||||
"#\n",
|
||||
"# Unless required by applicable law or agreed to in writing, software\n",
|
||||
"# distributed under the License is distributed on an \"AS IS\" BASIS,\n",
|
||||
"# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n",
|
||||
"# See the License for the specific language governing permissions and\n",
|
||||
"# limitations under the License."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "eoXf8TfQoVth"
|
||||
},
|
||||
"source": [
|
||||
"<table align=\"left\">\n",
|
||||
"\n",
|
||||
" <td>\n",
|
||||
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/training/xgboost_data_parallel_training_on_cpu_using_dask.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/training/xgboost_data_parallel_training_on_cpu_using_dask.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/notebooks/deploy-notebook?download_url=https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/training/xgboost_data_parallel_training_on_cpu_using_dask.ipynb\">\n",
|
||||
" <img src=\"https://lh3.googleusercontent.com/UiNooY4LUgW_oTvpsNhPpQzsstV5W8F7rYgxgGBD85cWJoLmrOzhVs_ksK_vgx40SHs7jCqkTkCk=e14-rj-sc0xffffff-h130-w32\" alt=\"Vertex AI logo\">\n",
|
||||
" Open in Vertex AI Workbench\n",
|
||||
" </a>\n",
|
||||
" </td>\n",
|
||||
"</table>"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "AksIKBzZ-nre"
|
||||
},
|
||||
"source": [
|
||||
"# Create a distributed custom training job\n",
|
||||
"## Overview\n",
|
||||
"\n",
|
||||
"This tutorial shows you how to create a distributed custom training job on Vertex AI that can handle large amounts of training data. \n",
|
||||
"\n",
|
||||
"### Objective\n",
|
||||
"\n",
|
||||
"In this tutorial, you learn how to create a distributed training job using Vertex AI SDK for Python. You build a custom docker container with simple Dask configuration to run a custom training job.\n",
|
||||
"\n",
|
||||
"This tutorial uses the following Google Cloud ML services:\n",
|
||||
"\n",
|
||||
"- `Vertex AI SDK`\n",
|
||||
"- `CustomContainerTrainingJob`\n",
|
||||
"- `Artifact Registry`\n",
|
||||
"\n",
|
||||
"The steps performed include:\n",
|
||||
"\n",
|
||||
"- Configure the `PROJECT_ID` and `REGION` variables for your Google Cloud project.\n",
|
||||
"- Create a Cloud Storage bucket to store your model artifacts.\n",
|
||||
"- Build a custom Docker container that hosts your training code and push the container image to Artifact Registry.\n",
|
||||
"- Run a Vertex AI SDK CustomContainerTrainingJob\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"### Data \n",
|
||||
"\n",
|
||||
"This tutorial uses the <a href=\"https://scikit-learn.org/stable/auto_examples/datasets/plot_iris_dataset.html\">IRIS dataset</a>, which consists of different types of irises. \n",
|
||||
"\n",
|
||||
"### Costs\n",
|
||||
" \n",
|
||||
"This tutorial uses billable components of Google Cloud:\n",
|
||||
"\n",
|
||||
"* Vertex AI\n",
|
||||
"\n",
|
||||
"* Cloud Storage\n",
|
||||
"\n",
|
||||
"* Artifact Registry\n",
|
||||
"\n",
|
||||
"Learn about [Vertex AI pricing](https://cloud.google.com/vertex-ai/pricing), [Cloud Storage pricing](https://cloud.google.com/storage/pricing) and [Artifact Registry](https://cloud.google.com/artifact-registry/pricing), and use the [Pricing Calculator](https://cloud.google.com/products/calculator/),\n",
|
||||
" to generate a cost estimate based on your projected usage.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "iMHz63rPbq6P"
|
||||
},
|
||||
"source": [
|
||||
"## Installation\n",
|
||||
"\n",
|
||||
"Install the packages required for executing this notebook."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "b6f3dc43494b"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"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_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",
|
||||
"! pip3 install --upgrade google-cloud-aiplatform {USER_FLAG} -q"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "64d24b4fab2c"
|
||||
},
|
||||
"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."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "O8AIwN0abq6U"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import os\n",
|
||||
"\n",
|
||||
"if not os.getenv(\"IS_TESTING\"):\n",
|
||||
" # Restart the kernel after pip installs\n",
|
||||
" import IPython\n",
|
||||
"\n",
|
||||
" app = IPython.Application.instance()\n",
|
||||
" app.kernel.do_shutdown(True)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "before_you_begin:nogpu"
|
||||
},
|
||||
"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",
|
||||
"\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",
|
||||
"\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",
|
||||
"\n",
|
||||
"4. [The Google Cloud SDK](https://cloud.google.com/sdk) is already installed in Google Cloud Notebook.\n",
|
||||
"\n",
|
||||
"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",
|
||||
"**Note**: Jupyter runs lines prefixed with `!` as shell commands, and it interpolates Python variables prefixed with `$`."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "set_project_id"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"PROJECT_ID = \"[your-project-id]\" # @param {type:\"string\"}"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "autoset_project_id"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"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)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "set_gcloud_project_id"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"! gcloud config set project $PROJECT_ID"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "region"
|
||||
},
|
||||
"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. We recommend 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": "04933ed28eef"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"REGION = \"[your-region]\" # @param {type: \"string\"}\n",
|
||||
"\n",
|
||||
"if REGION == \"[your-region]\":\n",
|
||||
" REGION = \"us-central1\""
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "mtMai39NpNtI"
|
||||
},
|
||||
"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": "OX0_fa3TpOog"
|
||||
},
|
||||
"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": "h0SMyUsC-mzi"
|
||||
},
|
||||
"source": [
|
||||
"### Authenticate your Google Cloud account\n",
|
||||
"\n",
|
||||
"**If you are using Vertex AI Workbench Notebook**, your environment is already authenticated. Skip this step.\n",
|
||||
"\n",
|
||||
"**If you are using Colab**, run the cell below and follow the instructions\n",
|
||||
"when prompted to authenticate your account via oAuth.\n",
|
||||
"\n",
|
||||
"**Otherwise**, follow these steps:\n",
|
||||
"\n",
|
||||
"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,
|
||||
"metadata": {
|
||||
"id": "iTQY9g4mRo6r"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# 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",
|
||||
"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",
|
||||
" google_auth.authenticate_user()\n",
|
||||
"\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.\n",
|
||||
" elif not os.getenv(\"IS_TESTING\"):\n",
|
||||
" %env GOOGLE_APPLICATION_CREDENTIALS ''"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "h0McDhrTpt-h"
|
||||
},
|
||||
"source": [
|
||||
"### Create a Cloud Storage bucket\n",
|
||||
"\n",
|
||||
"**The following steps are required, regardless of your notebook environment.**\n",
|
||||
"\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."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "KqdXNlFQqr-u"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"BUCKET_NAME = \"[your-bucket-name]\" # @param {type:\"string\"}\n",
|
||||
"BUCKET_URI = f\"gs://{BUCKET_NAME}\"\n",
|
||||
"\n",
|
||||
"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": "OxJaSKy7qymT"
|
||||
},
|
||||
"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": "8khtdIkVq0Ra"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"! gsutil mb -l $REGION $BUCKET_URI"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "2PKfdM-Yq1vT"
|
||||
},
|
||||
"source": [
|
||||
"Finally, validate access to your Cloud Storage bucket by examining its contents:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "StOSeEKaq4-7"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"! gsutil ls -al $BUCKET_URI"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "Dax2zrpTi2Xy"
|
||||
},
|
||||
"source": [
|
||||
"### Import libraries and define constants"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "MjeuNztBrLmr"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from google.cloud import aiplatform"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "Xx_z9JQlrNwG"
|
||||
},
|
||||
"source": [
|
||||
"# Create a custom training Python package \n",
|
||||
"\n",
|
||||
"Before you can perform local training, you must a create a training script file and a docker file.\n",
|
||||
"\n",
|
||||
"Create a `trainer` directory for all of your training code."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "-iYddwztr3g7"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"PYTHON_PACKAGE_APPLICATION_DIR = \"trainer\""
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "yjeHKqHwr4rV"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"!mkdir -p $PYTHON_PACKAGE_APPLICATION_DIR"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "ECBb7Lbqr9Hs"
|
||||
},
|
||||
"source": [
|
||||
"### Write the Training Script"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "5EStvMiC9tdS"
|
||||
},
|
||||
"source": [
|
||||
"The `train.py` file checks whether the current node is the chief node or a worker node and runs `dask-scheduler` for the chief node and `dask-worker` for worker nodes. Worker nodes connect to the chief node through the IP address and port number specified in `CLUSTER_SPEC`.\n",
|
||||
"\n",
|
||||
"After the Dask scheduler is set up and connected to worker nodes, call `xgb.dask.train` to train a model through Dask. Once model training is complete, the model is uploaded to `AIP_MODEL_DIR`."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "thNtAY2Gsx2h"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"%%writefile trainer/train.py\n",
|
||||
"from dask.distributed import Client, wait\n",
|
||||
"from xgboost.dask import DaskDMatrix\n",
|
||||
"from google.cloud import storage\n",
|
||||
"import xgboost as xgb\n",
|
||||
"import dask.dataframe as dd\n",
|
||||
"import sys\n",
|
||||
"import os\n",
|
||||
"import subprocess\n",
|
||||
"import time\n",
|
||||
"import json\n",
|
||||
"\n",
|
||||
"IRIS_DATA_FILENAME = 'gs://cloud-samples-data/ai-platform/iris/iris_data.csv'\n",
|
||||
"IRIS_TARGET_FILENAME = 'gs://cloud-samples-data/ai-platform/iris/iris_target.csv'\n",
|
||||
"MODEL_FILE = 'model.bst'\n",
|
||||
"MODEL_DIR = os.getenv(\"AIP_MODEL_DIR\")\n",
|
||||
"XGB_PARAMS = {\n",
|
||||
" 'verbosity': 2,\n",
|
||||
" 'learning_rate': 0.1,\n",
|
||||
" 'max_depth': 8,\n",
|
||||
" 'objective': 'reg:squarederror',\n",
|
||||
" 'subsample': 0.6,\n",
|
||||
" 'gamma': 1,\n",
|
||||
" 'verbose_eval': True,\n",
|
||||
" 'tree_method': 'hist',\n",
|
||||
" 'nthread': 1\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def square(x):\n",
|
||||
" return x ** 2\n",
|
||||
"\n",
|
||||
"def neg(x):\n",
|
||||
" return -x\n",
|
||||
"\n",
|
||||
"def launch(cmd):\n",
|
||||
" \"\"\" launch dask workers\n",
|
||||
" \"\"\"\n",
|
||||
" return subprocess.check_call(cmd, stdout=sys.stdout, stderr=sys.stderr, shell=True)\n",
|
||||
"\n",
|
||||
"def get_chief_ip(cluster_config_dict):\n",
|
||||
" ip_address = cluster_config_dict['cluster']['workerpool0'][0].split(\":\")[0]\n",
|
||||
" print('The ip address of workerpool 0 is : {}'.format(ip_address))\n",
|
||||
" return ip_address\n",
|
||||
"\n",
|
||||
"def get_chief_port(cluster_config_dict):\n",
|
||||
" print(\"The open port is: {}\".format(cluster_config_dict['open_ports'][0]))\n",
|
||||
" return cluster_config_dict['open_ports'][0]\n",
|
||||
"\n",
|
||||
"if __name__ == '__main__':\n",
|
||||
" cluster_config_str = os.environ.get('CLUSTER_SPEC')\n",
|
||||
" cluster_config_dict = json.loads(cluster_config_str)\n",
|
||||
" print(json.dumps(cluster_config_dict, indent=2))\n",
|
||||
" print('The workerpool type is:', flush=True)\n",
|
||||
" print(cluster_config_dict['task']['type'], flush=True)\n",
|
||||
" workerpool_type = cluster_config_dict['task']['type']\n",
|
||||
" chief_ip = get_chief_ip(cluster_config_dict)\n",
|
||||
" chief_port = get_chief_port(cluster_config_dict)\n",
|
||||
" chief_address = \"{}:{}\".format(chief_ip, chief_port)\n",
|
||||
"\n",
|
||||
" if workerpool_type == \"workerpool0\":\n",
|
||||
" print('Running the dask scheduler.', flush=True)\n",
|
||||
" proc_scheduler = launch('dask-scheduler --dashboard --dashboard-address 8888 --port {} &'.format(chief_port))\n",
|
||||
" print('Done the dask scheduler.', flush=True)\n",
|
||||
"\n",
|
||||
" client = Client(chief_address)\n",
|
||||
" print('Waiting the scheduler to be connected.', flush=True)\n",
|
||||
" client.wait_for_workers(1)\n",
|
||||
"\n",
|
||||
" X = dd.read_csv(IRIS_DATA_FILENAME, header=None)\n",
|
||||
" y = dd.read_csv(IRIS_TARGET_FILENAME, header=None)\n",
|
||||
" X.persist()\n",
|
||||
" y.persist()\n",
|
||||
" wait(X)\n",
|
||||
" wait(y)\n",
|
||||
" dtrain = DaskDMatrix(client, X, y)\n",
|
||||
" \n",
|
||||
" output = xgb.dask.train(client, XGB_PARAMS, dtrain, num_boost_round=100, evals=[(dtrain, 'train')])\n",
|
||||
" print(\"Output: {}\".format(output), flush=True)\n",
|
||||
" print(\"Saving file to: {}\".format(MODEL_FILE), flush=True)\n",
|
||||
" output['booster'].save_model(MODEL_FILE)\n",
|
||||
" bucket_name = MODEL_DIR.replace(\"gs://\", \"\").split(\"/\", 1)[0]\n",
|
||||
" folder = MODEL_DIR.replace(\"gs://\", \"\").split(\"/\", 1)[1]\n",
|
||||
" bucket = storage.Client().bucket(bucket_name)\n",
|
||||
" print(\"Uploading file to: {}/{}{}\".format(bucket_name, folder, MODEL_FILE), flush=True)\n",
|
||||
" blob = bucket.blob('{}{}'.format(folder, MODEL_FILE))\n",
|
||||
" blob.upload_from_filename(MODEL_FILE)\n",
|
||||
" print(\"Saved file to: {}/{}\".format(MODEL_DIR, MODEL_FILE), flush=True)\n",
|
||||
"\n",
|
||||
" client.shutdown()\n",
|
||||
"\n",
|
||||
" else:\n",
|
||||
" print('Running the dask worker.', flush=True)\n",
|
||||
" client = Client(chief_address, timeout=1200)\n",
|
||||
" print('client: {}.'.format(client), flush=True)\n",
|
||||
" launch('dask-worker {}'.format(chief_address))\n",
|
||||
" print('Done with the dask worker.', flush=True)\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "MxsT4Vaos2W5"
|
||||
},
|
||||
"source": [
|
||||
"### Write the docker file"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "xD60d6Q0i2X0"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"%%writefile Dockerfile\n",
|
||||
"FROM us-docker.pkg.dev/vertex-ai/training/tf-cpu.2-9:latest\n",
|
||||
"WORKDIR /root\n",
|
||||
"\n",
|
||||
"RUN apt-get update\n",
|
||||
"RUN apt-get install -y telnet netcat iputils-ping net-tools\n",
|
||||
"RUN python3.8 -m pip install dask==2022.7.1 distributed==2022.7.1 bokeh==2.1.1 dask-cuda --upgrade\n",
|
||||
"RUN python3.8 -m pip install 'xgboost>=1.4.2' 'dask-ml[complete]==2022.5.27' #'dask[complete]==2022.7,1' --upgrade\n",
|
||||
"RUN python3.8 -m pip install gcsfs --upgrade\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"## Make sure gsutil will use the default service account\n",
|
||||
"RUN echo '[GoogleCompute]\\nservice_account = default' > /etc/boto.cfg\n",
|
||||
"\n",
|
||||
"# Copies the trainer code\n",
|
||||
"RUN mkdir /root/trainer\n",
|
||||
"COPY trainer/train.py /root/trainer/train.py\n",
|
||||
"\n",
|
||||
"# Sets up the entry point to invoke the trainer.\n",
|
||||
"ENTRYPOINT [\"python3.8\", \"trainer/train.py\"]\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "K6Yj8pZWAD7c"
|
||||
},
|
||||
"source": [
|
||||
"## Create a custom training job\n",
|
||||
"\n",
|
||||
"### Build a custom training container\n",
|
||||
"\n",
|
||||
"#### Enable Artifact Registry API\n",
|
||||
"You must enable the Artifact Registry API for your project. You will store your custom training container in Artifact Registry.\n",
|
||||
"\n",
|
||||
"<a href=\"https://cloud.google.com/artifact-registry/docs/enable-service\">Learn more about Enabling service</a>.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "hd1j9BHeA81h"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"! gcloud services enable artifactregistry.googleapis.com"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "SMUUSWBgA_Mb"
|
||||
},
|
||||
"source": [
|
||||
"### Create a private Docker repository\n",
|
||||
"Your first step is to create a Docker repository in Artifact Registry.\n",
|
||||
"\n",
|
||||
"1 - Run the `gcloud artifacts repositories create` command to create a new Docker repository with your region with the description `docker repository`.\n",
|
||||
"\n",
|
||||
"2 - Run the `gcloud artifacts repositories list` command to verify that your repository was created."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "0_csN1pAH95F"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"PRIVATE_REPO = \"my-docker-repo\"\n",
|
||||
"\n",
|
||||
"! gcloud artifacts repositories create {PRIVATE_REPO} --repository-format=docker --location={REGION} --description=\"Docker repository\"\n",
|
||||
"\n",
|
||||
"! gcloud artifacts repositories list"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "KPpGuKi-BOAD"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"DEPLOY_IMAGE = (\n",
|
||||
" f\"{REGION}-docker.pkg.dev/\" + PROJECT_ID + f\"/{PRIVATE_REPO}\" + \"/dask_support\"\n",
|
||||
")\n",
|
||||
"print(\"Deployment:\", DEPLOY_IMAGE)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "_RgHDDL8BWgz"
|
||||
},
|
||||
"source": [
|
||||
"## Authenticate Docker to your repository\n",
|
||||
"### Configure authentication to your private repo\n",
|
||||
"Before you can push or pull container images to or from your Artifact Registry repository, you must configure Docker to use the gcloud command-line tool to authenticate requests to Artifact Registry for your region. On Colab, you'll have to use Cloud Build as the docker command is not available,"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "GRLMyQwdKiLr"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"if not IS_COLAB:\n",
|
||||
" ! gcloud auth configure-docker {REGION}-docker.pkg.dev --quiet"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "XW4EecX1Bj8j"
|
||||
},
|
||||
"source": [
|
||||
"### Set the custom Docker container image\n",
|
||||
"Set the custom Docker container image.\n",
|
||||
"\n",
|
||||
"1. Pull the corresponding CPU or GPU Docker image from Docker Hub.\n",
|
||||
"2. Create a tag for registering the image with Artifact Registry\n",
|
||||
"3. Register the image with Artifact Registry."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "Z2XTaEDHB9HK"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"if not IS_COLAB:\n",
|
||||
" ! docker build -t $DEPLOY_IMAGE -f Dockerfile .\n",
|
||||
" ! docker push $DEPLOY_IMAGE"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "3rzI1ZXQCA30"
|
||||
},
|
||||
"source": [
|
||||
"## Build and push the custom docker container image by using Cloud Build\n",
|
||||
"\n",
|
||||
"Build and push a Docker image with Cloud Build"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "AJMhP0kYCEgY"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"if IS_COLAB:\n",
|
||||
" ! gcloud builds submit --timeout=1800s --region={REGION} --tag $DEPLOY_IMAGE"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "PtUycdZhCJvQ"
|
||||
},
|
||||
"source": [
|
||||
"### Initialize Vertex AI SDK"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "QKONAbwtCMgJ"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"aiplatform.init(\n",
|
||||
" project=PROJECT_ID,\n",
|
||||
" staging_bucket=BUCKET_URI,\n",
|
||||
" location=REGION,\n",
|
||||
")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "_GB2j39BCXiy"
|
||||
},
|
||||
"source": [
|
||||
"### Run a Vertex AI SDK CustomContainerTrainingJob"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "aoEkXaaDepfo"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"gcs_output_uri_prefix = f\"{BUCKET_URI}/output\"\n",
|
||||
"replica_count = 2\n",
|
||||
"machine_type = \"n1-standard-4\"\n",
|
||||
"display_name = \"test_display_name\"\n",
|
||||
"\n",
|
||||
"custom_container_training_job = aiplatform.CustomContainerTrainingJob(\n",
|
||||
" display_name=display_name,\n",
|
||||
" model_serving_container_image_uri=\"us-docker.pkg.dev/vertex-ai/prediction/tf2-cpu.2-8:latest\",\n",
|
||||
" container_uri=DEPLOY_IMAGE,\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"custom_container_training_job.run(\n",
|
||||
" base_output_dir=gcs_output_uri_prefix,\n",
|
||||
" replica_count=replica_count,\n",
|
||||
" machine_type=machine_type,\n",
|
||||
")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "XpLMkJAzDTgx"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"print(f\"Custom Training Job Name: {custom_container_training_job.resource_name}\")\n",
|
||||
"print(f\"GCS Output URI Prefix: {gcs_output_uri_prefix}\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "SlsCCIFgDcGy"
|
||||
},
|
||||
"source": [
|
||||
"### View training output artifact"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "JjshJ2dcDdkQ"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"! gsutil ls $gcs_output_uri_prefix/model/"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "c26XO4bZDnDH"
|
||||
},
|
||||
"source": [
|
||||
"# 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:\n",
|
||||
"\n",
|
||||
"- Cloud Storage Bucket"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "Ue3SfrMODunu"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Set this to true only if you'd like to delete your bucket\n",
|
||||
"delete_bucket = False\n",
|
||||
"\n",
|
||||
"! gsutil rm -rf $gcs_output_uri_prefix\n",
|
||||
"\n",
|
||||
"if delete_bucket or os.getenv(\"IS_TESTING\"):\n",
|
||||
" ! gsutil rm -r $BUCKET_URI"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"colab": {
|
||||
"collapsed_sections": [],
|
||||
"name": "xgboost_data_parallel_training_on_cpu_using_dask.ipynb",
|
||||
"toc_visible": true
|
||||
},
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3",
|
||||
"name": "python3"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 0
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
|
||||
[Optimizing multiple objectives with Vertex AI Vizier](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/vizier/gapic-vizier-multi-objective-optimization.ipynb)
|
||||
|
||||
Learn how to use `Vertex AI Vizier` to optimize a multi-objective study.
|
||||
|
||||
|
||||
@@ -203,7 +203,9 @@
|
||||
"\n",
|
||||
"The Spark job executed in this notebook tutorial is compute intensive. Since the job can take a significant amount time to complete in a standard notebook environment, this notebook tutorial runs on a Dataproc cluster that is created with the Dataproc Component Gateway and Jupyter component installed on the cluster.\n",
|
||||
"\n",
|
||||
"**Existing Dataproc with Jupyter cluster?**: If you have a running Dataproc cluster that has the [Component Gateway and Jupyter component installed on the cluster](https://cloud.google.com/dataproc/docs/concepts/components/jupyter#gcloud-command), you can use it in this tutorial. If you plan to use it, skip this step, and go to `Switch your kernel`."
|
||||
"**Existing Dataproc with Jupyter cluster?**: If you have a running Dataproc cluster that has the [Component Gateway and Jupyter component installed on the cluster](https://cloud.google.com/dataproc/docs/concepts/components/jupyter#gcloud-command), you can use it in this tutorial. If you plan to use it, skip this step, and go to `Switch your kernel`.\n",
|
||||
"\n",
|
||||
"Set and name and [compute region](https://cloud.google.com/compute/docs/regions-zones#available) for your new cluster. Your `CLUSTER_NAME` must be **unique within your Google Cloud project**. It must start with a lowercase letter, followed by up to 51 lowercase letters, numbers, and hyphens, and cannot end with a hyphen."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -226,15 +228,6 @@
|
||||
" print(f\"CLUSTER_REGION: {CLUSTER_REGION}\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "XoEqT2Y4DJmf"
|
||||
},
|
||||
"source": [
|
||||
"Your `CLUSTER_NAME` must be **unique within your Google Cloud project**. It must start with a lowercase letter, followed by up to 51 lowercase letters, numbers, and hyphens, and cannot end with a hyphen."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
@@ -488,6 +481,15 @@
|
||||
"from shapely.geometry import Point"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "71ecd729c4b9"
|
||||
},
|
||||
"source": [
|
||||
"**Note**: After importing libraries, if you see `ERROR 1: PROJ: proj_create_from_database: Open of /opt/conda/miniconda3/share/proj failed`, you can ignore it. This is due to a bug with a `geopandas` dependency.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
@@ -519,7 +521,7 @@
|
||||
"\n",
|
||||
"# Initialize the SparkSession.\n",
|
||||
"spark = (\n",
|
||||
" SparkSession.builder.appName(\"spark-bigquery-polyglot-language-demo\")\n",
|
||||
" SparkSession.builder.appName(\"spark-ml-taxi-citibike\")\n",
|
||||
" .config(\"spark.jars\", connector)\n",
|
||||
" .getOrCreate()\n",
|
||||
")"
|
||||
@@ -552,7 +554,7 @@
|
||||
")\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# Load NYC_Citibike in Github Acitivity Public dataset from BQ.\n",
|
||||
"# Load NYC_Citibike in Github Activity Public dataset from BQ.\n",
|
||||
"bike_df = (\n",
|
||||
" spark.read.format(\"bigquery\")\n",
|
||||
" .option(\"table\", \"bigquery-public-data.new_york_citibike.citibike_trips\")\n",
|
||||
@@ -1553,6 +1555,8 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import os\n",
|
||||
"\n",
|
||||
"if not os.getenv(\"IS_TESTING\"):\n",
|
||||
" ! gcloud dataproc clusters delete $CLUSTER_NAME --region=$CLUSTER_REGION -q"
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user