Compare commits

...
Author SHA1 Message Date
ivanmkc 3700be4da1 fix: Fixed kernel spec by forcing it to use python3 2022-08-19 17:51:06 -04:00
Andrew FerlitschandGitHub 7804c860c5 fix: replace tabs with spaces in JSON template (#888)
* fix: replace tabs with spaces in JSON template

* fix: replace tabs with spaces in JSON template
2022-08-19 11:11:08 -07:00
Andrew FerlitschandGitHub ed0c1c74a6 fix: typo in serving_container_uri parameter (#887) 2022-08-19 08:49:12 -07:00
Andrew FerlitschandGitHub 5127a59e92 Model monitoring (#883)
* fix: notebook template tuning

* fix: notebook template tuning

* fix: possible confusion on when to wait for the email notification

* fix: possible confusion on when to wait for the email notification
2022-08-19 08:38:29 -07:00
d8df732d6b Replace GAPIC with SDK - Model Monitoring Notebook (#879)
* Replace GAPIC with SDK

* Run linter

* Remove unused variables

* Run linter

Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-08-18 11:41:11 -07:00
9c10899db8 AutoML Video Classificaton (#871)
* changes according to andrew review comments

* changes according to andrew review comments

Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-08-18 07:25:14 -07:00
Ivan NardiniandGitHub 80770188ec Vertex AI Experiments - Model training - Notebook review (#853)
* experiments cuj1 review

* linter test passed

* add IAM role

* linter test passed

* add rm local dir

* linter test passed

* add api

* linter test passed

* remove libraries

* linter test passed

* solve build error

* fix issue

* clean

* linter passed

* fix dependency

* linter passed

* add dependency

* linter passed

* add dependency

* linter passed

* delete bucket flag fix

* linter passed
2022-08-17 10:43:34 -04:00
fa91e45018 Adds the updated managed_notebooks/predictive_maintenance notebook to the official folder (#521)
* adds the updated predictive-maintenance (managed)notebook from community to official folder

* ran linter test

* resubmitting during phase2

* ran linter test

* addresses the review comments: updates based on the new template, sets delete_bucket to False

* ran linter test

* replaces timestamp with uuid

* ran linter test

Co-authored-by: Karl Weinmeister <11586922+kweinmeister@users.noreply.github.com>
Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-08-16 09:39:07 -07:00
fa27309134 Fixes the issues from the regression tests (#822)
* fixes tensorflow version, replaces timestamp with uuid, adds service-account and minor textual changes

* removes second defnition of random library

* ran linter test

* uncomments the user flag and updates the installation command

* ran linter test

* removes the extra backslash

* ran linter test

* updates the installation step to fix long running compatibility checks

* ran linter test

* updates the METADATA path during installation steps

* ran linter test

* adds google-api-core version in the installation

* ran linter test

* removes METADATA step during installation

* ran linter test

* updates google api-core & auth versions

* ran linter test

* fixes tensorflow version, replaces timestamp with uuid, adds service-account and minor textual changes

* removes second defnition of random library

* ran linter test

* uncomments the user flag and updates the installation command

* ran linter test

* removes the extra backslash

* ran linter test

* updates the installation step to fix long running compatibility checks

* ran linter test

* updates the METADATA path during installation steps

* ran linter test

* adds google-api-core version in the installation

* ran linter test

* removes METADATA step during installation

* ran linter test

* updates google api-core & auth versions

* ran linter test

* fixes the issues from review: cell descriptions, parameter definitions, tense changes, 3rd person --> 2nd person, list model after pipeline run

* ran linter test

* removes the METADATA hack and updates the installations

* ran linter test

Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-08-16 09:11:30 -07:00
udaypunnaandGitHub 7b85f76384 custom_model_training_and_batch_prediction (#873)
* changed based on andrew review comments

* changed based on andrew review comments

* import library issues

* import library issues

* import issues

* import issues
2022-08-16 08:40:33 -07:00
40a0477b08 modified notebook automl-text-classification.ipynb (#757)
* modified notebook

* modified notebook

* added new notebook

* added new notebook

* new auto_ml_text_classifiation

* new auto_ml_text_classifiation

* new automl text classification

* linter test

* linter test

* changes on andrew comments

* changes on andrew comments

Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-08-15 17:53:52 -07:00
839c7dddb8 Vertex AI Experiments - Compare Models - Notebook review (#852)
* experiments cuj1 review

* linter test passed

* typo

* linter test passed

* add andy reviews

* linter test passed

Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-08-15 09:49:50 -07:00
Andrew FerlitschandGitHub 578cfb7da7 fi: Issue 850 (#863)
* fix: add missing end_run() for experiment

* fix: add missing end_run() for experiment
2022-08-15 08:57:07 -07:00
Ivan CheungandGitHub b129c0bf43 Update CODEOWNERS (#864)
Use proper Github username.
2022-08-12 17:21:39 -04:00
07b4c37135 Automl links fix (#742)
* fixing links to open notebook - main and images

* linter test changes

* fixes the papermill execution error(hard-coded bucket link was the cause)

* ran linter test

* adds minor textual changes

* ran linter test

* fixes issues from review: future tense, copyright year, section placement, latest sdk methods, new updates from the template

* ran linter test

Co-authored-by: Manuel Amunategui <manuel.amunategui@springml.com>
Co-authored-by: Karl Weinmeister <11586922+kweinmeister@users.noreply.github.com>
Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-08-12 12:34:53 -07:00
f48fb1c650 Modified file churn_prediction_for_game_developers (#809)
* made changes

* made changes

* ran linter test

* made changes

* ran linter

* made changes

* ran linter

* changes suggested by andrew done

* ran linter

* replaced timestamp with uuid

* ran linter

* changed bucket creation command according to template

* ran linter

* changed text in overview

* changed region cell from markdown to code

* made changes

* replaced dataset from constant to a variable

* replaced constant dataset_id with a variable

* ran linter

* changed suggested by andrew done

* ran linter

Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-08-12 08:40:38 -07:00
3bbd59311c Made UUID Changes to SDK_BigQuery_Custom_Container_Training.ipynb (#849)
* MAde UUID changes

* Ran Linter test

* made some minor changes

* Ran Linter Test

Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-08-12 08:08:32 -07:00
Krishna Chaitanya MovvaandGitHub 15bb4cea73 Fixes the issues(missing variable) from regression tests, adds minor updates from the template. (#823)
* adds the missing delete_bucket variable, adds steps to configure SERVICE_ACCOUNT

* removes unnecessary random import

* ran linter test

* removes the src folder dependency to run on Colab, adds the pipeline.wait step, updates the cleanup steps

* ran linter test

* fixed issues from review: section posistions, tense changes, section descriptions, template updates

* ran linter test
2022-08-12 08:07:11 -07:00
Andrew FerlitschandGitHub 1511cc9fd1 fix: branding updates from autoreview (#862)
* autoreview: branding fixes

* fix: improve installation detection

* cleanup: rm tmp file

* fix: lint issues

* fix: 2nd try at lint fixes
2022-08-11 18:32:47 -07:00
2885a7a70f Migrated matching engine notebook to official and added VPC network support to CI (#836)
* Added matching engine notebook official

* Ran linter

* Added matching engine to .cloud-build/test_notebook_vm.txt

Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-08-11 18:30:22 -07:00
ea36f5c43e Vertex SDK Custom Image Classification with pre-built training container (#833)
* new notebook of custom image classification

* new notebook of custome image classification

* andrew commented changes

* andrew commented changes

* andrew commented changes

* andrew commented changes

Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-08-11 14:58:49 -07:00
a905a6305f fixed cleanup cell, cosmetic and doc improvements, and removed load test (to avoid flakiness), (#859)
* fix cleanup cell and print out more info on xai prediction test

* lint fix

* remove load test

* lint fixes

* lint fix

* fix andrews comments

* lint fix

* missing newline

* lint fixes

Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-08-11 14:04:28 -07:00
Ivan CheungandGitHub aeaeddcc75 Update PULL_REQUEST_TEMPLATE.md (#860)
Updated PR template to emphasize need for a summary and checklist. Otherwise, people tend to skip this standard practice.
2022-08-11 16:18:54 -04:00
161965cfb0 Fixes the exception in batch-explain notebook in the official folder (#810)
* fixes exception(reg-test), replaces timestamp with uuid, minor changes

* ran linter test

* resolved review comments: license year, Vertex AI SDK, dataset after objective and future tense

* ran linter test

Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-08-11 10:25:51 -07:00
b9d4457474 Modified notebook forecasting-retail-demand (#827)
* deleted file in community and added file in official folder

* renamed file

* ran linter test

* renamed file

* ran linter

* made changes

* ran linter test

* made changes

* ran linter test

* made changes

* ran linter test

* made changes

* ran linter

* made change

* ran linter test

* changes suggested by andrew done

* ran linter

Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-08-11 09:31:27 -07:00
a5b6bcfab1 those two files are moved to official folder.Deleting them in community content (#855)
Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-08-11 09:14:02 -07:00
5d55f5b0d2 Modified notebook pricing-optimization.ipynb (#834)
* modified notebook according to notebook_template.

* ran linter

* Added create dataset step

* ran linter

* replaced hardcoded dataset name with a variable

* ran linter

* changes suggested by nadrew done

* ran linter

Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-08-11 09:00:13 -07:00
36ace6f4a6 deleted inventory_prediction_folder,folder moved to official (#856)
Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-08-11 08:24:39 -07:00
32d9b416c1 UUID changes done comparing_pipeline_runs.ipynb (#759)
* done UUID changes

* ran lintertest

* made changes in cleanup section

* ran lintertest

* done UUID changes

* ran lintertest

* made changes in cleanup section

* ran lintertest

* made changes in cleanup section

* Ran linter test

* made UUID changes

* RAN linter test

* Made Some minor Chanages notebook

* Ran Linter Test

* small changes made

* Ran Linter Test

Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-08-11 08:07:17 -07:00
1c6309f401 Modified notebook SDK_AutoML_Video_Classification.ipynb (#839)
* modified notebook according to template, tensorflow library is used only for file opening so instead of tf we used bucket.blob.download_as_string()

* ran linter

* all changes requested by andrew are done

* cleared all outputs

* making changes to run linter test

* making changes to run linter test

* ran linter

* removed region text in create bucket step

* ran linter

Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-08-10 19:05:41 -07:00
728dec8526 Updates the custom-tabular-bq-managed-dataset notebook according to the new template (#780)
* updates the configuring steps, replaces timestamp with uuid, expands the imports

* ran linter test

* separates the vertex-ai and bigquery initialization steps

* adds comment to cell_24

* adds blank line to cell_24:7:1

* adds blank line to cell_24:7:1

* ran linter test

* fixes aiplatform+bigquery installation compatibility issue

* ran linter test

* fixes installation dependencies

* ran linter test

* fixes the issues from the review: future tense, section positions, updates from the latest template

* ran linter test

* fixes the issues from the review: Code formatting, delete redundant cells, resource name changes

* ran linter test

Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-08-10 08:41:50 -07:00
sudarshan-SpringMLandGitHub 7692f902dd Added minor changes to training-multi-class-classification-model-for-ads-targeting-usecase notebook (#735)
* added new file

* ran linter test

* made small changes

* ran linter

* added file

* ran linter

* changes requested by andrew done

* ran linter
2022-08-10 08:03:42 -07:00
9281403198 fix cleanup cell to undeploy models before deleting endpoint and remove BQ table and dataset (#846)
* fix artifact cleanup

* lint fixes

* remove extraneous echo

Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-08-09 20:09:25 -07:00
2be602fbef Update comparing_local_trained_models.ipynb (#704)
Install from Pypi

Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-08-09 15:39:54 -07:00
b140077eb1 Change REGION_NAME to REGION to match flag set earlier in notebook (#734)
Co-authored-by: Ivan Cheung <ivans.mailbox@gmail.com>
Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-08-09 14:54:22 -07:00
d3139f7df8 Added colab , installed some packages, added some code based on standard template and made changes in cleanup section for the file inventory_prediction.ipynb (#533)
* Added notebook

* Ran linter test

* added pyarrow to install

Co-authored-by: Andrew Ferlitsch <aferlitsch@gmail.com>
Co-authored-by: sudarshan-SpringML <82567512+sudarshan-SpringML@users.noreply.github.com>
Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-08-09 14:49:40 -07:00
72baced988 model monitoring notebook fixes (#841)
* fix model monitoring notebook

* lint fixes

* fixed Soheila's review comments

* fix Andrew's comments

* lint fixes

* clean up install packages per review request

* lint fixes

* fix more comments from Andrew

* lint fixes

Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-08-09 14:16:54 -07:00
Soheila ZangenehandGitHub 5232654705 Update folder name to training (#845) 2022-08-09 12:29:34 -07:00
Andrew FerlitschandGitHub 125fe32eb2 feat: notebook for DASK training (#837)
* feat: tune template

* feat: tune template

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* feat: auto review

* feat: auto review

* feat: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* feat: auto review script

* tune: project ID and Region

* tune: project ID and Region

* fix: set MODEL_DIR for HPT

* fix: set MODEL_DIR for HPT

* feat: add batch example

* feat: add batch example

* feat: add batch example

* feat: add batch example

* feat: add notebook for DASK training

* feat: add notebook for DASK training
2022-08-08 16:17:28 -07:00
Andrew FerlitschandGitHub 614f4154dc fix: owner names 2022-08-08 15:50:33 -07:00
Andrew FerlitschandGitHub 970415398b fix: owner username 2022-08-08 15:46:57 -07:00
Hyunuk LimandGitHub a052a3d361 A new notebook for Spark Sample (#720)
* Created spark notebook with test code

* Implemented experimental code for poly_view

* implemented the table

* WIP-notebook

* moved experimental to tutorial

* delete experimental code and rename the notebook

* clear all outputs

* fix: delete outputs again

* fix: changed template to the newer one

* fix: modify link on workbench

* add creating a cluster

* Completed Before you begin part

* Change execution sequence

* completed write back process

* change order that switching kernel goes top

* modify pie chart to bar chart

* Completed write up part

* WIP: adding description and comments.

* WIP: delete outputs

* fix: nbqa done

* Completed the first draft

* Delete %%time from cells

* Apply changes as per the code review from Brad except SparkSql

* delete outputs

* Change SparkSQL to Spark API

* change label to xlabel

* fix: description in Dataset

* fix: change BUCKET_NAME to DATASET_NAME, link for the region, and add descriptions and examples for frequency table

* fix: move normalize_name to top of the cell

* fix: refactor udf functions and descriptions

* fix: add link for udf

* fix: description in Dataset

* fix: grammer

* fix: add declared in the sentence

* fix: small changes on grammar

* fix: delete string

* fix: change UserDefinedFunction to udf

* fix: as per TW's code review

* fix: reorder REGION and TIMESTAMP under Creating a GCS bucket

* fix: lint

* chore: add bmiro@ as a codeowner of this doc

* fix: change the variable to fix a bug

* fix: as per TW's second review

* fix: add installation part to pass the ci test

* fix: url for links to main

* fix: delete disabling API since it doesn't affect to the pricing

* fix: add conditions for CI test

* fix: changed jar for testing

* fix: add gcs connector

* fix: change writing method to direct

* fix: delete gcs connector

* fix: specify java folder

* fix: change java_home location

* fix: change unzip instruction

* fix: delete mono_ranking_avg_bytes from testing env

* fix: delete frequency_table from testing env

* fix: delete GCS bucket part

* fix: as per Brad's review

* fix: lint

* fix: add version

* fix: change comment

* fix: add package due to switching the kernel

* fix: delete dataproc cluster command

* fix: change link

* fix: change link

* fix: revert cluster deletion command

* fix: change parenthesis to encoded character

* fix: change the name of the notebook

* fix: change timestamp to UUID

* fix: change the link and add description

* fix: change metadata
2022-08-08 16:23:16 -04:00
Krishna Chaitanya MovvaandGitHub f8203b9f46 UUID replaces Timestamp in the notebook template (#745)
* replaces timestamp with uuid #create *task #tag1 replace the TIMESTAMP with uuid in other official notebooks

* ran linter test

* updates the uuid code

* fixes the comment style highlighted through linter-test

* ran linter test

* adds length argument to uuid function defaulted to 8

* ran linter test
2022-08-08 11:20:33 -04:00
Andrew FerlitschandGitHub fac8c4c9b1 fix: improve batch description (#830)
* feat: tune template

* feat: tune template

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* feat: auto review

* feat: auto review

* feat: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* feat: auto review script

* tune: project ID and Region

* tune: project ID and Region

* fix: set MODEL_DIR for HPT

* fix: set MODEL_DIR for HPT

* feat: add batch example

* feat: add batch example

* feat: add batch example

* feat: add batch example
2022-08-05 13:50:14 -07:00
Andrew FerlitschandGitHub d6c13c201e Ml ops v9v4 (#817)
* feat: tune template

* feat: tune template

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* feat: auto review

* feat: auto review

* feat: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* feat: auto review script

* tune: project ID and Region

* tune: project ID and Region

* fix: set MODEL_DIR for HPT

* fix: set MODEL_DIR for HPT

* feat: add batch example

* feat: add batch example
2022-08-05 09:40:11 -07:00
Soheila ZangenehandGitHub 8db9ce0415 Move download link up (#813) 2022-08-04 15:05:18 -04:00
Ivan CheungandGitHub 8c7fb38136 Added missing dependency (#814) 2022-08-04 14:53:17 -04:00
Andrew FerlitschandGitHub acec861ad5 tune: notebook template (#812)
* feat: tune template

* feat: tune template

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* feat: auto review

* feat: auto review

* feat: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* feat: auto review script

* tune: project ID and Region

* tune: project ID and Region
2022-08-04 10:51:08 -07:00
Andrew FerlitschandGitHub b5cc2b425e feat: auto review script tuning (#811)
* feat: tune template

* feat: tune template

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* feat: auto review

* feat: auto review

* feat: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* feat: auto review script
2022-08-04 09:30:13 -07:00
Soheila ZangenehandGitHub 710e6ea0d8 Run commands in quiet mode (#789)
* Run commands in quiet mode in both yaml files
* Test CI against single and multiple notebooks
2022-08-04 11:00:49 -04:00
4dce246b57 Add single notebook test file and remove broken notebook from the list (#801)
Co-authored-by: Ivan Cheung <ivans.mailbox@gmail.com>
2022-08-04 10:39:09 -04:00
Andrew FerlitschandGitHub 696efb00ee fix: auto review (#807)
* feat: tune template

* feat: tune template

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* feat: auto review

* feat: auto review

* feat: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review
2022-08-03 21:19:10 -07:00
Andrew FerlitschandGitHub fea73bb9c0 obsolete 2022-08-03 20:28:16 -07:00
Andrew FerlitschandGitHub f50ea24dd1 fix: auto review (#806)
* feat: tune template

* feat: tune template

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* feat: auto review

* feat: auto review

* feat: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review
2022-08-03 20:27:45 -07:00
Andrew FerlitschandGitHub 473e673d0a fix: auto review (#805)
* feat: tune template

* feat: tune template

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* feat: auto review

* feat: auto review

* feat: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review
2022-08-03 17:22:25 -07:00
Andrew FerlitschandGitHub 127297ee4e tune: grammar 2022-08-03 15:38:44 -07:00
Chun-Hsiang WangandGitHub fb528b60c6 samples: Minor fix for CPR existing image use cases. (#778) 2022-08-03 15:23:35 -07:00
Andrew FerlitschandGitHub 1c1a2b2097 fix: auto review (#804)
* feat: tune template

* feat: tune template

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* feat: auto review

* feat: auto review

* feat: auto review

* fix: auto review
2022-08-03 14:56:26 -07:00
Andrew FerlitschandGitHub 8cb2a26817 fix: auto review (#803)
* feat: tune template

* feat: tune template

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* feat: auto review

* feat: auto review
2022-08-03 14:38:14 -07:00
Andrew FerlitschandGitHub 3bf098b361 feat: auto review (#802)
* feat: tune template

* feat: tune template

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review
2022-08-03 14:19:49 -07:00
433cffbf76 Tabnet (#732)
* Start a new branch for TabNet tutorial.

* format lint

* Clean version Created using Colaboratory

* Remove unused import

* Remove unused import

* Created using Colaboratory

* add import

* Add visualization for TabNet

* add gcs

* run format

* reformat

* reformat

* Rmove the - file

* run linter

* run linter

* Update the objective and data section

* Update the link.

* Update data description.

* Update data description.

Co-authored-by: Long Le <longtle@google.com>
Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-08-03 13:42:06 -07:00
0ec2f4fbe8 bugfix: pass Dataflow related parameters correct for AutoML Tabular pipeline notebook (#725)
Also corrected the required Roles for the service account.

Co-authored-by: Helin Wang <helin@google.com>
Co-authored-by: Karl Weinmeister <11586922+kweinmeister@users.noreply.github.com>
Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-08-03 13:39:32 -07:00
a9af97f1b9 Added notebook demonstrating Tensorboard Custom Training with custom container. (#611)
* Added notebook demonstrating Tensorboard Custom Training with custom container.

* Added notebook demonstrating Tensorboard Custom Training with custom container.

* update codeowners file

* call Vertex API instead of gapic API

* resolve comments for custom container

* resolve comments and format

* resolve comments

* using --quiet for delete doctor repository

* address more comments

Co-authored-by: gericdong <itseric@google.com>
Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-08-03 13:37:14 -07:00
d6431fab4c Added notebook demonstrating Tensorboard Custom Training with prebuilt container. (#603)
* Added notebook demonstrating Tensorboard Custom Training with prebuilt container

* Added notebook demonstrating Tensorboard Custom Training with prebuilt container

* small fix

* address comments

* format

* update project id to be [your-project-id], and populate tensorboard resource name automatically

* Added notebook demonstrating Tensorboard Custom Training with prebuilt container

* Added notebook demonstrating Tensorboard Custom Training with prebuilt container

* small fix

* address comments

* format

* fix typo for service account

* use vertex api instead of gapic api

* address comments

* minor fix

* minor fix for link

* minor fix

* resolve more comments

* a minor fix for comment

* format the notebook

* resolve comments

* address more comments

Co-authored-by: gericdong <itseric@google.com>
Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-08-03 13:35:41 -07:00
dcfde86928 Added colab , installation packages and few other changes to chicago_taxi_fare_prediction.ipynb file (#515)
* Added notebook

* Made changes in installing packages code cell

* Ran linter test

* fixes the installation issues and updates some textual content

* fixes the # formatting for comments

* ran linter test

* adds pyarrow to the packages

* ran linter test

* replaces timestamp with uuid

* ran linter test

* updates the uuid code

* fixes the comment style highlighted through linter-test

* ran linter test

Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
Co-authored-by: Karl Weinmeister <11586922+kweinmeister@users.noreply.github.com>
Co-authored-by: krishr2d2 <krishna.movva@springml.com>
2022-08-03 13:33:08 -07:00
5d747ffa0d Refresh of PyTorch Image Classification Multi-Node Distributed Data Parallel Training on GPU using Vertex Training with Custom Container (#509)
* notebook refresh from vertex ai sdk project

* linter test

* notebook refresh from vertex ai sdk project with trainer folder

* linter test

* add pyarrow

* modified notebook

* ran linter test

Co-authored-by: Andrew Ferlitsch <aferlitsch@gmail.com>
Co-authored-by: sudarshan-SpringML <sudarshan.c@springml.com>
Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-08-03 13:32:44 -07:00
53f25201cc Made minor changes to SDK_Custom_Training_Python_Package_Managed_Text_Dataset_Tensorflow_Serving_Container notebook (#507)
* modified notebook

* small changes done

* modified notebook and moved notebook to official folder

* ran linter test

* resolved comments

* ran linter test

* sentence case heading added for some more text

* ran linter test

* made changes

* ran linter test

* made changes

* ran linter test

Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-08-03 13:32:01 -07:00
9b17db3025 Refresh of PyTorch Image Classification Multi-Node Distributed Data Parallel Training on CPU using Vertex Training with Custom Container Notebook (#489)
* multi_node_ddp_gloo_vertex_training_with_custom_container refresh and related trainer folder

* linter test

* various fixes and colab update

* linter test

* modified notebook

* modified notebook

* ran linter test

* Update multi_node_ddp_gloo_vertex_training_with_custom_container.ipynb

Co-authored-by: sudarshan-SpringML <sudarshan.c@springml.com>
Co-authored-by: Andrew Ferlitsch <aferlitsch@gmail.com>
Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-08-03 13:24:45 -07:00
423f7ac584 Adding PrivateEndpoint CUJ notebook to notebooks/community (#721)
* moving REGION up

* moving REGION up and csv file name

* fix: changed bucket URL to console

* removing TODOs from Tabnet notebook

* adding notebook and editing CODEOWNERS file

* fixing links

* adding to community because of test issue

* removing CODEOWNERS

* reverting CODEOWNERS

* linting?

* adding fixes

Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
Co-authored-by: Karl Weinmeister <11586922+kweinmeister@users.noreply.github.com>
2022-08-03 12:54:46 -07:00
aec82c7e5b inardini -- bqml new operators release update to v1 (#717)
* update to v1

* linter test passed

Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-08-03 12:51:46 -07:00
b227509fbb chore(deps): update dependency black to v22.6.0 (#696)
Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-08-03 12:43:54 -07:00
Andrew FerlitschandGitHub e715e68273 fix: auto review (#800)
* feat: tune template

* feat: tune template

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review
2022-08-03 12:39:06 -07:00
406de6fe9a Adds the updated sdk-feature-store-pandas notebook to official from community folder (#488)
* adds the updated sdk-feature-store-pandas notebook to official and removes it from the community

* ran linter test

Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
Co-authored-by: nayaknishant <nishantnayak@google.com>
Co-authored-by: Karl Weinmeister <11586922+kweinmeister@users.noreply.github.com>
2022-08-03 12:30:10 -07:00
Andrew FerlitschandGitHub eacc49d911 fix: auto review (#798)
* feat: tune template

* feat: tune template

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auto review

* fix: auto review
2022-08-03 12:26:12 -07:00
Andrew FerlitschandGitHub b95959e7a1 cleanup 2022-08-03 10:58:57 -07:00
Andrew FerlitschandGitHub cc2cf876de fix: auto review (#797)
* feat: tune template

* feat: tune template

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review
2022-08-03 10:58:27 -07:00
Andrew FerlitschandGitHub 1047237335 Ml ops v9v4 (#796)
* feat: tune template

* feat: tune template

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review
2022-08-03 10:11:23 -07:00
Andrew FerlitschandGitHub 791d589d41 Ml ops v9v4 (#795)
* feat: tune template

* feat: tune template

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review
2022-08-03 09:53:21 -07:00
Andrew FerlitschandGitHub f7bdf75d90 fix: auto-review (#794)
* feat: tune template

* feat: tune template

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review
2022-08-03 09:37:14 -07:00
Andrew FerlitschandGitHub 785ca9f864 fix: auto review (#793)
* feat: tune template

* feat: tune template

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auti review

* fix: auti review

* fix: auti review

* fix: auti review
2022-08-03 09:22:59 -07:00
Andrew FerlitschandGitHub aaa7d5c259 fix: auto review (#792)
* feat: tune template

* feat: tune template

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auti review

* fix: auti review
2022-08-03 09:01:37 -07:00
Andrew FerlitschandGitHub e21cb948d6 feat: auto review (#784)
* feat: tune template

* feat: tune template

* fix: auto review

* fix: auto review

* fix: auto review

* fix: auto review
2022-08-02 18:46:08 -07:00
Andrew FerlitschandGitHub 5551c5f895 fix: auto review (#783)
* feat: tune template

* feat: tune template

* fix: auto review

* fix: auto review
2022-08-02 18:29:21 -07:00
Andrew FerlitschandGitHub e8853475bc feat: tune template (#782)
* feat: tune template

* feat: tune template
2022-08-02 17:33:32 -07:00
Andrew FerlitschandGitHub 33cb8139da Update get_started_vertex_training_lightgbm.ipynb 2022-08-02 16:33:03 -07:00
Andrew FerlitschandGitHub 0288fa3703 fix: link 2022-08-02 16:32:25 -07:00
Andrew FerlitschandGitHub d48edc2cb4 fix: links 2022-08-02 16:27:45 -07:00
Andrew FerlitschandGitHub 7b26f01671 fix: link 2022-08-02 16:25:45 -07:00
Andrew FerlitschandGitHub 59cd2cda3c fix: link 2022-08-02 16:23:46 -07:00
Andrew FerlitschandGitHub 3ac469f57c fix: link 2022-08-02 16:12:59 -07:00
Andrew FerlitschandGitHub 008833422c fix: link 2022-08-02 14:47:08 -07:00
Andrew FerlitschandGitHub 59c85c3085 fix: link 2022-08-02 14:44:57 -07:00
Andrew FerlitschandGitHub f2b5d0924e fix: link title 2022-08-02 14:35:38 -07:00
Andrew FerlitschandGitHub 772cd44cef fix: link 2022-08-02 14:28:58 -07:00
Andrew FerlitschandGitHub 379a4c6a1c fix: link 2022-08-02 14:27:16 -07:00
Andrew FerlitschandGitHub 5cea72848e fix: link 2022-08-02 14:25:47 -07:00
Andrew FerlitschandGitHub 9c12dd811b fix: links 2022-08-02 14:22:38 -07:00
Andrew FerlitschandGitHub 844cf5b047 fix: links 2022-08-02 14:19:52 -07:00
Andrew FerlitschandGitHub 1492051560 fix: link 2022-08-02 14:06:43 -07:00
Andrew FerlitschandGitHub 40bdd5fce3 fix: link 2022-08-02 14:03:36 -07:00
Andrew FerlitschandGitHub d1cc60e8d7 fix: link 2022-08-02 13:50:36 -07:00
Andrew FerlitschandGitHub 7ca4cf9912 fix: links 2022-08-02 13:34:59 -07:00
Andrew FerlitschandGitHub 294e40cb61 fix: link 2022-08-02 13:27:09 -07:00
Andrew FerlitschandGitHub f69e43d3d6 fix: link 2022-08-02 13:24:41 -07:00
Andrew FerlitschandGitHub 582c479dbe fix: link 2022-08-02 13:23:07 -07:00
Andrew FerlitschandGitHub f83660cf62 fix: link 2022-08-02 13:15:55 -07:00
Andrew FerlitschandGitHub e948fae793 fix: link 2022-08-02 13:13:57 -07:00
Andrew FerlitschandGitHub cd51333ff1 fix: link 2022-08-02 13:13:00 -07:00
Andrew FerlitschandGitHub cf5d266bd7 fix: link 2022-08-02 13:09:57 -07:00
Andrew FerlitschandGitHub 8ef840affb fix: link 2022-08-02 12:59:31 -07:00
Andrew FerlitschandGitHub 4dcc3d0183 fix: link 2022-08-02 12:31:11 -07:00
Andrew FerlitschandGitHub 0bcb6a8d8e fix: title 2022-08-02 12:24:32 -07:00
Andrew FerlitschandGitHub d26b385ec7 fix: title 2022-08-02 12:23:44 -07:00
Andrew FerlitschandGitHub d5a2766aa4 Update get_started_with_matching_engine.ipynb 2022-08-02 12:22:14 -07:00
Andrew FerlitschandGitHub 7abfbb5473 fix: title 2022-08-02 12:21:41 -07:00
Andrew FerlitschandGitHub 096423da33 fix: notice 2022-08-02 12:11:17 -07:00
Andrew FerlitschandGitHub 89a133549c fix: pinning (#779)
* feat: import automl tabular model

* feat: import automl tabular model

* feat: HPT for non-TF

* feat: HPT for non-TF

* fix: split guidelines from template

* fix: split guidelines from template

* fix: split guidelines from template

* upgrade: updates for new release

* upgrade: updates for new release

* update: tune title

* update: tune title

* feat: auto-discover

* fix: title

* fix: title

* fix: title

* fix: title

* fix: title

* fix: title

* feat: autodiscover

* feat: autodiscover

* fix: title

* fix: title

* feat: autodiscover

* fix: title

* fix: title

* feat: autodiscover

* fix: title

* fix: title

* feat: autodiscover

* fix: title

* fix: title

* fix: title

* fix: title

* feat: autodiscover

* fix: pinning

* fix: pinning
2022-08-01 19:56:29 -07:00
648f1c34e0 Add notebook to show how to deploy BQML models for online prediction via Vertex AI Model Registry (#736)
* adding new notebook on BQML online pred via Model Registry

* minor changes

* fixes to linting

Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-08-01 08:42:51 -07:00
Andrew FerlitschandGitHub 3f21907c31 feat: autodiscover (#775)
* feat: import automl tabular model

* feat: import automl tabular model

* feat: HPT for non-TF

* feat: HPT for non-TF

* fix: split guidelines from template

* fix: split guidelines from template

* fix: split guidelines from template

* upgrade: updates for new release

* upgrade: updates for new release

* update: tune title

* update: tune title

* feat: auto-discover

* fix: title

* fix: title

* fix: title

* fix: title

* fix: title

* fix: title

* feat: autodiscover

* feat: autodiscover

* fix: title

* fix: title

* feat: autodiscover

* fix: title

* fix: title

* feat: autodiscover

* fix: title

* fix: title

* feat: autodiscover

* fix: title

* fix: title

* fix: title

* fix: title

* feat: autodiscover
2022-07-29 22:23:59 -07:00
Andrew FerlitschandGitHub fce66b3e57 fix: title (#774)
* feat: import automl tabular model

* feat: import automl tabular model

* feat: HPT for non-TF

* feat: HPT for non-TF

* fix: split guidelines from template

* fix: split guidelines from template

* fix: split guidelines from template

* upgrade: updates for new release

* upgrade: updates for new release

* update: tune title

* update: tune title

* feat: auto-discover

* fix: title

* fix: title

* fix: title

* fix: title

* fix: title

* fix: title

* feat: autodiscover

* feat: autodiscover

* fix: title

* fix: title

* feat: autodiscover

* fix: title

* fix: title

* feat: autodiscover

* fix: title

* fix: title

* feat: autodiscover

* fix: title

* fix: title

* fix: title

* fix: title
2022-07-29 22:19:45 -07:00
Andrew FerlitschandGitHub 3b140f9caa fix: title (#773)
* feat: import automl tabular model

* feat: import automl tabular model

* feat: HPT for non-TF

* feat: HPT for non-TF

* fix: split guidelines from template

* fix: split guidelines from template

* fix: split guidelines from template

* upgrade: updates for new release

* upgrade: updates for new release

* update: tune title

* update: tune title

* feat: auto-discover

* fix: title

* fix: title

* fix: title

* fix: title

* fix: title

* fix: title

* feat: autodiscover

* feat: autodiscover

* fix: title

* fix: title

* feat: autodiscover

* fix: title

* fix: title

* feat: autodiscover

* fix: title

* fix: title

* feat: autodiscover

* fix: title

* fix: title
2022-07-29 21:57:11 -07:00
Andrew FerlitschandGitHub 89325d7e52 feat: autodiscover (#772)
* feat: import automl tabular model

* feat: import automl tabular model

* feat: HPT for non-TF

* feat: HPT for non-TF

* fix: split guidelines from template

* fix: split guidelines from template

* fix: split guidelines from template

* upgrade: updates for new release

* upgrade: updates for new release

* update: tune title

* update: tune title

* feat: auto-discover

* fix: title

* fix: title

* fix: title

* fix: title

* fix: title

* fix: title

* feat: autodiscover

* feat: autodiscover

* fix: title

* fix: title

* feat: autodiscover

* fix: title

* fix: title

* feat: autodiscover

* fix: title

* fix: title

* feat: autodiscover
2022-07-29 19:58:21 -07:00
Andrew FerlitschandGitHub e4d44f02d6 feat: autodiscover (#771)
* feat: import automl tabular model

* feat: import automl tabular model

* feat: HPT for non-TF

* feat: HPT for non-TF

* fix: split guidelines from template

* fix: split guidelines from template

* fix: split guidelines from template

* upgrade: updates for new release

* upgrade: updates for new release

* update: tune title

* update: tune title

* feat: auto-discover

* fix: title

* fix: title

* fix: title

* fix: title

* fix: title

* fix: title

* feat: autodiscover

* feat: autodiscover

* fix: title

* fix: title

* feat: autodiscover

* fix: title

* fix: title

* feat: autodiscover

* fix: title

* fix: title
2022-07-29 19:54:08 -07:00
Andrew FerlitschandGitHub 78993c4729 fix: title (#770)
* feat: import automl tabular model

* feat: import automl tabular model

* feat: HPT for non-TF

* feat: HPT for non-TF

* fix: split guidelines from template

* fix: split guidelines from template

* fix: split guidelines from template

* upgrade: updates for new release

* upgrade: updates for new release

* update: tune title

* update: tune title

* feat: auto-discover

* fix: title

* fix: title

* fix: title

* fix: title

* fix: title

* fix: title

* feat: autodiscover

* feat: autodiscover

* fix: title

* fix: title

* feat: autodiscover

* fix: title

* fix: title
2022-07-29 16:28:15 -07:00
Andrew FerlitschandGitHub c29e7d86bd feat: autodiscover (#769)
* feat: import automl tabular model

* feat: import automl tabular model

* feat: HPT for non-TF

* feat: HPT for non-TF

* fix: split guidelines from template

* fix: split guidelines from template

* fix: split guidelines from template

* upgrade: updates for new release

* upgrade: updates for new release

* update: tune title

* update: tune title

* feat: auto-discover

* fix: title

* fix: title

* fix: title

* fix: title

* fix: title

* fix: title

* feat: autodiscover

* feat: autodiscover

* fix: title

* fix: title

* feat: autodiscover
2022-07-29 16:18:24 -07:00
Andrew FerlitschandGitHub a8793fb00a fix: title (#768)
* feat: import automl tabular model

* feat: import automl tabular model

* feat: HPT for non-TF

* feat: HPT for non-TF

* fix: split guidelines from template

* fix: split guidelines from template

* fix: split guidelines from template

* upgrade: updates for new release

* upgrade: updates for new release

* update: tune title

* update: tune title

* feat: auto-discover

* fix: title

* fix: title

* fix: title

* fix: title

* fix: title

* fix: title

* feat: autodiscover

* feat: autodiscover

* fix: title

* fix: title
2022-07-29 16:08:49 -07:00
Andrew FerlitschandGitHub bb60a7d0db Ml ops v9v3 (#767)
* feat: import automl tabular model

* feat: import automl tabular model

* feat: HPT for non-TF

* feat: HPT for non-TF

* fix: split guidelines from template

* fix: split guidelines from template

* fix: split guidelines from template

* upgrade: updates for new release

* upgrade: updates for new release

* update: tune title

* update: tune title

* feat: auto-discover

* fix: title

* fix: title

* fix: title

* fix: title

* fix: title

* fix: title

* feat: autodiscover

* feat: autodiscover
2022-07-29 15:08:27 -07:00
Andrew FerlitschandGitHub eef758c719 feat: autodiscover index (#766)
* feat: import automl tabular model

* feat: import automl tabular model

* feat: HPT for non-TF

* feat: HPT for non-TF

* fix: split guidelines from template

* fix: split guidelines from template

* fix: split guidelines from template

* upgrade: updates for new release

* upgrade: updates for new release

* update: tune title

* update: tune title

* feat: auto-discover

* fix: title

* fix: title

* fix: title

* fix: title

* fix: title

* fix: title
2022-07-29 15:06:34 -07:00
Andrew FerlitschandGitHub 486ef17ab8 fix: title (#765)
* feat: import automl tabular model

* feat: import automl tabular model

* feat: HPT for non-TF

* feat: HPT for non-TF

* fix: split guidelines from template

* fix: split guidelines from template

* fix: split guidelines from template

* upgrade: updates for new release

* upgrade: updates for new release

* update: tune title

* update: tune title

* feat: auto-discover

* fix: title

* fix: title

* fix: title

* fix: title

* fix: title

* fix: title
2022-07-29 14:57:39 -07:00
Andrew FerlitschandGitHub 90dfef3db6 fix: title (#764)
* feat: import automl tabular model

* feat: import automl tabular model

* feat: HPT for non-TF

* feat: HPT for non-TF

* fix: split guidelines from template

* fix: split guidelines from template

* fix: split guidelines from template

* upgrade: updates for new release

* upgrade: updates for new release

* update: tune title

* update: tune title

* feat: auto-discover

* fix: title

* fix: title
2022-07-29 14:35:34 -07:00
Andrew FerlitschandGitHub d59c87b387 fix: title (#763)
* feat: import automl tabular model

* feat: import automl tabular model

* feat: HPT for non-TF

* feat: HPT for non-TF

* fix: split guidelines from template

* fix: split guidelines from template

* fix: split guidelines from template

* upgrade: updates for new release

* upgrade: updates for new release

* update: tune title

* update: tune title

* feat: auto-discover

* fix: title

* fix: title
2022-07-29 13:27:46 -07:00
Andrew FerlitschandGitHub 9d69b77ac6 feat: autodiscover index (#762)
* feat: import automl tabular model

* feat: import automl tabular model

* feat: HPT for non-TF

* feat: HPT for non-TF

* fix: split guidelines from template

* fix: split guidelines from template

* fix: split guidelines from template

* upgrade: updates for new release

* upgrade: updates for new release

* update: tune title

* update: tune title

* feat: auto-discover
2022-07-29 13:04:48 -07:00
Andrew FerlitschandGitHub b0da5d69f8 update: tune title (#761)
* feat: import automl tabular model

* feat: import automl tabular model

* feat: HPT for non-TF

* feat: HPT for non-TF

* fix: split guidelines from template

* fix: split guidelines from template

* fix: split guidelines from template

* upgrade: updates for new release

* upgrade: updates for new release

* update: tune title

* update: tune title
2022-07-29 12:44:46 -07:00
Andrew FerlitschandGitHub 830e10e583 upgrade: updates for new release (#760)
* feat: import automl tabular model

* feat: import automl tabular model

* feat: HPT for non-TF

* feat: HPT for non-TF

* fix: split guidelines from template

* fix: split guidelines from template

* fix: split guidelines from template

* upgrade: updates for new release

* upgrade: updates for new release
2022-07-29 12:17:43 -07:00
kthytangandGitHub db904b424e chore: Update CPR notebooks. (#756)
* chore: Update CPR notebooks to pip install latest released Vertex SDK pypi package.

* Update CPR notebooks wording for experimental -> preview.

* Update Objectives wording

* Update github links to main branch.

* Update Sklearn interface.

* Fix formatting and typos.

* Update Predictor interface
2022-07-28 17:13:50 -07:00
Andrew FerlitschandGitHub c371f05bfa fix: split guidelines from template (#754)
* feat: import automl tabular model

* feat: import automl tabular model

* feat: HPT for non-TF

* feat: HPT for non-TF

* fix: split guidelines from template

* fix: split guidelines from template

* fix: split guidelines from template
2022-07-28 08:13:04 -07:00
Andrew FerlitschandGitHub 5f7de16e2d fix: split off authoring guidelines (#753)
* feat: import automl tabular model

* feat: import automl tabular model

* feat: HPT for non-TF

* feat: HPT for non-TF

* fix: split guidelines from template
2022-07-28 08:08:55 -07:00
Andrew FerlitschandGitHub 3908580ad6 feat: add notebook for non-TF HPT (#751)
* feat: import automl tabular model

* feat: import automl tabular model

* feat: HPT for non-TF

* feat: HPT for non-TF
2022-07-27 14:57:24 -07:00
Andrew FerlitschandGitHub 77d2cac20a Update README.md 2022-07-27 13:39:38 -07:00
Andrew FerlitschandGitHub a92d5ce473 Update README.md 2022-07-27 13:38:51 -07:00
Andrew FerlitschandGitHub 416ec74af3 add entry 2022-07-27 13:37:51 -07:00
Andrew FerlitschandGitHub 8443bbfe44 feat: notebook for importing automl tabular model (#750)
* feat: import automl tabular model

* feat: import automl tabular model
2022-07-27 13:35:04 -07:00
kthytangandGitHub 23a599068a Update CPR notebooks. (#741)
* Update CPR notebooks.

- Update interfaces
- Fix missing timestamp
- Rename some variables

* Update cpr preprocess notebook.

- Change preprocessor import path.

* Update SDK_Custom_Predict_SDK_Integration.ipynb

* Update SDK_Custom_Predict_and_Handler_SDK_Integration.ipynb

* Update SDK_Pytorch_Custom_Predict.ipynb

* Update SDK_Triton_PyTorch_Local_Prediction.ipynb

* Fix lint and revert path change for pickle dumping preprocessor.
2022-07-27 10:58:28 -07:00
gericdongandGitHub c63bb4c464 New notebook to demonstrate how to enable TensorBoard Profiler (#719)
* New notebook to demonstrate how to enable TensorBoard Profiler

* Reformatted with Lint

* Changed service account handling and added a step to monitor job state

* Addressed review comments

* Addressed technical writerreview comments

* Addressed Ivan review comments

* Switched from GAPIC to Vertex SDK

* Removed an unused package

* Addressed review comments
2022-07-26 14:39:37 -04:00
Ivan CheungandGitHub 2226e915c0 Update CODEOWNERS 2022-07-25 16:24:10 -04:00
Ivan CheungandGitHub cd9f8b1d89 Update CODEOWNERS 2022-07-25 15:01:46 -04:00
Ivan CheungandGitHub aae9ad0422 Update CODEOWNERS 2022-07-25 15:00:33 -04:00
Ivan CheungandGitHub 89d50579a6 Add @GoogleCloudPlatform/caiis-tw to CODEOWNERS
Add @GoogleCloudPlatform/caiis-tw to default.
2022-07-25 15:00:01 -04:00
Ivan CheungandGitHub 2d6afa8313 Added better download instructions (#738)
* Improve download instruc
tions

* Added web download to notebook results list
2022-07-22 18:21:05 -04:00
Ivan CheungandGitHub 00cfb20c36 Notebook CI: Fixed variable replacement to handle numbers (#739)
* Removed replacement of variable comparisons

* Fixed issue with numbers in replacement content
2022-07-22 11:50:39 -04:00
152 changed files with 32466 additions and 12168 deletions
@@ -1 +1,2 @@
ratemate
google-cloud-aiplatform
@@ -68,6 +68,12 @@ parser.add_argument(
help="A service account. This is used to inject a variable value into the notebook before running. This is not the account that will run the notebook.",
required=True,
)
parser.add_argument(
"--variable_vpc_network",
type=str,
help="The full VPC network name. See https://cloud.google.com/compute/docs/networks-and-firewalls#networks. Format is projects/{project}/global/networks/{network}, where {project} is a project number, as in '12345', and {network} is network name. See <https://cloud.google.com/compute/docs/reference/rest/v1/networks/insert> for details. This is used to inject a variable value into the notebook before running.",
required=False,
)
parser.add_argument(
"--staging_bucket",
type=str,
@@ -114,10 +120,11 @@ execute_changed_notebooks_helper.process_and_execute_notebooks(
container_uri=args.container_uri,
staging_bucket=args.staging_bucket,
artifacts_bucket=args.artifacts_bucket,
should_parallelize=args.should_parallelize,
timeout=args.timeout,
variable_project_id=args.variable_project_id,
variable_region=args.variable_region,
variable_service_account=args.variable_service_account,
variable_vpc_network=args.variable_vpc_network,
private_pool_id=args.private_pool_id,
should_parallelize=args.should_parallelize,
timeout=args.timeout,
)
@@ -68,12 +68,20 @@ class NotebookExecutionResult:
build_id: str
error_message: Optional[str]
@property
def output_uri_web(self) -> Optional[str]:
if self.output_uri.startswith("gs://"):
return f"https://storage.googleapis.com/{self.output_uri[5:]}"
else:
return None
def _process_notebook(
notebook_path: str,
variable_project_id: str,
variable_region: str,
variable_service_account: str,
variable_vpc_network: Optional[str],
):
# Read notebook
with open(notebook_path) as f:
@@ -86,6 +94,7 @@ def _process_notebook(
"PROJECT_ID": variable_project_id,
"REGION": variable_region,
"SERVICE_ACCOUNT": variable_service_account,
"VPC_NETWORK": variable_vpc_network,
},
)
@@ -121,8 +130,9 @@ def process_and_execute_notebook(
variable_project_id: str,
variable_region: str,
variable_service_account: str,
variable_vpc_network: Optional[str],
private_pool_id: Optional[str],
deadline: datetime,
deadline: datetime.datetime,
notebook: str,
should_get_tail_logs: bool = False,
) -> NotebookExecutionResult:
@@ -130,6 +140,13 @@ def process_and_execute_notebook(
print(f"Running notebook: {notebook}")
# Handle empty strings
if not variable_vpc_network:
variable_vpc_network = None
if not private_pool_id:
private_pool_id = None
# Create paths
notebook_output_uri = "/".join([artifacts_bucket, pathlib.Path(notebook).name])
@@ -156,6 +173,7 @@ def process_and_execute_notebook(
variable_project_id=variable_project_id,
variable_region=variable_region,
variable_service_account=variable_service_account,
variable_vpc_network=variable_vpc_network,
)
# Upload the pre-processed code to a GCS bucket
@@ -259,8 +277,8 @@ def get_changed_notebooks(
notebooks = []
else:
print(f"Looking for all notebooks.")
notebooks = subprocess.check_output(["git", "ls-files"] + test_paths)
notebooks = notebooks.decode("utf-8").split("\n")
notebooks_str = subprocess.check_output(["git", "ls-files"] + test_paths)
notebooks = notebooks_str.decode("utf-8").split("\n")
notebooks = [notebook for notebook in notebooks if notebook.endswith(".ipynb")]
notebooks = [notebook for notebook in notebooks if len(notebook) > 0]
@@ -279,12 +297,13 @@ def process_and_execute_notebooks(
container_uri: str,
staging_bucket: str,
artifacts_bucket: str,
should_parallelize: bool,
timeout: int,
variable_project_id: str,
variable_region: str,
variable_service_account: str,
private_pool_id: Optional[str],
should_parallelize: bool,
timeout: int,
variable_vpc_network: Optional[str] = None,
private_pool_id: Optional[str] = None,
):
"""
Run the notebooks that exist under the folders defined in the test_paths_file.
@@ -342,6 +361,7 @@ def process_and_execute_notebooks(
variable_project_id,
variable_region,
variable_service_account,
variable_vpc_network,
private_pool_id,
deadline,
),
@@ -357,6 +377,7 @@ def process_and_execute_notebooks(
variable_project_id=variable_project_id,
variable_region=variable_region,
variable_service_account=variable_service_account,
variable_vpc_network=variable_vpc_network,
private_pool_id=private_pool_id,
deadline=deadline,
notebook=notebook,
@@ -382,10 +403,18 @@ def process_and_execute_notebooks(
format_timedelta(result.duration),
result.log_url,
result.output_uri,
result.output_uri_web,
]
for result in results_sorted
],
headers=["build_tag", "status", "duration", "log_url", "output_url"],
headers=[
"build_tag",
"status",
"duration",
"log_url",
"output_uri",
"output_uri_web",
],
)
)
@@ -414,6 +443,7 @@ def process_and_execute_notebooks(
variable_project_id=variable_project_id,
variable_region=variable_region,
variable_service_account=variable_service_account,
variable_vpc_network=variable_vpc_network,
)
execute_notebook_helper.execute_notebook(
+15 -4
View File
@@ -26,6 +26,9 @@ from utils import util
# This script is used to execute a notebook and write out the output notebook.
# This is used to force papermill to use this kernel to run the notebook instead of any defined inside the notebook itself
DEFAULT_KERNEL_NAME = "python3"
def execute_notebook(
notebook_source: str,
@@ -50,6 +53,17 @@ def execute_notebook(
execution_exception = None
print("\n=== DOWNLOAD EXECUTED NOTEBOOK ===\n")
print(f"Please debug the executed notebook by downloading the executed notebook:")
print("Option 1. Using gsutil. Run the following command in your terminal.")
print(f'\tgsutil cp "{output_file_or_uri}" .')
print("Option 2. Using this link.")
print(f"\thttps://storage.googleapis.com/{output_file_or_uri[5:]}")
print("\n======\n")
# Execute notebook
try:
# Execute notebook
@@ -58,6 +72,7 @@ def execute_notebook(
output_path=notebook_source,
progress_bar=should_log_output,
request_save_on_cell_execute=should_log_output,
kernel_name=DEFAULT_KERNEL_NAME,
log_output=should_log_output,
stdout_file=sys.stdout if should_log_output else None,
stderr_file=sys.stderr if should_log_output else None,
@@ -71,10 +86,6 @@ def execute_notebook(
util.upload_file(notebook_source, remote_file_path=output_file_or_uri)
print("\n=== EXECUTION FINISHED ===\n")
print(
f"Please debug the executed notebook by downloading: {output_file_or_uri}"
)
print("\n======\n")
else:
# Create directories if they don't exist
if not os.path.exists(os.path.dirname(output_file_or_uri)):
@@ -4,13 +4,13 @@ steps:
entrypoint: /bin/sh
args:
- -c
- 'gcloud config list'
- 'gcloud config list --quiet'
# Check the Python version
- name: ${_PYTHON_IMAGE}
entrypoint: /bin/sh
args:
- -c
- python3 .cloud-build/CheckPythonVersion.py
- python3 .cloud-build/CheckPythonVersion.py -q
# Create a virtual environment
- name: ${_PYTHON_IMAGE}
entrypoint: /bin/sh
@@ -21,26 +21,18 @@ steps:
- name: ${_PYTHON_IMAGE}
entrypoint: /bin/sh
args:
- -c
- -c
- . workspace/env/bin/activate &&
python3 -m pip install -U pip &&
python3 -m pip install -U -r .cloud-build/requirements.txt
# pip freeze
python3 -m pip -q install -U pip &&
python3 -m pip -q install -U -r .cloud-build/requirements.txt
# Install Python dependencies and run testing script
- name: ${_PYTHON_IMAGE}
entrypoint: /bin/sh
args:
- -c
- |
. workspace/env/bin/activate &&
python3 -m pip freeze
# Install Python dependencies and run testing script
- name: ${_PYTHON_IMAGE}
entrypoint: /bin/sh
args:
- -c
- |
. workspace/env/bin/activate &&
python3 .cloud-build/execute_notebook_cli.py --notebook_source "${_NOTEBOOK_GCS_URI}" --output_file_or_uri "${_NOTEBOOK_OUTPUT_GCS_URI}"
env:
- 'IS_TESTING=1'
timeout: 86400s
timeout: 86400s
@@ -4,16 +4,16 @@ steps:
entrypoint: /bin/sh
args:
- -c
- gcloud config list
- gcloud config list --quiet
# Check the Python version
- name: ${_PYTHON_IMAGE}
entrypoint: /bin/sh
args:
- -c
- python3 .cloud-build/CheckPythonVersion.py
- python3 .cloud-build/CheckPythonVersion.py -q
# Fetch full repo for diff purposes
- name: gcr.io/cloud-builders/git
args: [fetch, --unshallow]
args: [fetch, --unshallow, --quiet]
# Create a virtual environment
- name: ${_PYTHON_IMAGE}
entrypoint: /bin/sh
@@ -21,33 +21,25 @@ steps:
- -c
- python3 -m venv workspace/env
# Install Python dependencies
- name: ${_PYTHON_IMAGE}
entrypoint: /bin/sh
args:
- -c
- . workspace/env/bin/activate &&
python3 -m pip install -U pip &&
python3 -m pip install -U -r .cloud-build/requirements.txt
# pip freeze
- name: ${_PYTHON_IMAGE}
entrypoint: /bin/sh
args:
- -c
- |
. workspace/env/bin/activate &&
python3 -m pip freeze
- . workspace/env/bin/activate &&
python3 -m pip -q install -U pip &&
python3 -m pip -q install -U -r .cloud-build/requirements.txt
# Install Python dependencies and run testing script
# TODO: Only pass in private_pool_id if it is set
- name: ${_PYTHON_IMAGE}
entrypoint: /bin/sh
args:
- -c
- |
- |
. workspace/env/bin/activate &&
python3 .cloud-build/execute_changed_notebooks_cli.py --test_paths_file "${_TEST_PATHS_FILE}" --base_branch "${_FORCED_BASE_BRANCH}" --container_uri ${_PYTHON_IMAGE} --staging_bucket ${_GCS_STAGING_BUCKET} --artifacts_bucket ${_GCS_STAGING_BUCKET}/executed_notebooks/PR_${_PR_NUMBER}/BUILD_${BUILD_ID} --variable_project_id ${PROJECT_ID} --variable_region ${_GCP_REGION} --variable_service_account ${_GCP_SERVICE_ACCOUNT} `if [ ! -z "${_PRIVATE_POOL_NAME}" ]; then echo "--private_pool_id ${_PRIVATE_POOL_NAME}"; fi`
python3 .cloud-build/execute_changed_notebooks_cli.py --test_paths_file "${_TEST_PATHS_FILE}" --base_branch "${_FORCED_BASE_BRANCH}" --container_uri ${_PYTHON_IMAGE} --staging_bucket ${_GCS_STAGING_BUCKET} --artifacts_bucket ${_GCS_STAGING_BUCKET}/executed_notebooks/PR_${_PR_NUMBER}/BUILD_${BUILD_ID} --variable_project_id ${PROJECT_ID} --variable_region ${_GCP_REGION} --variable_service_account ${_GCP_SERVICE_ACCOUNT} --variable_vpc_network "${_GPC_VPC_NETWORK_NAME}" `if [ ! -z "${_PRIVATE_POOL_NAME}" ]; then echo "--private_pool_id ${_PRIVATE_POOL_NAME}"; fi`
env:
- 'IS_TESTING=1'
timeout: 86400s
options:
pool:
name: ${_PRIVATE_POOL_NAME}
name: ${_PRIVATE_POOL_NAME}
+1 -1
View File
@@ -1,5 +1,5 @@
notebooks/official/vizier/gapic-vizier-multi-objective-optimization.ipynb
notebooks/official/pipelines/lightweight_functions_component_io_kfp.ipynb
notebooks/official/matching_engine/intro-swivel.ipynb
notebooks/official/ml_metadata/sdk-metric-parameter-tracking-for-locally-trained-models.ipynb
notebooks/official/pipelines/metrics_viz_run_compare_kfp.ipynb
notebooks/official/matching_engine/sdk_matching_engine_for_indexing.ipynb
+1
View File
@@ -0,0 +1 @@
notebooks/official/pipelines/metrics_viz_run_compare_kfp.ipynb
+15 -1
View File
@@ -36,7 +36,7 @@ Variables in conditionals can also be replaced:
def get_updated_value(content: str, variable_name: str, variable_value: str) -> str:
return re.sub(
rf"({variable_name}.*? = .*?[\",\'])\[.+?\]([\",\'].*?)",
rf"\1{variable_value}\2",
rf"\g<1>{variable_value}\g<2>",
content,
flags=re.M,
)
@@ -80,6 +80,7 @@ def test_region():
)
assert new_content == 'REGION = "us-central1" # @param {type:"string"}'
def test_region_equal_equals_ignore():
# Tests that == is ignored
new_content = get_updated_value(
@@ -88,3 +89,16 @@ def test_region_equal_equals_ignore():
variable_value="us-central1",
)
assert new_content == 'REGION == "[your-region]" # @param {type:"string"}'
def test_service_account():
# Tests that == is ignored
new_content = get_updated_value(
content='SERVICE_ACCOUNT = "[your-service-account]" # @param {type:"string"}',
variable_name="SERVICE_ACCOUNT",
variable_value="12345-compute@developer.gserviceaccount.com",
)
assert (
new_content
== 'SERVICE_ACCOUNT = "12345-compute@developer.gserviceaccount.com" # @param {type:"string"}'
)
+13 -3
View File
@@ -1,4 +1,11 @@
If you are opening a PR for `Official Notebooks` under the [notebooks/official](https://github.com/GoogleCloudPlatform/vertex-ai-samples/tree/main/notebooks/official) folder, follow this mandatory checklist:
**REQUIRED:** Add a summary of your PR here, typically including why the change is needed and what was changed. Include any design alternatives for discussion purposes.
<br>
--- YOUR PR SUMMARY GOES HERE ---
<br><br><br>
**REQUIRED:** Fill out the below checklists or remove if irrelevant
1. If you are opening a PR for `Official Notebooks` under the [notebooks/official](https://github.com/GoogleCloudPlatform/vertex-ai-samples/tree/main/notebooks/official) folder, follow this mandatory checklist:
- [ ] Use the [notebook template](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/notebook_template.ipynb) as a starting point.
- [ ] Follow the style and grammar rules outlined in the above notebook template.
- [ ] Verify the notebook runs successfully in Colab since the automated tests cannot guarantee this even when it passes.
@@ -7,12 +14,15 @@ If you are opening a PR for `Official Notebooks` under the [notebooks/official](
- [ ] This notebook has been added to the [CODEOWNERS](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/CODEOWNERS) file under the `Official Notebooks` section, pointing to the author or the author's team.
- [ ] The Jupyter notebook cleans up any artifacts it has created (datasets, ML models, endpoints, etc) so as not to eat up unnecessary resources.
<br>
If you are opening a PR for `Community Notebooks` under the [notebooks/community](https://github.com/GoogleCloudPlatform/vertex-ai-samples/tree/main/notebooks/community) folder:
2. If you are opening a PR for `Community Notebooks` under the [notebooks/community](https://github.com/GoogleCloudPlatform/vertex-ai-samples/tree/main/notebooks/community) folder:
- [ ] This notebook has been added to the [CODEOWNERS](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/CODEOWNERS) file under the `Community Notebooks` section, pointing to the author or the author's team.
- [ ] Passes all the required formatting and linting checks. You can locally test with these [instructions](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/CONTRIBUTING.md#code-quality-checks).
If you are opening a PR for `Community Content` under the [community-content](https://github.com/GoogleCloudPlatform/vertex-ai-samples/tree/main/community-content) folder:
<br>
3. If you are opening a PR for `Community Content` under the [community-content](https://github.com/GoogleCloudPlatform/vertex-ai-samples/tree/main/community-content) folder:
- [ ] Make sure your main `Content Directory Name` is descriptive, informative, and includes some of the key products and attributes of your content, so that it is differentiable from other content
- [ ] The main content directory has been added to the [CODEOWNERS](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/community-content/CODEOWNERS) file under the `Community Content` section, pointing to the author or the author's team.
- [ ] Passes all the required formatting and linting checks. You can locally test with these [instructions](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/CONTRIBUTING.md#code-quality-checks).
+1 -1
View File
@@ -2,7 +2,7 @@ git+https://github.com/tensorflow/docs
ipython
jupyter
nbconvert
black==22.3.0
black==22.6.0
pyupgrade==2.34.0
isort==5.10.1
flake8==4.0.1
@@ -1,474 +0,0 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "a6b56b1c7b76"
},
"outputs": [],
"source": [
"# Copyright 2021 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": "c414a395a19b"
},
"source": [
"# PyTorch Image Classification Multi-Node Distributed Data Parallel Training on CPU using Vertex Training with Custom Container"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "b98238e32cf7"
},
"source": [
"<table align=\"left\">\n",
" <td>\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/master/community-content/pytorch_image_classification_distributed_data_parallel_training_with_vertex_sdk/multi_node_ddp_gloo_vertex_training_with_custom_container.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/github-logo-32px.png\" alt=\"GitHub logo\">\n",
" View on GitHub\n",
" </a>\n",
" </td>\n",
"</table>"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "03d216c7f7b1"
},
"source": [
"## Setup"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "c5ac73516218"
},
"outputs": [],
"source": [
"PROJECT_ID = \"YOUR PROJECT ID\"\n",
"BUCKET_NAME = \"gs://YOUR BUCKET NAME\"\n",
"REGION = \"YOUR REGION\"\n",
"SERVICE_ACCOUNT = \"YOUR SERVICE ACCOUNT\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "0b5ae674177e"
},
"outputs": [],
"source": [
"! gsutil ls -al $BUCKET_NAME"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "19a9b3bdd553"
},
"outputs": [],
"source": [
"content_name = \"pt-img-cls-multi-node-ddp-cust-cont\""
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "57bf6f8b4361"
},
"source": [
"## Local Training"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "e5d8a3443da0"
},
"outputs": [],
"source": [
"! ls trainer"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "07f79309472d"
},
"outputs": [],
"source": [
"! cat trainer/requirements.txt"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "e16cd8bb7483"
},
"outputs": [],
"source": [
"! pip install -r trainer/requirements.txt"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "0b8a210718c4"
},
"outputs": [],
"source": [
"! cat trainer/task.py"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "c0c6e7dfb3c6"
},
"outputs": [],
"source": [
"%run trainer/task.py --epochs 5 --no-cuda --local-mode"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "31dfdeede587"
},
"outputs": [],
"source": [
"! ls ./tmp"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "48d56ec621cc"
},
"outputs": [],
"source": [
"! rm -rf ./tmp"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "8f3ea1210749"
},
"source": [
"## Vertex Training using Vertex SDK and Custom Container"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "93002a20a2a6"
},
"source": [
"### Build Custom Container"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "4130ce43fd08"
},
"outputs": [],
"source": [
"hostname = \"gcr.io\"\n",
"image_name = content_name\n",
"tag = \"latest\"\n",
"\n",
"custom_container_image_uri = f\"{hostname}/{PROJECT_ID}/{image_name}:{tag}\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "2f1fc5b05240"
},
"outputs": [],
"source": [
"! cd trainer && docker build -t $custom_container_image_uri -f Dockerfile ."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "b4f274f499ac"
},
"outputs": [],
"source": [
"! docker run --rm $custom_container_image_uri --epochs 5 --no-cuda --local-mode"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "ee1a0a06d0b4"
},
"outputs": [],
"source": [
"! docker push $custom_container_image_uri"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "cb763be12fc9"
},
"outputs": [],
"source": [
"! gcloud container images list --repository $hostname/$PROJECT_ID"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "10c8cc6b3334"
},
"source": [
"### Initialize Vertex SDK"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "1a12348169fa"
},
"outputs": [],
"source": [
"! pip install -r requirements.txt"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "42e981cefe41"
},
"outputs": [],
"source": [
"from google.cloud import aiplatform\n",
"\n",
"aiplatform.init(\n",
" project=PROJECT_ID,\n",
" staging_bucket=BUCKET_NAME,\n",
" location=REGION,\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "73c92c9298e9"
},
"source": [
"### Create a Vertex Tensorboard Instance"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "bde509558cd5"
},
"outputs": [],
"source": [
"content_name = content_name + \"-cpu\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "6d7908c0083c"
},
"outputs": [],
"source": [
"tensorboard = aiplatform.Tensorboard.create(\n",
" display_name=content_name,\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "a1f0a4f54037"
},
"source": [
"#### Option: Use a Previously Created Vertex Tensorboard Instance\n",
"\n",
"```\n",
"tensorboard_name = \"Your Tensorboard Resource Name or Tensorboard ID\"\n",
"tensorboard = aiplatform.Tensorboard(tensorboard_name=tensorboard_name)\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "a4cac84e04ac"
},
"source": [
"### Run a Vertex SDK CustomContainerTrainingJob"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "f92e8fdd44ee"
},
"outputs": [],
"source": [
"display_name = content_name\n",
"gcs_output_uri_prefix = f\"{BUCKET_NAME}/{display_name}\"\n",
"\n",
"replica_count = 4\n",
"machine_type = \"n1-standard-4\"\n",
"\n",
"args = [\n",
" \"--backend\",\n",
" \"gloo\",\n",
" \"--no-cuda\",\n",
" \"--batch-size\",\n",
" \"128\",\n",
" \"--epochs\",\n",
" \"25\",\n",
"]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "ae4c57df7e07"
},
"outputs": [],
"source": [
"custom_container_training_job = aiplatform.CustomContainerTrainingJob(\n",
" display_name=display_name,\n",
" container_uri=custom_container_image_uri,\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "35cf3ecdf0df"
},
"outputs": [],
"source": [
"custom_container_training_job.run(\n",
" args=args,\n",
" base_output_dir=gcs_output_uri_prefix,\n",
" replica_count=replica_count,\n",
" machine_type=machine_type,\n",
" tensorboard=tensorboard.resource_name,\n",
" service_account=SERVICE_ACCOUNT,\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "49d10dded73b"
},
"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": "78398f52807b"
},
"source": [
"### Training Output Artifact"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "fc74422de1d1"
},
"outputs": [],
"source": [
"! gsutil ls $gcs_output_uri_prefix"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "5e99a6a05b10"
},
"source": [
"## Clean Up Artifact"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "b0c1b3f7466b"
},
"outputs": [],
"source": [
"! gsutil rm -rf $gcs_output_uri_prefix"
]
}
],
"metadata": {
"colab": {
"name": "multi_node_ddp_gloo_vertex_training_with_custom_container.ipynb",
"toc_visible": true
},
"kernelspec": {
"display_name": "Python 3",
"name": "python3"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
@@ -1,347 +0,0 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "a6b56b1c7b76"
},
"outputs": [],
"source": [
"# Copyright 2021 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": "20a5ea0081d0"
},
"source": [
"# PyTorch Image Classification Multi-Node Distributed Data Parallel Training on GPU using Vertex Training with Custom Container"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "8752d4a255fb"
},
"source": [
"<table align=\"left\">\n",
" <td>\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/master/community-content/pytorch_image_classification_distributed_data_parallel_training_with_vertex_sdk/multi_node_ddp_nccl_vertex_training_with_custom_container.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/github-logo-32px.png\" alt=\"GitHub logo\">\n",
" View on GitHub\n",
" </a>\n",
" </td>\n",
"</table>"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "03d216c7f7b1"
},
"source": [
"## Setup"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "c5ac73516218"
},
"outputs": [],
"source": [
"PROJECT_ID = \"YOUR PROJECT ID\"\n",
"BUCKET_NAME = \"gs://YOUR BUCKET NAME\"\n",
"REGION = \"YOUR REGION\"\n",
"SERVICE_ACCOUNT = \"YOUR SERVICE ACCOUNT\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "0b5ae674177e"
},
"outputs": [],
"source": [
"! gsutil ls -al $BUCKET_NAME"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "19a9b3bdd553"
},
"outputs": [],
"source": [
"content_name = \"pt-img-cls-multi-node-ddp-cust-cont\""
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "5307fe28b633"
},
"source": [
"## Vertex Training using Vertex SDK and Custom Container"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "46cb58c7fbf9"
},
"source": [
"### Built Custom Container"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "97e66e9f9bab"
},
"outputs": [],
"source": [
"hostname = \"gcr.io\"\n",
"image_name = content_name\n",
"tag = \"latest\"\n",
"\n",
"custom_container_image_uri = f\"{hostname}/{PROJECT_ID}/{image_name}:{tag}\""
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "ae9b29c4773f"
},
"source": [
"### Initialize Vertex SDK"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "dc1e84d5dec2"
},
"outputs": [],
"source": [
"! pip install -r requirements.txt"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "6964be27b98e"
},
"outputs": [],
"source": [
"from google.cloud import aiplatform\n",
"\n",
"aiplatform.init(\n",
" project=PROJECT_ID,\n",
" staging_bucket=BUCKET_NAME,\n",
" location=REGION,\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "594a91f438f2"
},
"source": [
"### Create a Vertex Tensorboard Instance"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "93134273261e"
},
"outputs": [],
"source": [
"content_name = content_name + \"-gpu\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "c2bd82dbcd9b"
},
"outputs": [],
"source": [
"tensorboard = aiplatform.Tensorboard.create(\n",
" display_name=content_name,\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "ebc593c6472e"
},
"source": [
"#### Option: Use a Previously Created Vertex Tensorboard Instance\n",
"\n",
"```\n",
"tensorboard_name = \"Your Tensorboard Resource Name or Tensorboard ID\"\n",
"tensorboard = aiplatform.Tensorboard(tensorboard_name=tensorboard_name)\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "0769e8e34c2f"
},
"source": [
"### Run a Vertex SDK CustomContainerTrainingJob"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "023f33ece826"
},
"outputs": [],
"source": [
"display_name = content_name\n",
"gcs_output_uri_prefix = f\"{BUCKET_NAME}/{display_name}\"\n",
"\n",
"replica_count = 1\n",
"machine_type = \"n1-standard-4\"\n",
"accelerator_count = 4\n",
"accelerator_type = \"NVIDIA_TESLA_K80\"\n",
"\n",
"args = [\n",
" \"--backend\",\n",
" \"nccl\",\n",
" \"--batch-size\",\n",
" \"128\",\n",
" \"--epochs\",\n",
" \"25\",\n",
"]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "d4b599e726ef"
},
"outputs": [],
"source": [
"custom_container_training_job = aiplatform.CustomContainerTrainingJob(\n",
" display_name=display_name,\n",
" container_uri=custom_container_image_uri,\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "81321e3bdf7f"
},
"outputs": [],
"source": [
"custom_container_training_job.run(\n",
" args=args,\n",
" base_output_dir=gcs_output_uri_prefix,\n",
" replica_count=replica_count,\n",
" machine_type=machine_type,\n",
" accelerator_count=accelerator_count,\n",
" accelerator_type=accelerator_type,\n",
" tensorboard=tensorboard.resource_name,\n",
" service_account=SERVICE_ACCOUNT,\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "5100712c2c4c"
},
"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": "f9b77676e5a6"
},
"source": [
"### Training Output Artifact"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "0e171ce95ace"
},
"outputs": [],
"source": [
"! gsutil ls $gcs_output_uri_prefix"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "cf1b74a12b87"
},
"source": [
"## Clean Up Artifact"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "a0b15089c341"
},
"outputs": [],
"source": [
"! gsutil rm -rf $gcs_output_uri_prefix"
]
}
],
"metadata": {
"colab": {
"name": "multi_node_ddp_nccl_vertex_training_with_custom_container.ipynb",
"toc_visible": true
},
"kernelspec": {
"display_name": "Python 3",
"name": "python3"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
+1
View File
@@ -11,6 +11,7 @@
/structured_data/rapid_prototyping_* @rafael-carvalho
/managed_notebooks/
/bigquery_ml/ @polong
/sdk/SDK_FBProphet_Forecasting_Online.ipynb @brianchunkang
/pipelines/google_cloud_pipeline_components_TPU_model_train_upload_deploy.ipynb @brianchunkang
/explainable_ai/SDK_Custom_Container_XAI.ipynb @brianchunkang
File diff suppressed because it is too large Load Diff
+43 -50
View File
@@ -28,11 +28,50 @@ The first stage in MLOps is the collection and preparation for the purpose of de
### Get Started
[Get Started with BQ datasets](get_started_bq_datasets.ipynb)
[Get started with Vertex AI datasets](get_started_vertex_datasets.ipynb)
```
The steps performed include:
- Create a Vertex AI `Dataset` resource for:
- image data
- text data
- video data
- tabular data
- forecasting data
- Search `Dataset` resources using a filter.
- Read a sample of a `BigQuery` dataset into a dataframe.
- Generate statistics and data schema using TensorFlow Data Validation from the samples in the dataframe.
- Detect anomalies in new data using TensorFlow Data Validation.
- Generate a TFRecord feature specification using TensorFlow Transform from the data schema.
- Export a dataset and convert to TFRecords.
```
[Get started with Dataflow](get_started_dataflow.ipynb)
```
The steps performed include:
- Offline preprocessing of data:
- Serially - w/o dataflow
- Parallel - with dataflow
- Upstream preprocessing of data:
- tabular data
- image data
```
[Create an unlabelled Vertex AI AutoML text entity extraction dataset from pdfs using Vision API](get_started_with_visionapi_and_vertex_datasets.ipynb)
```
The steps performed include:
1. Using `Vision API` to perform Optical Character Recognition (OCR) to extract text from PDF files.
2. Processing the results and saving them to text files.
3. Generating a `Vertex AI Dataset` import file.
4. Creating a new unlabelled text entity extraction `Vertex AI Dataset` resource in `Vertex AI`.
```
[Get started with BigQuery datasets](get_started_bq_datasets.ipynb)
```
The steps performed include:
- Create a Vertex AI `Dataset` resource from `BigQuery` table -- compatible for `AutoML` training.
- Extract a copy of the dataset from `BigQuery` to a CSV file in Cloud Storage -- compatible for `AutoML` or custom training.
- Select rows from a `BigQuery` dataset into a `pandas` dataframe -- compatible for custom training.
@@ -42,70 +81,25 @@ The steps performed include:
- Extract data from `BigQuery` table into a `DMatrix` -- compatible for custom training `XGBoost` models.
```
[Get Started with Vertex datasets](get_started_vertex_datasets.ipynb)
[Get started with Vertex AI data labeling](get_started_with_data_labeling.ipynb)
```
The steps performed include:
- Create a Vertex AI `Dataset` resource for:
- image data
- text data
- video data
- tabular data
- forecasting data
- Search `Dataset` resources using a filter.
- Read a sample of a `BigQuery` dataset into a dataframe.
- Generate statistics and data schema using TensorFlow Data Validation from the samples in the dataframe.
- Detect anomalies in new data using TensorFlow Data Validation.
- Generate a TFRecord feature specification using TensorFlow Transform from the data schema.
- Export a dataset and convert to TFRecords.
```
[Get Started with Dataflow](get_started_dataflow.ipynb)
```
The steps performed include:
- Offline preprocessing of data:
- Serially - w/o dataflow
- Parallel - with dataflow
- Upstream preprocessing of data:
- tabular data
- image data
```
[Get Started with Data Labeling](get_started_with_data_labeling.ipynb)
```
The steps performed include:
- Create a Specialist Pool for data labelers.
- Create a data labeling job.
- Submit the data labeling job.
- List data labeling jobs.
- Cancel a data labeling job.
```
[Get Started with Vision API and Vertex AI Datasets](get_started_with_visionapi_and_vertex_datasets.ipynb)
```
The steps performed include:
- Using Vision API to perform Optical Character Recognition (OCR) to extract text from PDF files.
- Processing the results and saving them to text files.
- Generating a Vertex AI Dataset import file.
- Creating a new unlabelled text entity extraction Vertex AI Dataset resource in Vertex AI.
```
### E2E Stage Example
[Stage 1: Data Management](mlops_data_management.ipynb)
```
The steps performed include:
- Explore and visualize the data.
- Create a Vertex AI `Dataset` resource from `BigQuery` table -- for AutoML training.
- Extract a copy of the dataset to a CSV file in Cloud Storage.
@@ -115,4 +109,3 @@ The steps performed include:
- Generate a TFRecord feature specification using TensorFlow Data Validation from the data schema.
- Preprocess a portion of the BigQuery data using `Dataflow` -- for custom training.
```
@@ -64,17 +64,6 @@
"This tutorial demonstrates how to use Vertex AI for E2E MLOps on Google Cloud in production. This tutorial covers stage 1 : data management: get started with BigQuery datasets."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dataset:gsod,lrg"
},
"source": [
"### Dataset\n",
"\n",
"The dataset used for this tutorial is the GSOD dataset from [BigQuery public datasets](https://cloud.google.com/bigquery/public-data). In this version of the dataset you consider the fields year, month and day to predict the value of mean daily temperature (mean_temp)."
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -140,8 +129,26 @@
"- Alternatively:\n",
" - Extract the BigQuery table to CSV files.\n",
" - Preprocess the CSV files.\n",
" - Create a tf.data.Dataset generator from the CSV files.\n",
" \n",
" - Create a tf.data.Dataset generator from the CSV files."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dataset:gsod,lrg"
},
"source": [
"### Dataset\n",
"\n",
"The dataset used for this tutorial is the GSOD dataset from [BigQuery public datasets](https://cloud.google.com/bigquery/public-data). In this version of the dataset you consider the fields year, month and day to predict the value of mean daily temperature (mean_temp)."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "9e483012a752"
},
"source": [
"### Costs\n",
"This tutorial uses billable components of Google Cloud:\n",
"\n",
@@ -65,17 +65,6 @@
"This tutorial demonstrates how to use Vertex AI for E2E MLOps on Google Cloud in production. This tutorial covers stage 1 : data management: get started with Dataflow."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dataset:gsod,lrg"
},
"source": [
"### Dataset\n",
"\n",
"The dataset used for this tutorial is the GSOD dataset from [BigQuery public datasets](https://cloud.google.com/bigquery/public-data). The version of the dataset you use only the fields year, month and day to predict the value of mean daily temperature (mean_temp)."
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -137,6 +126,34 @@
"Alternately for AutoML tabular model training, you can reconfigure the otherwise default preprocessing."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dataset:gsod,lrg"
},
"source": [
"### Dataset\n",
"\n",
"The dataset used for this tutorial is the GSOD dataset from [BigQuery public datasets](https://cloud.google.com/bigquery/public-data). The version of the dataset you use only the fields year, month and day to predict the value of mean daily temperature (mean_temp)."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "9e483012a752"
},
"source": [
"### Costs\n",
"This tutorial uses billable components of Google Cloud:\n",
"\n",
"- Vertex AI\n",
"- Cloud Storage\n",
"- BigQuery\n",
"- Dataflow\n",
"\n",
"Learn about [Vertex AI pricing](https://cloud.google.com/vertex-ai/pricing), [Cloud Storage pricing](https://cloud.google.com/storage/pricing), [BigQuery pricing](https://cloud.google.com/bigquery/pricing), and [Dataflow pricing](https://cloud.google.com/dataflow/pricing) and use the [Pricing Calculator](https://cloud.google.com/products/calculator/) to generate a cost estimate based on your projected usage."
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -29,7 +29,7 @@
"id": "title:generic,gcp"
},
"source": [
"# E2E ML on GCP: MLOps stage 1 : data management: get started with Vertex datasets\n",
"# E2E ML on GCP: MLOps stage 1 : data management: get started with Vertex AI datasets\n",
"\n",
"<table align=\"left\">\n",
" <td>\n",
@@ -136,9 +136,26 @@
" - Create a tf.data.Dataset generator from the CSV index file.\n",
" - If text strings are in text files:\n",
" - Using the JSON index file, convert the text files and labels to TFRecords.\n",
" - Create a tf.data.Dataset from the TFRecords.\n",
" - Create a tf.data.Dataset from the TFRecords."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "533dd6fe83c8"
},
"source": [
"### Datasets\n",
"\n",
" \n",
"This tutorial uses a variety of public datasets to demonstrate using a `Vertex AI` managed dataset."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "9e483012a752"
},
"source": [
"### Costs\n",
"This tutorial uses billable components of Google Cloud:\n",
"\n",
@@ -226,6 +243,8 @@
"id": "cb082379ed5b"
},
"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",
@@ -263,36 +282,22 @@
},
"outputs": [],
"source": [
"import os\n",
"\n",
"PROJECT_ID = \"\"\n",
"\n",
"if not os.getenv(\"IS_TESTING\"):\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": "markdown",
"metadata": {
"id": "37c0a68ff20d"
},
"source": [
"Otherwise, set your project ID here."
"PROJECT_ID = \"[your-project-id]\" # @param {type:\"string\"}"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "autoset_project_id"
"id": "nWlzLu5ELxWd"
},
"outputs": [],
"source": [
"if PROJECT_ID == \"\" or PROJECT_ID is None:\n",
" PROJECT_ID = \"[your-project-id]\" # @param {type:\"string\"}"
"if PROJECT_ID == \"\" or PROJECT_ID is None or PROJECT_ID == \"[your-project-id]\":\n",
" # Get your GCP project id from gcloud\n",
" shell_output = ! gcloud config list --format 'value(core.project)' 2>/dev/null\n",
" PROJECT_ID = shell_output[0]\n",
" print(\"Project ID:\", PROJECT_ID)"
]
},
{
@@ -65,17 +65,6 @@
"This tutorial demonstrates how to use Vertex AI for E2E MLOps on Google Cloud in production. This tutorial covers stage 1 : data management: get started with Vertex AI Data Labeling service."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dataset:flowers,icn"
},
"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."
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -102,6 +91,17 @@
"Learn more about [Request a Vertex AI Data Labeling job](https://cloud.google.com/vertex-ai/docs/datasets/data-labeling-job)."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dataset:flowers,icn"
},
"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 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."
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -167,7 +167,7 @@
"id": "restart"
},
"source": [
"### Restart the Kernel\n",
"### Restart the kernel\n",
"\n",
"Once you've installed the Vertex AI SDK and Google *cloud-storage*, you need to restart the notebook kernel so it can find the packages.\n"
]
@@ -220,6 +220,17 @@
"**Note**: Jupyter runs lines prefixed with `!` as shell commands, and it interpolates Python variables prefixed with `$` into these commands.\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "WReHDGG5g0XY"
},
"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`."
]
},
{
"cell_type": "code",
"execution_count": null,
@@ -53,7 +53,7 @@
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://raw.githubusercontent.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage1/get_started_with_visionapi_and_vertex_datasets.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_with_visionapi_and_vertex_datasets.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",
@@ -70,11 +70,36 @@
"source": [
"## Overview\n",
"\n",
"This notebook will create an unlabelled `Vertex AI AutoML` text entity extraction dataset based on a collection of PDF files stored in a Cloud Storage bucket. \n",
"This notebook creates an unlabelled `Vertex AI AutoML` text entity extraction dataset based on a collection of PDF files stored in a Cloud Storage bucket. \n",
"\n",
"The notebook can be modified to create different types of text datasets including sentiment analysis and classification."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "3f8c2f702ccd"
},
"source": [
"### Objective\n",
"\n",
"In this tutorial, you learn to use `Vision API` to extract text from PDF files stored on a Cloud Storage bucket. You then process the results and create an unlabelled `Vertex AI Dataset`, compatible with `AutoML`, for text entity extraction.\n",
"\n",
"You can then either use Google Cloud console to annotate / label the dataset, or create a labelling job as demonstrated in [this notebook](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage1/get_started_with_data_labeling.ipynb).\n",
"\n",
"This tutorial uses the following Google Cloud services:\n",
"\n",
"- `Vision AI`\n",
"- `Vertex AI AutoML`\n",
"\n",
"The steps performed include:\n",
"\n",
"1. Using `Vision API` to perform Optical Character Recognition (OCR) to extract text from PDF files.\n",
"2. Processing the results and saving them to text files.\n",
"3. Generating a `Vertex AI Dataset` import file.\n",
"4. Creating a new unlabelled text entity extraction `Vertex AI Dataset` resource in `Vertex AI`."
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -90,31 +115,6 @@
"The data is published as a [public dataset](https://cloud.google.com/bigquery/public-data) on `BigQuery`."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "3f8c2f702ccd"
},
"source": [
"### Objective\n",
"\n",
"In this tutorial, you learn to use `Vision API` to extract text from PDF files stored on a Cloud Storage bucket. You will then process the results and create an unlabelled `Vertex AI Dataset`, compatible with `AutoML`, for text entity extraction.\n",
"\n",
"You can then either use Google Cloud console to annotate / label the dataset, or create a labelling job as demonstrated in [this notebook](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage1/get_started_with_data_labeling.ipynb).\n",
"\n",
"This tutorial uses the following Google Cloud services:\n",
"\n",
"- `Vision AI`\n",
"- `Vertex AI AutoML`\n",
"\n",
"The steps performed include:\n",
"\n",
"1. Using `Vision API` to perform Optical Character Recognition (OCR) to extract text from PDF files.\n",
"2. Processing the results and saving them to text files.\n",
"3. Generating a `Vertex AI Dataset` import file.\n",
"4. Creating a new unlabelled text entity extraction `Vertex AI Dataset` resource in `Vertex AI`."
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -257,7 +257,7 @@
"\n",
"3. [Enable the following APIs: Vision API, Vertex AI APIs, Compute Engine APIs, and Cloud Storage.](https://console.cloud.google.com/flows/enableapi?apiid=vision.googleapis.com,aiplatform.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",
@@ -265,6 +265,17 @@
"**Note**: Jupyter runs lines prefixed with `!` as shell commands, and it interpolates Python variables prefixed with `$`."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "WReHDGG5g0XY"
},
"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`."
]
},
{
"cell_type": "code",
"execution_count": null,
@@ -65,17 +65,6 @@
"This tutorial demonstrates how to use Vertex AI for E2E MLOps on Google Cloud in production. This tutorial covers stage 1 : data management."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dataset:bq,chicago,lbn"
},
"source": [
"### Dataset\n",
"\n",
"The dataset used for this tutorial is the [Chicago Taxi](https://www.kaggle.com/chicago/chicago-taxi-trips-bq). The version of the dataset you will use in this tutorial is stored in a public BigQuery table. The trained model predicts whether someone would leave a tip for a taxi fare."
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -120,6 +109,34 @@
" - Preprocess the data with `Dataflow`"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dataset:bq,chicago,lbn"
},
"source": [
"### Dataset\n",
"\n",
"The dataset used for this tutorial is the [Chicago Taxi](https://www.kaggle.com/chicago/chicago-taxi-trips-bq). The version of the dataset used in this tutorial is stored in a public BigQuery table. The trained model predicts whether someone leaves a tip for a taxi fare."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "9e483012a752"
},
"source": [
"### Costs\n",
"This tutorial uses billable components of Google Cloud:\n",
"\n",
"- Vertex AI\n",
"- Cloud Storage\n",
"- BigQuery\n",
"- Dataflow\n",
"\n",
"Learn about [Vertex AI pricing](https://cloud.google.com/vertex-ai/pricing), [Cloud Storage pricing](https://cloud.google.com/storage/pricing), [BigQuery pricing](https://cloud.google.com/bigquery/pricing), and [Dataflow pricing](https://cloud.google.com/dataflow/pricing) and use the [Pricing Calculator](https://cloud.google.com/products/calculator/) to generate a cost estimate based on your projected usage."
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -154,18 +171,19 @@
"\n",
"ONCE_ONLY = True\n",
"if ONCE_ONLY:\n",
" ! pip3 install -U tensorflow==2.5 $USER_FLAG\n",
" ! pip3 install -U tensorflow-data-validation==1.2 $USER_FLAG\n",
" ! pip3 install -U tensorflow-transform==1.2 $USER_FLAG\n",
" ! pip3 install -U tensorflow-io==0.18 $USER_FLAG\n",
" ! pip3 install --upgrade google-cloud-aiplatform[tensorboard] $USER_FLAG\n",
" ! pip3 install --upgrade google-cloud-pipeline-components $USER_FLAG\n",
" ! pip3 install --upgrade google-cloud-bigquery $USER_FLAG\n",
" ! pip3 install --upgrade google-cloud-logging $USER_FLAG\n",
" ! pip3 install --upgrade apache-beam[gcp] $USER_FLAG\n",
" ! pip3 install --upgrade pyarrow $USER_FLAG\n",
" ! pip3 install --upgrade cloudml-hypertune $USER_FLAG\n",
" ! pip3 install --upgrade kfp $USER_FLAG"
" ! pip3 install -U tensorflow==2.5 $USER_FLAG -q\n",
" ! pip3 install -U tensorflow-data-validation==1.2 $USER_FLAG -q\n",
" ! pip3 install -U tensorflow-transform==1.2 $USER_FLAG -q\n",
" ! pip3 install -U tensorflow-io==0.18 $USER_FLAG -q\n",
" ! pip3 install --upgrade google-cloud-aiplatform[tensorboard] $USER_FLAG -q\n",
" ! pip3 install --upgrade google-cloud-pipeline-components $USER_FLAG -q\n",
" ! pip3 install --upgrade google-cloud-bigquery $USER_FLAG -q\n",
" ! pip3 install --upgrade google-cloud-logging $USER_FLAG -q\n",
" ! pip3 install --upgrade apache-beam[gcp]==2.33.0 $USER_FLAG -q\n",
" ! pip3 install --upgrade pyarrow $USER_FLAG -q\n",
" ! pip3 install --upgrade cloudml-hypertune $USER_FLAG -q\n",
" ! pip3 install --upgrade kfp $USER_FLAG -q\n",
" ! pip3 install future $USER_FLAG -q"
]
},
{
@@ -373,12 +391,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",
@@ -649,7 +666,7 @@
},
"outputs": [],
"source": [
"bqclient = bigquery.Client()"
"bqclient = bigquery.Client(project=PROJECT_ID)"
]
},
{
@@ -772,6 +789,11 @@
"LIMIT = 300000\n",
"YEAR = 2020\n",
"\n",
"# First, create the dataset entry\n",
"dataset = bigquery.Dataset(f\"{PROJECT_ID}.{BQ_DATASET}\")\n",
"dataset.location = \"US\"\n",
"dataset = bqclient.create_dataset(dataset, timeout=30)\n",
"\n",
"query = f\"\"\"\n",
"CREATE OR REPLACE TABLE `{BQ_TABLE_COPY}`\n",
"AS (\n",
@@ -1212,7 +1234,7 @@
"import setuptools\n",
"\n",
"REQUIRED_PACKAGES = [\n",
" \"google-cloud-aiplatform==1.4.2\",\n",
" \"google-cloud-aiplatform\",\n",
" \"tensorflow-transform==1.2.0\",\n",
" \"tensorflow-data-validation==1.2.0\",\n",
"]\n",
+134 -133
View File
@@ -35,20 +35,97 @@ The second stage in MLOps is experimenting in developing one or more baseline mo
### Get Started
[Get Started with Logging](get_started_with_logging.ipynb)
[Get started with Vertex AI Training for Pytorch](get_started_vertex_training_pytorch.ipynb)
```
The steps performed include:
- Use Python logging to log training configuration/results locally.
- Use Google Cloud Logging to log training configuration/results in cloud storage.
- Single node training using a Python package.
- Report accuracy when hyperparameter tuning.
- Save the model artifacts to Cloud Storage using GCSFuse.
- Create a `Vertex AI Model` resource.
```
[Get Started with Vertex Experiments and Vertex ML Metadata](get_started_vertex_experiments.ipynb)
[Get started with prebuilt TFHub models](get_started_with_tfhub_models.ipynb)
```
The steps performed include:
- Download a TensorFlow Hub prebuilt model.
- Add the task component as a classifier for the CIFAR-10 dataset.
- Fine tune locally the model with transfer learning training.
- Construct a custom training script:
- Get training data from TensorFlow Datasets
- Get model architecture from TensorFlow Hub
- Train then model
- Save model artifacts and upload as Vertex AI Model resource.
```
[Get started with Vertex AI TensorBoard](get_started_vertex_tensorboard.ipynb)
```
The steps performed include:
- Create a TensorBoard callback when training a model.
- Using Tensorboard with locally trained model.
- Using Vertex AI TensorBoard with Vertex AI Training.
```
[Get started with TabNet builtin algorithm for training tabular models](get_started_with_tabnet.ipynb)
```
The steps performed include:
- Get the training data.
- Configure training parameters for the `Vertex AI TabNet` container.
- Train the model using `Vertex AI Training` using CSV data.
- Upload the model as a `Vertex AI Model` resource.
- Deploy the `Vertex AI Model` resource to a `Vertex AI Endpoint` resource.
- Make a prediction with the deployed model.
- Hyperparameter tuning the `Vertex AI TabNet` model.
- Train the model using `Vertex AI Training` using BigQuery table.
```
[Get started with Vertex AI Vizier](get_started_vertex_vizier.ipynb)
```
The steps performed include:
- Hyperparameter tuning with Random algorithm.
- Hyperparameter tuning with Vizier (Bayesian) algorithm.
```
[Automl image classfication training with customer managed encryption keys (CMEK)](get_started_with_cmek_training.ipynb)
```
The steps performed include:
- Creating a customer managed encryption key.
- Creating an image dataset with CMEK encryption.
- Train an AutoML model with CMEK encryption.
```
[Get started with Vertex AI distributed training](get_started_vertex_distributed_training.ipynb)
```
The steps performed include:
- `MirroredStrategy`: Train on a single VM with multiple GPUs.
- `MultiWorkerMirroredStrategy`: Train on multiple VMs with automatic setup of replicas.
- `MultiWorkerMirroredStrategy`: Train on multiple VMs with fine grain control of replicas.
- `ReductionServer`: Train on multiple VMS and sync updates across VMS with `Vertex AI Reduction Server`.
- `TPUTraining`: Train with multiple Cloud TPUs.
```
[Get started with Vertex AI Training for scikit-learn](get_started_vertex_training_sklearn.ipynb)
```
The steps performed include:
- Training using a Python package.
- Report accuracy when hyperparameter tuning.
- Save the model artifacts to Cloud Storage using GCSFuse.
- Create a `Vertex AI Model` resource.
```
[Get started with Vertex AI Experiments](get_started_vertex_experiments.ipynb)
```
The steps performed include:
- Local (notebook) Training
- Create an experiment
- Create a first run in the experiment
@@ -67,65 +144,35 @@ The steps performed include:
- Visualize the experiment results
```
[Get Started with Vertex TensorBoard](get_started_vertex_tensorboard.ipynb)
[Get started with Vertex AI Hyperparameter Tuning for XGBoost](get_started_vertex_hpt_xgboost.ipynb)
```
The steps performed include:
- Create a TensorBoard callback when training a model.
- Using Tensorboard with locally trained model.
- Using Vertex AI TensorBoard with Vertex AI Training.
```
[Get Started with Custom Training Packages (Tensorflow)](get_started_vertex_training.ipynb)
```
The steps performed include:
- Training using a single Python script.
- Training using a Python package.
- Training using a custom training image.
- Laying out a training package.
```
[Get Started with Custom Training Packages (Scikit-Learn)](get_started_vertex_training_sklearn.ipynb)
```
The steps performed include:
- Training using a Python package.
- Report accuracy when hyperparameter tuning.
- Save the model artifacts to Cloud Storage using GCSFuse.
- Create a `Vertex AI Model` resource.
```
[Get Started with Custom Training Packages (XGBoost)](get_started_vertex_training_xgboost.ipynb)
[Get started with Vertex AI Feature Store](get_started_vertex_feature_store.ipynb)
```
The steps performed include:
- Training using a Python package.
- Report accuracy when hyperparameter tuning.
- Save the model artifacts to Cloud Storage using GCSFuse.
- Create a `Vertex AI Model` resource.
- Creating a Vertex AI `Featurestore` resource.
- Creating `EntityType` resources for the `Featurestore` resource.
- Creating `Feature` resources for each `EntityType` resource.
- Import feature values (entity data items) into `Featurestore` resource.
- From a Cloud Storage location.
- From a pandas DataFrame.
- Perform online serving from a `Featurestore` resource.
- Perform batch serving from a `Featurestore` resource.
```
[Get Started with Custom Training Packages (Pytorch)](get_started_vertex_training_pytorch.ipynb)
[Get started with Vertex AI Training for R](get_started_vertex_training_r.ipynb)
```
The steps performed include:
- Single node training using a Python package.
- Report accuracy when hyperparameter tuning.
- Save the model artifacts to Cloud Storage using GCSFuse.
- Create a `Vertex AI Model` resource.
```
[Get Started with Custom Training Packages (R)](get_started_vertex_training_r.ipynb)
```
The steps performed include:
- Locally train an R model in a notebook using %%R magic commands
- Create a deployment image with trained R model and serving functions.
- Test the deployment image locally.
@@ -137,70 +184,32 @@ The steps performed include:
- Train a R model using `Vertex AI Trainingh` service with the R-to-Python training package.
```
[Get Started with Custom Training Packages (R) and Deployment in R environment](get_started_vertex_training_r_using_r_kernel.ipynb)
[Get started with logging](get_started_with_logging.ipynb)
```
The steps performed include:
- Use Python logging to log training configuration/results locally.
- Use Google Cloud Logging to log training configuration/results in cloud storage.
```
[Get started with Vertex AI Training for R using R Kernel](get_started_vertex_training_r_using_r_kernel.ipynb)
```
The steps performed include:
- Create a custom R training script
- Create a custom R serving script
- Create a custom R deployment (serving) container.
- Train the model using `Vertex AI` custom training.
- Create an `Endpoint` resource.
- Create an `Endpoint` resouce.
- Deploy the `Model` resource (trained R model) to the `Endpoint` resource.
- Make an online prediction.
```
[Get Started with Custom Training Packages (LightGBM)](get_started_vertex_training_lightgbm.ipynb)
[Get started with BigQuery ML training](get_started_bqml_training.ipynb)
```
The steps performed include:
- Training using a Python package.
- Save the model artifacts to Cloud Storage using GCSFuse.
- Construct a FastAPI prediction server.
- Construct a Dockerfile deployment image.
- Test the deployment image locally.
- Create a `Vertex AI Model` resource.
```
[Get Started with Distributed Training](get_started_vertex_distributed_training.ipynb)
```
The steps performed include:
- `MirroredStrategy`: Train on a single VM with multiple GPUs.
- `MultiWorkerMirroredStrategy`: Train on multiple VMs with automatic setup of replicas.
- `MultiWorkerMirroredStrategy`: Train on multiple VMs with fine grain control of replicas.
- `ReductionServer`: Train on multiple VMS and sync updates across VMS with `Vertex AI Reduction Server`.
- `TPUTraining`: Train with multiple Cloud TPUs.
```
[Get Started with Vizier Hyperparameter Tuning](get_started_vertex_vizier.ipynb)
```
The steps performed include:
- Hyperparameter tuning with Random algorithm.
- Hyperparameter tuning with Vizier (Bayesian) algorithm.
```
[Get Started with AutoML Training](get_started_automl_training.ipynb)
```
The steps performed include:
- Train an image model.
- Export the image model as an edge model.
- Train a tabular model.
- Export the tabular model as a cloud model.
- Train a text model.
```
[Get Started with BQML Training](get_started_bqml_training.ipynb)
```
The steps performed include:
- Create a local BigQuery table in your project
- Train a BQML model
- Evaluate the BQML model
@@ -208,65 +217,59 @@ The steps performed include:
- Upload the exported model as a `Vertex AI Model` resource
- Hyperparameter tune a BQML model with `Vertex AI Vizier`
- Automatically register a BQML model to `Vertex AI Model Registry`
```
[Get Started with Vertex Feature Store](get_started_vertex_feature_store.ipynb)
[Get started with AutoML training](get_started_automl_training.ipynb)
```
The steps performed include:
- Creating a Vertex AI `Featurestore` resource.
- Creating `EntityType` resources for the `Featurestore` resource.
- Creating `Feature` resources for each `EntityType` resource.
- Import feature values (entity data items) into `Featurestore` resource from Cloud Storage.
- Import feature values (entity data items) into `Featurestore` resource from pandas DataFrame.
- Perform online serving from a `Featurestore` resource.
- Perform batch serving from a `Featurestore` resource.
- Train an image model
- Export the image model as an edge model
- Train a tabular model
- Export the tabular model as a cloud model
- Train a text model
- Train a video model
```
[Get Started with Google CMEK Training](get_started_with_cmek_training.ipynb)
[Get started with Vertex AI Training for XGBoost](get_started_vertex_training_xgboost.ipynb)
```
The steps performed include:
- Training using a Python package.
- Report accuracy when hyperparameter tuning.
- Save the model artifacts to Cloud Storage using GCSFuse.
- Create a `Vertex AI Model` resource.
- Creating a customer managed encryption key.
- Creating an image dataset with CMEK encryption.
- Train an AutoML model with CMEK encryption.
```
[Get Started with TensorFlow Hub models](get_started_with_tfhub_models.ipynb)
[Get started with Vertex AI Training](get_started_vertex_training.ipynb)
```
The steps performed include:
- Download a TensorFlow Hub prebuilt model.
- Add the task component as a classifier for the CIFAR-10 dataset.
- Fine tune locally the model with transfer learning training.
- Construct a custom training script:
- Get training data from TensorFlow Datasets
- Get model architecture from TensorFlow Hub
- Train then model
- Save model artifacts and upload as Vertex AI Model resource.
- Training using a single Python script.
- Training using a Python package.
- Training using a custom training image.
- Laying out a training package.
```
[Get Started with Vertex AI TabNet builtin algorithm](get_started_with_tabnet.ipynb)
[Get started with Vertex AI Training for LightGBM](get_started_vertex_training_lightgbm.ipynb)
```
The steps performed include:
- Training using a Python package.
- Save the model artifacts to Cloud Storage using GCSFuse.
- Construct a FastAPI prediction server.
- Construct a Dockerfile deployment image.
- Test the deployment image locally.
- Create a `Vertex AI Model` resource.
- Get the training data.
- Configure training parameters for the Vertex AI TabNet container.
- Train the model using Vertex AI Training using CSV data.
- Upload the model as a Vertex AI Model resource.
- Deploy the Vertex AI Model resource to a Vertex AI Endpoint resource.
- Make a prediction with the deployed model.
- Hyperparameter tuning the Vertex AI TabNet model.
- Train the model using Vertex AI Training using BigQuery table.
```
[Get Started with Vision API and AutoML](get_started_with_visionapi_and_automl.ipynb)
[Get started Vision API test preprocessing and AutoML text model generation](get_started_with_visionapi_and_automl.ipynb)
```
The steps performed include:
- Preprocess training files using `Vision AI` APIs to extract the text from PDF files.
- Create a custom import file that includes annotation data based on the sample `BigQuery` dataset.
- Create a `Vertex AI Dataset` resource.
@@ -277,14 +280,12 @@ The steps performed include:
- Undeploy the `Model`.
```
### E2E Stage Example
[Stage 2: Experimentation](mlops_experimentation.ipynb)
```
The steps performed include:
- Review the `Dataset` resource created during stage 1.
- Train an AutoML tabular binary classifier model in the background.
- Build the experimental model architecture.
@@ -65,52 +65,6 @@
"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 AutoML Training."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dataset:flowers,icn"
},
"source": [
"### Datasets\n",
"\n",
"#### Image\n",
"\n",
"The image 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 in a given image from a class of five flowers: daisy, dandelion, rose, sunflower, or tulip."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dataset:gsod,lrg"
},
"source": [
"#### Tabular\n",
"\n",
"The tabular dataset used for this tutorial is the GSOD dataset from [BigQuery public datasets](https://cloud.google.com/bigquery/public-data). The version of the dataset you use only the fields year, month and day to predict the value of mean daily temperature (mean_temp)."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dataset:happydb,tcn"
},
"source": [
"#### Text\n",
"\n",
"The text dataset used for this tutorial is the [Happy Moments dataset](https://www.kaggle.com/ritresearch/happydb) from [Kaggle Datasets](https://www.kaggle.com/ritresearch/happydb). The version of the dataset you will use in this tutorial is stored in a public Cloud Storage bucket."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "98eb93ec6faa"
},
"source": [
"#### Video\n",
"\n",
"The video dataset used for this tutorial is the golf swing recognition portion of the [Human Motion dataset](https://todo) from [MIT](http://cbcl.mit.edu/publications/ps/Kuehne_etal_iccv11.pdf). The version of the dataset you will use in this tutorial is stored in a public Cloud Storage bucket. The trained model will predict the start frame where a golf swing begins."
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -150,6 +104,31 @@
"* **You want to establish a baseline metric before experimenting with a custom model**"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dataset:flowers,icn"
},
"source": [
"### Datasets\n",
"\n",
"#### Image\n",
"\n",
"The image 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 in this tutorial is stored in a public Cloud Storage bucket. The trained model predicts the type of flower in a given image from a class of five flowers: daisy, dandelion, rose, sunflower, or tulip.\n",
"\n",
"#### Tabular\n",
"\n",
"The tabular dataset used for this tutorial is the GSOD dataset from [BigQuery public datasets](https://cloud.google.com/bigquery/public-data). The version of the dataset you use only the fields year, month and day to predict the value of mean daily temperature (mean_temp).\n",
"\n",
"#### Text\n",
"\n",
"The text dataset used for this tutorial is the [Happy Moments dataset](https://www.kaggle.com/ritresearch/happydb) from [Kaggle Datasets](https://www.kaggle.com/ritresearch/happydb). The version of the dataset you use in this tutorial is stored in a public Cloud Storage bucket.\n",
"\n",
"#### Video\n",
"\n",
"The video dataset used for this tutorial is the golf swing recognition portion of the [Human Motion dataset](https://todo) from [MIT](http://cbcl.mit.edu/publications/ps/Kuehne_etal_iccv11.pdf). The version of the dataset you use in this tutorial is stored in a public Cloud Storage bucket. The trained model predicts the start frame where a golf swing begins."
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -238,6 +217,8 @@
"id": "project_id"
},
"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",
@@ -253,8 +234,15 @@
"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.\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": "5aee4379e8e5"
},
"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`."
@@ -44,7 +44,7 @@
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://raw.githubusercontent.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage2/get_started_bqml_training.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_bqml_training.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",
@@ -65,17 +65,6 @@
"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 BigQuery ML Training."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dataset:penguins,lcn,bq"
},
"source": [
"### Dataset\n",
"\n",
"The dataset used for this tutorial is the Penguins dataset from [BigQuery public datasets](https://cloud.google.com/bigquery/public-data). This version of the dataset is used to predict the species of penguins from the available features like culmen-length, flipper-depth etc."
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -100,8 +89,26 @@
"- Export the BQML 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`\n",
"- Automatically register a BQML model to `Vertex AI Model Registry`"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dataset:penguins,lcn,bq"
},
"source": [
"### Dataset\n",
"\n",
"The dataset used for this tutorial is the Penguins dataset from [BigQuery public datasets](https://cloud.google.com/bigquery/public-data). This version of the dataset is used to predict the species of penguins from the available features like culmen-length, flipper-depth etc."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "81c777b8ad32"
},
"source": [
"### Costs\n",
"This tutorial uses billable components of Google Cloud:\n",
"\n",
@@ -184,6 +191,8 @@
"id": "project_id"
},
"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",
@@ -199,8 +208,15 @@
"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.\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": "56d591439df1"
},
"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`."
@@ -29,7 +29,7 @@
"id": "title:generic,gcp"
},
"source": [
"# E2E ML on GCP: MLOps stage 2 : experimentation: get started with Vertex Distributed Training\n",
"# E2E ML on GCP: MLOps stage 2 : experimentation: get started with Vertex AI Distributed Training\n",
"\n",
"<table align=\"left\">\n",
" <td>\n",
@@ -65,17 +65,6 @@
"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 Distributed Training. Please note: There are incompatibilities between Colab and Docker and the Docker section may not work until resolved by the platform."
]
},
{
"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": {
@@ -106,15 +95,6 @@
"id": "recommendation:mlops,stage2,vertex,distributed_training"
},
"source": [
"### Costs\n",
" \n",
"This tutorial uses billable components of Google Cloud:\n",
"\n",
"Vertex AI\n",
"Cloud Storage\n",
"\n",
"Learn about [Vertex AI pricing](https://cloud.google.com/vertex-ai/pricing) and [Cloud Storage pricing](https://cloud.google.com/storage/pricing), and use the [Pricing Calculator](https://cloud.google.com/products/calculator/),\n",
" to generate a cost estimate based on your projected usage.\n",
"### Recommendations\n",
"\n",
"When doing E2E MLOps on Google Cloud, the following are best practices for when to use Vertex AI Distributed Training:\n",
@@ -138,13 +118,41 @@
"While training across a large number of VMs and the model parameters updates to sync is very large."
]
},
{
"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 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": {
"id": "d10166df7141"
},
"source": [
"### Costs\n",
" \n",
"This tutorial uses billable components of Google Cloud:\n",
"\n",
"Vertex AI\n",
"Cloud Storage\n",
"\n",
"Learn about [Vertex AI pricing](https://cloud.google.com/vertex-ai/pricing) and [Cloud Storage pricing](https://cloud.google.com/storage/pricing), and use the [Pricing Calculator](https://cloud.google.com/products/calculator/),\n",
" to generate a cost estimate based on your projected usage."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "XkYpRvOQyVYb"
},
"source": [
"### Install additional packages\n",
"## Installation\n",
"\n",
"Install the packages required for executing this notebook."
]
@@ -170,7 +178,7 @@
"if IS_WORKBENCH_NOTEBOOK:\n",
" USER_FLAG = \"--user\"\n",
"\n",
"! pip3 install {USER_FLAG} --upgrade google-cloud-aiplatform"
"! pip3 install {USER_FLAG} --upgrade google-cloud-aiplatform -q"
]
},
{
@@ -248,8 +256,6 @@
},
"outputs": [],
"source": [
"import os\n",
"\n",
"PROJECT_ID = \"[your-project-id]\" # @param {type:\"string\"}"
]
},
@@ -130,8 +130,26 @@
"\n",
"#### Experiments\n",
"\n",
"Use Vertex AI Experiments in conjunction with logging when performing experiments to compare results for different experiment configurations.\n",
"Use Vertex AI Experiments in conjunction with logging when performing experiments to compare results for different experiment configurations."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "313c25f2f514"
},
"source": [
"### Dataset\n",
"\n",
"This tutorial does not use a dataset. References to example datasets is for demonstration purposes."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "bd73a4bd07ef"
},
"source": [
"### Costs\n",
"This tutorial uses billable components of Google Cloud:\n",
"\n",
@@ -211,6 +229,8 @@
"id": "project_id"
},
"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",
@@ -226,9 +246,15 @@
"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.\n",
"\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": "1460fd744366"
},
"source": [
"#### Set your project ID\n",
"\n",
"**If you don't know your project ID**, you may be able to get your project ID using `gcloud`."
@@ -29,7 +29,7 @@
"id": "title:generic,gcp"
},
"source": [
"# E2E ML on GCP: MLOps stage 2 : experimentation: get started with Feature Store\n",
"# E2E ML on GCP: MLOps stage 2 : experimentation: get started with Vertex AI Feature Store\n",
"\n",
"<table align=\"left\">\n",
" <td>\n",
@@ -68,19 +68,6 @@
"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 Feature Store."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dataset:movies,lbn,avro"
},
"source": [
"### Dataset\n",
"\n",
"The dataset used for this tutorial is the `Movie Recommendations` dataset. The version of the dataset you will use in this tutorial is stored in a public Cloud Storage bucket, in Avro format.\n",
"\n",
"This dataset is used to predict whether a person will watch a movie or not."
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -107,6 +94,19 @@
"- Perform batch serving from a `Featurestore` resource."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dataset:movies,lbn,avro"
},
"source": [
"### Dataset\n",
"\n",
"The dataset used for this tutorial is the `Movie Recommendations` dataset. The version of the dataset you use in this tutorial is stored in a public Cloud Storage bucket, in Avro format.\n",
"\n",
"This dataset is used to predict whether a person watches a movie or not."
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -194,6 +194,8 @@
"id": "project_id"
},
"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",
File diff suppressed because it is too large Load Diff
@@ -29,7 +29,7 @@
"id": "title:generic,gcp"
},
"source": [
"# E2E ML on GCP: MLOps stage 2 : experimentation: get started with Vertex AI Tensorboard\n",
"# E2E ML on GCP: MLOps stage 2 : experimentation: get started with Vertex AI TensorBoard\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 2 : experimentation: get started with Vertex AI Tensorboard."
"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 TensorBoard."
]
},
{
@@ -83,10 +83,44 @@
"The steps performed include:\n",
"\n",
"- Create a TensorBoard callback when training a model.\n",
"- Using Tensorboard with locally trained model.\n",
"- Using TensorBoard with locally trained model.\n",
"- Using Vertex AI TensorBoard with Vertex AI Training."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "recommendation:mlops,stage2,vertex,tensorboard"
},
"source": [
"### Recommendations\n",
"\n",
"When doing E2E MLOps on Google Cloud, the following are the best practices for visualizing your training with TensorBoard.\n",
"\n",
"#### Local TensorBoard\n",
"\n",
"Use the OSS version of TensorBoard, either command-line or daemon version, when doing ad-hoc training locally.\n",
"\n",
"#### Cloud TensorBoard\n",
"\n",
"Use the tensorboard.dev, when doing training on the cloud -- unless you have a privacy issue.\n",
"\n",
"#### Experiments\n",
"\n",
"Use Vertex AI TensorBoard when you have a privacy issue or doing experiments to compare results for different experiment configurations."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "03bfd1274241"
},
"source": [
"### Dataset\n",
"\n",
"In this tutorial you use the MNIST dataset. The version of the dataset is built into the TF.Keras framework. The dataset predicts which digit an image is, between 0 .. 9."
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -115,8 +149,8 @@
"source": [
"### Set up your local development environment\n",
"\n",
"**If you are using Colab or Google Cloud Notebooks**, your environment already meets\n",
"all the requirements to run this notebook. You can skip this step.\n",
"**If you are using Colab or Vertex AI Workbench Notebooks**, your environment already meets\n",
"all the requirements to run this notebook. \n",
"\n",
"**Otherwise**, make sure your environment meets this notebook's requirements.\n",
"You need the following:\n",
@@ -149,29 +183,6 @@
"1. Open this notebook in the Jupyter Notebook Dashboard.\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "recommendation:mlops,stage2,vertex,tensorboard"
},
"source": [
"### Recommendations\n",
"\n",
"When doing E2E MLOps on Google Cloud, the following are the best practices for visualizing your training with TensorBoard.\n",
"\n",
"#### Local TensorBoard\n",
"\n",
"Use the OSS version of TensorBoard, either command-line or daemon version, when doing ad-hoc training locally.\n",
"\n",
"#### Cloud TensorBoard\n",
"\n",
"Use the Tensorboard.dev, when doing training on the cloud -- unless you have a privacy issue.\n",
"\n",
"#### Experiments\n",
"\n",
"Use Vertex AI TensorBoard when you have a privacy issue or doing experiments to compare results for different experiment configurations."
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -255,7 +266,7 @@
"\n",
"1. [Enable the Vertex AI API](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com). \n",
"\n",
"1. If you are running this notebook locally, you will need to install the [Cloud SDK](https://cloud.google.com/sdk).\n",
"1. If you are running this notebook locally, you need to install the [Cloud SDK](https://cloud.google.com/sdk).\n",
"\n",
"1. Enter your project ID in the cell below. Then run the cell to make sure the\n",
"Cloud SDK uses the right project for all the commands in this notebook.\n",
@@ -774,9 +785,9 @@
"source": [
"## Training with TensorBoard\n",
"\n",
"Tensorboard provides the means to visualize your training in-real time and to visualize the results (metrics).\n",
"TensorBoard provides the means to visualize your training in-real time and to visualize the results (metrics).\n",
"\n",
"You can use Tensorboard in conjunction with local training, cloud training and with `Vertex AI Training`, which is referred to as `Vertex AI TensorBoard`"
"You can use TensorBoard in conjunction with local training, cloud training and with `Vertex AI Training`, which is referred to as `Vertex AI TensorBoard`"
]
},
{
@@ -62,18 +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 Training."
]
},
{
"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."
"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."
]
},
{
@@ -125,6 +114,38 @@
"CustomJob"
]
},
{
"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 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": {
"id": "c480fc50ec3c"
},
"source": [
"### Costs \n",
"\n",
"This tutorial uses billable components of Google Cloud:\n",
"\n",
"* Vertex AI\n",
"* Cloud Storage\n",
"\n",
"\n",
"Learn about [Vertex AI\n",
"pricing](https://cloud.google.com/vertex-ai/pricing) and [Cloud Storage\n",
"pricing](https://cloud.google.com/storage/pricing), and use the [Pricing\n",
"Calculator](https://cloud.google.com/products/calculator/)\n",
"to generate a cost estimate based on your projected usage."
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -209,7 +230,7 @@
"\n",
"3. [Enable the following APIs: Vertex AI APIs, Compute Engine APIs, and Cloud Storage.](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.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",
@@ -29,7 +29,7 @@
"id": "4f82ca678df6"
},
"source": [
"Notebook is a revised version of notebook from [Rajesh Thallam](https://github.com/RajeshThallam/vertex-ai-labs/blob/main/07-vertex-train-deploy-lightgbm/vertex-train-deploy-lightgbm-model.ipynb)"
"This notebook is a revised version of notebook from [Rajesh Thallam](https://github.com/RajeshThallam/vertex-ai-labs/blob/main/07-vertex-train-deploy-lightgbm/vertex-train-deploy-lightgbm-model.ipynb)"
]
},
{
@@ -43,12 +43,12 @@
"<table align=\"left\">\n",
"\n",
" <td>\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/master/notebooks/community/ml_ops/stage2/get_started_vertex_training_lightgbm.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_lightgbm.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/colab-logo-32px.png\" alt=\"Colab logo\"> Run in Colab\n",
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/tree/master/notebooks/ocommunity/ml_ops/stage2/get_started_vertex_training_lightgbm.ipynb\">\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/tree/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",
@@ -56,7 +56,7 @@
" <td>\n",
" <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://raw.githubusercontent.com/GoogleCloudPlatform/vertex-ai-samples/main/notebooks/community/ml_ops/stage2/get_started_vertex_training_lightgbm.ipynb\">\n",
" <img src=\"https://lh3.googleusercontent.com/UiNooY4LUgW_oTvpsNhPpQzsstV5W8F7rYgxgGBD85cWJoLmrOzhVs_ksK_vgx40SHs7jCqkTkCk=e14-rj-sc0xffffff-h130-w32\" alt=\"Vertex AI logo\">\n",
" Run in Vertex Workbench\n",
" Open in Vertex AI Workbench\n",
" </a>\n",
" </td>\n",
"</table>"
@@ -74,17 +74,6 @@
"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 LightGBM."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dataset:iris,lcn"
},
"source": [
"### Dataset\n",
"\n",
"The dataset used for this tutorial is the [Iris dataset](https://www.tensorflow.org/datasets/catalog/iris) from [TensorFlow Datasets](https://www.tensorflow.org/datasets/catalog/overview). This dataset does not require any feature engineering. The version of the dataset you will use in this tutorial is stored in a public Cloud Storage bucket. The trained model predicts the type of Iris flower species from a class of three species: setosa, virginica, or versicolor."
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -107,8 +96,26 @@
"- Construct a FastAPI prediction server.\n",
"- Construct a Dockerfile deployment image.\n",
"- Test the deployment image locally.\n",
"- Create a `Vertex AI Model` resource.\n",
"- Create a `Vertex AI Model` resource."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dataset:iris,lcn"
},
"source": [
"### Dataset\n",
"\n",
"The dataset used for this tutorial is the [Iris dataset](https://www.tensorflow.org/datasets/catalog/iris) from [TensorFlow Datasets](https://www.tensorflow.org/datasets/catalog/overview). This dataset does not require any feature engineering. The version of the dataset in this tutorial is stored in a public Cloud Storage bucket. The trained model predicts the type of Iris flower species from a class of three species: setosa, virginica, or versicolor."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "de76bb18c85b"
},
"source": [
"### Costs \n",
"\n",
"This tutorial uses billable components of Google Cloud:\n",
@@ -131,7 +138,7 @@
"source": [
"### Set up your local development environment\n",
"\n",
"If you are using Colab or Google Cloud Notebooks, your environment already meets all the requirements to run this notebook. You can skip this step.\n",
"If you are using Colab or Vertex AI Workbench Notebooks, your environment already meets all the requirements to run this notebook. You can skip this step.\n",
"\n",
"Otherwise, make sure your environment meets this notebook's requirements. You need the following:\n",
"\n",
@@ -190,19 +197,10 @@
"\n",
"! pip3 install --upgrade google-cloud-aiplatform $USER_FLAG -q\n",
"! pip3 install -U google-cloud-storage $USER_FLAG -q\n",
"! pip3 install -U lightgbm $USER_FLAG -q"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "install_tensorflow"
},
"outputs": [],
"source": [
"! pip3 install -U lightgbm $USER_FLAG -q\n",
"\n",
"if os.getenv(\"IS_TESTING\"):\n",
" ! pip3 install --upgrade tensorflow $USER_FLAG"
" ! pip3 install --upgrade tensorflow $USER_FLAG -q"
]
},
{
@@ -256,7 +254,7 @@
"\n",
"3. [Enable the following APIs: Vertex AI APIs, Compute Engine APIs, and Cloud Storage.](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.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",
@@ -29,7 +29,7 @@
"id": "title:generic,gcp"
},
"source": [
"# E2E ML on GCP: MLOps stage 2 : experimentation: get started with Vertex 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",
@@ -62,18 +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 Training for Pytorch."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dataset:pytorch,cifar10,icn"
},
"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 you will use 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."
"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."
]
},
{
@@ -100,13 +89,24 @@
"- Create a `Vertex AI Model` resource."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dataset:pytorch,cifar10,icn"
},
"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."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "85ee859437ed"
},
"source": [
"## Costs \n",
"### Costs \n",
"\n",
"This tutorial uses billable components of Google Cloud:\n",
"\n",
@@ -128,7 +128,7 @@
"source": [
"### Set up your local development environment\n",
"\n",
"**If you are using Colab or Google Cloud Notebooks**, your environment already meets\n",
"**If you are using Colab or Vertex AI Workbench Notebooks**, your environment already meets\n",
"all the requirements to run this notebook. You can skip this step."
]
},
@@ -65,17 +65,6 @@
"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 R. Please note that this notebook should be ran only in R notebook image (e.g., R4.1)."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dataset:r,iris,lcn"
},
"source": [
"### Dataset\n",
"\n",
"The dataset used for this tutorial is the Iris dataset built into the R package. This dataset does not require any feature engineering. The trained model predicts the type of Iris flower species from a class of three species: setosa, virginica, or versicolor."
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -104,6 +93,17 @@
"- Train a R model using `Vertex AI Trainingh` service with the R-to-Python training package."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dataset:r,iris,lcn"
},
"source": [
"### Dataset\n",
"\n",
"The dataset used for this tutorial is the Iris dataset built into the R package. This dataset does not require any feature engineering. The trained model predicts the type of Iris flower species from a class of three species: setosa, virginica, or versicolor."
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -216,7 +216,7 @@
"\n",
"1. [Enable the Vertex AI API](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com). \n",
"\n",
"1. If you are running this notebook locally, you will need to install the [Cloud SDK](https://cloud.google.com/sdk).\n",
"1. If you are running this notebook locally, you need to install the [Cloud SDK](https://cloud.google.com/sdk).\n",
"\n",
"1. Enter your project ID in the cell below. Then run the cell to make sure the\n",
"Cloud SDK uses the right project for all the commands in this notebook.\n",
@@ -243,8 +243,6 @@
},
"outputs": [],
"source": [
"import os\n",
"\n",
"PROJECT_ID = \"[your-project-id]\" # @param {type:\"string\"}"
]
},
@@ -29,7 +29,7 @@
"id": "e3ba05e16cf2"
},
"source": [
"This is an updated version of a notebook contributed by [Fabian Hirschmann](https://github.com/fhirschmann)."
"This notebook is an updated version of a notebook contributed by [Fabian Hirschmann](https://github.com/fhirschmann)."
]
},
{
@@ -38,15 +38,17 @@
"id": "JAPoU8Sm5E6e"
},
"source": [
"# E2E ML on GCP: MLOps stage 2 : experimentation: get started with Vertex AI Training for R using R Kernel\n",
"\n",
"<table align=\"left\">\n",
"\n",
" <td>\n",
" <a href=\"https://colab.sandbox.google.com/github/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage2/get_started_vertex_training_r_using_r_kernel.ipynb\">\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",
" <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/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage2/get_started_vertex_training_r_using_r_kernel.ipynb\">\n",
" <a href=\"https://github.com/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/github-logo-32px.png\" alt=\"GitHub logo\">\n",
" View on GitHub\n",
" </a>\n",
@@ -63,18 +65,20 @@
{
"cell_type": "markdown",
"metadata": {
"id": "tvgnzT1CKxrO"
"id": "be1799d4f500"
},
"source": [
"## Overview\n",
"\n",
"This example demonstrates how to train and deploy R models with `Vertex AI` using an R kernel -- such as in `Vertex AI Workbench Notebooks`.\n",
"\n",
"### 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",
"\n",
"\n",
"This example demonstrates how to train and deploy R models with `Vertex AI` using an R kernel -- such as in `Vertex AI Workbench Notebooks`."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "tvgnzT1CKxrO"
},
"source": [
"### Objective\n",
"\n",
"In this tutorial, you learn how to use `Vertex AI`, using an R kernel, for training and deploying an R custom model.\n",
@@ -94,9 +98,26 @@
"- Train the model using `Vertex AI` custom training.\n",
"- Create an `Endpoint` resouce.\n",
"- Deploy the `Model` resource (trained R model) to the `Endpoint` resource.\n",
"- Make an online prediction.\n",
"\n",
"- Make an online prediction.\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "e1266da324d2"
},
"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"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "de76bb18c85b"
},
"source": [
"### Costs \n",
"\n",
"This tutorial uses billable components of Google Cloud:\n",
@@ -216,10 +237,10 @@
},
"outputs": [],
"source": [
"required_packages <- c(\"reticulate\", \"glue\", \"httr\")\n",
"required_packages < -c(\"reticulate\", \"glue\", \"httr\")\n",
"install.packages(setdiff(required_packages, rownames(installed.packages())))\n",
"\n",
"sh(\"pip install --upgrade google-cloud-aiplatform\")"
"sh(\"pip3 install --upgrade google-cloud-aiplatform -q\")"
]
},
{
@@ -247,7 +268,7 @@
"\n",
"1. [Enable the Vertex AI API](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com) and the [Artifact Registry API](https://console.cloud.google.com/flows/enableapi?apiid=artifactregistry.googleapis.com).\n",
"\n",
"1. If you are running this notebook locally, you will need to install the [Cloud SDK](https://cloud.google.com/sdk).\n",
"1. If you are running this notebook locally, you need to install the [Cloud SDK](https://cloud.google.com/sdk).\n",
"\n",
"1. Have the project ID autodetected or enter it below. Then run the cell to make sure the\n",
"Cloud SDK uses the right project for all the commands in this notebook."
@@ -272,7 +293,7 @@
},
"outputs": [],
"source": [
"PROJECT_ID <- \"[your-project-id]\" # @param {type:\"string\"}"
"PROJECT_ID < -\"[your-project-id]\" # @param {type:\"string\"}"
]
},
{
@@ -440,8 +461,8 @@
},
"outputs": [],
"source": [
"BUCKET_NAME <- \"[your-bucket-name]\" # @param {type:\"string\"}\n",
"BUCKET_URI <- paste0(\"gs://\", BUCKET_NAME)"
"BUCKET_NAME < -\"[your-bucket-name]\" # @param {type:\"string\"}\n",
"BUCKET_URI < -paste0(\"gs://\", BUCKET_NAME)"
]
},
{
@@ -611,9 +632,11 @@
},
"outputs": [],
"source": [
"PRIVATE_REPO <- \"my-docker-repo\"\n",
"PRIVATE_REPO < -\"my-docker-repo\"\n",
"\n",
"sh(\"gcloud artifacts repositories create {PRIVATE_REPO} --repository-format=docker --location={REGION} --description=\\\"Docker repository\\\"\")\n",
"sh(\n",
" 'gcloud artifacts repositories create {PRIVATE_REPO} --repository-format=docker --location={REGION} --description=\"Docker repository\"'\n",
")\n",
"\n",
"sh(\"gcloud artifacts repositories list\")"
]
@@ -659,11 +682,13 @@
},
"outputs": [],
"source": [
"IMAGE_NAME <- \"vertex-r\" # @param {type:\"string\"}\n",
"IMAGE_TAG <- \"latest\" # @param {type:\"string\"}\n",
"IMAGE_URI <- glue(\"{REGION}-docker.pkg.dev/{PROJECT_ID}/{PRIVATE_REPO}/{IMAGE_NAME}:{IMAGE_TAG}\")\n",
"IMAGE_NAME < -\"vertex-r\" # @param {type:\"string\"}\n",
"IMAGE_TAG < -\"latest\" # @param {type:\"string\"}\n",
"IMAGE_URI < -glue(\n",
" \"{REGION}-docker.pkg.dev/{PROJECT_ID}/{PRIVATE_REPO}/{IMAGE_NAME}:{IMAGE_TAG}\"\n",
")\n",
"\n",
"dir.create(\"src\", showWarnings = FALSE)"
"dir.create(\"src\", showWarnings=FALSE)"
]
},
{
@@ -1051,20 +1076,22 @@
},
"outputs": [],
"source": [
"url <- glue(\"https://{REGION}-aiplatform.googleapis.com/v1/{endpoint$resource_name}:predict\")\n",
"access_token <- sh(\"gcloud auth print-access-token\", intern = TRUE)\n",
"url < -glue(\n",
" \"https://{REGION}-aiplatform.googleapis.com/v1/{endpoint$resource_name}:predict\"\n",
")\n",
"access_token < -sh(\"gcloud auth print-access-token\", intern=TRUE)\n",
"\n",
"sh(\n",
" \"curl\",\n",
" c(\"--tr-encoding\",\n",
" \"-s\",\n",
" \"-X POST\",\n",
" glue(\"-H 'Authorization: Bearer {access_token}'\"),\n",
" \"-H 'Content-Type: application/jsoin'\",\n",
" url,\n",
" glue(\"-d {json_instances}\")\n",
" ),\n",
" \n",
" c(\n",
" \"--tr-encoding\",\n",
" \"-s\",\n",
" \"-X POST\",\n",
" glue(\"-H 'Authorization: Bearer {access_token}'\"),\n",
" \"-H 'Content-Type: application/jsoin'\",\n",
" url,\n",
" glue(\"-d {json_instances}\"),\n",
" ),\n",
")"
]
},
@@ -29,7 +29,7 @@
"id": "title:generic,gcp"
},
"source": [
"# E2E ML on GCP: MLOps stage 2 : experimentation: get started with Vertex Training for Scikit-Learn\n",
"# E2E ML on GCP: MLOps stage 2 : experimentation: get started with Vertex AI Training for Scikit-Learn\n",
"\n",
"<table align=\"left\">\n",
" <td>\n",
@@ -65,17 +65,6 @@
"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 scikit-Learn."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dataset:custom,newsaggr,tcn"
},
"source": [
"### Dataset\n",
"\n",
"The dataset used for this tutorial is the [News Aggregation](https://archive.ics.uci.edu/ml/datasets/News+Aggregator) from [ICS Machine Learning Datasets](https://archive.ics.uci.edu/ml/datasets.php). The trained model predicts the news category of the news article."
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -99,6 +88,17 @@
"- Create a `Vertex AI Model` resource."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dataset:custom,newsaggr,tcn"
},
"source": [
"### Dataset\n",
"\n",
"The dataset used for this tutorial is the [News Aggregation](https://archive.ics.uci.edu/ml/datasets/News+Aggregator) from [ICS Machine Learning Datasets](https://archive.ics.uci.edu/ml/datasets.php). The trained model predicts the news category of the news article."
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -127,7 +127,7 @@
"source": [
"### Set up your local development environment\n",
"\n",
"**If you are using Colab or Google Cloud Notebooks**, your environment already meets\n",
"**If you are using Colab or Vertex AI Workbench Notebooks**, your environment already meets\n",
"all the requirements to run this notebook. You can skip this step.\n",
"\n",
"**Otherwise**, make sure your environment meets this notebook's requirements.\n",
@@ -167,7 +167,7 @@
"id": "install_mlops"
},
"source": [
"### Install additional packages\n",
"## Installation\n",
"\n",
"Install the following packages for executing this notebook."
]
@@ -243,7 +243,7 @@
"\n",
"1. [Enable the Vertex AI API](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com). \n",
"\n",
"1. If you are running this notebook locally, you will need to install the [Cloud SDK](https://cloud.google.com/sdk).\n",
"1. If you are running this notebook locally, you need to install the [Cloud SDK](https://cloud.google.com/sdk).\n",
"\n",
"1. Enter your project ID in the cell below. Then run the cell to make sure the\n",
"Cloud SDK uses the right project for all the commands in this notebook.\n",
@@ -66,17 +66,6 @@
"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 XGBoost."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dataset:iris,lcn"
},
"source": [
"### Dataset\n",
"\n",
"The dataset used for this tutorial is the [Iris dataset](https://www.tensorflow.org/datasets/catalog/iris) from [TensorFlow Datasets](https://www.tensorflow.org/datasets/catalog/overview). This dataset does not require any feature engineering. The version of the dataset you will use in this tutorial is stored in a public Cloud Storage bucket. The trained model predicts the type of Iris flower species from a class of three species: setosa, virginica, or versicolor."
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -97,8 +86,26 @@
"- Training using a Python package.\n",
"- Report accuracy when hyperparameter tuning.\n",
"- Save the model artifacts to Cloud Storage using GCSFuse.\n",
"- Create a `Vertex AI Model` resource.\n",
"- Create a `Vertex AI Model` resource."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dataset:iris,lcn"
},
"source": [
"### Dataset\n",
"\n",
"The dataset used for this tutorial is the [Iris dataset](https://www.tensorflow.org/datasets/catalog/iris) from [TensorFlow Datasets](https://www.tensorflow.org/datasets/catalog/overview). This dataset does not require any feature engineering. The version of the dataset in this tutorial is stored in a public Cloud Storage bucket. The trained model predicts the type of Iris flower species from a class of three species: setosa, virginica, or versicolor."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "4fc0ad661ebb"
},
"source": [
"### Costs \n",
"\n",
"This tutorial uses billable components of Google Cloud:\n",
@@ -149,6 +156,36 @@
"! pip3 install --upgrade google-cloud-aiplatform $USER_FLAG -q"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "oQhwq1iozAxh"
},
"source": [
"### Restart the kernel\n",
"\n",
"After you install the additional packages, you need to restart the notebook kernel so it can find the packages."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "zo3YFZXLzCRJ"
},
"outputs": [],
"source": [
"# Automatically restart kernel after installs\n",
"import os\n",
"\n",
"if not os.getenv(\"IS_TESTING\"):\n",
" # Automatically restart kernel after installs\n",
" import IPython\n",
"\n",
" app = IPython.Application.instance()\n",
" app.kernel.do_shutdown(True)"
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -167,7 +204,7 @@
"\n",
"1. [Enable the Vertex AI API](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com). \n",
"\n",
"1. If you are running this notebook locally, you will need to install the [Cloud SDK](https://cloud.google.com/sdk).\n",
"1. If you are running this notebook locally, you need to install the [Cloud SDK](https://cloud.google.com/sdk).\n",
"\n",
"1. Enter your project ID in the cell below. Then run the cell to make sure the\n",
"Cloud SDK uses the right project for all the commands in this notebook.\n",
@@ -62,18 +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 Vizier."
]
},
{
"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."
"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 Vizier."
]
},
{
@@ -134,6 +123,38 @@
"- multiple of objectives"
]
},
{
"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 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": {
"id": "c480fc50ec3c"
},
"source": [
"### Costs \n",
"\n",
"This tutorial uses billable components of Google Cloud:\n",
"\n",
"* Vertex AI\n",
"* Cloud Storage\n",
"\n",
"\n",
"Learn about [Vertex AI\n",
"pricing](https://cloud.google.com/vertex-ai/pricing) and [Cloud Storage\n",
"pricing](https://cloud.google.com/storage/pricing), and use the [Pricing\n",
"Calculator](https://cloud.google.com/products/calculator/)\n",
"to generate a cost estimate based on your projected usage."
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -166,7 +187,7 @@
"if IS_WORKBENCH_NOTEBOOK:\n",
" USER_FLAG = \"--user\"\n",
"\n",
"! pip3 install --upgrade google-cloud-aiplatform[tensorboard] $USER_FLAG"
"! pip3 install --upgrade google-cloud-aiplatform[tensorboard] $USER_FLAG -q"
]
},
{
@@ -216,7 +237,7 @@
"\n",
"1. [Enable the Vertex AI API](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com). \n",
"\n",
"1. If you are running this notebook locally, you will need to install the [Cloud SDK](https://cloud.google.com/sdk).\n",
"1. If you are running this notebook locally, you need to install the [Cloud SDK](https://cloud.google.com/sdk).\n",
"\n",
"1. Enter your project ID in the cell below. Then run the cell to make sure the\n",
"Cloud SDK uses the right project for all the commands in this notebook.\n",
@@ -1275,7 +1296,8 @@
"Use the class `CustomJob` to create a custom job, such as for hyperparameter tuning, with the following parameters:\n",
"\n",
"- `display_name`: A human readable name for the custom job.\n",
"- `worker_pool_specs`: The specification for the corresponding VM instances."
"- `worker_pool_specs`: The specification for the corresponding VM instances.\n",
"- `base_output_dir`: The Cloud Storage location for storing the model artifacts."
]
},
{
@@ -1287,7 +1309,9 @@
"outputs": [],
"source": [
"job = aip.CustomJob(\n",
" display_name=\"boston_\" + TIMESTAMP, worker_pool_specs=worker_pool_spec\n",
" display_name=\"boston_\" + TIMESTAMP,\n",
" worker_pool_specs=worker_pool_spec,\n",
" base_output_dir=MODEL_DIR,\n",
")"
]
},
@@ -1420,6 +1444,32 @@
"print(best)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "get_best_model"
},
"source": [
"### Get the Best Model\n",
"\n",
"If you used the method of having the service tell the tuning script where to save the model artifacts (`DIRECT = False`), then the model artifacts for the best model are saved at:\n",
"\n",
" MODEL_DIR/<best_trial_id>/model"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "get_best_model"
},
"outputs": [],
"source": [
"BEST_MODEL_DIR = MODEL_DIR + \"/\" + best[0] + \"/model\"\n",
"\n",
"! gsutil ls {BEST_MODEL_DIR}"
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -64,17 +64,6 @@
"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 AutoML training with a customer managed encyrption key CMEK."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dataset:flowers,icn"
},
"source": [
"### Dataset\n",
"\n",
"The dataset used for this tutorial is the [Flowers dataset](https://www.tensorflow.org/datasets/catalog/tf_flowers) from [TensorFlow](https://www.tensorflow.org/datasets/catalog/overview). The version of the dataset you will use in this tutorial is stored in a public #(GCS) bucket. The trained model predicts the type of flower an image is from a class of five flowers: daisy, dandelion, rose, sunflower, or tulip.\n"
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -97,6 +86,17 @@
"- Train an AutoML model with CMEK encryption."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dataset:flowers,icn"
},
"source": [
"### Dataset\n",
"\n",
"The dataset used for this tutorial is the [Flowers dataset](https://www.tensorflow.org/datasets/catalog/tf_flowers) from [TensorFlow](https://www.tensorflow.org/datasets/catalog/overview). The version of the dataset in this tutorial is stored in a public #(GCS) bucket. The trained model predicts the type of flower an image is from a class of five flowers: daisy, dandelion, rose, sunflower, or tulip.\n"
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -207,7 +207,7 @@
"\n",
"1. [Enable the Vertex AI API](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com). \n",
"\n",
"1. If you are running this notebook locally, you will need to install the [Cloud SDK](https://cloud.google.com/sdk).\n",
"1. If you are running this notebook locally, you need to install the [Cloud SDK](https://cloud.google.com/sdk).\n",
"\n",
"1. Enter your project ID in the cell below. Then run the cell to make sure the\n",
"Cloud SDK uses the right project for all the commands in this notebook.\n",
@@ -105,8 +105,26 @@
"\n",
"#### Experiments\n",
"\n",
"Use Vertex AI Experiments in conjunction with logging when performing experiments to compare results for different experiment configurations.\n",
"Use Vertex AI Experiments in conjunction with logging when performing experiments to compare results for different experiment configurations."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "5341f31587c8"
},
"source": [
"### Dataset\n",
"\n",
"This tutorial does not use a dataset. References to example datasets is for demonstration purposes."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "41512a89f379"
},
"source": [
"### Costs\n",
"This tutorial uses billable components of Google Cloud:\n",
"\n",
@@ -185,6 +203,8 @@
"id": "project_id"
},
"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",
@@ -200,9 +220,15 @@
"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.\n",
"\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": "5aee4379e8e5"
},
"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`."
@@ -39,7 +39,7 @@
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samplestree/main/notebooks/community/ml_ops/stage2/get_started_with_tabnet.ipynb\">\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage2/get_started_with_tabnet.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",
@@ -67,15 +67,18 @@
"\n",
"TabNet uses a machine learning technique called sequential attention to select which model features to reason from at each step in the model. This mechanism makes it possible to explain how the model arrives at its predictions and helps it learn more accurate models. TabNet not only outperforms other neural networks and decision trees but also provides interpretable feature attributions. \n",
"\n",
"Research paper: [TabNet: Attentive Interpretable Tabular Learning](https://arxiv.org/pdf/1908.07442.pdf)\n",
"\n",
"### Dataset\n",
"\n",
"This tutorial uses the `petfinder` in the public Cloud Storage bucket `gs://cloud-samples-data/ai-platform-unified/datasets/tabular/`, which was generated from the [PetFinder.my Adoption Prediction](https://www.kaggle.com/c/petfinder-adoption-prediction). This dataset predicts how quickly an animal will be adopted.\n",
"\n",
"Research paper: [TabNet: Attentive Interpretable Tabular Learning](https://arxiv.org/pdf/1908.07442.pdf)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "c5040751873a"
},
"source": [
"### Objective\n",
"\n",
"In this notebook, you will learn how to run `Vertex AI TabNet` built algorithm for training custom tabular models.\n",
"In this notebook, you learn how to run `Vertex AI TabNet` built algorithm for training custom tabular models.\n",
"\n",
"This tutorial uses the following Google Cloud ML services and resources:\n",
"\n",
@@ -93,11 +96,28 @@
"- Deploy the `Vertex AI Model` resource to a `Vertex AI Endpoint` resource.\n",
"- Make a prediction with the deployed model.\n",
"- Hyperparameter tuning the `Vertex AI TabNet` model.\n",
"- Train the model using `Vertex AI Training` using BigQuery table.\n",
"- Train the model using `Vertex AI Training` using BigQuery table."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "ac8c8586ab03"
},
"source": [
"### Dataset\n",
"\n",
"This tutorial uses the `petfinder` in the public Cloud Storage bucket `gs://cloud-samples-data/ai-platform-unified/datasets/tabular/`, which was generated from the [PetFinder.my Adoption Prediction](https://www.kaggle.com/c/petfinder-adoption-prediction). This dataset predicts how quickly an animal is adopted.\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "4fc0ad661ebb"
},
"source": [
"### Costs \n",
"\n",
"\n",
"This tutorial uses billable components of Google Cloud:\n",
"\n",
"* Vertex AI\n",
@@ -143,8 +163,8 @@
"if IS_WORKBENCH_NOTEBOOK:\n",
" USER_FLAG = \"--user\"\n",
"\n",
"! pip3 install {USER_FLAG} --upgrade tensorflow\n",
"! pip3 install {USER_FLAG} --upgrade google-cloud-aiplatform tensorboard-plugin-profile\n",
"! pip3 install {USER_FLAG} --upgrade tensorflow -q\n",
"! pip3 install {USER_FLAG} --upgrade google-cloud-aiplatform tensorboard-plugin-profile -q\n",
"! gcloud components update --quiet"
]
},
@@ -200,7 +220,7 @@
"\n",
"3. [Enable the following APIs: Vertex AI APIs, Compute Engine APIs, and Cloud Storage.](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.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",
@@ -65,17 +65,6 @@
"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 prebuilt TensorFlow Hub (TFHub) models."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dataset:flowers,icn"
},
"source": [
"### Dataset\n",
"\n",
"The dataset used for this tutorial is the [CIFAR10 dataset](https://www.tensorflow.org/datasets/catalog/cifar10) from [TensorFlow Datasets](https://www.tensorflow.org/datasets/catalog/overview). The version of the dataset you will use 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, truck."
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -103,6 +92,17 @@
" - Save model artifacts and upload as Vertex AI Model resource."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dataset:flowers,icn"
},
"source": [
"### Dataset\n",
"\n",
"The dataset used for this tutorial is the [CIFAR10 dataset](https://www.tensorflow.org/datasets/catalog/cifar10) from [TensorFlow Datasets](https://www.tensorflow.org/datasets/catalog/overview). 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, truck."
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -157,27 +157,8 @@
" USER_FLAG = \"\"\n",
"\n",
"! pip3 install --upgrade google-cloud-aiplatform $USER_FLAG -q\n",
"! pip3 install tensorflow-datasets $USER_FLAG -q"
]
},
{
"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"
"! pip3 install tensorflow-datasets $USER_FLAG -q\n",
"! pip3 install -U google-cloud-storage $USER_FLAG -q"
]
},
{
@@ -231,7 +212,7 @@
"\n",
"3. [Enable the following APIs: Vertex AI APIs, Compute Engine APIs, and Cloud Storage.](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.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",
@@ -29,7 +29,7 @@
"id": "3f8c2f702ccd"
},
"source": [
"This is an updated version of a notebook contributed by [Mohammad Al-Ansari](https://github.com/Mansari). Special thanks to [Andrew Ferlitsch](https://github.com/andrewferlitsch) for his reviews and edits.\n",
"This notebook is an updated version of a notebook contributed by [Mohammad Al-Ansari](https://github.com/Mansari). Special thanks to [Andrew Ferlitsch](https://github.com/andrewferlitsch) for his reviews and edits.\n",
"\n",
"This is an extension of the [Vertex AI SDK for Python: AutoML training text entity extraction model for online prediction notebook](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/automl/sdk_automl_text_entity_extraction_online.ipynb) originally co-authored by [Andrew Ferlitsch](https://github.com/andrewferlitsch) and [\n",
"Karl Weinmeister](https://github.com/kweinmeister). This version add the use of `Vision API` and `BigQuery` to preprocess a `Vertex AI AutoML` dataset for text entity extraction model training."
@@ -76,21 +76,6 @@
"This tutorial demonstrates how to use `BigQuery`, `Vision AI`, and `Vertex AI SDK` for Python to train a text entity extraction model based on existing training data."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dataset:biomedical,ten"
},
"source": [
"### Dataset\n",
"\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",
"\n",
"The data is published as a [public dataset](https://cloud.google.com/bigquery/public-data) on `BigQuery`."
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -99,7 +84,7 @@
"source": [
"### Objective\n",
"\n",
"In this tutorial, you create an `AutoML` text entity extraction model pre-existing extracted data by generating a custom import file. You will deploy this mode for online prediction from a Python script using the `BigQuery`, `Vision AI`, Cloud Storage and `Vertex AI SDK` for Python. You can alternatively create and deploy models using the `gcloud` command-line tool or online using the Cloud Console.\n",
"In this tutorial, you create an `AutoML` text entity extraction model pre-existing extracted data by generating a custom import file. You deploy this mode for online prediction from a Python script using the `BigQuery`, `Vision AI`, Cloud Storage and `Vertex AI SDK` for Python. You can alternatively create and deploy models using the `gcloud` command-line tool or online using the Cloud Console.\n",
"\n",
"Using existing training data that have been previously annotated can be very useful in training a model, as it allows you to use a larger data set with minimal resources.\n",
"\n",
@@ -121,6 +106,21 @@
"- Undeploy the `Model`."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dataset:biomedical,ten"
},
"source": [
"### Dataset\n",
"\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",
"\n",
"The data is published as a [public dataset](https://cloud.google.com/bigquery/public-data) on `BigQuery`."
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -151,7 +151,7 @@
"source": [
"### Set up your local development environment\n",
"\n",
"If you are using Colab or Google Cloud Notebooks, your environment already meets all the requirements to run this notebook. You can skip this step.\n",
"If you are using Colab or Vertex AI Workbench Notebooks, your environment already meets all the requirements to run this notebook. \n",
"\n",
"Otherwise, make sure your environment meets this notebook's requirements. You need the following:\n",
"\n",
@@ -265,7 +265,7 @@
"\n",
"3. [Enable the following APIs: BigQuery APIs, Vision API, Vertex AI APIs, Compute Engine APIs, and Cloud Storage.](https://console.cloud.google.com/flows/enableapi?apiid=bigquery.googleapis.com,vision.googleapis.com,aiplatform.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",
@@ -273,6 +273,17 @@
"**Note**: Jupyter runs lines prefixed with `!` as shell commands, and it interpolates Python variables prefixed with `$`."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "WReHDGG5g0XY"
},
"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`."
]
},
{
"cell_type": "code",
"execution_count": null,
@@ -65,17 +65,6 @@
"This tutorial demonstrates how to use Vertex AI for E2E MLOps on Google Cloud in production. This tutorial covers stage 2 : experimentation."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dataset:bq,chicago,lbn"
},
"source": [
"### Dataset\n",
"\n",
"The dataset used for this tutorial is the [Chicago Taxi](https://www.kaggle.com/chicago/chicago-taxi-trips-bq). The version of the dataset you will use in this tutorial is stored in a public BigQuery table. The trained model predicts whether someone would leave a tip for a taxi fare."
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -160,6 +149,39 @@
" - If greater then baseline, then upload model as the new baseline and save evaluation results with the model."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dataset:bq,chicago,lbn"
},
"source": [
"### Dataset\n",
"\n",
"The dataset used for this tutorial is the [Chicago Taxi](https://www.kaggle.com/chicago/chicago-taxi-trips-bq). The version of the dataset in this tutorial is stored in a public BigQuery table. The trained model predicts whether someone leaves a tip for a taxi fare."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "costs"
},
"source": [
"### Costs\n",
"\n",
"This tutorial uses billable components of Google Cloud:\n",
"\n",
"* BigQuery\n",
"* Vision API\n",
"* Vertex AI\n",
"* Cloud Storage\n",
"\n",
"Learn about [Vertex AI\n",
"pricing](https://cloud.google.com/vertex-ai/pricing), [Vision API pricing](https://cloud.google.com/vision/pricing), [BigQuery pricing](https://cloud.google.com/bigquery/pricing), [Cloud Storage\n",
"pricing](https://cloud.google.com/storage/pricing), and use the [Pricing\n",
"Calculator](https://cloud.google.com/products/calculator/)\n",
"to generate a cost estimate based on your projected usage."
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -194,20 +216,20 @@
"\n",
"ONCE_ONLY = False\n",
"if ONCE_ONLY:\n",
" ! pip3 install -U tensorflow==2.5 $USER_FLAG\n",
" ! pip3 install -U tensorflow-data-validation==1.2 $USER_FLAG\n",
" ! pip3 install -U tensorflow-transform==1.2 $USER_FLAG\n",
" ! pip3 install -U tensorflow-io==0.18 $USER_FLAG\n",
" ! pip3 install --upgrade google-cloud-aiplatform[tensorboard] $USER_FLAG\n",
" ! pip3 install --upgrade google-cloud-pipeline-components $USER_FLAG\n",
" ! pip3 install --upgrade google-cloud-bigquery $USER_FLAG\n",
" ! pip3 install --upgrade google-cloud-logging $USER_FLAG\n",
" ! pip3 install --upgrade apache-beam[gcp] $USER_FLAG\n",
" ! pip3 install --upgrade pyarrow $USER_FLAG\n",
" ! pip3 install --upgrade cloudml-hypertune $USER_FLAG\n",
" ! pip3 install --upgrade kfp $USER_FLAG\n",
" ! pip3 install --upgrade torchvision $USER_FLAG\n",
" ! pip3 install --upgrade rpy2 $USER_FLAG"
" ! pip3 install -U tensorflow==2.5 $USER_FLAG -q\n",
" ! pip3 install -U tensorflow-data-validation==1.2 $USER_FLAG -q\n",
" ! pip3 install -U tensorflow-transform==1.2 $USER_FLAG -q\n",
" ! pip3 install -U tensorflow-io==0.18 $USER_FLAG -q\n",
" ! pip3 install --upgrade google-cloud-aiplatform[tensorboard] $USER_FLAG -q\n",
" ! pip3 install --upgrade google-cloud-pipeline-components $USER_FLAG -q\n",
" ! pip3 install --upgrade google-cloud-bigquery $USER_FLAG -q\n",
" ! pip3 install --upgrade google-cloud-logging $USER_FLAG -q\n",
" ! pip3 install --upgrade apache-beam[gcp] $USER_FLAG -q\n",
" ! pip3 install --upgrade pyarrow $USER_FLAG -q\n",
" ! pip3 install --upgrade cloudml-hypertune $USER_FLAG -q\n",
" ! pip3 install --upgrade kfp $USER_FLAG -q\n",
" ! pip3 install --upgrade torchvision $USER_FLAG -q\n",
" ! pip3 install --upgrade rpy2 $USER_FLAG -q"
]
},
{
@@ -257,7 +279,7 @@
"\n",
"1. [Enable the Vertex AI API](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com). \n",
"\n",
"1. If you are running this notebook locally, you will need to install the [Cloud SDK](https://cloud.google.com/sdk).\n",
"1. If you are running this notebook locally, you need to install the [Cloud SDK](https://cloud.google.com/sdk).\n",
"\n",
"1. Enter your project ID in the cell below. Then run the cell to make sure the\n",
"Cloud SDK uses the right project for all the commands in this notebook.\n",
+158 -162
View File
@@ -33,170 +33,10 @@ The third stage in MLOps is formalization to develop an automated pipeline proce
### Get Started
[Get Started with Kubeflow pipelines](get_started_with_kubeflow_pipelines.ipynb)
[Get started with AutoML Tabular Pipeline Workflows](get_started_with_automl_tabular_pipeline_workflow.ipynb)
```
The steps performed include:
- Building KFP lightweight Python function components.
- Assembling and compiling KFP components into a pipeline.
- Executing a KFP pipeline using Vertex AI Pipelines.
- Loading component and pipeline definitions from a source code repository.
- Building sequential, parallel, multiple output components.
- Building control flow into pipelines.
```
[Get Started with BQ and TFDV components](get_started_with_bq_tfdv_pipeline_components.ipynb)
```
The steps performed include:
- Build and execute a pipeline component for creating a Vertex AI Tabular Dataset from a BigQuery table.
- Build and execute a pipeline component for generating TFDV statistics and schema from a Vertex AI Tabular Dataset.
- Execute a Vertex AI pipeline.
```
[Get Started with Dataflow components](get_started_with_dataflow_pipeline_components.ipynb)
```
The steps performed include:
- Build an Apache Beam data pipeline.
- Encapsulate the Apache Beam data pipeline with a Dataflow component in a Vertex AI pipeline.
- Execute a Vertex AI pipeline.
```
[Get Started with Dataproc components](get_started_with_dataproc_pipeline_components.ipynb)
```
The steps performed include:
- DataprocPySparkBatchOp for PySpark batch workloads.
- DataprocSparkBatchOp for Spark batch workloads.
- DataprocSparkSqlBatchOp for running Spark SQL batch workloads.
- DataprocSparkRBatchOp for running SparkR batch workloads.
```
[Get Started with Vertex AI AutoML components](get_started_with_automl_pipeline_components.ipynb)
```
The steps performed include:
- Construct a pipeline for:
- Training a Vertex AI AutoML trained model.
- Test the serving binary with a batch prediction job.
- Deploying a Vertex AI AutoML trained model.
- Execute a Vertex AI pipeline.
```
[Get Started with Vertex AI Custom Training components](get_started_with_custom_training_pipeline_components.ipynb)
```
The steps performed include:
- Construct a pipeline for:
- Training a Vertex AI custom trained model.
- Test the serving binary with a batch prediction job.
- Deploying a Vertex AI custom trained model.
- Execute a Vertex AI pipeline.
```
[Get Started with Vertex AI Hyperparameter Tuning components](get_started_with_hpt_pipeline_components.ipynb)
```
The steps performed include:
- Construct a pipeline for:
- Hyperparameter tune/train a custom model.
- Retrieve the tuned hyperparameter values and metrics to optimize.
- If the metrics exceed a specified threshold.
- Get the location of the model artifacts for the best tuned model.
- Upload the model artifacts to a `Vertex AI Model` resource.
- Execute a Vertex AI pipeline.
```
[Get Started with BQML components](get_started_with_bqml_pipeline_components.ipynb)
```
The steps performed include:
- Construct a pipeline for:
- Training BigQuery ML model.
- Evaluating the BigQuery ML model.
- Exporting the BigQuery ML model.
- Importing the BigQuery ML model to a Vertex AI model.
- Deploy the Vertex AI model.
- Execute a Vertex AI pipeline.
- Make a prediction with the deployed Vertex AI model.
```
[Get Started with rapid prototyping with BQML and AutoML components](get_started_with_rapid_prototyping_bqml_automl.ipynb)
```
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.
```
[Get Started with TFX Pipelines with Vertex AI](get_started_with_tfx_pipeline.ipynb)
```
The steps performed include:
- Create a TFX e2e pipeline.
- Execute the pipeline locally.
- Execute the pipeline on Google Cloud using `Vertex AI Training`
- Execute the pipeline using `Vertex AI Pipelines`.
```
[Get Started with machine management](get_started_with_machine_management.ipynb)
```
The steps performed in this tutorial include:
- Create a custom component with a self-contained training job.
- Execute pipeline using component-level settings for machine resources
- Convert the self-contained training componnt into a Vertex AI CustomJob.
- Execute pipeline using customjob-level settings for machine resources
```
[Get Started with Apache Airflow and Vertex AI Pipelines](get_started_with_airflow_and_vertex_pipelines.ipynb)
```
The steps performed in this tutorial include:
- Create Cloud Composer environment.
- Upload Airflow DAG to Composer environment that performs data processing -- i.e., creates a BigQuery table from a CSV file.
- Create a Vertex Pipeline that triggers the Airflow DAG.
- Execute the `Vertex AI Pipeline`.
```
[Get Started with Vertex AI Model Registry](get_started_with_model_registry.ipynb)
```
The steps performed in this tutorial include:
- Create and register a first version of a model to `Vertex AI Model Registry`
- Create and register a second version of a model to `Vertex AI Model Registry`
- List all versions of a `Model` resource.
- Change the default version of a `Model` resource`
- Deploy the default version of a `Model` resource.
- Delete a model version from a `Model` resource.
- Delete a `Model` resource along with all model versions.
```
[Get Started with AutoML Tabular Pipeline Workflow](get_started_with_automl_tabular_pipeline_workflow.ipynb)
```
The steps performed in this tutorial include:
- Define training specification.
- Dataset specification
- Hyperparameter overide specification
@@ -208,15 +48,170 @@ The steps performed in this tutorial include:
- Create `Endpoint` resource.
- Deploy exported OSS TF model.
- Make a prediction.
```
[Get started with Vertex AI Model Registry](get_started_with_model_registry.ipynb)
```
The steps performed include:
- Create and register a first version of a model to `Vertex AI Model Registry`.
- Create and register a second version of a model to `Vertex AI Model Registry`.
- Updating the model version which is the default (blessed).
- Deleting a model version.
- Retraining the next model version.
```
[Get started with Dataproc serverless pipeline components](get_started_with_dataproc_serverless_pipeline_components.ipynb)
```
The steps performed include:
- `DataprocPySparkBatchOp` for running PySpark batch workloads.
- `DataprocSparkBatchOp` for running Spark batch workloads.
- `DataprocSparkSqlBatchOp` for running Spark SQL batch workloads.
- `DataprocSparkRBatchOp` for running SparkR batch workloads.
```
[Get started with TFX pipelines](get_started_with_tfx_pipeline.ipynb)
```
The steps performed include:
- Create a TFX e2e pipeline.
- Execute the pipeline locally.
- Execute the pipeline on Google Cloud using `Vertex AI Training`
- Execute the pipeline using `Vertex AI Pipelines`.
```
[Get started with Vertex AI Hyperparameter Tuning pipeline components](get_started_with_hpt_pipeline_components.ipynb)
```
The steps performed include:
- Construct a pipeline for:
- Hyperparameter tune/train a custom model.
- Retrieve the tuned hyperparameter values and metrics to optimize.
- If the metrics exceed a specified threshold.
- Get the location of the model artifacts for the best tuned model.
- Upload the model artifacts to a `Vertex AI Model` resource.
- Execute a Vertex AI pipeline.
```
[Get started with Apache Airflow and Vertex AI Pipelines](get_started_with_airflow_and_vertex_pipelines.ipynb)
```
The steps performed include:
- Create Cloud Composer environment.
- Upload Airflow DAG to Composer environment that performs data processing -- i.e., creates a BigQuery table from a CSV file.
- Create a `Vertex AI Pipeline` that triggers the Airflow DAG.
- Execute the `Vertex AI Pipeline`.
```
[Get started with Vertex AI custom training pipeline components](get_started_with_custom_training_pipeline_components.ipynb)
```
The steps performed include:
- Construct a pipeline for:
- Training a Vertex AI custom trained model.
- Test the serving binary with a batch prediction job.
- Deploying a Vertex AI custom trained model.
- Execute a Vertex AI pipeline.
- Construct a pipeline for:
- Construct a custom training component.
- Convert custom training component to CustomTrainingJobOp.
- Training a Vertex AI custom trained model using the converted component.
- Deploying a Vertex AI custom trained model.
- Execute a Vertex AI pipeline.
```
[Get started with AutoML pipeline components](get_started_with_automl_pipeline_components.ipynb)
```
The steps performed include:
- Construct a pipeline for:
- Training a Vertex AI AutoML trained model.
- Test the serving binary with a batch prediction job.
- Deploying a Vertex AI AutoML trained model.
- Execute a Vertex AI pipeline.
```
[Get started with Kubeflow pipelines](get_started_with_kubeflow_pipelines.ipynb)
```
The steps performed include:
- Building KFP lightweight Python function components.
- Assembling and compiling KFP components into a pipeline.
- Executing a KFP pipeline using Vertex AI Pipelines.
- Loading component and pipeline definitions from a source code repository.
- Building sequential, parallel, multiple output components.
- Building control flow into pipelines.
```
[Get started with machine management for Vertex AI Pipelines](get_started_with_machine_management.ipynb)
```
The steps performed in this tutorial include:
- Create a custom component with a self-contained training job.
- Execute pipeline using component-level settings for machine resources
- Convert the self-contained training component into a `Vertex AI CustomJob`.
- Execute pipeline using customjob-level settings for machine resources
```
[Get started with BigQuery and TFDV pipeline components](get_started_with_bq_tfdv_pipeline_components.ipynb)
```
The steps performed include:
- Build and execute a pipeline component for creating a Vertex AI Tabular Dataset from a BigQuery table.
- Build and execute a pipeline component for generating TFDV statistics and schema from a Vertex AI Tabular Dataset.
- Execute a Vertex AI pipeline.
```
[Get started with Dataflow pipeline components](get_started_with_dataflow_pipeline_components.ipynb)
```
The steps performed include:
- Build an Apache Beam data pipeline.
- Encapsulate the Apache Beam data pipeline with a Dataflow component in a Vertex AI pipeline.
- Execute a Vertex AI pipeline.
```
[Get started with BigQuery ML pipeline components](get_started_with_bqml_pipeline_components.ipynb)
```
The steps performed include:
- Construct a pipeline for:
- Training BigQuery ML model.
- Evaluating the BigQuery ML model.
- Exporting the BigQuery ML model.
- Importing the BigQuery ML model to a Vertex AI model.
- Deploy the Vertex AI model.
- Execute a Vertex AI pipeline.
- Make a prediction with the deployed Vertex AI model.
```
[Get started with rapid prototyping with AutoML and BigQuery ML](get_started_with_rapid_prototyping_bqml_automl.ipynb)
```
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.
```
### E2E Stage Example
[Stage 3: Formalization](mlops_formalization.ipynb)
```
The steps performed include:
- Obtain resources from the experimentation stage.
- Baseline model.
- Dataset schema/statistics for baseline model.
@@ -229,3 +224,4 @@ The steps performed include:
- Create the Vertex AI Model base model.
- Formalize a training pipeline.
```
@@ -64,17 +64,6 @@
"This tutorial demonstrates how to use Vertex AI for E2E MLOps on Google Cloud in production. This tutorial covers stage 3 : formalization: get started with Apache Airflow and Vertex AI Pipelines."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dataset:flowers,icn"
},
"source": [
"### Dataset\n",
"\n",
"The dataset used for this tutorial is [Condensed Game Data](gs://example-datasets/game_data_condensed.csv), which comes from the [Apache Beam examples](https://github.com/apache/beam/tree/master/sdks/python/apache_beam/examples/complete/game). The version used in this tutorial is stored in a Cloud Storage bucket."
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -97,16 +86,35 @@
"- Create Cloud Composer environment.\n",
"- Upload Airflow DAG to Composer environment that performs data processing -- i.e., creates a BigQuery table from a CSV file.\n",
"- Create a `Vertex AI Pipeline` that triggers the Airflow DAG.\n",
"- Execute the `Vertex AI Pipeline`.\n",
"- Execute the `Vertex AI Pipeline`."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dataset:flowers,icn"
},
"source": [
"### Dataset\n",
"\n",
"The dataset used for this tutorial is [Condensed Game Data](gs://example-datasets/game_data_condensed.csv), which comes from the [Apache Beam examples](https://github.com/apache/beam/tree/master/sdks/python/apache_beam/examples/complete/game). The version used in this tutorial is stored in a Cloud Storage bucket."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "b8a374d1a7dc"
},
"source": [
"### Costs\n",
"\n",
"This tutorial uses billable components of Google Cloud:\n",
"\n",
"- Vertex AI\n",
"- Cloud Storage\n",
"- BigQuery\n",
"\n",
"Learn about [Vertex AI pricing](https://cloud.google.com/vertex-ai/pricing) and [Cloud Storage pricing](https://cloud.google.com/storage/pricing) and use the [Pricing Calculator](https://cloud.google.com/products/calculator/) to generate a cost estimate based on your projected usage."
"Learn about [Vertex AI pricing](https://cloud.google.com/vertex-ai/pricing), [Cloud Storage pricing](https://cloud.google.com/storage/pricing) and [BigQuery pricing](https://cloud.google.com/bigquery/pricing) and use the [Pricing Calculator](https://cloud.google.com/products/calculator/) to generate a cost estimate based on your projected usage."
]
},
{
@@ -182,6 +190,8 @@
"id": "ce9e86b26403"
},
"source": [
"#### Check package versions\n",
"\n",
"Check that you have correctly installed the packages. The KFP SDK version should be >=1.6:"
]
},
@@ -203,6 +213,8 @@
"id": "BF1j6f9HApxa"
},
"source": [
"## Before you begin\n",
"\n",
"### Set up your Google Cloud project\n",
"\n",
"**The following steps are required, regardless of your notebook environment.**\n",
@@ -213,7 +225,7 @@
"\n",
"1. [Enable the Vertex AI](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com) and [Composer API](https://console.cloud.google.com/flows/enableapi?apiid=composer.googleapis.com).\n",
"\n",
"1. If you are running this notebook locally, you will need to install the [Cloud SDK](https://cloud.google.com/sdk).\n",
"1. If you are running this notebook locally, you need to install the [Cloud SDK](https://cloud.google.com/sdk).\n",
"\n",
"1. Enter your project ID in the cell below. Then run the cell to make sure the\n",
"Cloud SDK uses the right project for all the commands in this notebook.\n",
@@ -747,7 +759,7 @@
"source": [
"# This code is modified version of https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/composer/rest/get_client_id.py\n",
"\n",
"shell_output=! python3 get_composer_config.py $PROJECT_ID $REGION $COMPOSER_ENV_NAME\n",
"shell_output = ! python3 get_composer_config.py $PROJECT_ID $REGION $COMPOSER_ENV_NAME\n",
"COMPOSER_WEB_URI = shell_output[0]\n",
"COMPOSER_DAG_GCS = shell_output[1]\n",
"COMPOSER_CLIENT_ID = shell_output[2]\n",
@@ -977,7 +989,7 @@
" dag_name: str,\n",
" composer_client_id: str,\n",
" composer_webserver_id: str,\n",
" response: Output[Artifact]\n",
" response: Output[Artifact],\n",
"):\n",
" # [START composer_trigger]\n",
"\n",
@@ -988,10 +1000,9 @@
" 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",
" 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",
@@ -1008,13 +1019,13 @@
" \"\"\"\n",
"\n",
" # Form webserver URL to make REST API calls\n",
" webserver_url = f'{composer_webserver_id}/api/experimental/dags/{dag_name}/dag_runs'\n",
" webserver_url = f\"{composer_webserver_id}/api/experimental/dags/{dag_name}/dag_runs\"\n",
" # print(webserver_url)\n",
"\n",
" # This code is copied from\n",
" # https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/iap/make_iap_request.py\n",
" # START COPIED IAP CODE\n",
" def make_iap_request(url, client_id, method='GET', **kwargs):\n",
" def make_iap_request(url, client_id, method=\"GET\", **kwargs):\n",
" \"\"\"Makes a request to an application protected by Identity-Aware Proxy.\n",
" Args:\n",
" url: The Identity-Aware Proxy-protected URL to fetch.\n",
@@ -1028,8 +1039,8 @@
" The page body, or raises an exception if the page couldn't be retrieved.\n",
" \"\"\"\n",
" # Set the default timeout, if missing\n",
" if 'timeout' not in kwargs:\n",
" kwargs['timeout'] = 90\n",
" if \"timeout\" not in kwargs:\n",
" kwargs[\"timeout\"] = 90\n",
"\n",
" # Obtain an OpenID Connect (OIDC) token from metadata server or using service\n",
" # account.\n",
@@ -1039,32 +1050,41 @@
" # Authorization header containing \"Bearer \" followed by a\n",
" # Google-issued OpenID Connect token for the service account.\n",
" resp = requests.request(\n",
" method, url,\n",
" headers={'Authorization': 'Bearer {}'.format(\n",
" google_open_id_connect_token)}, **kwargs)\n",
" method,\n",
" url,\n",
" headers={\"Authorization\": \"Bearer {}\".format(google_open_id_connect_token)},\n",
" **kwargs,\n",
" )\n",
" if resp.status_code == 403:\n",
" raise Exception('Service account does not have permission to '\n",
" 'access the IAP-protected application.')\n",
" raise Exception(\n",
" \"Service account does not have permission to \"\n",
" \"access the IAP-protected application.\"\n",
" )\n",
" elif resp.status_code != 200:\n",
" raise Exception(\n",
" 'Bad response from application: {!r} / {!r} / {!r}'.format(\n",
" resp.status_code, resp.headers, resp.text))\n",
" \"Bad response from application: {!r} / {!r} / {!r}\".format(\n",
" resp.status_code, resp.headers, resp.text\n",
" )\n",
" )\n",
" else:\n",
" print(f\"response = {resp.text}\")\n",
" # not executed when testing locally\n",
" if response:\n",
" file_path = os.path.join(response.path)\n",
" os.makedirs(file_path)\n",
" with open(os.path.join(file_path, \"airflow_response.json\"), 'w') as f:\n",
" with open(os.path.join(file_path, \"airflow_response.json\"), \"w\") as f:\n",
" json.dump(resp.text, f)\n",
"\n",
" # END COPIED IAP CODE\n",
"\n",
" \n",
" # Make a POST request to IAP which then Triggers the DAG\n",
" make_iap_request(\n",
" webserver_url, composer_client_id, method='POST', json={\"conf\": data, \"replace_microseconds\": 'false'})\n",
" \n",
" webserver_url,\n",
" composer_client_id,\n",
" method=\"POST\",\n",
" json={\"conf\": data, \"replace_microseconds\": \"false\"},\n",
" )\n",
"\n",
" # [END composer_trigger]"
]
},
@@ -1094,7 +1114,7 @@
" dag_name=COMPOSER_DAG_NAME,\n",
" composer_client_id=COMPOSER_CLIENT_ID,\n",
" composer_webserver_id=COMPOSER_WEB_URI,\n",
" response=None\n",
" response=None,\n",
" )\n",
"except Exception as e:\n",
" print(e)"
@@ -1121,12 +1141,13 @@
},
"outputs": [],
"source": [
"PATH=%env PATH\n",
"PATH = %env PATH\n",
"%env PATH={PATH}:/home/jupyter/.local/bin\n",
"\n",
"PIPELINE_ROOT = f\"{BUCKET_URI}/pipeline_root/\"\n",
"print(PIPELINE_ROOT)\n",
"\n",
"\n",
"@dsl.pipeline(\n",
" name=\"pipeline-trigger-airflow-dag\",\n",
" description=\"Trigger Airflow DAG from Vertex AI Pipelines\",\n",
@@ -1140,7 +1161,7 @@
" data_processing_task = trigger_airflow_dag(\n",
" dag_name=data_processing_task_dag_name,\n",
" composer_client_id=COMPOSER_CLIENT_ID,\n",
" composer_webserver_id=COMPOSER_WEB_URI\n",
" composer_webserver_id=COMPOSER_WEB_URI,\n",
" )"
]
},
@@ -1171,9 +1192,8 @@
" display_name=\"airflow_pipeline\",\n",
" template_path=\"pipeline-trigger-airflow-dag.json\",\n",
" pipeline_root=PIPELINE_ROOT,\n",
" parameter_values={\n",
" },\n",
" enable_caching=False\n",
" parameter_values={},\n",
" enable_caching=False,\n",
")\n",
"\n",
"pipeline.run()\n",
@@ -1213,7 +1233,7 @@
},
"outputs": [],
"source": [
"COMPOSER_WEB_URI + '/admin/airflow/tree?dag_id=dag_gcs_to_bq_orch'"
"COMPOSER_WEB_URI + \"/admin/airflow/tree?dag_id=dag_gcs_to_bq_orch\""
]
},
{
@@ -65,17 +65,6 @@
"This tutorial demonstrates how to use Vertex AI for E2E MLOps on Google Cloud in production. This tutorial covers stage 3 : formalization: get started with AutoML pipeline components."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dataset:flowers,icn"
},
"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 in the given image from the five classes of flowers: daisy, dandelion, rose, sunflower, or tulip."
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -100,8 +89,26 @@
" - Training a Vertex AI AutoML trained model.\n",
" - Test the serving binary with a batch prediction job.\n",
" - Deploying a Vertex AI AutoML trained model.\n",
"- Execute a Vertex AI pipeline.\n",
"- Execute a Vertex AI pipeline.\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dataset:flowers,icn"
},
"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 in this tutorial is stored in a public Cloud Storage bucket. The trained model predicts the type of flower in the given image from the five classes of flowers: daisy, dandelion, rose, sunflower, or tulip."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "eef426a35e17"
},
"source": [
"### Costs\n",
"This tutorial uses billable components of Google Cloud:\n",
"\n",
@@ -186,6 +193,8 @@
"id": "BF1j6f9HApxa"
},
"source": [
"## Before you begin\n",
"\n",
"### Set up your Google Cloud project\n",
"\n",
"**The following steps are required, regardless of your notebook environment.**\n",
@@ -196,7 +205,7 @@
"\n",
"1. [Enable the Vertex AI API](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com).\n",
"\n",
"1. If you are running this notebook locally, you will need to install the [Cloud SDK](https://cloud.google.com/sdk).\n",
"1. If you are running this notebook locally, you need to install the [Cloud SDK](https://cloud.google.com/sdk).\n",
"\n",
"1. Enter your project ID in the cell below. Then run the cell to make sure the\n",
"Cloud SDK uses the right project for all the commands in this notebook.\n",
@@ -33,18 +33,18 @@
"\n",
"<table align=\"left\">\n",
" <td>\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/master/notebooks/community/ml_ops/stage3/get_started_with_automl_tabular_pipeline_workflow.ipynb\">\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage3/get_started_with_automl_tabular_pipeline_workflow.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/colab-logo-32px.png\" alt=\"Colab logo\"> Run in Colab\n",
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/master/notcommunity/ml_ops/stage3ebooks/community/ml_ops/stage3/get_started_with_automl_tabular_pipeline_workflow.ipynb\">\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage3/get_started_with_automl_tabular_pipeline_workflow.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/master/notebooks/official/automl/get_started_with_automl_tabular_pipeline_workflow.ipynb\">\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",
" <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",
@@ -65,17 +65,6 @@
"This tutorial demonstrates how to use Vertex AI for E2E MLOps on Google Cloud in production. This tutorial covers stage 3 : formalization: get started with AutoML Tabular pipeline template."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dataset:iris,lcn"
},
"source": [
"### Dataset\n",
"\n",
"The dataset used for this tutorial is the [Iris dataset](https://www.tensorflow.org/datasets/catalog/iris) from [TensorFlow Datasets](https://www.tensorflow.org/datasets/catalog/overview). This dataset does not require any feature engineering. The version of the dataset you will use in this tutorial is stored in a public Cloud Storage bucket. The trained model predicts the type of Iris flower species from a class of three species: setosa, virginica, or versicolor."
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -105,8 +94,26 @@
"- Export AutoML model as an OSS TF model.\n",
"- Create `Endpoint` resource.\n",
"- Deploy exported OSS TF model.\n",
"- Make a prediction.\n",
"- Make a prediction."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dataset:iris,lcn"
},
"source": [
"### Dataset\n",
"\n",
"The dataset used for this tutorial is the [Iris dataset](https://www.tensorflow.org/datasets/catalog/iris) from [TensorFlow Datasets](https://www.tensorflow.org/datasets/catalog/overview). This dataset does not require any feature engineering. The version of the dataset in this tutorial is stored in a public Cloud Storage bucket. The trained model predicts the type of Iris flower species from a class of three species: setosa, virginica, or versicolor."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "4fc0ad661ebb"
},
"source": [
"### Costs \n",
"\n",
"This tutorial uses billable components of Google Cloud:\n",
@@ -212,7 +219,7 @@
"\n",
"3. [Enable the following APIs: Vertex AI APIs, Dataflow APIs, Compute Engine APIs, and Cloud Storage.](https://console.cloud.google.com/flows/enableapi?apiid=ml.googleapis.com,dataflow.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",
@@ -220,32 +227,6 @@
"**Note**: Jupyter runs lines prefixed with `!` as shell commands, and it interpolates Python variables prefixed with `$`."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "zebLBGXOky2A"
},
"source": [
"## Notes about service account and permission\n",
"\n",
"**By default no configuration is required**, if you run into any permission related issue, please make sure the service accounts above have the required roles:\n",
"\n",
"|Service account email|Description|Roles|\n",
"|---|---|---|\n",
"|PROJECT_NUMBER-compute@developer.gserviceaccount.com|Compute Engine default service account|Dataflow Admin, Dataflow Worker, Storage Admin, BigQuery Admin, Vertex AI User|\n",
"|service-PROJECT_NUMBER@gcp-sa-aiplatform.iam.gserviceaccount.com|AI Platform Service Agent|Vertex AI Service Agent|\n",
"\n",
"\n",
"1. Goto https://console.cloud.google.com/iam-admin/iam.\n",
"2. Check the \"Include Google-provided role grants\" checkbox.\n",
"3. Find the above emails.\n",
"4. Grant the corresponding roles.\n",
"\n",
"### Using data source from a different project\n",
"- For the BQ data source, grant both service accounts the \"BigQuery Data Viewer\" role.\n",
"- For the CSV data source, grant both service accounts the \"Storage Object Viewer\" role.\n"
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -519,6 +500,32 @@
"! rm gcs_lifecycle.tmp"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "zebLBGXOky2A"
},
"source": [
"### Notes about service account and permission\n",
"\n",
"**By default no configuration is required**, if you run into any permission related issue, please make sure the service accounts above have the required roles:\n",
"\n",
"|Service account email|Description|Roles|\n",
"|---|---|---|\n",
"|PROJECT_NUMBER-compute@developer.gserviceaccount.com|Compute Engine default service account|Dataflow Admin, Dataflow Worker, Storage Admin, BigQuery Admin, Vertex AI User|\n",
"|service-PROJECT_NUMBER@gcp-sa-aiplatform.iam.gserviceaccount.com|AI Platform Service Agent|Vertex AI Service Agent|\n",
"\n",
"\n",
"1. Goto https://console.cloud.google.com/iam-admin/iam.\n",
"2. Check the \"Include Google-provided role grants\" checkbox.\n",
"3. Find the above emails.\n",
"4. Grant the corresponding roles.\n",
"\n",
"### Using data source from a different project\n",
"- For the BQ data source, grant both service accounts the \"BigQuery Data Viewer\" role.\n",
"- For the CSV data source, grant both service accounts the \"Storage Object Viewer\" role.\n"
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -65,17 +65,6 @@
"This tutorial demonstrates how to use Vertex AI for E2E MLOps on Google Cloud in production. This tutorial covers stage 3 : formalization: get started with BigQuery and TFDV pipeline components."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dataset:gsod,lrg"
},
"source": [
"### Dataset\n",
"\n",
"The dataset used for this tutorial is the GSOD dataset from [BigQuery public datasets](https://cloud.google.com/bigquery/public-data). The version of the dataset you use only the fields year, month and day to predict the value of mean daily temperature (mean_temp)."
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -84,7 +73,7 @@
"source": [
"### Objective\n",
"\n",
"In this tutorial, you learn how to use build lightweight Python components for BigQuery and Tensorflow Data Validation.\n",
"In this tutorial, you learn how to use build lightweight Python components for BigQuery and TensorFlow Data Validation.\n",
"\n",
"This tutorial uses the following Google Cloud ML services:\n",
"\n",
@@ -99,26 +88,31 @@
"- Execute a Vertex AI pipeline."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dataset:gsod,lrg"
},
"source": [
"### Dataset\n",
"\n",
"The dataset used for this tutorial is the GSOD dataset from [BigQuery public datasets](https://cloud.google.com/bigquery/public-data). The version of the dataset you use only the fields year, month and day to predict the value of mean daily temperature (mean_temp)."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "0c997d8d92ce"
},
"source": [
"### Costs \n",
"\n",
"\n",
"### Costs\n",
"This tutorial uses billable components of Google Cloud:\n",
"\n",
"* Vertex AI\n",
"* Cloud Storage\n",
"- Vertex AI\n",
"- Cloud Storage\n",
"- BigQuery\n",
"\n",
"\n",
"Learn about [Vertex AI\n",
"pricing](https://cloud.google.com/vertex-ai/pricing) and [Cloud Storage\n",
"pricing](https://cloud.google.com/storage/pricing), and use the [Pricing\n",
"Calculator](https://cloud.google.com/products/calculator/)\n",
"to generate a cost estimate based on your projected usage."
"Learn about [Vertex AI pricing](https://cloud.google.com/vertex-ai/pricing), [Cloud Storage pricing](https://cloud.google.com/storage/pricing) and [BigQuery pricing](https://cloud.google.com/bigquery/pricing) and use the [Pricing Calculator](https://cloud.google.com/products/calculator/) to generate a cost estimate based on your projected usage."
]
},
{
@@ -193,6 +187,8 @@
"id": "BF1j6f9HApxa"
},
"source": [
"## Before you begin\n",
"\n",
"### Set up your Google Cloud project\n",
"\n",
"**The following steps are required, regardless of your notebook environment.**\n",
@@ -203,7 +199,7 @@
"\n",
"1. [Enable the Vertex AI API](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com,dataflow.googleapis.com).\n",
"\n",
"1. If you are running this notebook locally, you will need to install the [Cloud SDK](https://cloud.google.com/sdk).\n",
"1. If you are running this notebook locally, you need to install the [Cloud SDK](https://cloud.google.com/sdk).\n",
"\n",
"1. Enter your project ID in the cell below. Then run the cell to make sure the\n",
"Cloud SDK uses the right project for all the commands in this notebook.\n",
@@ -230,8 +226,6 @@
},
"outputs": [],
"source": [
"import os\n",
"\n",
"PROJECT_ID = \"[your-project-id]\" # @param {type:\"string\"}"
]
},
@@ -65,17 +65,6 @@
"This tutorial demonstrates how to use Vertex AI for E2E MLOps on Google Cloud in production. This tutorial covers stage 3 : formalization: get started with BigQuery ML pipeline components."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dataset:penguins,lcn,bq"
},
"source": [
"### Dataset\n",
"\n",
"The dataset used for this tutorial is the Penguins dataset from [BigQuery public datasets](https://cloud.google.com/bigquery/public-data). The version of the dataset predicts the species."
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -105,26 +94,31 @@
"- Make a prediction with the deployed Vertex AI model."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dataset:penguins,lcn,bq"
},
"source": [
"### Dataset\n",
"\n",
"The dataset used for this tutorial is the Penguins dataset from [BigQuery public datasets](https://cloud.google.com/bigquery/public-data). The version of the dataset predicts the species."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "0c997d8d92ce"
},
"source": [
"### Costs \n",
"\n",
"\n",
"### Costs\n",
"This tutorial uses billable components of Google Cloud:\n",
"\n",
"* Vertex AI\n",
"* Cloud Storage\n",
"- Vertex AI\n",
"- Cloud Storage\n",
"- BigQuery\n",
"\n",
"\n",
"Learn about [Vertex AI\n",
"pricing](https://cloud.google.com/vertex-ai/pricing) and [Cloud Storage\n",
"pricing](https://cloud.google.com/storage/pricing), and use the [Pricing\n",
"Calculator](https://cloud.google.com/products/calculator/)\n",
"to generate a cost estimate based on your projected usage."
"Learn about [Vertex AI pricing](https://cloud.google.com/vertex-ai/pricing), [Cloud Storage pricing](https://cloud.google.com/storage/pricing) and [BigQuery pricing](https://cloud.google.com/bigquery/pricing) and use the [Pricing Calculator](https://cloud.google.com/products/calculator/) to generate a cost estimate based on your projected usage."
]
},
{
@@ -201,6 +195,8 @@
"id": "BF1j6f9HApxa"
},
"source": [
"## Before you begin\n",
"\n",
"### Set up your Google Cloud project\n",
"\n",
"**The following steps are required, regardless of your notebook environment.**\n",
@@ -211,7 +207,7 @@
"\n",
"1. [Enable the Vertex AI API](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com,dataflow.googleapis.com).\n",
"\n",
"1. If you are running this notebook locally, you will need to install the [Cloud SDK](https://cloud.google.com/sdk).\n",
"1. If you are running this notebook locally, you need to install the [Cloud SDK](https://cloud.google.com/sdk).\n",
"\n",
"1. Enter your project ID in the cell below. Then run the cell to make sure the\n",
"Cloud SDK uses the right project for all the commands in this notebook.\n",
@@ -238,8 +234,6 @@
},
"outputs": [],
"source": [
"import os\n",
"\n",
"PROJECT_ID = \"[your-project-id]\" # @param {type:\"string\"}"
]
},
@@ -29,7 +29,7 @@
"id": "title:generic,gcp"
},
"source": [
"# E2E ML on GCP: MLOps stage 3 : formalization: get started with custom training pipeline components\n",
"# E2E ML on GCP: MLOps stage 3 : formalization: get started with Vertex AI custom training pipeline components\n",
"\n",
"<table align=\"left\">\n",
" <td>\n",
@@ -65,17 +65,6 @@
"This tutorial demonstrates how to use Vertex AI for E2E MLOps on Google Cloud in production. This tutorial covers stage 3 : formalization: get started with custom training pipeline components."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dataset:flowers,icn"
},
"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."
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -109,6 +98,17 @@
"- Execute a Vertex AI pipeline."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dataset:flowers,icn"
},
"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 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."
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -204,6 +204,8 @@
"id": "BF1j6f9HApxa"
},
"source": [
"## Before you begin\n",
"\n",
"### Set up your Google Cloud project\n",
"\n",
"**The following steps are required, regardless of your notebook environment.**\n",
@@ -214,7 +216,7 @@
"\n",
"1. [Enable the Vertex AI API](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com,dataflow.googleapis.com).\n",
"\n",
"1. If you are running this notebook locally, you will need to install the [Cloud SDK](https://cloud.google.com/sdk).\n",
"1. If you are running this notebook locally, you need to install the [Cloud SDK](https://cloud.google.com/sdk).\n",
"\n",
"1. Enter your project ID in the cell below. Then run the cell to make sure the\n",
"Cloud SDK uses the right project for all the commands in this notebook.\n",
@@ -241,8 +243,6 @@
},
"outputs": [],
"source": [
"import os\n",
"\n",
"PROJECT_ID = \"[your-project-id]\" # @param {type:\"string\"}"
]
},
@@ -67,17 +67,6 @@
"This tutorial demonstrates how to use Vertex AI for E2E MLOps on Google Cloud in production. This tutorial covers stage 3 : formalization: get started with Dataflow pipeline components."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dataset:gsod,lrg"
},
"source": [
"### Dataset\n",
"\n",
"The dataset used for this tutorial is the GSOD dataset from [BigQuery public datasets](https://cloud.google.com/bigquery/public-data). The version of the dataset you use only the fields year, month and day to predict the value of mean daily temperature (mean_temp)."
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -101,6 +90,39 @@
"- Execute a Vertex AI pipeline."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dataset:gsod,lrg"
},
"source": [
"### Dataset\n",
"\n",
"The dataset used for this tutorial is the GSOD dataset from [BigQuery public datasets](https://cloud.google.com/bigquery/public-data). The version of the dataset you use only the fields year, month and day to predict the value of mean daily temperature (mean_temp)."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "0c997d8d92ce"
},
"source": [
"### Costs\n",
"\n",
"This tutorial uses billable components of Google Cloud:\n",
"\n",
"* Vertex AI\n",
"* Cloud Storage\n",
"* Dataflow\n",
"\n",
"Learn about [Vertex AI\n",
"pricing](https://cloud.google.com/vertex-ai/pricing), [Cloud Storage\n",
"pricing](https://cloud.google.com/storage/pricing), and [Dataflow pricing](https://cloud.google.com/dataflow/pricing)\n",
"and use the [Pricing\n",
"Calculator](https://cloud.google.com/products/calculator/)\n",
"to generate a cost estimate based on your projected usage."
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -176,6 +198,8 @@
"id": "BF1j6f9HApxa"
},
"source": [
"## Before you begin\n",
"\n",
"### Set up your Google Cloud project\n",
"\n",
"**The following steps are required, regardless of your notebook environment.**\n",
@@ -186,7 +210,7 @@
"\n",
"1. [Enable the Vertex AI API and Dataflow API](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com,dataflow.googleapis.com).\n",
"\n",
"1. If you are running this notebook locally, you will need to install the [Cloud SDK](https://cloud.google.com/sdk).\n",
"1. If you are running this notebook locally, you need to install the [Cloud SDK](https://cloud.google.com/sdk).\n",
"\n",
"1. Enter your project ID in the cell below. Then run the cell to make sure the\n",
"Cloud SDK uses the right project for all the commands in this notebook.\n",
@@ -213,24 +237,7 @@
},
"outputs": [],
"source": [
"import os\n",
"\n",
"PROJECT_ID = \"\"\n",
"\n",
"if not os.getenv(\"IS_TESTING\"):\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": "markdown",
"metadata": {
"id": "37c0a68ff20d"
},
"source": [
"Otherwise, set your project ID here."
"PROJECT_ID = \"[your-project-id]\" # @param {type:\"string\"}"
]
},
{
@@ -241,8 +248,22 @@
},
"outputs": [],
"source": [
"if PROJECT_ID == \"\" or PROJECT_ID is None:\n",
" PROJECT_ID = \"[your-project-id]\" # @param {type:\"string\"}"
"if PROJECT_ID == \"\" or PROJECT_ID is None or PROJECT_ID == \"[your-project-id]\":\n",
" # Get your GCP project id from gcloud\n",
" shell_output = ! gcloud config list --format 'value(core.project)' 2>/dev/null\n",
" PROJECT_ID = shell_output[0]\n",
" print(\"Project ID:\", PROJECT_ID)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "250cb8c648d5"
},
"outputs": [],
"source": [
"! gcloud config set project $PROJECT_ID"
]
},
{
@@ -29,7 +29,7 @@
"id": "title:generic,gcp"
},
"source": [
"# E2E ML on GCP: MLOps stage 3 : formalization: get started with Datproc Serverless pipeline components\n",
"# E2E ML on GCP: MLOps stage 3 : formalization: get started with Dataproc Serverless pipeline components\n",
"\n",
"<table align=\"left\">\n",
" <td>\n",
@@ -80,12 +80,31 @@
"- `Google Cloud Pipeline Components`\n",
"- `Dataproc Serverless`\n",
"\n",
"An example pipeline is provided for each Dataproc Serverless component, which includes:\n",
"The steps performed include:\n",
"\n",
"- `DataprocPySparkBatchOp` for running PySpark batch workloads.\n",
"- `DataprocSparkBatchOp` for running Spark batch workloads.\n",
"- `DataprocSparkSqlBatchOp` for running Spark SQL batch workloads.\n",
"- `DataprocSparkRBatchOp` for running SparkR batch workloads.\n",
"- `DataprocSparkRBatchOp` for running SparkR batch workloads."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "4ced09c1b4ce"
},
"source": [
"### Dataset\n",
"\n",
"No dataset is used in this tutorial. References to an example dataset are for demonstration purposes."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "25697c6fccd3"
},
"source": [
"### Costs\n",
"This tutorial uses billable components of Google Cloud:\n",
"\n",
@@ -96,23 +115,6 @@
"Learn about [Vertex AI pricing](https://cloud.google.com/vertex-ai/pricing), [Dataproc Serverless pricing](https://cloud.google.com/dataproc-serverless/pricing) and [Cloud Storage pricing](https://cloud.google.com/storage/pricing) and use the [Pricing Calculator](https://cloud.google.com/products/calculator/) to generate a cost estimate based on your projected usage."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "bucket:mbsdk"
},
"source": [
"### Before you begin\n",
"\n",
"**Before proceeding, you should complete the following pre-requisites:**\n",
"\n",
"* [Configure your project for Vertex AI Pipelines](https://cloud.google.com/vertex-ai/docs/pipelines/configure-project).\n",
"\n",
"* [Enable the Dataproc API](https://console.cloud.google.com/flows/enableapi?apiid=dataproc.googleleapis.com) in your project.\n",
"\n",
"* Ensure your project meets the networking requirements detailed in [Dataproc Serverless for Spark network configuration](https://cloud.google.com/dataproc-serverless/docs/concepts/network)."
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -197,7 +199,13 @@
"\n",
"1. [Enable the Vertex AI API](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com).\n",
"\n",
"1. If you are running this notebook locally, you will need to install the [Cloud SDK](https://cloud.google.com/sdk).\n",
"1. [Configure your project for Vertex AI Pipelines](https://cloud.google.com/vertex-ai/docs/pipelines/configure-project).\n",
"\n",
"1. [Enable the Dataproc API](https://console.cloud.google.com/flows/enableapi?apiid=dataproc.googleleapis.com) in your project.\n",
"\n",
"1. Ensure your project meets the networking requirements detailed in [Dataproc Serverless for Spark network configuration](https://cloud.google.com/dataproc-serverless/docs/concepts/network).\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",
@@ -29,7 +29,7 @@
"id": "title:generic,gcp"
},
"source": [
"# E2E ML on GCP: MLOps stage 3 : formalization: get started with Hyperparameter Tuning pipeline components\n",
"# E2E ML on GCP: MLOps stage 3 : formalization: get started with Vertex AI Hyperparameter Tuning pipeline components\n",
"\n",
"<table align=\"left\">\n",
" <td>\n",
@@ -46,7 +46,7 @@
" <td>\n",
" <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://raw.githubusercontent.com/GoogleCloudPlatform/vertex-ai-samples/main/notebooks/community/ml_ops/stage3/get_started_with_hpt_pipeline_components.ipynb\">\n",
" <img src=\"https://lh3.googleusercontent.com/UiNooY4LUgW_oTvpsNhPpQzsstV5W8F7rYgxgGBD85cWJoLmrOzhVs_ksK_vgx40SHs7jCqkTkCk=e14-rj-sc0xffffff-h130-w32\" alt=\"Vertex AI logo\">\n",
" Open in Google Cloud Notebooks\n",
" Open in Vertex AI Workbench\n",
" </a>\n",
" </td>\n",
"</table>\n",
@@ -62,18 +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 3 : formalization: get started with Hyperparameter Tuning pipeline components."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dataset:horses_or_humans,icn"
},
"source": [
"### Dataset\n",
"\n",
"The dataset used for this tutorial is the [Horses or Humans](https://www.tensorflow.org/datasets/catalog/horses_or_humans) from [TensorFlow Datasets](https://www.tensorflow.org/datasets/catalog/overview). The trained model predicts whether an image is a horse or human being."
"This tutorial demonstrates how to use Vertex AI for E2E MLOps on Google Cloud in production. This tutorial covers stage 3 : formalization: get started with Vertex AI Hyperparameter Tuning pipeline components."
]
},
{
@@ -100,8 +89,26 @@
" - If the metrics exceed a specified threshold.\n",
" - Get the location of the model artifacts for the best tuned model.\n",
" - Upload the model artifacts to a `Vertex AI Model` resource.\n",
"- Execute a Vertex AI pipeline.\n",
"- Execute a Vertex AI pipeline."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dataset:horses_or_humans,icn"
},
"source": [
"### Dataset\n",
"\n",
"The dataset used for this tutorial is the [Horses or Humans](https://www.tensorflow.org/datasets/catalog/horses_or_humans) from [TensorFlow Datasets](https://www.tensorflow.org/datasets/catalog/overview). The trained model predicts whether an image is a horse or human being."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "5e2eba58ad71"
},
"source": [
"### Costs \n",
"\n",
"This tutorial uses billable components of Google Cloud:\n",
@@ -204,7 +211,7 @@
"\n",
"1. [Enable the Vertex AI API](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com).\n",
"\n",
"1. If you are running this notebook locally, you will need to install the [Cloud SDK](https://cloud.google.com/sdk).\n",
"1. If you are running this notebook locally, you need to install the [Cloud SDK](https://cloud.google.com/sdk).\n",
"\n",
"1. Enter your project ID in the cell below. Then run the cell to make sure the\n",
"Cloud SDK uses the right project for all the commands in this notebook.\n",
@@ -87,8 +87,26 @@
"- Executing a KFP pipeline using Vertex AI Pipelines.\n",
"- Loading component and pipeline definitions from a source code repository.\n",
"- Building sequential, parallel, multiple output components.\n",
"- Building control flow into pipelines.\n",
"- Building control flow into pipelines."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "4ced09c1b4ce"
},
"source": [
"### Dataset\n",
"\n",
"No dataset is used in this tutorial. References to an example dataset are for demonstration purposes."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "eef426a35e17"
},
"source": [
"### Costs\n",
"This tutorial uses billable components of Google Cloud:\n",
"\n",
@@ -181,7 +199,7 @@
"\n",
"1. [Enable the Vertex AI API](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com).\n",
"\n",
"1. If you are running this notebook locally, you will need to install the [Cloud SDK](https://cloud.google.com/sdk).\n",
"1. If you are running this notebook locally, you need to install the [Cloud SDK](https://cloud.google.com/sdk).\n",
"\n",
"1. Enter your project ID in the cell below. Then run the cell to make sure the\n",
"Cloud SDK uses the right project for all the commands in this notebook.\n",
File diff suppressed because it is too large Load Diff
@@ -32,18 +32,18 @@
"# E2E ML on GCP: MLOps stage 3 : formalization: Get started with Vertex AI Model Registry\n",
"<table align=\"left\">\n",
" <td>\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage3/get_started_with_vertex_model_registry.ipynb\">\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage3/get_started_with_model_registry.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/colab-logo-32px.png\" alt=\"Colab logo\"> Run in Colab\n",
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage3/get_started_with_vertex_model_registry.ipynb\">\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage3/get_started_with_model_registry.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/ml_ops/stage3/get_started_with_vertex_model_registry.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_model_registry.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",
@@ -81,9 +81,11 @@
"\n",
"The steps performed include:\n",
"\n",
"- Create and register a first version of a model to `Vertex AI Model Registry`\n",
"- Create and register a second version of a model to `Vertex AI Model Registry`\n",
"- BLAH"
"- Create and register a first version of a model to `Vertex AI Model Registry`.\n",
"- Create and register a second version of a model to `Vertex AI Model Registry`.\n",
"- Updating the model version which is the default (blessed).\n",
"- Deleting a model version.\n",
"- Retraining the next model version."
]
},
{
@@ -208,7 +210,7 @@
"\n",
"3. [Enable the following APIs: Vertex AI APIs, Compute Engine APIs, and Cloud Storage.](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.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",
@@ -29,7 +29,7 @@
"id": "title:generic,gcp"
},
"source": [
"# E2E ML on GCP: MLOps stage 3 : Get started with rapid prototyping with AutoML and BQML\n",
"# E2E ML on GCP: MLOps stage 3 : Get started with rapid prototyping with AutoML and BigQuery ML\n",
"<table align=\"left\">\n",
" <td>\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage3/get_started_with_rapid_prototyping_bqml_automl.ipynb\">\n",
@@ -65,6 +65,33 @@
"<img src=\"https://storage.googleapis.com/rafacarv-public-bucket-do-not-delete/abalone/automl_and_bqml.png\" />"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "6c75b63ad57e"
},
"source": [
"### Objective\n",
"\n",
"In this tutorial, you learn how to use `Vertex AI Predictions` for rapid prototyping a model.\n",
"\n",
"This tutorial uses the following Google Cloud ML services:\n",
"\n",
"- `Vertex AI Pipelines`\n",
"- `Vertex AI AutoML`\n",
"- `Vertex AI BigQuery ML`\n",
"- `Google Cloud Pipeline Components`\n",
"\n",
"The steps performed include:\n",
"\n",
"- Creating a BigQuery and Vertex AI training dataset.\n",
"- Training a BigQuery ML and AutoML model.\n",
"- Extracting evaluation metrics from the BigQueryML and AutoML models.\n",
"- Selecting the best trained model.\n",
"- Deploying the best trained model.\n",
"- Testing the deployed model infrastructure."
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -153,33 +180,6 @@
"</body>\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "6c75b63ad57e"
},
"source": [
"### Objective\n",
"\n",
"In this tutorial, you learn how to use `Vertex AI Predictions` for rapid prototyping a model.\n",
"\n",
"This tutorial uses the following Google Cloud ML services:\n",
"\n",
"- `Vertex AI Pipelines`\n",
"- `Vertex AI AutoML`\n",
"- `Vertex AI BigQuery ML`\n",
"- `Google Cloud Pipeline Components`\n",
"\n",
"The steps performed include:\n",
"\n",
"- Creating a BigQuery and Vertex AI training dataset.\n",
"- Training a BigQuery ML and AutoML model.\n",
"- Extracting evaluation metrics from the BigQueryML and AutoML models.\n",
"- Selecting the best trained model.\n",
"- Deploying the best trained model.\n",
"- Testing the deployed model infrastructure."
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -187,17 +187,13 @@
},
"source": [
"### Costs\n",
"\n",
"This tutorial uses billable components of Google Cloud:\n",
"\n",
"* Vertex AI\n",
"* Cloud Storage\n",
"- Vertex AI\n",
"- Cloud Storage\n",
"- BigQuery\n",
"\n",
"Learn about [Vertex AI\n",
"pricing](https://cloud.google.com/vertex-ai/pricing) and [Cloud Storage\n",
"pricing](https://cloud.google.com/storage/pricing), and use the [Pricing\n",
"Calculator](https://cloud.google.com/products/calculator/)\n",
"to generate a cost estimate based on your projected usage."
"Learn about [Vertex AI pricing](https://cloud.google.com/vertex-ai/pricing), [Cloud Storage pricing](https://cloud.google.com/storage/pricing) and [BigQuery pricing](https://cloud.google.com/bigquery/pricing) and use the [Pricing Calculator](https://cloud.google.com/products/calculator/) to generate a cost estimate based on your projected usage."
]
},
{
@@ -208,7 +204,7 @@
"source": [
"### Set up your local development environment\n",
"\n",
"If you are using Colab or Google Cloud Notebooks, your environment already meets all the requirements to run this notebook. You can skip this step.\n",
"If you are using Colab or Vertex AI Workbench Notebooks, your environment already meets all the requirements to run this notebook. \n",
"\n",
"Otherwise, make sure your environment meets this notebook's requirements. You need the following:\n",
"\n",
@@ -300,69 +296,6 @@
" app.kernel.do_shutdown(True)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "gcp_authenticate"
},
"source": [
"### Authenticate your Google Cloud account\n",
"\n",
"**If you are using Vertex AI Workbench Notebooks**, your environment is already\n",
"authenticated. Skip this step.\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",
"\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",
"**Click Create service account**.\n",
"\n",
"In the **Service account name** field, enter a name, and click **Create**.\n",
"\n",
"In the **Grant this service account access to project** section, click the Role drop-down list. Type \"Vertex\" into the filter box, and select **Vertex Administrator**. Type \"Storage Object Admin\" into the filter box, and select **Storage Object Admin**.\n",
"\n",
"Click Create. A JSON file that contains your key downloads to your local environment.\n",
"\n",
"Enter the path to your service account key as the GOOGLE_APPLICATION_CREDENTIALS variable in the cell below and run the cell."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "gcp_authenticate"
},
"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",
" 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": {
@@ -385,7 +318,7 @@
"\n",
"3. [Enable the following APIs: Vertex AI APIs, Compute Engine APIs, and Cloud Storage.](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.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",
@@ -412,8 +345,6 @@
},
"outputs": [],
"source": [
"import os\n",
"\n",
"PROJECT_ID = \"[your-project-id]\" # @param {type:\"string\"}"
]
},
@@ -500,6 +431,69 @@
"TIMESTAMP = datetime.now().strftime(\"%Y%m%d%H%M%S\")"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "gcp_authenticate"
},
"source": [
"### Authenticate your Google Cloud account\n",
"\n",
"**If you are using Vertex AI Workbench Notebooks**, your environment is already\n",
"authenticated. Skip this step.\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",
"\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",
"**Click Create service account**.\n",
"\n",
"In the **Service account name** field, enter a name, and click **Create**.\n",
"\n",
"In the **Grant this service account access to project** section, click the Role drop-down list. Type \"Vertex\" into the filter box, and select **Vertex Administrator**. Type \"Storage Object Admin\" into the filter box, and select **Storage Object Admin**.\n",
"\n",
"Click Create. A JSON file that contains your key downloads to your local environment.\n",
"\n",
"Enter the path to your service account key as the GOOGLE_APPLICATION_CREDENTIALS variable in the cell below and run the cell."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "gcp_authenticate"
},
"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",
" 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": {
@@ -29,7 +29,7 @@
"id": "ff60de67fa8d"
},
"source": [
"Notebook is a revised version of an unpublished notebook from Juan Acevedo"
"This notebook is a revised version of an unpublished notebook from Juan Acevedo"
]
},
{
@@ -49,7 +49,7 @@
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samplestree/main/notebooks/community/ml_ops/stage3/get_started_with_tfx_pipeline.ipynb\">\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage3/get_started_with_tfx_pipeline.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",
@@ -75,17 +75,6 @@
"This tutorial demonstrates how to use Vertex AI for E2E MLOps on Google Cloud in production. This tutorial covers stage 3 : formalization: get started with TFX and Vertex AI Pipelines."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dataset:bank,lbn"
},
"source": [
"### Dataset\n",
"\n",
"The dataset used for this tutorial is the [CIFAR10 dataset](https://www.tensorflow.org/datasets/catalog/cifar10) from [TensorFlow Datasets](https://www.tensorflow.org/datasets/catalog/overview). The version of the dataset you will use 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."
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -112,6 +101,17 @@
"- Execute the pipeline using `Vertex AI Pipelines`."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dataset:bank,lbn"
},
"source": [
"### Dataset\n",
"\n",
"The dataset used for this tutorial is the [CIFAR10 dataset](https://www.tensorflow.org/datasets/catalog/cifar10) from [TensorFlow Datasets](https://www.tensorflow.org/datasets/catalog/overview). 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."
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -124,10 +124,12 @@
"\n",
"* Vertex AI\n",
"* Cloud Storage\n",
"* Dataflow\n",
"\n",
"Learn about [Vertex AI\n",
"pricing](https://cloud.google.com/vertex-ai/pricing) and [Cloud Storage\n",
"pricing](https://cloud.google.com/storage/pricing), and use the [Pricing\n",
"pricing](https://cloud.google.com/vertex-ai/pricing), [Cloud Storage\n",
"pricing](https://cloud.google.com/storage/pricing), and [Dataflow pricing](https://cloud.google.com/dataflow/pricing)\n",
"and use the [Pricing\n",
"Calculator](https://cloud.google.com/products/calculator/)\n",
"to generate a cost estimate based on your projected usage."
]
@@ -225,7 +227,7 @@
"\n",
"3. Enable the APIs necessary to execute this notebook -- see cell below.\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",
@@ -233,6 +235,17 @@
"**Note**: Jupyter runs lines prefixed with `!` as shell commands, and it interpolates Python variables prefixed with `$`."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "c4ccf556d4ea"
},
"source": [
"### Enable APIs\n",
"\n",
"You can enable the required APIs using `gcloud`."
]
},
{
"cell_type": "code",
"execution_count": null,
@@ -38,7 +38,7 @@
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samplestree/main/notebooks/community/ml_ops/stage3/mlops_formalization.ipynb\">\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage3/mlops_formalization.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",
@@ -65,17 +65,6 @@
"This tutorial demonstrates how to use Vertex AI for E2E MLOps on Google Cloud in production. This tutorial covers stage 3 : formalization."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dataset:bq,chicago,lbn"
},
"source": [
"### Dataset\n",
"\n",
"The dataset used for this tutorial is the [Chicago Taxi](https://www.kaggle.com/chicago/chicago-taxi-trips-bq). The version of the dataset you will use in this tutorial is stored in a public BigQuery table. The trained model predicts whether someone would leave a tip for a taxi fare."
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -91,7 +80,7 @@
"- `Vertex AI Pipelines`\n",
"- `Vertex AI Training`\n",
"- `Google Cloud Pipeline Components`\n",
"- `Vertex AI Dataset, and Model resources\n",
"- `Vertex AI Dataset, and Model` resources\n",
"- `Dataflow`\n",
"\n",
"The steps performed include:\n",
@@ -101,7 +90,7 @@
" - Dataset schema/statistics for baseline model.\n",
"- Formalize a data preprocessing pipeline.\n",
" - Extract columns/rows from BigQuery table to local BigQuery table.\n",
" - Use Tensorflow Data Validation library to determine statistics, schema, and features.\n",
" - Use TensorFlow Data Validation library to determine statistics, schema, and features.\n",
" - Use Dataflow to preprocess the data.\n",
" - Create a Vertex AI Dataset.\n",
"- Formalize a build model architecture pipeline.\n",
@@ -130,7 +119,7 @@
" - Training pipeline\n",
"\n",
"- The data pipeline should perform the following tasks:\n",
" - Do satistical analysis on the dataset using Tensorflow Data Validation library.\n",
" - Do satistical analysis on the dataset using TensorFlow Data Validation library.\n",
" - Split the dataset examples into training, validation and test datasets using `Dataflow` components.\n",
" - Preprocess and transform the split datasets into machine learning ready format, i.e., `TFRecord`, using `Dataflow` components.\n",
" - Preprocess copies of test dataset for testing serving model using `Dataflow` components.\n",
@@ -156,7 +145,7 @@
" - Load and compile the model artifacts.\n",
" - Train the model.\n",
" - Train the model with corresponding hyperparameters.\n",
" - Track the training with a `Vertex AI Tensorboard` instance.\n",
" - Track the training with a `Vertex AI TensorBoard` instance.\n",
" - Store the trained model artifacts on Cloud Storage.\n",
" - Evaluate the model.\n",
" - Evaluate the model using the test dataset.\n",
@@ -169,6 +158,39 @@
" - Deploy the trained `Vertex AI Model` resource to the `Vertex AI Endpoint` resource."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dataset:bq,chicago,lbn"
},
"source": [
"### Dataset\n",
"\n",
"The dataset used for this tutorial is the [Chicago Taxi](https://www.kaggle.com/chicago/chicago-taxi-trips-bq). The version of the dataset in this tutorial is stored in a public BigQuery table. The trained model predicts whether someone leaves a tip for a taxi fare."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "0c997d8d92ce"
},
"source": [
"### Costs\n",
"\n",
"This tutorial uses billable components of Google Cloud:\n",
"\n",
"* Vertex AI\n",
"* Cloud Storage\n",
"* Dataflow\n",
"\n",
"Learn about [Vertex AI\n",
"pricing](https://cloud.google.com/vertex-ai/pricing), [Cloud Storage\n",
"pricing](https://cloud.google.com/storage/pricing), and [Dataflow pricing](https://cloud.google.com/dataflow/pricing)\n",
"and use the [Pricing\n",
"Calculator](https://cloud.google.com/products/calculator/)\n",
"to generate a cost estimate based on your projected usage."
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -203,22 +225,22 @@
"\n",
"ONCE_ONLY = False\n",
"if ONCE_ONLY:\n",
" ! pip3 install -U tensorflow==2.5 $USER_FLAG\n",
" ! pip3 install -U tensorflow-data-validation==1.2 $USER_FLAG\n",
" ! pip3 install -U tensorflow-transform==1.2 $USER_FLAG\n",
" ! pip3 install -U tensorflow-io==0.18 $USER_FLAG\n",
" ! pip3 install --upgrade google-cloud-aiplatform[tensorboard] $USER_FLAG\n",
" ! pip3 install --upgrade google-cloud-pipeline-components $USER_FLAG\n",
" ! pip3 install --upgrade google-cloud-bigquery $USER_FLAG\n",
" ! pip3 install --upgrade google-cloud-logging $USER_FLAG\n",
" ! pip3 install --upgrade apache-beam[gcp] $USER_FLAG\n",
" ! pip3 install --upgrade pyarrow $USER_FLAG\n",
" ! pip3 install --upgrade cloudml-hypertune $USER_FLAG\n",
" ! pip3 install --upgrade kfp $USER_FLAG\n",
" ! pip3 install --upgrade torchvision $USER_FLAG\n",
" ! pip3 install --upgrade rpy2 $USER_FLAG\n",
" ! pip3 install --upgrade python-tabulate $USER_FLAG\n",
" ! pip3 install -U opencv-python-headless==4.5.2.52 $USER_FLAG"
" ! pip3 install -U tensorflow==2.5 $USER_FLAG -q\n",
" ! pip3 install -U tensorflow-data-validation==1.2 $USER_FLAG -q\n",
" ! pip3 install -U tensorflow-transform==1.2 $USER_FLAG -q\n",
" ! pip3 install -U tensorflow-io==0.18 $USER_FLAG -q\n",
" ! pip3 install --upgrade google-cloud-aiplatform[tensorboard] $USER_FLAG -q\n",
" ! pip3 install --upgrade google-cloud-pipeline-components $USER_FLAG -q\n",
" ! pip3 install --upgrade google-cloud-bigquery $USER_FLAG -q\n",
" ! pip3 install --upgrade google-cloud-logging $USER_FLAG -q\n",
" ! pip3 install --upgrade apache-beam[gcp] $USER_FLAG -q\n",
" ! pip3 install --upgrade pyarrow $USER_FLAG -q\n",
" ! pip3 install --upgrade cloudml-hypertune $USER_FLAG -q\n",
" ! pip3 install --upgrade kfp $USER_FLAG -q\n",
" ! pip3 install --upgrade torchvision $USER_FLAG -q\n",
" ! pip3 install --upgrade rpy2 $USER_FLAG -q\n",
" ! pip3 install --upgrade python-tabulate $USER_FLAG -q\n",
" ! pip3 install -U opencv-python-headless==4.5.2.52 $USER_FLAG -q"
]
},
{
@@ -268,7 +290,7 @@
"\n",
"1. [Enable the Vertex AI API and Dataflow API](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com,dataflow.googleapis.com).\n",
"\n",
"1. If you are running this notebook locally, you will need to install the [Cloud SDK](https://cloud.google.com/sdk).\n",
"1. If you are running this notebook locally, you need to install the [Cloud SDK](https://cloud.google.com/sdk).\n",
"\n",
"1. Enter your project ID in the cell below. Then run the cell to make sure the\n",
"Cloud SDK uses the right project for all the commands in this notebook.\n",
@@ -2797,7 +2819,7 @@
" - `dataset-id`: The resource ID of the `Dataset` resource to use for training.\n",
" - `experiment`: The name of the experiment.\n",
" - `run`: The name of the run within this experiment.\n",
" - `tensorboard-logdir`: The logging directory for Vertex AI Tensorboard.\n",
" - `tensorboard-logdir`: The logging directory for Vertex AI TensorBoard.\n",
"\n",
"\n",
"- `get_data()`:\n",
+74 -57
View File
@@ -42,67 +42,10 @@ This stage may be done entirely by MLOps. We recommend:
### Get Started
[Get started with Google Artifact Registry](get_started_with_google_artifact_registry.ipynb)
```
The steps performed include:
- Creating a private Docker repository.
- Tagging a container image, specific to the private Docker repository.
- Pushing a container image to the private Docker repository.
- Pulling a container image from the private Docker repository.
- Deleting a private Docker repository.
```
Get started with Vertex Model Registry
[Get started with Vertex ML Metadata](get_started_with_vertex_ml_metadata.ipynb)
```
The steps performed include:
- Create a `Metadatastore` resource.
- Create (record)/List an `Artifact`, with artifacts and metadata.
- Create (record)/List an `Execution`.
- Create (record)/List a `Context`.
- Add `Artifact` to `Execution` as events.
- Add `Execution` and `Artifact` into the `Context`
- Delete `Artifact`, `Execution` and `Context`.
- Create and run a `Vertex AI Pipeline` ML workflow to train and deploy a scikit-learn model.
- Create custom pipeline components that generate artifacts and metadata.
- Compare Vertex AI Pipelines runs.
- Trace the lineage for pipeline-generated artifacts.
- Query your pipeline run metadata.
```
[Get started with Vertex ML Metadata and AutoML](get_started_with_vertex_ml_metadata_and_automl.ipynb)
```
The steps performed include:
- Create a `Dataset` resource.
- Create a corresponding `google.VertexDataset` artifact.
- Train a model using `AutoML`.
- Create a corresponding `google.VertexModel` artifact.
- Create an `Endpoint` resource.
- Create a corresponding `google.Endpoint` artifact.
- Deploy the train model to the `Endpoint`.
- Create an execution and context for the `AutoML` training job and deployment.
- Add the corresponding artifacts and context to the execution.
- Add artifact links (event) to the execution.
- Display the execution graph.
```
Get started with custom model evaluation
Get started with A/B Testing
[Get started with Vertex Explainable AI](get_started_with_vertex_xai.ipynb)
```
The steps performed include:
- Train an AutoML tabular model.
- Do a batch prediction with explanations.
- Do an online prediction with explanations.
@@ -121,8 +64,82 @@ The steps performed include:
- Train an custom scikit-learn tabular model.
- Manually set configuration metadata.
- Do an online prediction with explanations.
```
[Get started with Google Artifact Registry](get_started_with_google_artifact_registry.ipynb)
```
The steps performed include:
- Creating a private Docker repository.
- Tagging a container image, specific to the private Docker repository.
- Pushing a container image to the private Docker repository.
- Pulling a container image from the private Docker repository.
- Deleting a private Docker repository.
```
[Get started with AutoML training and ML Metadata](get_started_with_vertex_ml_metadata_and_automl.ipynb)
```
The steps performed include:
- Create a `Dataset` resource.
- Create a corresponding `google.VertexDataset` artifact.
- Train a model using `AutoML`.
- Create a corresponding `google.VertexModel` artifact.
- Create an `Endpoint` resource.
- Create a corresponding `google.Endpoint` artifact.
- Deploy the train model to the `Endpoint`.
- Create an execution and context for the `AutoML` training job and deployment.
- Add the corresponding artifacts and context to the execution.
- Add artifact links (event) to the execution.
- Display the execution graph.
```
[Get started with Vertex AI ML Metadata](get_started_with_vertex_ml_metadata.ipynb)
```
The steps performed include:
- Create a `Metadatastore` resource.
- Create (record)/List an `Artifact`, with artifacts and metadata.
- Create (record)/List an `Execution`.
- Create (record)/List a `Context`.
- Add `Artifact` to `Execution` as events.
- Add `Execution` and `Artifact` into the `Context`
- Delete `Artifact`, `Execution` and `Context`.
- Create and run a `Vertex AI Pipeline` ML workflow to train and deploy a scikit-learn model.
- Create custom pipeline components that generate artifacts and metadata.
- Compare Vertex AI Pipelines runs.
- Trace the lineage for pipeline-generated artifacts.
- Query your pipeline run metadata.
```
[Get started with Vertex AI Model Evaluation](get_started_with_model_evaluation.ipynb)
```
The steps performed include:
- Evaluate an `AutoML` model.
- Train an `AutoML` image classification model.
- Retrieve the default evaluation metrics from training.
- Do a batch evaluation for a custom evaluation slice.
- Evaluate a BigQuery ML model.
- Train a `BigQuery ML` tabular classification model.
- Retrieve the default evaluation metrics from training.
- Do a batch evaluation for a custom evaluation slice.
- Evaluate a custom model.
- Do a batch evaluation for a custom evaluation slice.
- Add an evaluation to the `Model Registry` for the `Model` resource.
- Evaluate an `AutoML` model.
- Train an `AutoML` image classification model.
- Retrieve the default evaluation metrics from training.
- Do a batch evaluation for a custom evaluation slice.
- Evaluate a BigQuery ML model.
- Train a `BigQuery ML` tabular classification model.
- Retrieve the default evaluation metrics from training.
- Do a batch evaluation for a custom evaluation slice.
- Evaluate a custom model.
- Do a batch evaluation for a custom evaluation slice.
- Add an evaluation to the `Model Registry` for the `Model` resource.
```
### E2E Stage Example
Stage 4: Evaluation
@@ -88,6 +88,33 @@
"- Deleting a private Docker repository."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "4ced09c1b4ce"
},
"source": [
"### Dataset\n",
"\n",
"No dataset is used in this tutorial. References to an example dataset are for demonstration purposes."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "35bee437737d"
},
"source": [
"### Costs\n",
"\n",
"This tutorial uses billable components of Google Cloud:\n",
"\n",
"* Vertex AI\n",
"* Cloud Storage\n",
"\n",
"Learn about [Vertex AI pricing](https://cloud.google.com/vertex-ai/pricing) and [Cloud Storage pricing](https://cloud.google.com/storage/pricing), and use the [Pricing Calculator](https://cloud.google.com/products/calculator/) to generate a cost estimate based on your projected usage."
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -174,7 +201,7 @@
"\n",
"3. [Enable the following APIs: Vertex AI APIs, Compute Engine APIs, and Cloud Storage.](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.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",
@@ -40,7 +40,7 @@
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samplestree/main/notebooks/community/ml_ops/stage4/get_started_with_model_evaluation.ipynb\">\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage4/get_started_with_model_evaluation.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",
@@ -66,35 +66,6 @@
"This tutorial demonstrates how to use Vertex AI for E2E MLOps on Google Cloud in production. This tutorial covers stage 4 : evaluation: get started with Vertex AI Model Evaluation."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dataset:bank,lbn"
},
"source": [
"### Datasets\n",
"\n",
"**AutoML image model**\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.\n",
"\n",
"**BigQuery ML tabular model**\n",
"\n",
"The dataset used for this tutorial is the Penguins dataset from [BigQuery public datasets](https://cloud.google.com/bigquery/public-data). This version of the dataset is used to predict the species of penguins from the available features like culmen-length, flipper-depth etc.\n",
"\n",
"**Custom model**\n",
"\n",
"This tutorial uses a pre-trained image classification model from TensorFlow Hub, which is trained on ImageNet dataset.\n",
"\n",
"Learn more about [ResNet V2 pretained model](https://tfhub.dev/google/imagenet/resnet_v2_101/classification/5). \n",
"\n",
"\n",
"**Pipeline**\n",
"BLAH\n",
"\n",
"The dataset used for this tutorial is the [Bank Marketing](https://pantheon.corp.google.com/storage/browser/_details/cloud-ml-tables-data/bank-marketing.csv) . This dataset does not require any feature engineering. The version of the dataset you will use in this tutorial is stored in a public Cloud Storage bucket."
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -145,6 +116,50 @@
" - Add an evaluation to the `Model Registry` for the `Model` resource."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dataset:bank,lbn"
},
"source": [
"### Datasets\n",
"\n",
"**AutoML image model**\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 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.\n",
"\n",
"**BigQuery ML tabular model**\n",
"\n",
"The dataset used for this tutorial is the Penguins dataset from [BigQuery public datasets](https://cloud.google.com/bigquery/public-data). This version of the dataset is used to predict the species of penguins from the available features like culmen-length, flipper-depth etc.\n",
"\n",
"**Custom model**\n",
"\n",
"This tutorial uses a pre-trained image classification model from TensorFlow Hub, which is trained on ImageNet dataset.\n",
"\n",
"Learn more about [ResNet V2 pretained model](https://tfhub.dev/google/imagenet/resnet_v2_101/classification/5). \n",
"\n",
"\n",
"**Pipeline**\n",
"\n",
"The dataset used for this tutorial is the [Bank Marketing](https://pantheon.corp.google.com/storage/browser/_details/cloud-ml-tables-data/bank-marketing.csv) . This dataset does not require any feature engineering. The version of the dataset in this tutorial is stored in a public Cloud Storage bucket."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "0c997d8d92ce"
},
"source": [
"### Costs\n",
"This tutorial uses billable components of Google Cloud:\n",
"\n",
"- Vertex AI\n",
"- Cloud Storage\n",
"- BigQuery\n",
"\n",
"Learn about [Vertex AI pricing](https://cloud.google.com/vertex-ai/pricing), [Cloud Storage pricing](https://cloud.google.com/storage/pricing) and [BigQuery pricing](https://cloud.google.com/bigquery/pricing) and use the [Pricing Calculator](https://cloud.google.com/products/calculator/) to generate a cost estimate based on your projected usage."
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -236,7 +251,7 @@
"\n",
"3. [Enable the following APIs: Vertex AI APIs, Compute Engine APIs, and Cloud Storage.](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.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",
File diff suppressed because it is too large Load Diff
@@ -65,17 +65,6 @@
"This tutorial demonstrates how to use Vertex AI for E2E MLOps on Google Cloud in production. This tutorial covers stage 4 : evaluation: get started with Vertex ML Metadata and AutoML."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dataset:flowers,icn"
},
"source": [
"### Datasets\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 in a given image from a class of five flowers: daisy, dandelion, rose, sunflower, or tulip."
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -108,6 +97,17 @@
"- Display the execution graph."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dataset:flowers,icn"
},
"source": [
"### Datasets\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 in this tutorial is stored in a public Cloud Storage bucket. The trained model predicts the type of flower in a given image from a class of five flowers: daisy, dandelion, rose, sunflower, or tulip."
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -196,6 +196,8 @@
"id": "project_id"
},
"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",
@@ -211,8 +213,15 @@
"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.\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": "56d591439df1"
},
"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`."
@@ -29,7 +29,7 @@
"id": "title"
},
"source": [
"# Vertex SDK: E2E ML on GCP: MLOps stage 4 : evaluation: get started with Vertex AI Explanations\n",
"# E2E ML on GCP: MLOps stage 4 : evaluation: get started with Vertex Explainable AI\n",
"\n",
"<table align=\"left\">\n",
" <td>\n",
@@ -62,40 +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 Explanations."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dataset:iris,lcn"
},
"source": [
"### Dataset\n",
"\n",
"The dataset used for this tutorial is the [Iris dataset](https://www.tensorflow.org/datasets/catalog/iris) from [TensorFlow Datasets](https://www.tensorflow.org/datasets/catalog/overview). This dataset does not require any feature engineering. The version of the dataset you will use in this tutorial is stored in a public Cloud Storage bucket. The trained model predicts the type of Iris flower species from a class of three species: setosa, virginica, or versicolor."
]
},
{
"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": {
"id": "dataset:custom,cifar10,icn"
},
"source": [
"### Dataset\n",
"\n",
"The dataset used for this tutorial is the [CIFAR10 dataset](https://www.tensorflow.org/datasets/catalog/cifar10) from [TensorFlow Datasets](https://www.tensorflow.org/datasets/catalog/overview). The version of the dataset you will use 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."
"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 Explainable AI."
]
},
{
@@ -138,6 +105,43 @@
"Learn more about [Introduction to Vertex AI Explainable AI ](https://cloud.google.com/vertex-ai/docs/explainable-ai/overview)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dataset:iris,lcn"
},
"source": [
"### Datasets\n",
"\n",
"***AutoML Tabular***\n",
"\n",
"The dataset used for this tutorial is the [Iris dataset](https://www.tensorflow.org/datasets/catalog/iris) from [TensorFlow Datasets](https://www.tensorflow.org/datasets/catalog/overview). This dataset does not require any feature engineering. The version of the dataset in this tutorial is stored in a public Cloud Storage bucket. The trained model predicts the type of Iris flower species from a class of three species: setosa, virginica, or versicolor.\n",
"\n",
"***Custom Tabular***\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 in this tutorial is built into TensorFlow. The trained model predicts the median price of a house in units of 1K USD.\n",
"\n",
"***Custom Image***\n",
"\n",
"The dataset used for this tutorial is the [CIFAR10 dataset](https://www.tensorflow.org/datasets/catalog/cifar10) from [TensorFlow Datasets](https://www.tensorflow.org/datasets/catalog/overview). The version of the dataset is built into TensorFlow. The trained model predicts which type of class an i"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "35bee437737d"
},
"source": [
"### Costs\n",
"\n",
"This tutorial uses billable components of Google Cloud:\n",
"\n",
"* Vertex AI\n",
"* Cloud Storage\n",
"\n",
"Learn about [Vertex AI pricing](https://cloud.google.com/vertex-ai/pricing) and [Cloud Storage pricing](https://cloud.google.com/storage/pricing), and use the [Pricing Calculator](https://cloud.google.com/products/calculator/) to generate a cost estimate based on your projected usage."
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -228,7 +232,7 @@
"\n",
"3. [Enable the following APIs: Vertex AI APIs, Compute Engine APIs, and Cloud Storage.](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.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",
+29 -32
View File
@@ -28,8 +28,7 @@ The fifth stage in MLOps is deployment to production of the blessed model, which
[Get started with Vertex AI Endpoints](get_started_with_vertex_endpoints.ipynb)
```
The steps include:
The steps performed include:
- Creating an `Endpoint` resource.
- List all `Endpoint` resources.
- List `Endpoint` resources by query filter.
@@ -46,39 +45,10 @@ The steps include:
- In pipeline: Deploy an existing `Model` resource to an existing `Endpoint` resource.
```
[Get started with Vertex AI Private Endpoints](get_started_with_vertex_private_endpoints.ipynb)
[Get started with configuring autoscaling for Vertex AI Endpoint deployment](get_started_with_autoscaling.ipynb)
```
The steps performed include:
- Creating a `Private Endpoint` resource.
- Configure a VPC peering connection.
- Configuring the serving binary of a `Model` resource for deployment to a `Private Endpoint` resource.
- Deploying a `Model` resource to a `Private Endpoint` resource.
- Send a prediction request to a `Private Endpoint`
```
[Get started with Vertex AI Endpoints and co-hosting models on shared VM](get_started_with_vertex_endpoint_and_shared_vm.ipynb)
```
The steps performed include:
- Upload a pre-trained image classification model as a `Model` resource (model A).
- Upload a pre-trained text sentence encoder model as a `Model` resource (model B).
- Create a shared VM deployment resource pool.
- List shared VM deployment resource pools.
- Create two `Endpoint` resources.
- Deploy first model (model A) to first `Endpoint` resource using shared VM deployment resource pool.
- Deploy second model (model B) to second `Endpoint` resource using shared VM deployment resource pool.
- Make a prediction request with first deployed model (model A).
- Make a prediction request with second deployed model (model B).
```
[Get started with Auto-Scaling for Vertex AI Endpoints](get_started_with_autoscaling.ipynb)
```
The steps performed include:
- Download a pretrained image classification model from TensorFlow Hub.
- Upload the pretrained model as a `Model` resource.
- Create an `Endpoint` resource.
@@ -89,3 +59,30 @@ The steps performed include:
- Fine-tune scaling thresholds for GPU utilization.
- Deploy mix of CPU and GPU model instances with auto-scaling to an `Endpoint` resource.
```
[Get started with Vertex AI Private Endpoints](get_started_with_vertex_private_endpoints.ipynb)
```
The steps performed include:
- Creating a `Private Endpoint` resource.
- Configure a VPC peering connection.
- Configuring the serving binary of a `Model` resource for deployment to a `Private Endpoint` resource.
- Deploying a `Model` resource to a `Private Endpoint` resource.
- Send a prediction request to a `Private Endpoint`
```
[Get started with Vertex AI Endpoint and shared VM](get_started_with_vertex_endpoint_and_shared_vm.ipynb)
```
The steps performed include:
- Upload a pre-trained image classification model as a `Model` resource (model A).
- Upload a pre-trained text sentence encoder model as a `Model` resource (model B).
- Create a shared VM deployment resource pool.
- List shared VM deployment resource pools.
- Create two `Endpoint` resources.
- Deploy first model (model A) to first `Endpoint` resource using deployment resource pool.
- Deploy second model (model B) to second `Endpoint` resource using deployment resource pool.
- Make a prediction request with first deployed model (model A).
- Make a prediction request with second deployed model (model B).
```
@@ -29,22 +29,22 @@
"id": "title:generic,gcp"
},
"source": [
"# E2E ML on GCP: MLOps stage 5 : deployment: get started with configuring autoscaling for deployment\n",
"# E2E ML on GCP: MLOps stage 5 : deployment: get started with configuring autoscaling for Vertex AI Endpoint deployment\n",
"\n",
"<table align=\"left\">\n",
" <td>\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage4/get_started_with_autoscaling.ipynb\">\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage5/get_started_with_autoscaling.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://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage4/get_started_with_autoscaling.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/colab-logo-32px.png\\\" alt=\"Colab logo\"> Run in Colab\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage5/get_started_with_autoscaling.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/colab-logo-32px.png\" alt=\"Colab logo\"> Run in Colab\n",
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://raw.githubusercontent.com/GoogleCloudPlatform/vertex-ai-samples/main/notebooks/community/ml_ops/stage4/get_started_with_autoscaling.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/stage5/get_started_with_autoscaling.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",
@@ -65,19 +65,6 @@
"This tutorial demonstrates how to use Vertex AI for E2E MLOps on Google Cloud in production. This tutorial covers stage 5 : deployment: get started with autoscaling for deployment."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dataset:flowers,icn"
},
"source": [
"### Dataset\n",
"\n",
"This tutorial uses a pre-trained image classification model from TensorFlow Hub, which is trained on ImageNet dataset.\n",
"\n",
"Learn more about [ResNet V2 pretained model](https://tfhub.dev/google/imagenet/resnet_v2_101/classification/5). "
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -105,6 +92,19 @@
"- Deploy mix of CPU and GPU model instances with auto-scaling to an `Endpoint` resource."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dataset:flowers,icn"
},
"source": [
"### Dataset\n",
"\n",
"This tutorial uses a pre-trained image classification model from TensorFlow Hub, which is trained on ImageNet dataset.\n",
"\n",
"Learn more about [ResNet V2 pretained model](https://tfhub.dev/google/imagenet/resnet_v2_101/classification/5). "
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -194,6 +194,8 @@
"id": "project_id"
},
"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",
@@ -209,8 +211,15 @@
"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.\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": "56d591439df1"
},
"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`."
@@ -877,7 +886,7 @@
" deployed_model_display_name=\"example_\" + TIMESTAMP,\n",
" machine_type=DEPLOY_COMPUTE,\n",
" min_replica_count=MIN_NODES,\n",
" max_replica_count=MAX_NODES\n",
" max_replica_count=MAX_NODES,\n",
")"
]
},
@@ -966,7 +975,7 @@
" deployed_model_display_name=\"example_\" + TIMESTAMP,\n",
" machine_type=DEPLOY_COMPUTE,\n",
" min_replica_count=MIN_NODES,\n",
" max_replica_count=MAX_NODES\n",
" max_replica_count=MAX_NODES,\n",
")"
]
},
@@ -1049,7 +1058,7 @@
" machine_type=DEPLOY_COMPUTE,\n",
" min_replica_count=MIN_NODES,\n",
" max_replica_count=MAX_NODES,\n",
" autoscaling_target_cpu_utilization=50\n",
" autoscaling_target_cpu_utilization=50,\n",
")"
]
},
@@ -1170,7 +1179,7 @@
" accelerator_count=DEPLOY_NGPU,\n",
" min_replica_count=MIN_NODES,\n",
" max_replica_count=MAX_NODES,\n",
" autoscaling_target_accelerator_duty_cycle=50\n",
" autoscaling_target_accelerator_duty_cycle=50,\n",
")"
]
},
@@ -1229,7 +1238,7 @@
" min_replica_count=MIN_NODES,\n",
" max_replica_count=MAX_NODES,\n",
" autoscaling_target_cpu_utilization=50,\n",
" traffic_split={\"0\": 20, deployed_model_id: 80 }\n",
" traffic_split={\"0\": 20, deployed_model_id: 80},\n",
")"
]
},
@@ -29,7 +29,7 @@
"id": "title:generic,gcp"
},
"source": [
"# E2E ML on GCP: MLOps stage 5 : deployment: get started with Endpoint and shared VM\n",
"# E2E ML on GCP: MLOps stage 5 : deployment: get started with Vertex AI Endpoint and shared VM\n",
"\n",
"<table align=\"left\">\n",
" <td>\n",
@@ -65,20 +65,6 @@
"This tutorial demonstrates how to use Vertex AI for E2E MLOps on Google Cloud in production. This tutorial covers stage 5 : deployment: get started with Endpoints and shared VM for co-hosting models."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dataset:flowers,icn"
},
"source": [
"### Pre-trained Models\n",
"\n",
"The pre-trained models used for this tutorial are from the [TensorFlow Hub](https://tfhub.dev/) repository:\n",
"\n",
"- [image classification](https://tfhub.dev/google/imagenet/inception_v3/classification/5): trained with ImageNet.\n",
"- [text sentence encoder](https://tfhub.dev/google/universal-sentence-encoder/4): Google's universal sentence encoder"
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -110,6 +96,20 @@
"- Make a prediction request with second deployed model (model B)."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dataset:flowers,icn"
},
"source": [
"### Model\n",
"\n",
"The pre-trained models used for this tutorial are from the [TensorFlow Hub](https://tfhub.dev/) repository:\n",
"\n",
"- [image classification](https://tfhub.dev/google/imagenet/inception_v3/classification/5): trained with ImageNet.\n",
"- [text sentence encoder](https://tfhub.dev/google/universal-sentence-encoder/4): Google's universal sentence encoder"
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -199,6 +199,8 @@
"id": "project_id"
},
"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",
@@ -214,8 +216,15 @@
"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.\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": "56d591439df1"
},
"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`."
@@ -218,7 +218,7 @@
"\n",
"3. [Enable the following APIs: Vertex AI APIs, Compute Engine APIs, and Cloud Storage.](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.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",
@@ -37,7 +37,7 @@
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samplestree/main/notebooks/community/ml_ops/stage5/get_started_with_vertex_private_endpoints.ipynb\">\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage5/get_started_with_vertex_private_endpoints.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",
@@ -227,7 +227,7 @@
"\n",
"5. [Enable the Cloud DNS API](https://console.cloud.google.com/flows/enableapi?apiid=dns.googleapis.com).\n",
"\n",
"6. If you are running this notebook locally, you will need to install the [Cloud SDK]((https://cloud.google.com/sdk)).\n",
"6. If you are running this notebook locally, you need to install the [Cloud SDK]((https://cloud.google.com/sdk)).\n",
"\n",
"7. 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",
+130 -127
View File
@@ -29,11 +29,49 @@ This stage may be done entirely by MLOps. We recommend:
### Get Started
[Get started with Custom Prediction Routine](get_started_with_cpr.ipynb)
[Get started with TensorFlow serving functions with Vertex AI Prediction](get_started_with_tf_serving_function.ipynb)
```
The steps performed include:
- Download a pretrained image classification model from TensorFlow Hub.
- Create a serving function to receive compressed image data, and output decomopressed preprocessed data for the model input.
- Upload the TensorFlow Hub model and serving function as a `Vertex AI Model` resource.
- Creating an `Endpoint` resource.
- Deploying the `Model` resource to an `Endpoint` resource.
- Make an online prediction to the `Model` resource instance deployed to the `Endpoint` resource.
```
[Get started with FastAPI with Vertex AI Prediction](get_started_with_fastapi.ipynb)
```
The steps performed include:
- Download a pretrained image classification model from TensorFlow Hub.
- Create a serving function to receive compressed image data, and output decomopressed preprocessed data for the model input.
- Upload the TensorFlow Hub model and serving function as a `Vertex AI Model` resource.
- Creating an `Endpoint` resource.
- Deploying the `Model` resource to an `Endpoint` resource with `FastAPI` custom serving binary.
- Make an online prediction to the `Model` resource instance deployed to the `Endpoint` resource.
```
[Get started with Nvidia Triton server](get_started_with_nvidia_triton_serving.ipynb)
```
The steps performed in this tutorial include:
- Download the model artifacts from TensorFlow Hub.
- Create Triton serving configuration file for the model.
- Construct a custom container, with Triton serving image, for model deployment.
- Upload the model as a `Vertex AI Model` resource.
- Deploy the `Vertex AI Model` resource to a `Vertex AI Endpoint` resource.
- Make a prediction request
- Undeploy the `Model` resource and delete the `Endpoint`
```
[Get started with Custom Prediction Routine (CPR)](get_started_with_cpr.ipynb)
```
The steps performed include:
- Write a custom data preprocessor.
- Train the model.
- Build a custom scikit-learn serving container with custom data preprocessing using the Custom Prediction Routine model server.
@@ -57,140 +95,20 @@ The steps performed include:
- Make a prediction request.
```
[Get started with Vertex AI Raw Prediction](get_started_with_raw_predict.ipynb)
[Get started with re-importing AutoML tabular models](get_started_automl_tabular_exported_deploy.ipynb)
```
The steps performed include:
- Download a pretrained tabular classification model artifacts for a TensorFlow 1.x estimator.
- Upload the TensorFlow estimator model as a `Vertex AI Model` resource.
- Creating an `Endpoint` resource.
- Deploying the `Model` resource to an `Endpoint` resource.
- Make an online raw prediction to the `Model` resource instance deployed to the `Endpoint` resource.
- Importing a pretrained AutoML tabular exported model artifacts, as a `Model` resource.
- Create an `Endpoint` resource.
- Deploy the `Model` resource to the `Endpoint` resource.
- Make a prediction.
```
[Get started with serving functions for TensorFlow model](get_started_with_tf_serving_function.ipynb)
[Get started with Vertex Explainable AI using custom deployment container](get_started_with_xai_and_custom_server.ipynb)
```
The steps performed include:
- Download a pretrained image classification model from TensorFlow Hub.
- Create a serving function to receive compressed image data, and output decomopressed preprocessed data for the model input.
- Upload the TensorFlow Hub model and serving function as a `Vertex AI Model` resource.
- Creating an `Endpoint` resource.
- Deploying the `Model` resource to an `Endpoint` resource.
- Make an online prediction to the `Model` resource instance deployed to the `Endpoint` resource.
```
[Get started with TensorFlow Serving](get_started_with_tf_serving.ipynb)
```
The steps performed include:
- Download a pretrained image classification model from TensorFlow Hub.
- Create a serving function to receive compressed image data, and output decomopressed preprocessed data for the model input.
- Upload the TensorFlow Hub model and serving function as a `Vertex AI Model` resource.
- Creating an `Endpoint` resource.
- Deploying the `Model` resource to an `Endpoint` resource with `TensorFlow Serving` serving binary.
- Make an online prediction to the `Model` resource instance deployed to the `Endpoint` resource.
```
[Get started with FastAPI serving binary](get_started_with_fastapi.ipynb)
```
The steps performed include:
- Download a pretrained image classification model from TensorFlow Hub.
- Create a serving function to receive compressed image data, and output decomopressed preprocessed data for the model input.
- Upload the TensorFlow Hub model and serving function as a `Vertex AI Model` resource.
- Creating an `Endpoint` resource.
- Deploying the `Model` resource to an `Endpoint` resource with `FastAPI` custom serving binary.
- Make an online prediction to the `Model` resource instance deployed to the `Endpoint` resource.
```
[Get started with Vertex AI Prediction optimized TensorFlow run-time container](get_started_with_optimized_tfe_bert.ipynb)
```
The steps performed include:
- Download a pretrained BERT model from TensorFlow Hub.
- Fine-tune (transfer learning) the BERT model as a binary classifier.
- Upload the TensorFlow Hub model as a `Vertex AI Model` resource, with standard TensorFlow serving container.
- Upload the TensorFlow Hub model as a `Vertex AI Model` resource, with `Vertex AI Prediction optimized TensorFlow runtime` container
- Create two `Endpoint` resources.
- Deploying both `Model` resources to separate `Endpoint` resources.
- Make the same online prediction requests to both `Model` resource instances deployed to the `Endpoint` resources.
- Compare the prediction accuracy between the two deployed `Model` resources.
- Configuring container settings for fine-tune control of optimizations.
- Create a `Private Endpoint` resource.
- Deploy the `Model` resoure with then `Vertex AI Prediction optimized TensorFlow runtime` to the `Private Endpoint` resource.
- Make an online prediction request to the `Private Endpoint` resource.
```
[Get started with Nvidia Triton Server](get_started_with_nvidia_triton_server.ipynb)
```
The steps performed in this tutorial include:
- Download the model artifacts from TensorFlow Hub.
- Create Triton serving configuration file for the model.
- Construct a custom container, with Triton serving image, for model deployment.
- Locally test the custom container.
- Upload the model as a Vertex AI Model resource.
- Deploy the Vertex AI Model resource to a Vertex AI Endpoint resource.
- Make a prediction request
- Undeploy the Model resource and delete the Endpoint
```
[Get started with Vertex AI Matching Engine](get_started_with_matching_engine.ipynb)
```
The steps performed include:
- Create ANN Index.
- Create an IndexEndpoint with VPC Network
- Deploy ANN Index
- Perform online query
- Deploy brute force Index.
- Perform calibration between ANN and brute force index.
```
[Get started with Vertex AI Matching Engine using Two Towers builtin algorithm](get_started_with_matchine_engine_twotowers.ipynb)
```
The steps performed include:
1. Train the `Two-Tower` algorithm to generate embeddings (encoder) for the dataset.
2. Hyperparameter tune the trained `Two-Tower` encoder.
3. Make example predictions (embeddings) from then trained encoder.
4. Generate embeddings using the trained `Two-Tower` builtin algorithm.
5. Store embeddings to format supported by `Matching Engine`.
6. Create a `Matching Engine Index` for the embeddings.
7. Deploy the `Matching Engine Index` to a `Index Endpoint`.
8. Make a matching engine prediction request.
```
[Get started with Vertex AI Matching Engine using Swivel builtin algorithm](get_started_with_matchine_swivel.ipynb)
```
The steps performed include:
1. Train the `Swivel` algorithm to generate embeddings (encoder) for the dataset.
2. Hyperparameter tune the trained `Swivel` encoder.
3. Make example predictions (embeddings) from then trained encoder.
4. Generate embeddings using the trained `Swivel` builtin algorithm.
5. Store embeddings to format supported by `Matching Engine`.
6. Create a `Matching Engine Index` for the embeddings.
7. Deploy the `Matching Engine Index` to a `Index Endpoint`.
8. Make a matching engine prediction request.
```
[Get started with Explainable AI and custom model server](get_started_with_xai_and_custom_server.ipynb)
```
The steps performed include:
- Locally train a Pytorch tabular classifier.
- Locally test the trained model.
- Build a HTTP server using FastAPI.
@@ -201,4 +119,89 @@ The steps performed include:
- Deploy the `Model` resource to an `Endpoint` resource.
- Make a prediction request to the deployed custom serving container.
- Make an explanation request to the deployed custom serving container.
```
[Get started with TensorFlow serving functions with Vertex AI Raw Prediction](get_started_with_raw_predict.ipynb)
```
The steps performed include:
- Download a pretrained tabular classification model artifacts for a TensorFlow 1.x estimator.
- Upload the TensorFlow estimator model as a `Vertex AI Model` resource.
- Creating an `Endpoint` resource.
- Deploying the `Model` resource to an `Endpoint` resource.
- Make an online raw prediction to the `Model` resource instance deployed to the `Endpoint` resource.
```
[Get started with Vertex AI Matching Engine and Two Towers builtin algorithm](get_started_with_matching_engine_twotowers.ipynb)
```
The steps performed include:
1. Train the `Two-Tower` algorithm to generate embeddings (encoder) for the dataset.
2. Hyperparameter tune the trained `Two-Tower` encoder.
3. Make example predictions (embeddings) from then trained encoder.
4. Generate embeddings using the trained `Two-Tower` builtin algorithm.
5. Store embeddings to format supported by `Matching Engine`.
6. Create a `Matching Engine Index` for the embeddings.
7. Deploy the `Matching Engine Index` to a `Index Endpoint`.
8. Make a matching engine prediction request.
```
[Get started with Optimized TensorFlow Enterprise container with Vertex AI Prediction / text models](get_started_with_optimized_tfe_bert.ipynb)
```
The steps performed include:
- Download a pretrained BERT model from TensorFlow Hub.
- Fine-tune (transfer learning) the BERT model as a binary classifier.
- Upload the TensorFlow Hub model as a `Vertex AI Model` resource, with standard TensorFlow serving container.
- Upload the TensorFlow Hub model as a `Vertex AI Model` resource, with TensorFlow Enterprise Optimized container
- Create two `Endpoint` resources.
- Deploying both `Model` resources to separate `Endpoint` resources.
- Make the same online prediction requests to both `Model` resource instances deployed to the `Endpoint` resources.
- Compare the prediction accuracy between the two deployed `Model` resources.
- Configuring container settings for fine-tune control of optimizations.
- Create a `Private Endpoint` resource.
- Deploy the `Model` resoure with then `TensorFlow Enterprise Optimized` to the `Private Endpoint` resource.
- Make an online prediction request to the `Private Endpoint` resource.
```
[Get started with Vertex AI Matching Engine](get_started_with_matching_engine.ipynb)
```
The steps performed include:
- Create ANN Index.
- Create an IndexEndpoint with VPC Network
- Deploy ANN Index
- Perform online query
- Deploy brute force Index.
- Perform calibration between ANN and brute force index.
```
[Get started with Vertex AI Matching Engine and Swivel builtin algorithm](get_started_with_matching_engine_swivel.ipynb)
```
The steps performed include:
1. Train the `Swivel` algorithm to generate embeddings (encoder) for the dataset.
2. Make example predictions (embeddings) from then trained encoder.
3. Generate embeddings using the trained `Swivel` builtin algorithm.
4. Store embeddings to format supported by `Matching Engine`.
5. Create a `Matching Engine Index` for the embeddings.
6. Deploy the `Matching Engine Index` to a `Index Endpoint`.
7. Make a matching engine prediction request.
```
[Get started with TensorFlow serving with Vertex AI Prediction](get_started_with_tf_serving.ipynb)
```
The steps performed include:
- Download a pretrained image classification model from TensorFlow Hub.
- Create a serving function to receive compressed image data, and output decomopressed preprocessed data for the model input.
- Upload the TensorFlow Hub model and serving function as a `Vertex AI Model` resource.
- Creating an `Endpoint` resource.
- Deploying the `Model` resource to an `Endpoint` resource with `TensorFlow Serving` serving binary.
- Make an online prediction to the `Model` resource instance deployed to the `Endpoint` resource.
```
@@ -0,0 +1,879 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "copyright"
},
"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": "title:generic,gcp"
},
"source": [
"# E2E ML on GCP: MLOps stage 6 : serving: get started with re-importing AutoML tabular models\n",
"\n",
"<table align=\"left\">\n",
" <td>\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage6/get_started_automl_tabular_exported_deploy.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://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage6/get_started_automl_tabular_exported_deploy.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/colab-logo-32px.png\" alt=\"Colab logo\"> Run in Colab\n",
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://raw.githubusercontent.com/GoogleCloudPlatform/vertex-ai-samples/main/notebooks/community/ml_ops/stage6/get_started_automl_tabular_exported_deploy.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/>"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "overview:mlops"
},
"source": [
"## 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 AutoML Training."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "objective:mlops,stage2,get_started_automl_training"
},
"source": [
"### Objective\n",
"\n",
"In this tutorial, you learn how to use `AutoML Tabular` for re-importing exported model artifacts as a `Model` resource. This is useful for example, if one wants to move the exported model across projects.\n",
"\n",
"This tutorial uses the following Google Cloud ML services:\n",
"\n",
"- `AutoML Tabular`\n",
"- `Vertex AI Model` resource\n",
"- `Vertex AI Prediction`\n",
"\n",
"The steps performed include:\n",
"\n",
"- Importing a pretrained AutoML tabular exported model artifacts, as a `Model` resource.\n",
"- Create an `Endpoint` resource.\n",
"- Deploy the `Model` resource to the `Endpoint` resource.\n",
"- Make a prediction."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dataset:flowers,icn"
},
"source": [
"### Dataset\n",
"\n",
"This tutorial uses a pretrained AutoML tabular model with exported model artifacts.\n",
"\n",
"\n",
"The tabular dataset used for the pretrained model is the GSOD dataset from [BigQuery public datasets](https://cloud.google.com/bigquery/public-data). The version of the dataset you use only the fields year, month and day to predict the value of mean daily temperature (mean_temp).\n",
"\n",
"*Note:* This version of the exported model contains the custom op and requires the model server: us-docker.pkg.dev/vertex-ai/automl-tabular/prediction-server"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "fb3451ce8e47"
},
"source": [
"### Costs\n",
"This tutorial uses billable components of Google Cloud:\n",
"\n",
"- Vertex AI\n",
"- Cloud Storage\n",
"\n",
"Learn about [Vertex AI pricing](https://cloud.google.com/vertex-ai/pricing) and [Cloud Storage pricing](https://cloud.google.com/storage/pricing) and use the [Pricing Calculator](https://cloud.google.com/products/calculator/) to generate a cost estimate based on your projected usage."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "install_mlops"
},
"source": [
"## Installations\n",
"\n",
"Install the packages required for executing this notebook."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "install_mlops"
},
"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",
"# Install the packages\n",
"\n",
"! pip3 install --upgrade google-cloud-aiplatform {USER_FLAG} -q\n",
"! pip3 install --upgrade google-cloud-storage {USER_FLAG} -q"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "restart"
},
"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": "restart"
},
"outputs": [],
"source": [
"import os\n",
"\n",
"if not os.getenv(\"IS_TESTING\"):\n",
" # Automatically restart kernel after installs\n",
" import IPython\n",
"\n",
" app = IPython.Application.instance()\n",
" app.kernel.do_shutdown(True)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "project_id"
},
"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",
"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, Compute Engine and Cloud Storage APIs](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com,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": "56d591439df1"
},
"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`."
]
},
{
"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": "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": "3ffa6b6c7cdb"
},
"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": "2b72272258fc"
},
"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": "bucket:mbsdk"
},
"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 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": "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"
]
},
{
"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"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "import_aip:mbsdk"
},
"outputs": [],
"source": [
"import google.cloud.aiplatform as aiplatform"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "init_aip:mbsdk"
},
"source": [
"### Initialize Vertex AI SDK for Python\n",
"\n",
"Initialize the Vertex AI SDK for Python for your project and corresponding bucket."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "init_aip:mbsdk"
},
"outputs": [],
"source": [
"aiplatform.init(project=PROJECT_ID, staging_bucket=BUCKET_URI)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "machine:training"
},
"source": [
"#### Set machine type\n",
"\n",
"Next, set the machine type to use for training.\n",
"\n",
"- Set the variable `DEPLOY_COMPUTE` to configure the compute resources for the VMs you will use for for training.\n",
" - `machine type`\n",
" - `n1-standard`: 3.75GB of memory per vCPU.\n",
" - `n1-highmem`: 6.5GB of memory per vCPU\n",
" - `n1-highcpu`: 0.9 GB of memory per vCPU\n",
" - `vCPUs`: number of \\[2, 4, 8, 16, 32, 64, 96 \\]\n",
"\n",
"*Note: The following is not supported for training:*\n",
"\n",
" - `standard`: 2 vCPUs\n",
" - `highcpu`: 2, 4 and 8 vCPUs\n",
"\n",
"*Note: You may also use n2 and e2 machine types for training and deployment, but they do not support GPUs*."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "machine:training"
},
"outputs": [],
"source": [
"if os.getenv(\"IS_TESTING_DEPLOY_MACHINE\"):\n",
" MACHINE_TYPE = os.getenv(\"IS_TESTING_DEPLOY_MACHINE\")\n",
"else:\n",
" MACHINE_TYPE = \"n1-standard\"\n",
"\n",
"VCPU = \"4\"\n",
"DEPLOY_COMPUTE = MACHINE_TYPE + \"-\" + VCPU\n",
"print(\"Train machine type\", DEPLOY_COMPUTE)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "import_file:u_dataset,csv"
},
"source": [
"### Location of pretrained `AutoML Tabular` exported model\n",
"\n",
"Now set the variable `MODEL_PACKAGE` to the location of the exported model artifacts in Cloud Storage."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "import_file:flowers,csv,icn"
},
"outputs": [],
"source": [
"MODEL_PACKAGE = \"gs://cloud-samples-data/vertex-ai/tabular-workflows/models/custom_op\""
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "quick_peek:csv"
},
"source": [
"#### Quick peek at your model package.\n",
"\n",
"Next, take a look at the contents of the model package for the exported AutoML tabular model."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "quick_peek:csv"
},
"outputs": [],
"source": [
"! gsutil ls {MODEL_PACKAGE}"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "automl_tabular_intro"
},
"source": [
"## AutoML tabular models\n",
"\n",
"AutoML can train the following types of tabular models:\n",
"\n",
"- classification\n",
"- regression\n",
"- forecasting\n",
"\n",
"A model can be trained for either automatic deployment to the cloud or exported for manual deployment to the cloud. In this tutorial, you use a pretrained exported AutoML tabular model.\n",
"\n",
"Learn more about [AutoML Model Types](https://cloud.google.com/vertex-ai/docs/start/automl-model-types)\n",
"\n",
"Learn more about [Exporting AutoML Tabular models](https://cloud.google.com/vertex-ai/docs/export/export-model-tabular)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "c10efb34321b"
},
"source": [
"### Set the model server\n",
"\n",
"Next, you set the pre-built container for the model server. The container will be a version of `us-docker.pkg.dev/vertex-ai/automl-tabular/prediction-server`. If the model package contains an `environment.json` file, use the container version specified by the key `container_uri`; otherwise, use `us-docker.pkg.dev/vertex-ai/automl-tabular/prediction-server:latest` "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "a5f271de9040"
},
"outputs": [],
"source": [
"import json\n",
"\n",
"output = !gsutil cat {MODEL_PACKAGE}/environment.json\n",
"\n",
"MODEL_SERVER = json.loads(output[0])[\"container_uri\"]"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "e8ce91147c93"
},
"source": [
"### Upload the pretrained exported `AutoML Tabular` model package to a `Vertex AI Model` resource\n",
"\n",
"Next, you upload the model artifacts for the pretrained exported `AutoML Tabular` model into a `Vertex AI Model` resource, using the `Model.upload()` method with the following parameters:\n",
"\n",
"- `display_name`: A human readable name for the `Model` resource.\n",
"- `artifact_uri`: The Cloud Storage location of the model package.\n",
"- `serving_container_image_uri`: The serving container image.\n",
"- `serving_container_ports`: The serving port.\n",
"\n",
"*Note:* When you upload the model artifacts to a `Vertex Model` resource, you specify the corresponding deployment container image."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "7988eae27f80"
},
"outputs": [],
"source": [
"model = aiplatform.Model.upload(\n",
" display_name=\"gsod_\" + TIMESTAMP,\n",
" artifact_uri=MODEL_PACKAGE,\n",
" serving_container_image_uri=MODEL_SERVER,\n",
" serving_container_ports=[8080],\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "628de0914ba1"
},
"source": [
"## Creating an `Endpoint` resource\n",
"\n",
"You create an `Endpoint` resource using the `Endpoint.create()` method. At a minimum, you specify the display name for the endpoint. Optionally, you can specify the project and location (region); otherwise the settings are inherited by the values you set when you initialized the Vertex AI SDK with the `init()` method.\n",
"\n",
"In this example, the following parameters are specified:\n",
"\n",
"- `display_name`: A human readable name for the `Endpoint` resource.\n",
"- `project`: Your project ID.\n",
"- `location`: Your region.\n",
"- `labels`: (optional) User defined metadata for the `Endpoint` in the form of key/value pairs.\n",
"\n",
"This method returns an `Endpoint` object.\n",
"\n",
"Learn more about [Vertex AI Endpoints](https://cloud.google.com/vertex-ai/docs/predictions/deploy-model-api)."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "0ea443f9593b"
},
"outputs": [],
"source": [
"endpoint = aiplatform.Endpoint.create(\n",
" display_name=\"gsod_\" + TIMESTAMP,\n",
" project=PROJECT_ID,\n",
" location=REGION,\n",
" labels={\"your_key\": \"your_value\"},\n",
")\n",
"\n",
"print(endpoint)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "ca3fa3f6a894"
},
"source": [
"## Deploying `Model` resources to an `Endpoint` resource.\n",
"\n",
"You can deploy one of more `Vertex AI Model` resource instances to the same endpoint. Each `Vertex AI Model` resource that is deployed will have its own deployment container for the serving binary. \n",
"\n",
"*Note:* For this example, you specified the deployment container for the exported AutoML Tabular model in the previous step of uploading the model artifacts to a `Vertex AI Model` resource.\n",
"\n",
"To deploy, you specify the following additional configuration settings:\n",
"\n",
"- The machine type.\n",
"- The (if any) type and number of GPUs.\n",
"- Static, manual or auto-scaling of VM instances.\n",
"\n",
"In this example, you deploy the model with the minimal amount of specified parameters, as follows:\n",
"\n",
"- `model`: The `Model` resource.\n",
"- `deployed_model_displayed_name`: The human readable name for the deployed model instance.\n",
"- `machine_type`: The machine type for each VM instance.\n",
"\n",
"Do to the requirements to provision the resource, this may take upto a few minutes."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "4e93b034a72f"
},
"outputs": [],
"source": [
"response = endpoint.deploy(\n",
" model=model,\n",
" deployed_model_display_name=\"gsod_\" + TIMESTAMP,\n",
" machine_type=DEPLOY_COMPUTE,\n",
")\n",
"\n",
"print(response)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "f75331c946d5"
},
"source": [
"## Make a prediction\n",
"\n",
"Finally, you make an online prediction using the `endpoint()` method, with the following parameters:\n",
"\n",
"- `instances`: The instances to predict.\n",
"\n",
"The following is the for a prediction request:\n",
"\n",
" [ INSTANCE_1, INSTANCE_2, ... ]\n",
" \n",
" INSTANCE : { \"column_1\": value, \"column_2\": value, ... }\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "72683bd9d777"
},
"outputs": [],
"source": [
"INSTANCES = [{\"year\": \"2020\", \"month\": \"1\", \"day\": \"23\"}]\n",
"\n",
"prediction = endpoint.predict(instances=INSTANCES)\n",
"print(prediction)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "endpoint_delete:mbsdk"
},
"source": [
"#### Delete the endpoint\n",
"\n",
"The method 'delete()' will delete the endpoint."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "endpoint_delete:mbsdk"
},
"outputs": [],
"source": [
"endpoint.undeploy_all()\n",
"endpoint.delete()"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "model_delete:mbsdk"
},
"source": [
"#### Delete the model\n",
"\n",
"The method 'delete()' will delete the model."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "model_delete:mbsdk"
},
"outputs": [],
"source": [
"model.delete()"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "cleanup"
},
"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"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "cleanup"
},
"outputs": [],
"source": [
"# Set this to true only if you'd like to delete your bucket\n",
"delete_bucket = False\n",
"\n",
"if delete_bucket or os.getenv(\"IS_TESTING\"):\n",
" ! gsutil rm -r $BUCKET_URI"
]
}
],
"metadata": {
"colab": {
"name": "get_started_automl_tabular_exported_deploy.ipynb",
"toc_visible": true
},
"kernelspec": {
"display_name": "Python 3",
"name": "python3"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
@@ -32,18 +32,18 @@
"# E2E ML on GCP: MLOps stage 6 : Get started with Custom Prediction Routine (CPR)\n",
"<table align=\"left\">\n",
" <td>\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage6/get_started_with_custom_predictions.ipynb\">\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage6/get_started_with_cpr.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/colab-logo-32px.png\" alt=\"Colab logo\"> Run in Colab\n",
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage6/get_started_with_custom_predictions.ipynb\">\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage6/get_started_with_cpr.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/ml_ops/stage6/get_started_with_custom_predictions.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/stage6/get_started_with_cpr.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",
@@ -113,7 +113,22 @@
"source": [
"### Dataset\n",
"\n",
"The dataset used for this tutorial is the [Iris dataset](https://www.tensorflow.org/datasets/catalog/iris) from [Tensorflow Datasets](https://www.tensorflow.org/datasets/catalog/overview). This dataset does not require any feature engineering. The version of the dataset you will use in this tutorial is stored in a public Cloud Storage bucket. The trained model predicts the type of Iris flower species from a class of three species: setosa, virginica, or versicolor."
"The dataset used for this tutorial is the [Iris dataset](https://www.tensorflow.org/datasets/catalog/iris) from [TensorFlow Datasets](https://www.tensorflow.org/datasets/catalog/overview). This dataset does not require any feature engineering. The version of the dataset in this tutorial is stored in a public Cloud Storage bucket. The trained model predicts the type of Iris flower species from a class of three species: setosa, virginica, or versicolor."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "fb3451ce8e47"
},
"source": [
"### Costs\n",
"This tutorial uses billable components of Google Cloud:\n",
"\n",
"- Vertex AI\n",
"- Cloud Storage\n",
"\n",
"Learn about [Vertex AI pricing](https://cloud.google.com/vertex-ai/pricing) and [Cloud Storage pricing](https://cloud.google.com/storage/pricing) and use the [Pricing Calculator](https://cloud.google.com/products/calculator/) to generate a cost estimate based on your projected usage."
]
},
{
@@ -122,7 +137,7 @@
"id": "i7EUnXsZhAGF"
},
"source": [
"### Install additional packages\n",
"## Installation\n",
"\n",
"Install additional package dependencies not installed in your notebook environment, such as NumPy, Scikit-learn, FastAPI, Uvicorn, and joblib. Use the latest major GA version of each package."
]
@@ -151,18 +166,7 @@
"uvicorn\n",
"joblib~=1.0\n",
"numpy~=1.20\n",
"scikit-learn~=0.24\n",
"google-cloud-storage>=1.26.0,<2.0.0dev\n",
"google-cloud-aiplatform[prediction] @ git+https://github.com/googleapis/python-aiplatform.git@custom-prediction-routine"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "faf22f3af1ce"
},
"source": [
"**The model you deploy will have a different set of dependencies pre-installed than your notebook environment has. You should not assume that because things work in the notebook, they will work in the model. Instead, you will be very explicit about the dependencies for the model by listing them in requirements.txt and then use `pip install` to install the exact same dependencies in the notebook. Please note, of course, that there is a chance that a dependency is missed in requirements.txt that already exists in the notebook. If that's the case, things will run in the notebook, but not in the model. To guard against that, you will test the model locally before deploying to the cloud.**"
"scikit-learn~=0.24"
]
},
{
@@ -186,6 +190,10 @@
"if IS_WORKBENCH_NOTEBOOK:\n",
" USER_FLAG = \"--user\"\n",
"\n",
"\n",
"! pip3 install --upgrade google-cloud-aiplatform[prediction] {USER_FLAG} -q\n",
"! pip3 install --upgrade google-cloud-storage {USER_FLAG} -q\n",
"\n",
"# Install the same dependencies used in the serving container in the notebook\n",
"# environment.\n",
"! pip3 install -U {USER_FLAG} -r src/requirements.txt"
@@ -243,7 +251,7 @@
"\n",
"3. [Enable the following APIs: Vertex AI APIs, Compute Engine APIs, and Cloud Storage.](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.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",
@@ -453,8 +461,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-\" + TIMESTAMP\n",
" BUCKET_URI = \"gs://\" + BUCKET_NAME"
]
},
{
@@ -955,7 +964,7 @@
"REPOSITORY = \"custom-preprocess-container-prediction\" # @param {type:\"string\"}\n",
"SERVER_IMAGE = \"sklearn-cpr-preprocess-server\" # @param {type:\"string\"}\n",
"\n",
"local_model = LocalModel.create_cpr_model(\n",
"local_model = LocalModel.build_cpr_model(\n",
" \"src\",\n",
" f\"{REGION}-docker.pkg.dev/{PROJECT_ID}/{REPOSITORY}/{SERVER_IMAGE}\",\n",
" predictor=CprPredictor,\n",
@@ -1206,7 +1215,8 @@
},
"outputs": [],
"source": [
"model = local_model.upload(\n",
"model = aip.Model.upload(\n",
" local_model=local_model,\n",
" display_name=\"iris_\" + TIMESTAMP,\n",
" artifact_uri=f\"{BUCKET_URI}/model\",\n",
")"
@@ -1465,7 +1475,7 @@
"from google.cloud.aiplatform.prediction import LocalModel\n",
"from src.predictor import CprPredictor\n",
"\n",
"local_model = LocalModel.create_cpr_model(\n",
"local_model = LocalModel.build_cpr_model(\n",
" \"src\",\n",
" f\"{REGION}-docker.pkg.dev/{PROJECT_ID}/{REPOSITORY}/{SERVER_IMAGE}\",\n",
" predictor=CprPredictor,\n",
@@ -1651,7 +1661,8 @@
},
"outputs": [],
"source": [
"model = local_model.upload(\n",
"model = aip.Model.upload(\n",
" local_model=local_model,\n",
" display_name=\"iris_\" + TIMESTAMP,\n",
" artifact_uri=f\"{BUCKET_URI}/model\",\n",
")"
@@ -1853,7 +1864,7 @@
"from src.handler import CprHandler\n",
"from src.predictor import CprPredictor\n",
"\n",
"local_model = LocalModel.create_cpr_model(\n",
"local_model = LocalModel.build_cpr_model(\n",
" \"src\",\n",
" f\"{REGION}-docker.pkg.dev/{PROJECT_ID}/{REPOSITORY}/{SERVER_IMAGE}\",\n",
" predictor=CprPredictor,\n",
@@ -2079,7 +2090,8 @@
},
"outputs": [],
"source": [
"model = local_model.upload(\n",
"model = aip.Model.upload(\n",
" local_model=local_model,\n",
" display_name=\"iris_\" + TIMESTAMP,\n",
" artifact_uri=f\"{BUCKET_URI}/model\",\n",
")"
@@ -2403,7 +2415,7 @@
"id": "212b2935ea12"
},
"source": [
"### Push the container to artifact registry\n",
"### Push the container to Artifact Registry\n",
"\n",
"#### Configure Docker to access Artifact Registry"
]
@@ -2460,7 +2472,8 @@
},
"outputs": [],
"source": [
"model = local_model.upload(\n",
"model = aip.Model.upload(\n",
" local_model=local_model,\n",
" display_name=\"iris_\" + TIMESTAMP,\n",
" artifact_uri=f\"{BUCKET_URI}/model\",\n",
")"
@@ -212,7 +212,7 @@
"\n",
"3. [Enable the following APIs: Vertex AI APIs, Compute Engine APIs, and Cloud Storage.](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.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",
@@ -29,7 +29,7 @@
"id": "3e4b7925f2ff"
},
"source": [
"Notebook is a revised version of notebook from [Sara Robinson and Ivan Chueng](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/matching_engine/sdk_matching_engine_for_indexing.ipynb)"
"This notebook is a revised version of notebook from [Sara Robinson and Ivan Chueng](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/matching_engine/sdk_matching_engine_for_indexing.ipynb)"
]
},
{
@@ -49,14 +49,14 @@
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/communityml_ops/stage6/get_started_with_matching_engine.ipynbb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/colab-logo-32px.png\\\" alt=\"Colab logo\"> Run in Colab\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage6/get_started_with_matching_engine.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/colab-logo-32px.png\" alt=\"Colab logo\"> Run in Colab\n",
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://raw.githubusercontent.com/GoogleCloudPlatform/vertex-ai-samples/main/notebooks/community/ml_ops/stage6/get_started_with_matching_engine.ipynbb\">\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/stage6/get_started_with_matching_engine.ipynb\">\n",
" <img src=\"https://lh3.googleusercontent.com/UiNooY4LUgW_oTvpsNhPpQzsstV5W8F7rYgxgGBD85cWJoLmrOzhVs_ksK_vgx40SHs7jCqkTkCk=e14-rj-sc0xffffff-h130-w32\" alt=\"Vertex AI logo\">\n",
" Run in Vertex Workbench\n",
" Open in Vertex AI Workbench\n",
" </a>\n",
" </td>\n",
"</table>"
@@ -87,28 +87,52 @@
"\n",
"The user configures the serving binary how to generate embeddings from the model, indexing and querying, using `Vertex AI Explanations by Examples`\n",
"\n",
"Learn more about [Vertex AI Matching Engine](https://cloud.google.com/vertex-ai/docs/matching-engine/overview)\n",
"Learn more about [Vertex AI Matching Engine](https://cloud.google.com/vertex-ai/docs/matching-engine/overview)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "f0550a2d6016"
},
"source": [
"### Objective\n",
"\n",
"In this notebook, you learn how to create Approximate Nearest Neighbor (ANN) Index, query against indexes. \n",
"\n",
"This tutorial uses the following Google Cloud ML services:\n",
"\n",
"- `Vertex AI Matching Engine`\n",
"\n",
"The steps performed include:\n",
"\n",
"- Create ANN Index.\n",
"- Create an IndexEndpoint with VPC Network\n",
"- Deploy ANN Index\n",
"- Perform online query\n",
"- Deploy brute force Index.\n",
"- Perform calibration between ANN and brute force index."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "d63423fd74f7"
},
"source": [
"### Embeddings\n",
"\n",
"The prebuilt embeddings used for this tutorial is the [GloVe dataset](https://nlp.stanford.edu/projects/glove/).\n",
"\n",
" \"GloVe is an unsupervised learning algorithm for obtaining vector representations for words. Training is performed on aggregated global word-word co-occurrence statistics from a corpus, and the resulting representations showcase interesting linear substructures of the word vector space.\"\n",
"\n",
"### Objective\n",
"\n",
"In this notebook, you will learn how to create Approximate Nearest Neighbor (ANN) Index, query against indexes. \n",
"\n",
"The steps performed include:\n",
"\n",
"* Create ANN Index.\n",
"* Create an IndexEndpoint with VPC Network\n",
"* Deploy ANN Index\n",
"* Perform online query\n",
"* Deploy brute force Index.\n",
"* Perform calibration between ANN and brute force index.\n",
"\n",
"\n",
" \"GloVe is an unsupervised learning algorithm for obtaining vector representations for words. Training is performed on aggregated global word-word co-occurrence statistics from a corpus, and the resulting representations showcase interesting linear substructures of the word vector space.\"\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "de76bb18c85b"
},
"source": [
"### Costs \n",
"\n",
"This tutorial uses billable components of Google Cloud:\n",
@@ -216,9 +240,9 @@
"\n",
"5. [Enable the Cloud DNS API](https://console.cloud.google.com/flows/enableapi?apiid=dns.googleapis.com).\n",
"\n",
"6. If you are running this notebook locally, you will need to install the [Cloud SDK]((https://cloud.google.com/sdk)).\n",
"6. If you are running this notebook locally, you need to install the [Cloud SDK]((https://cloud.google.com/sdk)).\n",
"\n",
"7. Enter your project ID in the cell below. Then run the cell to make sure the\n",
"7. 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 `$`."
@@ -29,7 +29,7 @@
"id": "63084117b407"
},
"source": [
"Notebook is a revised version of notebook from [Amy Wu](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/matching_engine/intro-swivel.ipynb)"
"This notebook is a revised version of notebook from [Amy Wu](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/matching_engine/intro-swivel.ipynb)"
]
},
{
@@ -43,12 +43,12 @@
"<table align=\"left\">\n",
"\n",
" <td>\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/master/notebooks/community/ml_ops/stage6/get_started_with_matching_engine_swivel.ipynb\">\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage6/get_started_with_matching_engine_swivel.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/colab-logo-32px.png\" alt=\"Colab logo\"> Run in Colab\n",
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/tree/master/notebooks/ocommunity/ml_ops/stage6/get_started_with_matching_engine_swivel.ipynb\">\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage6/get_started_with_matching_engine_swivel.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",
@@ -56,7 +56,7 @@
" <td>\n",
" <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://raw.githubusercontent.com/GoogleCloudPlatform/vertex-ai-samples/main/notebooks/community/ml_ops/stage6/get_started_with_matching_engine_swivel.ipynb\">\n",
" <img src=\"https://lh3.googleusercontent.com/UiNooY4LUgW_oTvpsNhPpQzsstV5W8F7rYgxgGBD85cWJoLmrOzhVs_ksK_vgx40SHs7jCqkTkCk=e14-rj-sc0xffffff-h130-w32\" alt=\"Vertex AI logo\">\n",
" Run in Vertex Workbench\n",
" Open in Vertex AI Workbench\n",
" </a>\n",
" </td>\n",
"</table>"
@@ -65,7 +65,7 @@
{
"cell_type": "markdown",
"metadata": {
"id": "tvgnzT1CKxrO"
"id": "bb1b0670754f"
},
"source": [
"## Overview\n",
@@ -73,16 +73,24 @@
"This notebook demonstrate how to train an embedding with Submatrix-wise Vector Embedding Learner ([Swivel](https://arxiv.org/abs/1602.02215)) using Vertex AI Pipelines. The purpose of the embedding learner is to compute cooccurrences between tokens in a given dataset and to use the cooccurrences to generate embeddings.\n",
"\n",
"Vertex AI provides a pipeline template for training with Swivel, so you don't need to design your own pipeline or write\n",
"your own training code.\n",
"\n",
"### Dataset\n",
"\n",
"This tutorial uses the `movielens sample dataset` in the public bucket `gs://cloud-samples-data/vertex-ai/matching-engine/swivel`, which was generated from the [MovieLens movie rating dataset](https://grouplens.org/datasets/movielens/100k/). This dataset is processed so that each line contains the movies that have same rating by the same user. The directory also includes `movies.csv`, which maps the movie ids to their names.\n",
"\n",
"\n",
"your own training code."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "tvgnzT1CKxrO"
},
"source": [
"### Objective\n",
"\n",
"In this notebook, you will learn how to train custom embeddings using Vertex AI Pipelines and subsequently train and deploy a matching engine index using the embeddings.\n",
"In this notebook, you learn how to train custom embeddings using Vertex AI Pipelines and subsequently train and deploy a matching engine index using the embeddings.\n",
"\n",
"This tutorial uses the following Google Cloud ML services:\n",
"\n",
"- `Vertex AI Swivel` builtin algorithm\n",
"- `Vertex AI Matching Engine`\n",
"- `Vertex AI Batch Prediction`\n",
"\n",
"The steps performed include:\n",
"\n",
@@ -92,8 +100,26 @@
"4. Store embeddings to format supported by `Matching Engine`.\n",
"5. Create a `Matching Engine Index` for the embeddings.\n",
"6. Deploy the `Matching Engine Index` to a `Index Endpoint`.\n",
"7. Make a matching engine prediction request.\n",
"7. Make a matching engine prediction request."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dfe5159ce8cd"
},
"source": [
"### Dataset\n",
"\n",
"This tutorial uses the `movielens sample dataset` in the public bucket `gs://cloud-samples-data/vertex-ai/matching-engine/swivel`, which was generated from the [MovieLens movie rating dataset](https://grouplens.org/datasets/movielens/100k/). This dataset is processed so that each line contains the movies that have same rating by the same user. The directory also includes `movies.csv`, which maps the movie ids to their names."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "302344ccc14b"
},
"source": [
"### Costs \n",
"\n",
"This tutorial uses billable components of Google Cloud:\n",
@@ -117,7 +143,7 @@
"source": [
"### Set up your local development environment\n",
"\n",
"**If you are using Colab or Google Cloud Notebooks**, your environment already meets\n",
"**If you are using Colab or Vertex AI Workbench Notebooks**, your environment already meets\n",
"all the requirements to run this notebook. You can skip this step."
]
},
@@ -164,7 +190,7 @@
"id": "i7EUnXsZhAGF"
},
"source": [
"### Install additional packages\n",
"## Installation\n",
"\n",
"Install packages required for executing this notebook."
]
@@ -251,7 +277,7 @@
"\n",
"1. [Enable the Vertex AI API and Dataflow API](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com,dataflow.googleapis.com).\n",
"\n",
"1. If you are running this notebook locally, you will need to install the [Cloud SDK](https://cloud.google.com/sdk).\n",
"1. If you are running this notebook locally, you need to install the [Cloud SDK](https://cloud.google.com/sdk).\n",
"\n",
"1. Enter your project ID in the cell below. Then run the cell to make sure the\n",
"Cloud SDK uses the right project for all the commands in this notebook.\n",
@@ -398,7 +424,7 @@
"### Authenticate your Google Cloud account\n",
"\n",
"**If you are using Vertex AI Workbench Notebooks**, your environment is already\n",
"authenticated. Skip this step."
"authenticated. "
]
},
{
@@ -1042,7 +1068,7 @@
"model = aiplatform.Model.upload(\n",
" display_name=\"movies_\" + TIMESTAMP,\n",
" artifact_uri=SAVEDMODEL_DIR,\n",
" serving_container_image_uri=DELOY_IMAGE,\n",
" serving_container_image_uri=DEPLOY_IMAGE,\n",
")"
]
},
@@ -1329,8 +1355,6 @@
"source": [
"QUERY_EMBEDDING_PATH = f\"{BUCKET_URI}/embeddings/train.jsonl\"\n",
"\n",
"import tensorflow as tf\n",
"\n",
"with tf.io.gfile.GFile(QUERY_EMBEDDING_PATH, \"w\") as f:\n",
" for i in range(1, 200001):\n",
" query = str(i)\n",
@@ -1391,7 +1415,7 @@
"MAX_NODES = 4\n",
"\n",
"batch_predict_job = model.batch_predict(\n",
" job_display_name=f\"batch_predict_swivel\",\n",
" job_display_name=\"batch_predict_swivel\",\n",
" gcs_source=[QUERY_EMBEDDING_PATH],\n",
" gcs_destination_prefix=f\"{BUCKET_URI}/embeddings/output\",\n",
" machine_type=DEPLOY_COMPUTE,\n",
@@ -29,7 +29,7 @@
"id": "9f40d4af2746"
},
"source": [
"Notebook is a revised version of notebook from [Amy Wu and Shen Zhimo](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/matching_engine/two-tower-model-introduction.ipynb)"
"This notebook is a revised version of notebook from [Amy Wu and Shen Zhimo](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/matching_engine/two-tower-model-introduction.ipynb)"
]
},
{
@@ -48,7 +48,7 @@
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/tree/main/notebooks/ocommunity/ml_ops/stage6/get_started_with_matching_engine_twotowers.ipynb\">\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage6/get_started_with_matching_engine_twotowers.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",
@@ -56,7 +56,7 @@
" <td>\n",
" <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://raw.githubusercontent.com/GoogleCloudPlatform/vertex-ai-samples/main/notebooks/community/ml_ops/stage6/get_started_with_matching_engine_twotowers.ipynb\">\n",
" <img src=\"https://lh3.googleusercontent.com/UiNooY4LUgW_oTvpsNhPpQzsstV5W8F7rYgxgGBD85cWJoLmrOzhVs_ksK_vgx40SHs7jCqkTkCk=e14-rj-sc0xffffff-h130-w32\" alt=\"Vertex AI logo\">\n",
" Run in Vertex Workbench\n",
" Open in Vertex AI Workbench\n",
" </a>\n",
" </td>\n",
"</table>"
@@ -65,20 +65,23 @@
{
"cell_type": "markdown",
"metadata": {
"id": "tvgnzT1CKxrO"
"id": "e955277e5653"
},
"source": [
"## Overview\n",
"\n",
"This tutorial demonstrates how to use the `Vertex AI Two-Tower` built-in algorithm with `Vertex AI Matching Engine`.\n",
"\n",
"### Dataset\n",
"\n",
"This tutorial uses the `movielens_100k sample dataset` in the public bucket `gs://cloud-samples-data/vertex-ai/matching-engine/two-tower`, which was generated from the [MovieLens movie rating dataset](https://grouplens.org/datasets/movielens/100k/). For this tutorial, the data only includes the user id feature for users, and the movie id and movie title features for movies. In this example, the user is the query object and the movie is the candidate object, and each training example in the dataset contains a user and a movie they rated (we only include positive ratings in the dataset). The two-tower model will embed the user and the movie in the same embedding space, so that given a user, the model will recommend movies it thinks the user will like.\n",
"\n",
"This tutorial demonstrates how to use the `Vertex AI Two-Tower` built-in algorithm with `Vertex AI Matching Engine`."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "tvgnzT1CKxrO"
},
"source": [
"### Objective\n",
"\n",
"In this notebook, you will learn how to use the `Two-Tower` builtin algorithms for generating embeddings for a dataset, for use with generating an `Matching Engine Index`, with the `Vertex AI Matching Engine` service.\n",
"In this notebook, you learn how to use the `Two-Tower` builtin algorithms for generating embeddings for a dataset, for use with generating an `Matching Engine Index`, with the `Vertex AI Matching Engine` service.\n",
"\n",
"This tutorial uses the following Google Cloud ML services:\n",
" \n",
@@ -86,7 +89,7 @@
"- `Vertex AI Matching Engine`\n",
"- `Vertex AI Batch Prediction`\n",
"\n",
"The tutorial covers the following steps:\n",
"The steps performed include:\n",
"\n",
"1. Train the `Two-Tower` algorithm to generate embeddings (encoder) for the dataset.\n",
"2. Hyperparameter tune the trained `Two-Tower` encoder.\n",
@@ -95,9 +98,26 @@
"5. Store embeddings to format supported by `Matching Engine`.\n",
"6. Create a `Matching Engine Index` for the embeddings.\n",
"7. Deploy the `Matching Engine Index` to a `Index Endpoint`.\n",
"8. Make a matching engine prediction request.\n",
"\n",
"8. Make a matching engine prediction request.\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "604409190dde"
},
"source": [
"### Dataset\n",
"\n",
"This tutorial uses the `movielens_100k sample dataset` in the public bucket `gs://cloud-samples-data/vertex-ai/matching-engine/two-tower`, which was generated from the [MovieLens movie rating dataset](https://grouplens.org/datasets/movielens/100k/). For this tutorial, the data only includes the user id feature for users, and the movie id and movie title features for movies. In this example, the user is the query object and the movie is the candidate object, and each training example in the dataset contains a user and a movie they rated (only positive ratings are included in the dataset). The two-tower model embeds the user and the movie in the same embedding space, so that given a user, the model recommends movies for the user."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "9cfa2678eec4"
},
"source": [
"### Costs \n",
"\n",
"\n",
@@ -122,7 +142,7 @@
"source": [
"### Set up your local development environment\n",
"\n",
"**If you are using Colab or Google Cloud Notebooks**, your environment already meets\n",
"**If you are using Colab or Vertex AI Workbench Notebooks**, your environment already meets\n",
"all the requirements to run this notebook. You can skip this step."
]
},
@@ -255,7 +275,7 @@
"\n",
"1. [Enable the Vertex AI API](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com).\n",
"\n",
"1. If you are running this notebook locally, you will need to install the [Cloud SDK](https://cloud.google.com/sdk).\n",
"1. If you are running this notebook locally, you need to install the [Cloud SDK](https://cloud.google.com/sdk).\n",
"\n",
"1. Enter your project ID in the cell below. Then run the cell to make sure the\n",
"Cloud SDK uses the right project for all the commands in this notebook.\n",
@@ -402,7 +422,7 @@
"### Authenticate your Google Cloud account\n",
"\n",
"**If you are using Vertex AI Workbench Notebooks**, your environment is already\n",
"authenticated. Skip this step."
"authenticated. "
]
},
{
@@ -29,7 +29,7 @@
"id": "8e6e4a3496b0"
},
"source": [
"Notebook is a revised version of notebook from [Rajesh Thallam](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/vertex_endpoints/nvidia-triton/nvidia-triton-custom-container-prediction.ipynb)"
"This notebook is a revised version of notebook from [Rajesh Thallam](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/vertex_endpoints/nvidia-triton/nvidia-triton-custom-container-prediction.ipynb)"
]
},
{
@@ -43,18 +43,18 @@
"<table align=\"left\">\n",
"\n",
" <td>\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage6/get_started_with_nvidia_triton_server.ipynb\">\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage6/get_started_with_nvidia_triton_serving.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-samplestree/main/notebooks/community/ml_ops/stage6/get_started_with_nvidia_triton_server.ipynb\">\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage6/get_started_with_nvidia_triton_serving.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/ml_ops/stage6/get_started_with_nvidia_triton_server.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/stage6/get_started_with_nvidia_triton_serving.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",
@@ -65,17 +65,20 @@
{
"cell_type": "markdown",
"metadata": {
"id": "8b10d2fb975d"
"id": "ffbf1d56b5a6"
},
"source": [
"## Overview\n",
"\n",
"This tutorial demonstrates how to deploy a `Vertex AI Model` resource to a [NVIDIA Triton Inference Server (Triton)](https://developer.nvidia.com/nvidia-triton-inference-server), and make online predictions using [Vertex AI Prediction](https://cloud.google.com/vertex-ai/docs/predictions/getting-predictions).\n",
"\n",
"### Dataset\n",
"\n",
"The tutorial uses Faster R-CNN with ResNet-101 v1 object detection model provided on [TensorFlow Hub](https://tfhub.dev/tensorflow/faster_rcnn/resnet101_v1_640x640/1) that has been trained on the [COCO 2017 dataset](https://cocodataset.org/#download) with training images scaled to 640x640.\n",
"\n",
"This tutorial demonstrates how to deploy a `Vertex AI Model` resource to a [NVIDIA Triton Inference Server (Triton)](https://developer.nvidia.com/nvidia-triton-inference-server), and make online predictions using [Vertex AI Prediction](https://cloud.google.com/vertex-ai/docs/predictions/getting-predictions)."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "8b10d2fb975d"
},
"source": [
"### Objective\n",
"\n",
"In this tutorial, you deploy a container running Nvidia Triton Server with a `Vertex AI Model` resource to a `Vertex AI Endpoint` for making online predictions.\n",
@@ -95,8 +98,26 @@
"- Upload the model as a `Vertex AI Model` resource.\n",
"- Deploy the `Vertex AI Model` resource to a `Vertex AI Endpoint` resource.\n",
"- Make a prediction request\n",
"- Undeploy the `Model` resource and delete the `Endpoint`\n",
"- Undeploy the `Model` resource and delete the `Endpoint`"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "32ed93a8f8c4"
},
"source": [
"### Dataset\n",
"\n",
"The tutorial uses Faster R-CNN with ResNet-101 v1 object detection model provided on [TensorFlow Hub](https://tfhub.dev/tensorflow/faster_rcnn/resnet101_v1_640x640/1) that has been trained on the [COCO 2017 dataset](https://cocodataset.org/#download) with training images scaled to 640x640."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "35bee437737d"
},
"source": [
"### Costs\n",
"\n",
"This tutorial uses billable components of Google Cloud:\n",
@@ -193,7 +214,7 @@
"\n",
"3. [Enable the following APIs: Vertex AI APIs, Compute Engine APIs, and Cloud Storage.](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.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",
@@ -33,18 +33,18 @@
"\n",
"<table align=\"left\">\n",
" <td>\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage6/get_started_with_optimized_tfe.ipynb\">\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage6/get_started_with_optimized_tfe_bert.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/colab-logo-32px.png\" alt=\"Colab logo\"> Run in Colab\n",
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage6/get_started_with_optimized_tfe.ipynb\">\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage6/get_started_with_optimized_tfe_bert.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/ml_ops/stage6/get_started_with_optimized_tfe.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/stage6/get_started_with_optimized_tfe_bert.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",
@@ -65,7 +65,7 @@
"\n",
"While the optimizations can be applied to any TensorFlow model, the optimizations work best for tabular and text model types.\n",
"\n",
"*Note:* To train the model it will take about 15 minutes with a T4. If training on a CPU, it will take several hours."
"*Note:* To train the model it takes about 15 minutes with a T4. If training on a CPU, it takes several hours."
]
},
{
@@ -227,7 +227,7 @@
"\n",
"3. [Enable the following APIs: Vertex AI APIs, Compute Engine APIs, and Cloud Storage.](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.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",
File diff suppressed because it is too large Load Diff
@@ -77,6 +77,7 @@
"This tutorial uses the following Google Cloud ML services and resources:\n",
"\n",
"- `Vertex AI Prediction`\n",
"- `Vertex AI Batch Prediction`\n",
"- `Vertex AI Models`\n",
"- `Vertex AI Endpoints`\n",
"\n",
@@ -87,7 +88,8 @@
"- Upload the TensorFlow Hub model and serving function as a `Vertex AI Model` resource.\n",
"- Creating an `Endpoint` resource.\n",
"- Deploying the `Model` resource to an `Endpoint` resource with `TensorFlow Serving` serving binary.\n",
"- Make an online prediction to the `Model` resource instance deployed to the `Endpoint` resource."
"- Make an online prediction to the `Model` resource instance deployed to the `Endpoint` resource.\n",
"- Make a batch prediction to the `Model` resource instance."
]
},
{
@@ -212,7 +214,7 @@
"\n",
"3. [Enable the following APIs: Vertex AI APIs, Compute Engine APIs, and Cloud Storage.](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.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",
@@ -422,8 +424,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-\" + TIMESTAMP\n",
" BUCKET_URI = \"gs://\" + BUCKET_NAME"
]
},
{
@@ -702,7 +705,10 @@
" TF_IMAGE = \"tensorflow/serving:latest-gpu\"\n",
"else:\n",
" DEPLOY_IMAGE = (\n",
" f\"{REGION}-docker.pkg.dev/\" + PROJECT_ID + f\"/{PRIVATE_REPO}\" + \"/tf_serving\"\n",
" f\"{REGION}-docker.pkg.dev/\"\n",
" + PROJECT_ID\n",
" + f\"/{PRIVATE_REPO}\"\n",
" + \"/tf_serving:cpu\"\n",
" )\n",
" TF_IMAGE = \"tensorflow/serving:latest\"\n",
"\n",
@@ -712,8 +718,8 @@
" else:\n",
" ! sudo docker pull tensorflow/serving:latest\n",
"\n",
" ! sudo docker tag tensorflow/serving $DEPLOY_IMAGE\n",
" ! sudo docker push $DEPLOY_IMAGE\n",
" ! docker tag tensorflow/serving $DEPLOY_IMAGE\n",
" ! docker push $DEPLOY_IMAGE\n",
"else:\n",
" # install docker daemon\n",
" ! apt-get -qq install docker.io\n",
@@ -1155,6 +1161,243 @@
"print(prediction)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "11e16f54bc90"
},
"source": [
"## Introduction to Batch Prediction\n",
"\n",
"Batch prediction provides the ability to do offline batch processing of large amounts of prediction requests. Resources are only provisioned during the batch process and then deprovisioned when the batch request is completed. The results are stored in Cloud Storage, in contrast to online prediction where the results are returned as a HTTP response packet.\n",
"\n",
"The input format for your batch job is dependent on the format supported by your model server. Foremost, the web server in your model server must support a JSONL format, which the web server will convert to a format support either directly by the model input intertace or a serving function interface. For batch prediction, this JSONL format is referred to as the `pivot` format.\n",
"\n",
"### Input format for batch prediction jobs\n",
"\n",
"The batch server accepts the following input formats:\n",
"\n",
"- JSONL\n",
"- CSV\n",
"- TFRecords\n",
"- File-List\n",
"\n",
"### Pivot format\n",
"\n",
"The batch server converts the input format to the `pivot` (JSONL) format as follows:\n",
"\n",
"**JSONL**\n",
"\n",
"Each input line (request) should contain one and only one valid json value.\n",
"\n",
" {\"values\": [1, 2, 3, 4], \"key\": 1}\n",
" {\"values\": [5, 6, 7, 8], \"key\": 2}\n",
"\n",
"The batch server generates the pivot data with the same format. The generated pivot data is then wrapped into a payload request:\n",
"\n",
" {\"instances\": [\n",
" {\"values\": [1, 2, 3, 4], \"key\": 1},\n",
" {\"values\": [5, 6, 7, 8], \"key\": 2}\n",
" ]}\n",
"\n",
"**CSV**\n",
"\n",
"The csv header in the first line will always be ignored. String fields are required to be double quoted explicitly, otherwise the row is discarded and parsing error messages are outputted to error files. Non-quoted values are always transferred as floats.\n",
"\n",
" col1,col2,col3\n",
" 1,3,\"cat1\"\n",
" 2,4,\"cat2\"\n",
"\n",
"The batch server converts each input row (request) to a JSON array.\n",
"\n",
" {\"instances\": [\n",
" [1.0,3.0,\"cat1\"],\n",
" [2.0,4.0,\"cat2\"]\n",
" ]}\n",
"\n",
"**TFRecords**\n",
"\n",
"Instances in TFRecord files are read as binary by apache_beam.io.tfrecordio module. The binary objects are then serialized as ASCII strings. Predictor server is responsible to know the decoder to recover the instance. \n",
"\n",
" {\"instances\": [\n",
" {\"b64\",\"b64EncodedASCIIString\"},\n",
" {\"b64\",\"b64EncodedASCIIString\"}\n",
" ]}\n",
"\n",
"**FileList**\n",
"\n",
"The FileList format contains a list of files. Each line in a “FileList” file specifies a single file path, specified as a Cloud Storage location.\n",
"\n",
" gs://my-bucket/file1.txt\n",
" gs://my-bucket/file2.txt\n",
"\n",
"The batch server reads the files as binaries. The binary objects are serialized as ASCII strings.\n",
"\n",
" {\"instances\": [\n",
" {\"b64\",\"b64EncodedASCIIString\"},\n",
" {\"b64\",\"b64EncodedASCIIString\"}\n",
" ]}"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "9ccd46a186da"
},
"source": [
"### Make the batch input file\n",
"\n",
"Next, make a batch input file, which you store in your local Cloud Storage bucket. For custom models, you format the batch input file in JSONL format. Each JSON object entry in the JSONL file is specified in the same format as you specified for the online prediction request.\n",
"\n",
"In otherwords, both online and batch prediction use the same predict request format. The difference is that with online prediction, you pass the request as an in-memory dictionary object using the SDK method `predict()`. For batch prediction, you write each prediction request (dictionary entry) as a JSON object, one per line.\n",
"\n",
"The dictionary contains the key/value pairs:\n",
"\n",
"- `input_name`: the name of the input layer of the underlying model.\n",
"- `'b64'`: A key that indicates the content is base64 encoded.\n",
"- `content`: The compressed JPG image bytes as a base64 encoded string.\n",
"\n",
"Each instance in the prediction request is a dictionary entry of the form:\n",
"\n",
" {serving_input: {'b64': content}}\n",
"\n",
"To pass the image data to the prediction service you encode the bytes into base64 -- which makes the content safe from modification when transmitting binary data over the network."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "f88fdb54269b"
},
"outputs": [],
"source": [
"# For demonstration purposes, you write the same image (instance[0]) request twice to the JSONL file.\n",
"# You will receive back two predictions, one for each instance.\n",
"\n",
"import json\n",
"\n",
"with open(\"test.jsonl\", \"w\") as f:\n",
" json.dump(instances[0], f)\n",
" f.write(\"\\n\")\n",
" json.dump(instances[0], f)\n",
"\n",
"! gsutil cp test.jsonl {BUCKET_URI}/test.jsonl"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "batch_request:mbsdk,jsonl,custom"
},
"source": [
"### Make the batch prediction request\n",
"\n",
"Now that your Model resource is trained, you can make a batch prediction by invoking the batch_predict() method, with the following parameters:\n",
"\n",
"- `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",
"- `instances_format`: The format for the input instances, either 'csv' or 'jsonl'. Defaults to 'jsonl'.\n",
"- `predictions_format`: The format for the output predictions, either 'csv' or 'jsonl'. Defaults to 'jsonl'.\n",
"- `machine_type`: The type of machine to use for training.\n",
"- `accelerator_type`: The hardware accelerator type.\n",
"- `accelerator_count`: The number of accelerators to attach to a worker replica.\n",
"- `sync`: If set to True, the call will block while waiting for the asynchronous batch job to complete."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "f98ed28340ba"
},
"outputs": [],
"source": [
"MIN_NODES = 1\n",
"MAX_NODES = 1\n",
"\n",
"batch_predict_job = model.batch_predict(\n",
" job_display_name=\"example_\" + TIMESTAMP,\n",
" instances_format=\"jsonl\",\n",
" predictions_format=\"jsonl\",\n",
" model_parameters=None,\n",
" gcs_source=f\"{BUCKET_URI}/test.jsonl\",\n",
" gcs_destination_prefix=f\"{BUCKET_URI}/results\",\n",
" machine_type=DEPLOY_COMPUTE,\n",
" accelerator_type=DEPLOY_GPU,\n",
" accelerator_count=DEPLOY_NGPU,\n",
" starting_replica_count=MIN_NODES,\n",
" max_replica_count=MAX_NODES,\n",
" sync=False,\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "batch_request_wait:mbsdk"
},
"source": [
"### Wait for completion of batch prediction job\n",
"\n",
"Next, wait for the batch job to complete. Alternatively, one can set the parameter `sync` to `True` in the `batch_predict()` method to block until the batch prediction job is completed."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "batch_request_wait:mbsdk"
},
"outputs": [],
"source": [
"batch_predict_job.wait()"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "get_batch_prediction:mbsdk,custom,icn"
},
"source": [
"### Get the predictions\n",
"\n",
"Next, get the results from the completed batch prediction job.\n",
"\n",
"The results are written to the Cloud Storage output bucket you specified in the batch prediction request. You call the method iter_outputs() to get a list of each Cloud Storage file generated with the results. Each file contains one or more prediction requests in a JSON format:\n",
"\n",
"- `instance`: The prediction request.\n",
"- `prediction`: The prediction response."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "get_batch_prediction:mbsdk,custom,icn"
},
"outputs": [],
"source": [
"import json\n",
"\n",
"bp_iter_outputs = batch_predict_job.iter_outputs()\n",
"\n",
"prediction_results = list()\n",
"for blob in bp_iter_outputs:\n",
" if blob.name.split(\"/\")[-1].startswith(\"prediction\"):\n",
" prediction_results.append(blob.name)\n",
"\n",
"tags = list()\n",
"for prediction_result in prediction_results:\n",
" gfile_name = f\"gs://{bp_iter_outputs.bucket.name}/{prediction_result}\"\n",
" with tf.io.gfile.GFile(name=gfile_name, mode=\"r\") as gfile:\n",
" for line in gfile.readlines():\n",
" line = json.loads(line)\n",
" print(line)\n",
" break"
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -1180,6 +1423,7 @@
"delete_bucket = False\n",
"delete_model = True\n",
"delete_endpoint = True\n",
"delete_batch_job = True\n",
"\n",
"if delete_endpoint:\n",
" try:\n",
@@ -1194,6 +1438,12 @@
" except Exception as e:\n",
" print(e)\n",
"\n",
"if delete_bucket:\n",
" try:\n",
" batch_predict_job.delete()\n",
" except Exception as e:\n",
" print(e)\n",
"\n",
"if delete_bucket or os.getenv(\"IS_TESTING\"):\n",
" ! gsutil rm -rf {BUCKET_URI}"
]
@@ -212,7 +212,7 @@
"\n",
"3. [Enable the following APIs: Vertex AI APIs, Compute Engine APIs, and Cloud Storage.](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.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",
@@ -1054,17 +1054,36 @@
]
}
],
"metadata": {
"colab": {
"collapsed_sections": [],
"name": "get_started_with_tf_serving_function.ipynb",
"toc_visible": true
},
"kernelspec": {
"display_name": "Python 3",
"name": "python3"
}
"metadata": {
"colab": {
"collapsed_sections": [],
"name": "get_started_with_tf_serving_function.ipynb",
"toc_visible": true
},
"nbformat": 4,
"nbformat_minor": 0
"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
}
@@ -29,7 +29,7 @@
"id": "5dd626314fed"
},
"source": [
"# E2E ML on GCP: MLOps stage 6 : serving: get started with Explainable AI using custom deployment container\n",
"# E2E ML on GCP: MLOps stage 6 : serving: get started with Vertex Explainable AI using custom deployment container\n",
"\n",
"This is an updated version of a Colab notebook contributed by [Brian Kang and Siping Hu](https://colab.corp.google.com/drive/1aYERnouogPXqlCHlfDRCff04BMV1JpyE?resourcekey=0-BrkuuARc--pA7CvD5LS-oQ#scrollTo=cuKvd9SrmIQw).\n",
"\n",
@@ -58,22 +58,23 @@
{
"cell_type": "markdown",
"metadata": {
"id": "tvgnzT1CKxrO"
"id": "424e4efb7a8d"
},
"source": [
"## Overview\n",
"\n",
"This tutorial demonstrates how to use Vertex AI for E2E MLOps on Google Cloud in production. This tutorial covers stage 6 : serving: get started with Explainable AI for a custom deployment container.\n",
"\n",
"\n",
"### Dataset\n",
"\n",
"The dataset used for this tutorial is the [Iris dataset](https://scikit-learn.org/stable/datasets/index.html#iris-dataset) from [Scikit-Learn Datasets](https://scikit-learn.org/stable/datasets/). This dataset does not require any feature engineering. The trained model predicts the type of Iris flower species from a class of three species: setosa, virginica, or versicolor.\n",
"\n",
"\n",
"This tutorial demonstrates how to use Vertex AI for E2E MLOps on Google Cloud in production. This tutorial covers stage 6 : serving: get started with Explainable AI for a custom deployment container."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "tvgnzT1CKxrO"
},
"source": [
"### Objective\n",
"\n",
"In this tutorial, you learn to build a custom container to serve a PyTorch model on `Vertex AI Endpoint`. You will use the FastAPI Python web server framework to create the HTTP server for the serving binary. You then push the container to `Artifact Registry`, deploy the model and make predictions and explanations requests.\n",
"In this tutorial, you learn to build a custom container to serve a PyTorch model on `Vertex AI Endpoint`. You use the FastAPI Python web server framework to create the HTTP server for the serving binary. You then push the container to `Artifact Registry`, deploy the model and make predictions and explanations requests.\n",
"\n",
"\n",
"This tutorial uses the following Google Cloud ML services:\n",
@@ -93,8 +94,26 @@
"- Upload the custom serving container as a `Model` resource.\n",
"- Deploy the `Model` resource to an `Endpoint` resource.\n",
"- Make a prediction request to the deployed custom serving container.\n",
"- Make an explanation request to the deployed custom serving container.\n",
"- Make an explanation request to the deployed custom serving container."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "2c2f46b60759"
},
"source": [
"### Dataset\n",
"\n",
"The dataset used for this tutorial is the [Iris dataset](https://scikit-learn.org/stable/datasets/index.html#iris-dataset) from [Scikit-Learn Datasets](https://scikit-learn.org/stable/datasets/). This dataset does not require any feature engineering. The trained model predicts the type of Iris flower species from a class of three species: setosa, virginica, or versicolor."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "a61ca6d7eb5c"
},
"source": [
"### Costs \n",
"\n",
"This tutorial uses billable components of Google Cloud:\n",
@@ -115,7 +134,7 @@
"source": [
"### Set up your local development environment\n",
"\n",
"**If you are using Colab or Google Cloud Notebooks**, your environment already meets\n",
"**If you are using Colab or Vertex AI Workbench Notebooks**, your environment already meets\n",
"all the requirements to run this notebook. You can skip this step."
]
},
@@ -254,7 +273,7 @@
"\n",
"1. [Enable the Vertex AI API and Compute Engine API](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com,compute_component).\n",
"\n",
"1. If you are running this notebook locally, you will need to install the [Cloud SDK](https://cloud.google.com/sdk).\n",
"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",
@@ -376,7 +395,7 @@
"source": [
"### Authenticate your Google Cloud account\n",
"\n",
"**If you are using Vertex AI Workbench Notebooks**, your environment is already authenticated. Skip this step.\n",
"**If you are using Vertex AI Workbench Notebooks**, your environment is already authenticated. \n",
"\n",
"**If you are using Colab**, run the cell below and follow the instructions when prompted to authenticate your account via oAuth.\n",
"\n",
@@ -631,7 +631,7 @@
"# Simulate operations\n",
"from google.cloud import bigquery\n",
"# ML pipeline\n",
"from google_cloud_pipeline_components.experimental.bigquery import (\n",
"from google_cloud_pipeline_components.v1.bigquery import (\n",
" BigqueryCreateModelJobOp, BigqueryEvaluateModelJobOp,\n",
" BigqueryExplainForecastModelJobOp, BigqueryForecastModelJobOp,\n",
" BigqueryMLArimaEvaluateJobOp, BigqueryQueryJobOp)\n",
@@ -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 an **experimental** feature and is not yet officially supported by the Vertex AI SDK. In this tutorial, you will be installing the Vertex AI SDK from an experimental branch on github. \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",
"\n",
"\n",
"\n",
@@ -70,7 +70,7 @@
"The goal is to:\n",
"- Train a model that uses a flower's measurements as input to predict what type of iris it is.\n",
"- Save the model and its serialized pre-processor\n",
"- Build a custom sklearn serving container with custom preprocessing using the Custom Prediction Routine model server using Vertex AI SDK\n",
"- Build a custom sklearn serving container with custom prediction using the Custom Prediction Routine feature in the Vertex AI SDK\n",
"- Test the built container locally\n",
"- Upload and deploy custom container to Vertex Prediction\n",
"\n",
@@ -162,7 +162,7 @@
"numpy~=1.20\n",
"scikit-learn~=0.24\n",
"google-cloud-storage>=1.26.0,<2.0.0dev\n",
"google-cloud-aiplatform[prediction] @ git+https://github.com/googleapis/python-aiplatform.git@custom-prediction-routine"
"google-cloud-aiplatform[prediction]>=1.16.0"
]
},
{
@@ -377,6 +377,37 @@
"### Configure project and resource names"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "TeCDGXHrR0SP"
},
"source": [
"If you are in a live tutorial session, you might be using a shared test account or project. To avoid name collisions between users on resources created, you create a timestamp for each instance session, and append it onto the name of resources you create in this tutorial."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "XqmZZuKJR26-"
},
"outputs": [],
"source": [
"from datetime import datetime\n",
"\n",
"TIMESTAMP = datetime.now().strftime(\"%Y%m%d%H%M%S\")"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "AByKXYgRR7tv"
},
"source": [
"Configure GCP resource names."
]
},
{
"cell_type": "code",
"execution_count": null,
@@ -427,7 +458,7 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "MzGDU7TWdts_"
"id": "idnZotjzQxDd"
},
"outputs": [],
"source": [
@@ -444,7 +475,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-\" + TIMESTAMP\n",
" BUCKET_URI = f\"gs://{BUCKET_NAME}\""
]
},
@@ -534,7 +565,7 @@
},
"outputs": [],
"source": [
"USER_MODEL_ARTIFACTS = \"model_artifacts\" # @param {type:\"string\"}"
"LOCAL_MODEL_ARTIFACTS_DIR = \"model_artifacts\" # @param {type:\"string\"}"
]
},
{
@@ -557,7 +588,7 @@
"outputs": [],
"source": [
"%mkdir $USER_SRC_DIR\n",
"%mkdir $USER_MODEL_ARTIFACTS"
"%mkdir $LOCAL_MODEL_ARTIFACTS_DIR"
]
},
{
@@ -626,8 +657,8 @@
"model = RandomForestClassifier()\n",
"model.fit(X, y)\n",
"\n",
"joblib.dump(model, f\"../{USER_MODEL_ARTIFACTS}/model.joblib\")\n",
"with open(f\"../{USER_MODEL_ARTIFACTS}/preprocessor.pkl\", \"wb\") as f:\n",
"joblib.dump(model, f\"../{LOCAL_MODEL_ARTIFACTS_DIR}/model.joblib\")\n",
"with open(f\"../{LOCAL_MODEL_ARTIFACTS_DIR}/preprocessor.pkl\", \"wb\") as f:\n",
" pickle.dump(scaler, f)"
]
},
@@ -656,69 +687,89 @@
"outputs": [],
"source": [
"%cd ..\n",
"!gsutil cp {USER_MODEL_ARTIFACTS}/* {BUCKET_URI}/{MODEL_ARTIFACT_DIR}/\n",
"!gsutil cp {LOCAL_MODEL_ARTIFACTS_DIR}/* {BUCKET_URI}/{MODEL_ARTIFACT_DIR}/\n",
"!gsutil ls {BUCKET_URI}/{MODEL_ARTIFACT_DIR}/"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "7b68b0404a33"
},
"source": [
"## Build a custom serving container using the CPR model server"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "480a1d88ecdb"
},
"source": [
"## Build a custom serving container using the CPR model server\n",
"Now that the model and processor has been trained and saved, it's time to build the custom serving container. Typically building a serving container requires writing model server code. However, with the Custom Prediction Routine feature, Vertex AI Prediction provides a model server that can be used out of the box.\n",
"\n",
"Now that the model and processor has been trained and saved, it's time to build the custom serving container. Typically building a serving container requires writing model server code. However, with the Custom Prediction Routine feature, Vertex AI Prediction generates a model server while building images that can be used out of the box.\n",
"\n",
"A custom serving container contains the follow 3 pieces of code:\n",
"1. Model server (generated in user-provided directory by SDK)\n",
" * HTTP server that hosts the model\n",
"A custom serving container contains the following 3 pieces of code:\n",
"1. [Model Server](https://github.com/googleapis/python-aiplatform/blob/main/google/cloud/aiplatform/prediction/model_server.py)\n",
" * HTTP server that hosts the model.\n",
" * Responsible for setting up routes/ports/etc.\n",
"1. [Request Handler](https://github.com/googleapis/python-aiplatform/blob/custom-prediction-routine/google/cloud/aiplatform/prediction/handler.py)\n",
" * Responsible for webserver aspects of handling a request, such as deserializing the request body, and serializing the reponse, setting response headers, etc.\n",
"1. [Request Handler](https://github.com/googleapis/python-aiplatform/blob/main/google/cloud/aiplatform/prediction/handler.py)\n",
" * Responsible for webserver aspects of handling a request, such as deserializing the request body, serializing the response, setting response headers, etc.\n",
" * In this example, you will use the default Handler, `google.cloud.aiplatform.prediction.handler.PredictionHandler` provided in the SDK.\n",
"1. [Predictor](https://github.com/googleapis/python-aiplatform/blob/custom-prediction-routine/google/cloud/aiplatform/prediction/predictor.py)\n",
"1. [Predictor](https://github.com/googleapis/python-aiplatform/blob/main/google/cloud/aiplatform/prediction/predictor.py)\n",
" * Responsible for the ML logic for processing a prediction request.\n",
"\n",
"Each of these three pieces can be customized based on the requirements of the custom container. In this example, you will only be implementing the `Predictor`.\n",
"\n",
"\n",
"A [`Predictor`](https://github.com/googleapis/python-aiplatform/blob/custom-prediction-routine/google/cloud/aiplatform/prediction/predictor.py) must implement the following interface:\n",
"A [`Predictor`](https://github.com/googleapis/python-aiplatform/blob/main/google/cloud/aiplatform/prediction/predictor.py) must implement the following interface:\n",
"\n",
"```\n",
"class Predictor:\n",
" \"\"\"Interface for Predictor class that users would be implementing.\"\"\"\n",
"from abc import ABC, abstractmethod\n",
"from typing import Any\n",
"\n",
"\n",
"class Predictor(ABC):\n",
" \"\"\"Interface of the Predictor class for Custom Prediction Routines.\n",
" The Predictor is responsible for the ML logic for processing a prediction request.\n",
" Specifically, the Predictor must define:\n",
" (1) How to load all model artifacts used during prediction into memory.\n",
" (2) The logic that should be executed at predict time.\n",
" When using the default PredictionHandler, the Predictor will be invoked as follows:\n",
" predictor.postprocess(predictor.predict(predictor.preprocess(prediction_input)))\n",
" \"\"\"\n",
"\n",
" def __init__(self):\n",
" raise NotImplementedError(\"Predictor.__init__ has not been implemented yet.\")\n",
" return\n",
"\n",
" def load(self, artifacts_uri: str):\n",
" @abstractmethod\n",
" def load(self, artifacts_uri: str) -> None:\n",
" \"\"\"Loads the model artifact.\n",
" Args:\n",
" artifacts_uri (str):\n",
" Required. The value of the environment variable AIP_STORAGE_URI.\n",
" \"\"\"\n",
" raise NotImplementedError(\"Predictor.load has not been implemented yet.\")\n",
" pass\n",
"\n",
" def preprocess(self, prediction_input: Any) -> Any:\n",
" \"\"\"Preprocesses the prediction input before doing the prediction.\n",
" Args:\n",
" prediction_input (Any):\n",
" Required. The prediction input needs to be preprocessed.\n",
" Required. The prediction input that needs to be preprocessed.\n",
" Returns:\n",
" The preprocessed prediction input.\n",
" \"\"\"\n",
" return prediction_input\n",
"\n",
" @abstractmethod\n",
" def predict(self, instances: Any) -> Any:\n",
" \"\"\"Performs prediction.\n",
" Args:\n",
" instances (Any):\n",
" Required. The instances to perform prediction.\n",
" Required. The instance(s) used for performing prediction.\n",
" Returns:\n",
" Prediction results.\n",
" \"\"\"\n",
" raise NotImplementedError(\"Predictor.predict has not been implemented yet.\")\n",
" pass\n",
"\n",
" def postprocess(self, prediction_results: Any) -> Any:\n",
" \"\"\"Postprocesses the prediction results.\n",
@@ -740,11 +791,11 @@
"source": [
"First, implement a custom `Predictor` that loads in both the preprocesor and the model. The preprocessor and the model will then be used at `predict` time.\n",
"\n",
"Custom Prediction Routines support a way to run the containers locally for testing your images. You can pass either a GCS path or a local path while testing your images locally.\n",
"Custom Prediction Routine supports a way to run the containers locally for testing your images. You can pass either a GCS path or a local path while testing your images locally.\n",
"- You need to set up the credentials if you pass a GCS path. \n",
"- You need to support loading your models remotely and locally in your `Predictor` if you want to testing by passing a local path.\n",
"\n",
"Vertex AI SDK provides a function `download_model_artifacts` to help you download model artifacts from either GCS paths or local paths. See the example in the `load` function below."
"Vertex AI SDK provides a [function `download_model_artifacts`](https://github.com/googleapis/python-aiplatform/blob/main/google/cloud/aiplatform/utils/prediction_utils.py) to help you download model artifacts from either GCS paths or local paths. See the example in the `load` function below."
]
},
{
@@ -858,7 +909,7 @@
"from src_dir_sdk.predictor import \\\n",
" CprPredictor # Update this path as the variable $USER_SRC_DIR to import the custom predictor.\n",
"\n",
"local_model = LocalModel.create_cpr_model(\n",
"local_model = LocalModel.build_cpr_model(\n",
" USER_SRC_DIR,\n",
" f\"{REGION}-docker.pkg.dev/{PROJECT_ID}/{REPOSITORY}/{IMAGE}\",\n",
" predictor=CprPredictor,\n",
@@ -944,7 +995,7 @@
"1. A local path.\n",
"2. A GCS path.\n",
"\n",
"To use a local path, your `Predictor` needs to support both ways to load models so it can be tested locally and deployed to Vertex AI Prediction service. SDK provides a method `download_model_artifacts` to support these two ways in [prediction_utils.py](https://github.com/googleapis/python-aiplatform/blob/custom-prediction-routine/google/cloud/aiplatform/utils/prediction_utils.py) which you can call in the `load` function in your `Predictor`.\n",
"To use a local path, your `Predictor` needs to support both ways to load models so it can be tested locally and deployed to Vertex AI Prediction service. SDK provides a method `download_model_artifacts` to support these two ways in [prediction_utils.py](https://github.com/googleapis/python-aiplatform/blob/main/google/cloud/aiplatform/utils/prediction_utils.py) which you can call in the `load` function in your `Predictor`.\n",
"\n",
"If you want to test images locally with a GCS path, you need to follow the instructions to set up the credentials."
]
@@ -1291,7 +1342,7 @@
"outputs": [],
"source": [
"with local_model.deploy_to_local_endpoint(\n",
" artifact_uri=f\"{USER_MODEL_ARTIFACTS}\",\n",
" artifact_uri=f\"{LOCAL_MODEL_ARTIFACTS_DIR}\",\n",
") as local_endpoint:\n",
" predict_response = local_endpoint.predict(\n",
" request_file=INPUT_FILE,\n",
@@ -1504,7 +1555,7 @@
},
"outputs": [],
"source": [
"!gcloud beta artifacts repositories create {REPOSITORY} \\\n",
"!gcloud artifacts repositories create {REPOSITORY} \\\n",
" --repository-format=docker \\\n",
" --location=$REGION"
]
@@ -1597,7 +1648,8 @@
},
"outputs": [],
"source": [
"model = local_model.upload(\n",
"model = aiplatform.Model.upload(\n",
" local_model=local_model,\n",
" display_name=MODEL_DISPLAY_NAME,\n",
" artifact_uri=f\"{BUCKET_URI}/{MODEL_ARTIFACT_DIR}\",\n",
")"
@@ -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 an **experimental** feature and is not yet officially supported by the Vertex AI SDK. In this tutorial, we'll be installing the Vertex AI SDK from an experimental branch on github. \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",
"\n",
"\n",
"\n",
@@ -70,7 +70,7 @@
"The goal is to:\n",
"- Train a model that uses a flower's measurements as input to predict what type of iris it is.\n",
"- Save the model and its serialized pre-processor\n",
"- Build a custom sklearn serving container with custom preprocessing using the Custom Prediction Routine model server using Vertex SDK\n",
"- Build a custom sklearn serving container with custom request handling and preprocessing using the Custom Prediction Routine feature in the Vertex AI SDK\n",
"- Test the built container locally\n",
"- Upload and deploy custom container to Vertex Prediction\n",
"\n",
@@ -165,7 +165,7 @@
"numpy~=1.20\n",
"scikit-learn~=0.24\n",
"google-cloud-storage>=1.26.0,<2.0.0dev\n",
"google-cloud-aiplatform[prediction] @ git+https://github.com/googleapis/python-aiplatform.git@custom-prediction-routine"
"google-cloud-aiplatform[prediction]>=1.16.0"
]
},
{
@@ -380,6 +380,37 @@
"### Configure project and resource names"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "KekutBxiTYR8"
},
"source": [
"If you are in a live tutorial session, you might be using a shared test account or project. To avoid name collisions between users on resources created, you create a timestamp for each instance session, and append it onto the name of resources you create in this tutorial."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "1-2mvK_cTakz"
},
"outputs": [],
"source": [
"from datetime import datetime\n",
"\n",
"TIMESTAMP = datetime.now().strftime(\"%Y%m%d%H%M%S\")"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "CYlZ-K9PUAXL"
},
"source": [
"Configure GCP resource names."
]
},
{
"cell_type": "code",
"execution_count": null,
@@ -453,7 +484,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-\" + TIMESTAMP\n",
" BUCKET_URI = f\"gs://{BUCKET_NAME}\""
]
},
@@ -543,7 +574,7 @@
},
"outputs": [],
"source": [
"USER_MODEL_ARTIFACTS = \"model_artifacts\" # @param {type:\"string\"}"
"LOCAL_MODEL_ARTIFACTS_DIR = \"model_artifacts\" # @param {type:\"string\"}"
]
},
{
@@ -566,7 +597,7 @@
"outputs": [],
"source": [
"%mkdir $USER_SRC_DIR\n",
"%mkdir $USER_MODEL_ARTIFACTS"
"%mkdir $LOCAL_MODEL_ARTIFACTS_DIR"
]
},
{
@@ -635,8 +666,8 @@
"model = RandomForestClassifier()\n",
"model.fit(X, y)\n",
"\n",
"joblib.dump(model, f\"../{USER_MODEL_ARTIFACTS}/model.joblib\")\n",
"with open(f\"../{USER_MODEL_ARTIFACTS}/preprocessor.pkl\", \"wb\") as f:\n",
"joblib.dump(model, f\"../{LOCAL_MODEL_ARTIFACTS_DIR}/model.joblib\")\n",
"with open(f\"../{LOCAL_MODEL_ARTIFACTS_DIR}/preprocessor.pkl\", \"wb\") as f:\n",
" pickle.dump(scaler, f)"
]
},
@@ -665,69 +696,89 @@
"outputs": [],
"source": [
"%cd ..\n",
"!gsutil cp {USER_MODEL_ARTIFACTS}/* {BUCKET_URI}/{MODEL_ARTIFACT_DIR}/\n",
"!gsutil cp {LOCAL_MODEL_ARTIFACTS_DIR}/* {BUCKET_URI}/{MODEL_ARTIFACT_DIR}/\n",
"!gsutil ls {BUCKET_URI}/{MODEL_ARTIFACT_DIR}/"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "7b68b0404a33"
},
"source": [
"## Build a custom serving container using the CPR model server"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "480a1d88ecdb"
},
"source": [
"## Build a custom serving container using the CPR model server\n",
"Now that the model and processor has been trained and saved, it's time to build the custom serving container. Typically building a serving container requires writing model server code. However, with the Custom Prediction Routine feature, Vertex AI Prediction provides a model server that can be used out of the box.\n",
"\n",
"Now that the model and processor has been trained and saved, it's time to build the custom serving container. Typically building a serving container requires writing model server code. However, with the Custom Prediction Routine feature, Vertex AI Prediction generates a model server while building images that can be used out of the box.\n",
"\n",
"A custom serving container contains the follow 3 pieces of code:\n",
"1. Model server (generated in user-provided directory by SDK)\n",
" * HTTP server that hosts the model\n",
"A custom serving container contains the following 3 pieces of code:\n",
"1. [Model Server](https://github.com/googleapis/python-aiplatform/blob/main/google/cloud/aiplatform/prediction/model_server.py)\n",
" * HTTP server that hosts the model.\n",
" * Responsible for setting up routes/ports/etc.\n",
"1. [Request Handler](https://github.com/googleapis/python-aiplatform/blob/custom-prediction-routine/google/cloud/aiplatform/prediction/handler.py)\n",
" * Responsible for webserver aspects of handling a request, such as deserializing the request body, and serializing the reponse, setting response headers, etc.\n",
"1. [Request Handler](https://github.com/googleapis/python-aiplatform/blob/main/google/cloud/aiplatform/prediction/handler.py)\n",
" * Responsible for webserver aspects of handling a request, such as deserializing the request body, serializing the response, setting response headers, etc.\n",
" * In this example, we will use the default Handler, `google.cloud.aiplatform.prediction.handler.PredictionHandler` provided in the SDK.\n",
"1. [Predictor](https://github.com/googleapis/python-aiplatform/blob/custom-prediction-routine/google/cloud/aiplatform/prediction/predictor.py)\n",
"1. [Predictor](https://github.com/googleapis/python-aiplatform/blob/main/google/cloud/aiplatform/prediction/predictor.py)\n",
" * Responsible for the ML logic for processing a prediction request.\n",
"\n",
"Each of these three pieces can be customized based on the requirements of the custom container. In this example, we will implement the `Predictor` and `Handler`.\n",
"\n",
"\n",
"A [`Predictor`](https://github.com/googleapis/python-aiplatform/blob/custom-prediction-routine/google/cloud/aiplatform/prediction/predictor.py) must implement the following interface:\n",
"A [`Predictor`](https://github.com/googleapis/python-aiplatform/blob/main/google/cloud/aiplatform/prediction/predictor.py) must implement the following interface:\n",
"\n",
"```\n",
"class Predictor:\n",
" \"\"\"Interface for Predictor class that users would be implementing.\"\"\"\n",
"from abc import ABC, abstractmethod\n",
"from typing import Any\n",
"\n",
"\n",
"class Predictor(ABC):\n",
" \"\"\"Interface of the Predictor class for Custom Prediction Routines.\n",
" The Predictor is responsible for the ML logic for processing a prediction request.\n",
" Specifically, the Predictor must define:\n",
" (1) How to load all model artifacts used during prediction into memory.\n",
" (2) The logic that should be executed at predict time.\n",
" When using the default PredictionHandler, the Predictor will be invoked as follows:\n",
" predictor.postprocess(predictor.predict(predictor.preprocess(prediction_input)))\n",
" \"\"\"\n",
"\n",
" def __init__(self):\n",
" raise NotImplementedError(\"Predictor.__init__ has not been implemented yet.\")\n",
" return\n",
"\n",
" def load(self, artifacts_uri: str):\n",
" @abstractmethod\n",
" def load(self, artifacts_uri: str) -> None:\n",
" \"\"\"Loads the model artifact.\n",
" Args:\n",
" artifacts_uri (str):\n",
" Required. The value of the environment variable AIP_STORAGE_URI.\n",
" \"\"\"\n",
" raise NotImplementedError(\"Predictor.load has not been implemented yet.\")\n",
" pass\n",
"\n",
" def preprocess(self, prediction_input: Any) -> Any:\n",
" \"\"\"Preprocesses the prediction input before doing the prediction.\n",
" Args:\n",
" prediction_input (Any):\n",
" Required. The prediction input needs to be preprocessed.\n",
" Required. The prediction input that needs to be preprocessed.\n",
" Returns:\n",
" The preprocessed prediction input.\n",
" \"\"\"\n",
" return prediction_input\n",
"\n",
" @abstractmethod\n",
" def predict(self, instances: Any) -> Any:\n",
" \"\"\"Performs prediction.\n",
" Args:\n",
" instances (Any):\n",
" Required. The instances to perform prediction.\n",
" Required. The instance(s) used for performing prediction.\n",
" Returns:\n",
" Prediction results.\n",
" \"\"\"\n",
" raise NotImplementedError(\"Predictor.predict has not been implemented yet.\")\n",
" pass\n",
"\n",
" def postprocess(self, prediction_results: Any) -> Any:\n",
" \"\"\"Postprocesses the prediction results.\n",
@@ -749,11 +800,11 @@
"source": [
"First, implement a custom `Predictor` that loads in both the preprocesor and the model. The preprocessor and the model will then be used at `predict` time.\n",
"\n",
"Custom Prediction Routines support a way to run the containers locally for testing your images. You can pass either a GCS path or a local path while testing your images locally.\n",
"Custom Prediction Routine supports a way to run the containers locally for testing your images. You can pass either a GCS path or a local path while testing your images locally.\n",
"- You need to set up the credentials if you pass a GCS path. \n",
"- You need to support loading your models remotely and locally in your `Predictor` if you want to testing by passing a local path.\n",
"\n",
"Vertex SDK provides a function `download_model_artifacts` to help you download model artifacts from either GCS paths or local paths. See the example in the `load` function below."
"Vertex SDK provides a [function `download_model_artifacts`](https://github.com/googleapis/python-aiplatform/blob/main/google/cloud/aiplatform/utils/prediction_utils.py) to help you download model artifacts from either GCS paths or local paths. See the example in the `load` function below."
]
},
{
@@ -809,7 +860,7 @@
"source": [
"Then implement a custom `Handler`.\n",
"\n",
"A [`Handler`](https://github.com/googleapis/python-aiplatform/blob/custom-prediction-routine/google/cloud/aiplatform/prediction/handler.py) must implement the following interface.\n",
"A [`Handler`](https://github.com/googleapis/python-aiplatform/blob/main/google/cloud/aiplatform/prediction/handler.py) must implement the following interface.\n",
"\n",
"```\n",
"class Handler:\n",
@@ -966,7 +1017,7 @@
"from src_dir_handler_sdk.predictor import \\\n",
" CprPredictor # Update this path as the variable $USER_SRC_DIR to import the custom predictor.\n",
"\n",
"local_model = LocalModel.create_cpr_model(\n",
"local_model = LocalModel.build_cpr_model(\n",
" USER_SRC_DIR,\n",
" f\"{REGION}-docker.pkg.dev/{PROJECT_ID}/{REPOSITORY}/{IMAGE}\",\n",
" predictor=CprPredictor, # Update this to the custom predictor class.\n",
@@ -1049,7 +1100,7 @@
"1. A local path.\n",
"2. A GCS path.\n",
"\n",
"To use a local path, your `Predictor` needs to support both ways to load models so it can be tested locally and deployed to Vertex AI Prediction service. SDK provides a method `download_model_artifacts` to support these two ways in [prediction_utils.py](https://github.com/googleapis/python-aiplatform/blob/custom-prediction-routine/google/cloud/aiplatform/utils/prediction_utils.py) which you can call in the `load` function in your `Predictor`.\n",
"To use a local path, your `Predictor` needs to support both ways to load models so it can be tested locally and deployed to Vertex AI Prediction service. SDK provides a method `download_model_artifacts` to support these two ways in [prediction_utils.py](https://github.com/googleapis/python-aiplatform/blob/main/google/cloud/aiplatform/utils/prediction_utils.py) which you can call in the `load` function in your `Predictor`.\n",
"\n",
"If you want to test images locally with a GCS path, you need to follow the instructions to set up the credentials."
]
@@ -1368,7 +1419,7 @@
"outputs": [],
"source": [
"with local_model.deploy_to_local_endpoint(\n",
" artifact_uri=f\"{USER_MODEL_ARTIFACTS}\",\n",
" artifact_uri=f\"{LOCAL_MODEL_ARTIFACTS_DIR}\",\n",
") as local_endpoint:\n",
" predict_response = local_endpoint.predict(\n",
" request_file=INPUT_FILE,\n",
@@ -1579,7 +1630,7 @@
},
"outputs": [],
"source": [
"!gcloud beta artifacts repositories create {REPOSITORY} \\\n",
"!gcloud artifacts repositories create {REPOSITORY} \\\n",
" --repository-format=docker \\\n",
" --location=$REGION"
]
@@ -1672,7 +1723,8 @@
},
"outputs": [],
"source": [
"model = local_model.upload(\n",
"model = aiplatform.Model.upload(\n",
" local_model=local_model,\n",
" display_name=MODEL_DISPLAY_NAME,\n",
" artifact_uri=f\"{BUCKET_URI}/{MODEL_ARTIFACT_DIR}\",\n",
")"
@@ -1842,7 +1894,8 @@
"!gcloud artifacts docker images delete \\\n",
" --quiet \\\n",
" --delete-tags \\\n",
" {REGION}-docker.pkg.dev/{PROJECT_ID}/{REPOSITORY}/{IMAGE}",
" {REGION}-docker.pkg.dev/{PROJECT_ID}/{REPOSITORY}/{IMAGE}\n",
"\n",
"delete_bucket = False\n",
"\n",
"if delete_bucket or os.getenv(\"IS_TESTING\"):\n",
@@ -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 an **experimental** feature and is not yet officially supported by the Vertex AI SDK. In this tutorial, you will be installing the Vertex AI SDK from an experimental branch on github. \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",
"\n",
"\n",
"\n",
@@ -70,7 +70,7 @@
"The goal is to:\n",
"- Train a model that uses a flower's measurements as input to predict what type of iris it is.\n",
"- Save the model and its serialized pre-processor\n",
"- Build a custom sklearn serving container with custom preprocessing using the Custom Prediction Routine model server using Vertex AI SDK\n",
"- Build a custom sklearn serving container with custom preprocessing using the Custom Prediction Routine feature in the Vertex AI SDK\n",
"- Test the built container locally\n",
"- Upload and deploy custom container to Vertex Prediction\n",
"\n",
@@ -162,7 +162,7 @@
"numpy~=1.20\n",
"scikit-learn~=0.24\n",
"google-cloud-storage>=1.26.0,<2.0.0dev\n",
"google-cloud-aiplatform[prediction] @ git+https://github.com/googleapis/python-aiplatform.git@custom-prediction-routine"
"google-cloud-aiplatform[prediction]>=1.16.0"
]
},
{
@@ -377,6 +377,37 @@
"### Configure project and resource names"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "Cpvsl3wC08G-"
},
"source": [
"If you are in a live tutorial session, you might be using a shared test account or project. To avoid name collisions between users on resources created, you create a timestamp for each instance session, and append it onto the name of resources you create in this tutorial."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "8jDd9Ijf08G_"
},
"outputs": [],
"source": [
"from datetime import datetime\n",
"\n",
"TIMESTAMP = datetime.now().strftime(\"%Y%m%d%H%M%S\")"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "4yMGUdqp08G_"
},
"source": [
"Configure GCP resource names."
]
},
{
"cell_type": "code",
"execution_count": null,
@@ -444,7 +475,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-\" + TIMESTAMP\n",
" BUCKET_URI = f\"gs://{BUCKET_NAME}\""
]
},
@@ -534,7 +565,7 @@
},
"outputs": [],
"source": [
"USER_MODEL_ARTIFACTS = \"model_artifacts\" # @param {type:\"string\"}"
"LOCAL_MODEL_ARTIFACTS_DIR = \"model_artifacts\" # @param {type:\"string\"}"
]
},
{
@@ -557,7 +588,7 @@
"outputs": [],
"source": [
"%mkdir $USER_SRC_DIR\n",
"%mkdir $USER_MODEL_ARTIFACTS"
"%mkdir $LOCAL_MODEL_ARTIFACTS_DIR"
]
},
{
@@ -626,8 +657,8 @@
"model = RandomForestClassifier()\n",
"model.fit(X, y)\n",
"\n",
"joblib.dump(model, f\"../{USER_MODEL_ARTIFACTS}/model.joblib\")\n",
"with open(f\"../{USER_MODEL_ARTIFACTS}/preprocessor.pkl\", \"wb\") as f:\n",
"joblib.dump(model, f\"../{LOCAL_MODEL_ARTIFACTS_DIR}/model.joblib\")\n",
"with open(f\"../{LOCAL_MODEL_ARTIFACTS_DIR}/preprocessor.pkl\", \"wb\") as f:\n",
" pickle.dump(scaler, f)"
]
},
@@ -656,75 +687,102 @@
"outputs": [],
"source": [
"%cd ..\n",
"!gsutil cp {USER_MODEL_ARTIFACTS}/* {BUCKET_URI}/{MODEL_ARTIFACT_DIR}/\n",
"!gsutil cp {LOCAL_MODEL_ARTIFACTS_DIR}/* {BUCKET_URI}/{MODEL_ARTIFACT_DIR}/\n",
"!gsutil ls {BUCKET_URI}/{MODEL_ARTIFACT_DIR}/"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "7b68b0404a33"
},
"source": [
"## Build a custom serving container using the CPR model server"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "480a1d88ecdb"
},
"source": [
"## Build a custom serving container using the CPR model server\n",
"Now that the model and processor has been trained and saved, it's time to build the custom serving container. Typically building a serving container requires writing model server code. However, with the Custom Prediction Routine feature, Vertex AI Prediction provides a model server that can be used out of the box.\n",
"\n",
"Now that the model and processor has been trained and saved, it's time to build the custom serving container. Typically building a serving container requires writing model server code. However, with the Custom Prediction Routine feature, Vertex AI Prediction generates a model server while building images that can be used out of the box.\n",
"\n",
"A custom serving container contains the follow 3 pieces of code:\n",
"1. Model server (generated in user-provided directory by SDK)\n",
" * HTTP server that hosts the model\n",
"A custom serving container contains the following 3 pieces of code:\n",
"1. [Model Server](https://github.com/googleapis/python-aiplatform/blob/main/google/cloud/aiplatform/prediction/model_server.py)\n",
" * HTTP server that hosts the model.\n",
" * Responsible for setting up routes/ports/etc.\n",
"1. [Request Handler](https://github.com/googleapis/python-aiplatform/blob/custom-prediction-routine/google/cloud/aiplatform/prediction/handler.py)\n",
" * Responsible for webserver aspects of handling a request, such as deserializing the request body, and serializing the reponse, setting response headers, etc.\n",
"1. [Request Handler](https://github.com/googleapis/python-aiplatform/blob/main/google/cloud/aiplatform/prediction/handler.py)\n",
" * Responsible for webserver aspects of handling a request, such as deserializing the request body, serializing the response, setting response headers, etc.\n",
" * In this example, you will use the default Handler, `google.cloud.aiplatform.prediction.handler.PredictionHandler` provided in the SDK.\n",
"1. [Predictor](https://github.com/googleapis/python-aiplatform/blob/custom-prediction-routine/google/cloud/aiplatform/prediction/predictor.py)\n",
"1. [Predictor](https://github.com/googleapis/python-aiplatform/blob/main/google/cloud/aiplatform/prediction/predictor.py)\n",
" * Responsible for the ML logic for processing a prediction request.\n",
"\n",
"Each of these three pieces can be customized based on the requirements of the custom container. In this example, you will only be implementing the `Predictor`.\n",
"\n",
"\n",
"You will use the predefined [`SklearnPredictor`](https://github.com/googleapis/python-aiplatform/blob/custom-prediction-routine/google/cloud/aiplatform/prediction/sklearn/predictor.py) as our `CprPredictor`'s base class. You will only need to implement the `load`, `preprocess`, and `postprocess` methods.\n",
"You will use the predefined [`SklearnPredictor`](https://github.com/googleapis/python-aiplatform/blob/main/google/cloud/aiplatform/prediction/sklearn/predictor.py) as our `CprPredictor`'s base class. You will only need to implement the `load`, `preprocess`, and `postprocess` methods.\n",
"\n",
"```\n",
"import joblib\n",
"import numpy as np\n",
"import os\n",
"import pickle\n",
"\n",
"from google.cloud.aiplatform.constants import prediction\n",
"from google.cloud.aiplatform.utils import prediction_utils\n",
"from google.cloud.aiplatform.prediction.predictor import Predictor\n",
"\n",
"\n",
"class SklearnPredictor(Predictor):\n",
" \"\"\"Default Predictor implementation for Sklearn models.\"\"\"\n",
"\n",
" def __init__(self):\n",
" return\n",
"\n",
" def load(self, artifacts_uri: str):\n",
" def load(self, artifacts_uri: str) -> None:\n",
" \"\"\"Loads the model artifact.\n",
" Args:\n",
" artifacts_uri (str):\n",
" Required. The value of the environment variable AIP_STORAGE_URI.\n",
" Raises:\n",
" ValueError: If there's no required model files provided in the artifacts\n",
" uri.\n",
" \"\"\"\n",
" gcs_client = storage.Client()\n",
" with open(\"model.joblib\", 'wb') as model_f:\n",
" gcs_client.download_blob_to_file(\n",
" f\"{artifacts_uri}/model.joblib\", model_f\n",
" prediction_utils.download_model_artifacts(artifacts_uri)\n",
" if os.path.exists(prediction.MODEL_FILENAME_JOBLIB):\n",
" self._model = joblib.load(prediction.MODEL_FILENAME_JOBLIB)\n",
" elif os.path.exists(prediction.MODEL_FILENAME_PKL):\n",
" self._model = pickle.load(open(prediction.MODEL_FILENAME_PKL, \"rb\"))\n",
" else:\n",
" valid_filenames = [\n",
" prediction.MODEL_FILENAME_JOBLIB,\n",
" prediction.MODEL_FILENAME_PKL,\n",
" ]\n",
" raise ValueError(\n",
" f\"One of the following model files must be provided: {valid_filenames}.\"\n",
" )\n",
" self._model = joblib.load(\"model.joblib\")\n",
"\n",
" def preprocess(self, prediction_input: dict) -> np.ndarray:\n",
" \"\"\"Converts the request body to a numpy array before prediction.\n",
" Args:\n",
" prediction_input (dict):\n",
" Required. The prediction input needs to be preprocessed.\n",
" Required. The prediction input that needs to be preprocessed.\n",
" Returns:\n",
" The preprocessed prediction input.\n",
" \"\"\"\n",
" instances = instances[\"instances\"]\n",
" instances = prediction_input[\"instances\"]\n",
" return np.asarray(instances)\n",
"\n",
" def predict(self, instances: np.ndarray) -> np.ndarray:\n",
" \"\"\"Performs prediction.\n",
" Args:\n",
" instances (np.ndarray):\n",
" Required. The instances to perform prediction.\n",
" Required. The instance(s) used for performing prediction.\n",
" Returns:\n",
" Prediction results.\n",
" \"\"\"\n",
" return self._model.predict(inputs)\n",
" return self._model.predict(instances)\n",
"\n",
" def postprocess(self, prediction_results: np.ndarray) -> dict:\n",
" \"\"\"Converts numpy array to a dict.\n",
@@ -737,7 +795,7 @@
" return {\"predictions\": prediction_results.tolist()}\n",
"```\n",
"\n",
"Note, the [`PredictionHandler`](https://github.com/googleapis/python-aiplatform/blob/custom-prediction-routine/google/cloud/aiplatform/prediction/handler.py) will be used for prediction request handling, and the following will be executed:\n",
"Note, the [`PredictionHandler`](https://github.com/googleapis/python-aiplatform/blob/main/google/cloud/aiplatform/prediction/handler.py) will be used for prediction request handling, and the following will be executed:\n",
"```\n",
"self._predictor.postprocess(self._predictor.predict(self._predictor.preprocess(prediction_input)))\n",
"```"
@@ -751,11 +809,11 @@
"source": [
"First, implement a custom `Predictor` that loads in the preprocesor. The processor is then used at `preprocess` time.\n",
"\n",
"Custom Prediction Routines support a way to run the containers locally for testing your images. You can pass either a GCS path or a local path while testing your images locally.\n",
"Custom Prediction Routine supports a way to run the containers locally for testing your images. You can pass either a GCS path or a local path while testing your images locally.\n",
"- You need to set up the credentials if you pass a GCS path. \n",
"- You need to support loading your models remotely and locally in your `Predictor` if you want to testing by passing a local path.\n",
"\n",
"Vertex AI SDK provides a function `download_model_artifacts` to help you download model artifacts from either GCS paths or local paths. See the example in the `load` function below. The `load` function in the `SklearnPredictor` use the function `download_model_artifacts` to prepare for the model artifacts."
"Vertex AI SDK provides the [function `download_model_artifacts`](https://github.com/googleapis/python-aiplatform/blob/main/google/cloud/aiplatform/utils/prediction_utils.py) to help you download model artifacts from either GCS paths or local paths. See the example in the `load` function below. The `load` function in the `SklearnPredictor` uses the function `download_model_artifacts` to prepare for the model artifacts."
]
},
{
@@ -868,7 +926,7 @@
"from src_dir.predictor import \\\n",
" CprPredictor # Update this path as the variable $USER_SRC_DIR to import the custom predictor.\n",
"\n",
"local_model = LocalModel.create_cpr_model(\n",
"local_model = LocalModel.build_cpr_model(\n",
" USER_SRC_DIR,\n",
" f\"{REGION}-docker.pkg.dev/{PROJECT_ID}/{REPOSITORY}/{IMAGE}\",\n",
" predictor=CprPredictor,\n",
@@ -954,7 +1012,7 @@
"1. A local path.\n",
"2. A GCS path.\n",
"\n",
"To use a local path, your `Predictor` needs to support both ways to load models so it can be tested locally and deployed to Vertex AI Prediction service. SDK provides a method `download_model_artifacts` to support these two ways in [prediction_utils.py](https://github.com/googleapis/python-aiplatform/blob/custom-prediction-routine/google/cloud/aiplatform/utils/prediction_utils.py) which you can call in the `load` function in your `Predictor`.\n",
"To use a local path, your `Predictor` needs to support both ways to load models so it can be tested locally and deployed to Vertex AI Prediction service. SDK provides a method `download_model_artifacts` to support these two ways in [prediction_utils.py](https://github.com/googleapis/python-aiplatform/blob/main/google/cloud/aiplatform/utils/prediction_utils.py) which you can call in the `load` function in your `Predictor`.\n",
"\n",
"If you want to test images locally with a GCS path, you need to follow the instructions to set up the credentials."
]
@@ -1301,7 +1359,7 @@
"outputs": [],
"source": [
"with local_model.deploy_to_local_endpoint(\n",
" artifact_uri=f\"{USER_MODEL_ARTIFACTS}\",\n",
" artifact_uri=f\"{LOCAL_MODEL_ARTIFACTS_DIR}\",\n",
") as local_endpoint:\n",
" predict_response = local_endpoint.predict(\n",
" request_file=INPUT_FILE,\n",
@@ -1415,7 +1473,7 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "ce629eea32fd"
"id": "fTKvsXLs08HL"
},
"outputs": [],
"source": [
@@ -1445,7 +1503,7 @@
{
"cell_type": "markdown",
"metadata": {
"id": "a29fcbbe0188"
"id": "LeJ4r6DB08HL"
},
"source": [
"Also print out all the container logs. You will see the logs of container startup, serving requests, and container teardown."
@@ -1514,7 +1572,7 @@
},
"outputs": [],
"source": [
"!gcloud beta artifacts repositories create {REPOSITORY} \\\n",
"!gcloud artifacts repositories create {REPOSITORY} \\\n",
" --repository-format=docker \\\n",
" --location=$REGION"
]
@@ -1607,7 +1665,8 @@
},
"outputs": [],
"source": [
"model = local_model.upload(\n",
"model = aiplatform.Model.upload(\n",
" local_model=local_model,\n",
" display_name=MODEL_DISPLAY_NAME,\n",
" artifact_uri=f\"{BUCKET_URI}/{MODEL_ARTIFACT_DIR}\",\n",
")"
@@ -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 an **experimental** feature and is not yet officially supported by the Vertex AI SDK. In this tutorial, we'll be installing the Vertex AI SDK from an experimental branch on github. \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",
"\n",
"\n",
"\n",
@@ -69,7 +69,7 @@
"The goal is to:\n",
"- Train a model that uses a flower's measurements as input to predict what type of iris it is.\n",
"- Save the model.\n",
"- Build a custom PyTorch serving container with custom preprocessing using the Custom Prediction Routine model server using Vertex SDK.\n",
"- Build a custom PyTorch serving container with custom preprocessing using the Custom Prediction Routine feature in the Vertex AI SDK.\n",
"- Test the built container locally.\n",
"- Upload and deploy custom container to Vertex Prediction.\n",
"\n",
@@ -163,7 +163,7 @@
"pandas\n",
"torch==1.11.0\n",
"google-cloud-storage>=1.26.0,<2.0.0dev\n",
"google-cloud-aiplatform[prediction] @ git+https://github.com/googleapis/python-aiplatform.git@custom-prediction-routine"
"google-cloud-aiplatform[prediction]>=1.16.0"
]
},
{
@@ -378,6 +378,37 @@
"### Configure project and resource names"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "UYxy9q6vVNIw"
},
"source": [
"If you are in a live tutorial session, you might be using a shared test account or project. To avoid name collisions between users on resources created, you create a timestamp for each instance session, and append it onto the name of resources you create in this tutorial."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "AZ6rEERzVPdb"
},
"outputs": [],
"source": [
"from datetime import datetime\n",
"\n",
"TIMESTAMP = datetime.now().strftime(\"%Y%m%d%H%M%S\")"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "vE0Zo2mxVVMT"
},
"source": [
"Configure GCP resource names."
]
},
{
"cell_type": "code",
"execution_count": null,
@@ -451,7 +482,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-\" + TIMESTAMP\n",
" BUCKET_URI = f\"gs://{BUCKET_NAME}\""
]
},
@@ -541,7 +572,7 @@
},
"outputs": [],
"source": [
"USER_MODEL_ARTIFACTS = \"model_artifacts\" # @param {type:\"string\"}"
"LOCAL_MODEL_ARTIFACTS_DIR = \"model_artifacts\" # @param {type:\"string\"}"
]
},
{
@@ -553,7 +584,7 @@
"outputs": [],
"source": [
"%mkdir $USER_SRC_DIR\n",
"%mkdir $USER_MODEL_ARTIFACTS"
"%mkdir $LOCAL_MODEL_ARTIFACTS_DIR"
]
},
{
@@ -788,7 +819,7 @@
},
"outputs": [],
"source": [
"LOCAL_MODEL_FILE = f\"{USER_MODEL_ARTIFACTS}/model.pt\"\n",
"LOCAL_MODEL_FILE = f\"{LOCAL_MODEL_ARTIFACTS_DIR}/model.pt\"\n",
"\n",
"torch.save(model, LOCAL_MODEL_FILE)"
]
@@ -847,69 +878,89 @@
},
"outputs": [],
"source": [
"!gsutil cp {USER_MODEL_ARTIFACTS}/* {BUCKET_URI}/{MODEL_ARTIFACT_DIR}/\n",
"!gsutil cp {LOCAL_MODEL_ARTIFACTS_DIR}/* {BUCKET_URI}/{MODEL_ARTIFACT_DIR}/\n",
"!gsutil ls {BUCKET_URI}/{MODEL_ARTIFACT_DIR}/"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "b2b675059515"
},
"source": [
"## Build a custom serving container using the CPR model server"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "480a1d88ecdb"
},
"source": [
"## Build a custom serving container using the CPR model server\n",
"Now that the model and processor has been trained and saved, it's time to build the custom serving container. Typically building a serving container requires writing model server code. However, with the Custom Prediction Routine feature, Vertex AI Prediction provides a model server that can be used out of the box.\n",
"\n",
"Now that the model and processor has been trained and saved, it's time to build the custom serving container. Typically building a serving container requires writing model server code. However, with the Custom Prediction Routine feature, Vertex AI Prediction generates a model server while building images that can be used out of the box.\n",
"\n",
"A custom serving container contains the follow 3 pieces of code:\n",
"1. Model server (generated in user-provided directory by SDK)\n",
" * HTTP server that hosts the model\n",
"A custom serving container contains the following 3 pieces of code:\n",
"1. [Model Server](https://github.com/googleapis/python-aiplatform/blob/main/google/cloud/aiplatform/prediction/model_server.py)\n",
" * HTTP server that hosts the model.\n",
" * Responsible for setting up routes/ports/etc.\n",
"1. [Request Handler](https://github.com/googleapis/python-aiplatform/blob/custom-prediction-routine/google/cloud/aiplatform/prediction/handler.py)\n",
" * Responsible for webserver aspects of handling a request, such as deserializing the request body, and serializing the reponse, setting response headers, etc.\n",
"1. [Request Handler](https://github.com/googleapis/python-aiplatform/blob/main/google/cloud/aiplatform/prediction/handler.py)\n",
" * Responsible for webserver aspects of handling a request, such as deserializing the request body, serializing the response, setting response headers, etc.\n",
" * In this example, we will use the default Handler, `google.cloud.aiplatform.prediction.handler.PredictionHandler` provided in the SDK.\n",
"1. [Predictor](https://github.com/googleapis/python-aiplatform/blob/custom-prediction-routine/google/cloud/aiplatform/prediction/predictor.py)\n",
"1. [Predictor](https://github.com/googleapis/python-aiplatform/blob/main/google/cloud/aiplatform/prediction/predictor.py)\n",
" * Responsible for the ML logic for processing a prediction request.\n",
"\n",
"Each of these three pieces can be customized based on the requirements of the custom container. In this example, we will only be implementing the `Predictor`.\n",
"\n",
"\n",
"A [`Predictor`](https://github.com/googleapis/python-aiplatform/blob/custom-prediction-routine/google/cloud/aiplatform/prediction/predictor.py) must implement the following interface:\n",
"A [`Predictor`](https://github.com/googleapis/python-aiplatform/blob/main/google/cloud/aiplatform/prediction/predictor.py) must implement the following interface:\n",
"\n",
"```\n",
"class Predictor:\n",
" \"\"\"Interface for Predictor class that users would be implementing.\"\"\"\n",
"from abc import ABC, abstractmethod\n",
"from typing import Any\n",
"\n",
"\n",
"class Predictor(ABC):\n",
" \"\"\"Interface of the Predictor class for Custom Prediction Routines.\n",
" The Predictor is responsible for the ML logic for processing a prediction request.\n",
" Specifically, the Predictor must define:\n",
" (1) How to load all model artifacts used during prediction into memory.\n",
" (2) The logic that should be executed at predict time.\n",
" When using the default PredictionHandler, the Predictor will be invoked as follows:\n",
" predictor.postprocess(predictor.predict(predictor.preprocess(prediction_input)))\n",
" \"\"\"\n",
"\n",
" def __init__(self):\n",
" raise NotImplementedError(\"Predictor.__init__ has not been implemented yet.\")\n",
" return\n",
"\n",
" def load(self, artifacts_uri: str):\n",
" @abstractmethod\n",
" def load(self, artifacts_uri: str) -> None:\n",
" \"\"\"Loads the model artifact.\n",
" Args:\n",
" artifacts_uri (str):\n",
" Required. The value of the environment variable AIP_STORAGE_URI.\n",
" \"\"\"\n",
" raise NotImplementedError(\"Predictor.load has not been implemented yet.\")\n",
" pass\n",
"\n",
" def preprocess(self, prediction_input: Any) -> Any:\n",
" \"\"\"Preprocesses the prediction input before doing the prediction.\n",
" Args:\n",
" prediction_input (Any):\n",
" Required. The prediction input needs to be preprocessed.\n",
" Required. The prediction input that needs to be preprocessed.\n",
" Returns:\n",
" The preprocessed prediction input.\n",
" \"\"\"\n",
" return prediction_input\n",
"\n",
" @abstractmethod\n",
" def predict(self, instances: Any) -> Any:\n",
" \"\"\"Performs prediction.\n",
" Args:\n",
" instances (Any):\n",
" Required. The instances to perform prediction.\n",
" Required. The instance(s) used for performing prediction.\n",
" Returns:\n",
" Prediction results.\n",
" \"\"\"\n",
" raise NotImplementedError(\"Predictor.predict has not been implemented yet.\")\n",
" pass\n",
"\n",
" def postprocess(self, prediction_results: Any) -> Any:\n",
" \"\"\"Postprocesses the prediction results.\n",
@@ -931,11 +982,11 @@
"source": [
"First, implement a custom `Predictor` that loads in both the preprocesor and the model. The preprocessor and the model will then be used at `predict` time.\n",
"\n",
"Custom Prediction Routines support a way to run the containers locally for testing your images. You can pass either a GCS path or a local path while testing your images locally.\n",
"Custom Prediction Routine supports a way to run the containers locally for testing your images. You can pass either a GCS path or a local path while testing your images locally.\n",
"- You need to set up the credentials if you pass a GCS path. \n",
"- You need to support loading your models remotely and locally in your `Predictor` if you want to testing by passing a local path.\n",
"\n",
"Vertex SDK provides a function `download_model_artifacts` to help you download model artifacts from either GCS paths or local paths. See the example in the `load` function below."
"Vertex SDK provides a [function `download_model_artifacts`](https://github.com/googleapis/python-aiplatform/blob/main/google/cloud/aiplatform/utils/prediction_utils.py) to help you download model artifacts from either GCS paths or local paths. See the example in the `load` function below."
]
},
{
@@ -1049,7 +1100,7 @@
"from src_dir_pytorch.predictor import \\\n",
" CustomPyTorchPredictor # Update this path as the variable $USER_SRC_DIR to import the custom predictor.\n",
"\n",
"local_model = LocalModel.create_cpr_model(\n",
"local_model = LocalModel.build_cpr_model(\n",
" USER_SRC_DIR,\n",
" f\"{REGION}-docker.pkg.dev/{PROJECT_ID}/{REPOSITORY}/{IMAGE}\",\n",
" predictor=CustomPyTorchPredictor,\n",
@@ -1135,7 +1186,7 @@
"1. A local path.\n",
"2. A GCS path.\n",
"\n",
"To use a local path, your `Predictor` needs to support both ways to load models so it can be tested locally and deployed to Vertex AI Prediction service. SDK provides a method `download_model_artifacts` to support these two ways in [prediction_utils.py](https://github.com/googleapis/python-aiplatform/blob/custom-prediction-routine/google/cloud/aiplatform/utils/prediction_utils.py) which you can call in the `load` function in your `Predictor`.\n",
"To use a local path, your `Predictor` needs to support both ways to load models so it can be tested locally and deployed to Vertex AI Prediction service. SDK provides a method `download_model_artifacts` to support these two ways in [prediction_utils.py](https://github.com/googleapis/python-aiplatform/blob/main/google/cloud/aiplatform/utils/prediction_utils.py) which you can call in the `load` function in your `Predictor`.\n",
"\n",
"If you want to test images locally with a GCS path, you need to follow the instructions to set up the credentials."
]
@@ -1454,7 +1505,7 @@
"outputs": [],
"source": [
"with local_model.deploy_to_local_endpoint(\n",
" artifact_uri=f\"{USER_MODEL_ARTIFACTS}\",\n",
" artifact_uri=f\"{LOCAL_MODEL_ARTIFACTS_DIR}\",\n",
") as local_endpoint:\n",
" predict_response = local_endpoint.predict(\n",
" request_file=INPUT_FILE,\n",
@@ -1665,7 +1716,7 @@
},
"outputs": [],
"source": [
"!gcloud beta artifacts repositories create {REPOSITORY} \\\n",
"!gcloud artifacts repositories create {REPOSITORY} \\\n",
" --repository-format=docker \\\n",
" --location=$REGION"
]
@@ -1758,7 +1809,8 @@
},
"outputs": [],
"source": [
"model = local_model.upload(\n",
"model = aiplatform.Model.upload(\n",
" local_model=local_model,\n",
" display_name=MODEL_DISPLAY_NAME,\n",
" artifact_uri=f\"{BUCKET_URI}/{MODEL_ARTIFACT_DIR}\",\n",
")"
@@ -1896,8 +1948,7 @@
"!gcloud artifacts docker images delete \\\n",
" --quiet \\\n",
" --delete-tags \\\n",
" {REGION}-docker.pkg.dev/{PROJECT_ID}/{REPOSITORY}/{IMAGE}",
"\n",
" {REGION}-docker.pkg.dev/{PROJECT_ID}/{REPOSITORY}/{IMAGE}\n",
"delete_bucket = False\n",
"\n",
"if delete_bucket or os.getenv(\"IS_TESTING\"):\n",
@@ -53,8 +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 an **experimental** feature and is not yet officially supported by the Vertex AI SDK. In this tutorial, you will be installing the Vertex AI SDK from an experimental branch on github. \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",
"\n",
"\n",
"### Dataset\n",
@@ -157,7 +156,7 @@
"pandas\n",
"torch==1.11.0\n",
"google-cloud-storage>=1.26.0,<2.0.0dev\n",
"google-cloud-aiplatform[prediction] @ git+https://github.com/googleapis/python-aiplatform.git@custom-prediction-routine"
"google-cloud-aiplatform[prediction]>=1.16.0"
]
},
{
@@ -372,6 +371,37 @@
"### Configure project and resource names"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "HUISYGKYuO6D"
},
"source": [
"If you are in a live tutorial session, you might be using a shared test account or project. To avoid name collisions between users on resources created, you create a timestamp for each instance session, and append it onto the name of resources you create in this tutorial."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "I0-_FM9ZuJRG"
},
"outputs": [],
"source": [
"from datetime import datetime\n",
"\n",
"TIMESTAMP = datetime.now().strftime(\"%Y%m%d%H%M%S\")"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "Xgn_h2xRuJ1h"
},
"source": [
"Configure GCP resource names."
]
},
{
"cell_type": "code",
"execution_count": null,
@@ -422,7 +452,7 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "MzGDU7TWdts_"
"id": "4hODsLSwV6We"
},
"outputs": [],
"source": [
@@ -439,7 +469,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-\" + TIMESTAMP\n",
" BUCKET_URI = f\"gs://{BUCKET_NAME}\""
]
},
@@ -495,7 +525,7 @@
{
"cell_type": "markdown",
"metadata": {
"id": "3c2d091d9e73"
"id": "SCou_jfQV6Wg"
},
"source": [
"Decide the directory to put your model artifacts."
@@ -505,11 +535,11 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "3c2d091d9e73"
"id": "x3njoTraV6Wg"
},
"outputs": [],
"source": [
"MODEL_ARTIFACTS_DIRECTORY = \"model_artifacts\" # @param {type:\"string\"}"
"LOCAL_MODEL_ARTIFACTS_DIR = \"model_artifacts\" # @param {type:\"string\"}"
]
},
{
@@ -520,7 +550,7 @@
},
"outputs": [],
"source": [
"%mkdir $MODEL_ARTIFACTS_DIRECTORY"
"%mkdir $LOCAL_MODEL_ARTIFACTS_DIR"
]
},
{
@@ -772,7 +802,7 @@
"outputs": [],
"source": [
"MODEL_NAME = \"pytorch\"\n",
"LOCAL_MODEL_DIRECTORY = f\"{MODEL_ARTIFACTS_DIRECTORY}/{MODEL_NAME}\"\n",
"LOCAL_MODEL_DIRECTORY = f\"{LOCAL_MODEL_ARTIFACTS_DIR}/{MODEL_NAME}\"\n",
"LOCAL_MODEL_VERSION_1 = f\"{LOCAL_MODEL_DIRECTORY}/1\"\n",
"\n",
"%mkdir $LOCAL_MODEL_DIRECTORY\n",
@@ -888,7 +918,7 @@
},
"outputs": [],
"source": [
"!gsutil cp -r {MODEL_ARTIFACTS_DIRECTORY}/* {BUCKET_URI}/{MODEL_ARTIFACT_DIR}/\n",
"!gsutil cp -r {LOCAL_MODEL_ARTIFACTS_DIR}/* {BUCKET_URI}/{MODEL_ARTIFACT_DIR}/\n",
"!gsutil ls {BUCKET_URI}/{MODEL_ARTIFACT_DIR}/"
]
},
@@ -937,7 +967,7 @@
"source": [
"from google.cloud.aiplatform.prediction import LocalModel\n",
"\n",
"local_model = LocalModel.create(\n",
"local_model = LocalModel(\n",
" serving_container_image_uri=f\"nvcr.io/nvidia/tritonserver:{TRITON_VERSION}-py3\",\n",
" serving_container_predict_route=f\"/v2/models/{MODEL_NAME}/infer\",\n",
" serving_container_health_route=f\"/v2/models/{MODEL_NAME}\",\n",
@@ -1029,7 +1059,7 @@
"1. A local path.\n",
"2. A GCS path.\n",
"\n",
"To use a local path, your `Predictor` needs to support both ways to load models so it can be tested locally and deployed to Vertex AI Prediction service. SDK provides a method `download_model_artifacts` to support these two ways in [prediction_utils.py](https://github.com/googleapis/python-aiplatform/blob/custom-prediction-routine/google/cloud/aiplatform/utils/prediction_utils.py) which you can call in the `load` function in your `Predictor`.\n",
"To use a local path, your `Predictor` needs to support both ways to load models so it can be tested locally and deployed to Vertex AI Prediction service. SDK provides a method `download_model_artifacts` to support these two ways in [prediction_utils.py](https://github.com/googleapis/python-aiplatform/blob/main/google/cloud/aiplatform/utils/prediction_utils.py) which you can call in the `load` function in your `Predictor`.\n",
"\n",
"If you want to test images locally with a GCS path, you need to follow the instructions to set up the credentials."
]
@@ -1203,7 +1233,7 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "set_service_account"
"id": "Hs-_LvqHV6Wo"
},
"outputs": [],
"source": [
@@ -1378,7 +1408,7 @@
"outputs": [],
"source": [
"with local_model.deploy_to_local_endpoint(\n",
" artifact_uri=f\"{MODEL_ARTIFACTS_DIRECTORY}\",\n",
" artifact_uri=f\"{LOCAL_MODEL_ARTIFACTS_DIR}\",\n",
") as local_endpoint:\n",
" predict_response = local_endpoint.predict(\n",
" request_file=INPUT_FILE,\n",
@@ -1492,7 +1522,7 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "ce629eea32fd"
"id": "RDhahk8jV6Wr"
},
"outputs": [],
"source": [
@@ -1512,7 +1542,7 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "56986f93438e"
"id": "53PJx1DaV6Ws"
},
"outputs": [],
"source": [
@@ -1522,7 +1552,7 @@
{
"cell_type": "markdown",
"metadata": {
"id": "a29fcbbe0188"
"id": "j9WZtEYPV6Ws"
},
"source": [
"Also print out all the container logs. You will see the logs of container startup, serving requests, and container teardown."
@@ -1635,7 +1665,7 @@
},
"outputs": [],
"source": [
"!gcloud beta artifacts repositories create {REPOSITORY} \\\n",
"!gcloud artifacts repositories create {REPOSITORY} \\\n",
" --repository-format=docker \\\n",
" --location=$REGION"
]
@@ -1728,7 +1758,8 @@
},
"outputs": [],
"source": [
"model = local_model_ar.upload(\n",
"model = aiplatform.Model.upload(\n",
" local_model=local_model_ar,\n",
" display_name=MODEL_DISPLAY_NAME,\n",
" artifact_uri=f\"{BUCKET_URI}/{MODEL_ARTIFACT_DIR}\",\n",
")"
@@ -1,496 +0,0 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "modular-concentration"
},
"outputs": [],
"source": [
"# Copyright 2021 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": "insured-graduation"
},
"source": [
"# Feedback or issues?\n",
"\n",
"For any feedback or questions, please open an [issue](https://github.com/googleapis/python-aiplatform/issues)."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "pregnant-going"
},
"source": [
"# Vertex SDK for Python: AutoML Video Classification Example\n",
"To use this Jupyter notebook, copy the notebook to a Google Cloud Notebooks instance with Tensorflow installed and open it. You can run each step, or cell, and see its results. To run a cell, use Shift+Enter. Jupyter automatically displays the return value of the last line in each cell. For more information about running notebooks in Google Cloud Notebook, see the [Google Cloud Notebook guide](https://cloud.google.com/vertex-ai/docs/general/notebooks).\n",
"\n",
"\n",
"This notebook demonstrate how to create an AutoML Video Classification Model, with a Vertex AI video dataset, and how to serve the model for batch prediction. It will require you provide a bucket where the dataset will be stored.\n",
"\n",
"Note: you may incur charges for training, prediction, storage or usage of other GCP products in connection with testing this SDK."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "pending-chamber"
},
"source": [
"### Install Vertex SDK for Python\n",
"\n",
"\n",
"After the SDK installation the kernel will be automatically restarted."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "coated-remark"
},
"outputs": [],
"source": [
"!pip3 uninstall -y google-cloud-aiplatform\n",
"!pip3 install google-cloud-aiplatform\n",
"import IPython\n",
"\n",
"app = IPython.Application.instance()\n",
"app.kernel.do_shutdown(True)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "incorporated-edgar"
},
"source": [
"### Enter Your Project and GCS Bucket\n",
"\n",
"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."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "hispanic-macedonia"
},
"outputs": [],
"source": [
"MY_PROJECT = \"YOUR PROJECT\"\n",
"MY_STAGING_BUCKET = \"gs://YOUR BUCKET\" # bucket should be in same region as ucaip"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "efovKMU5WW7u"
},
"outputs": [],
"source": [
"import sys\n",
"\n",
"if \"google.colab\" in sys.modules:\n",
" import os\n",
"\n",
" from google.colab import auth\n",
"\n",
" auth.authenticate_user()\n",
" os.environ[\"GOOGLE_CLOUD_PROJECT\"] = MY_PROJECT"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "historical-consciousness"
},
"source": [
"### Set Your Task Name, and GCS Prefix\n",
"\n",
"If you want to centeralize all input and output files under the gcs location."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "organizational-salad"
},
"outputs": [],
"source": [
"TASK_TYPE = \"mbsdk_automl-video-training\"\n",
"PREDICTION_TYPE = \"classification\"\n",
"MODEL_TYPE = \"CLOUD\"\n",
"\n",
"TASK_NAME = f\"{TASK_TYPE}_{PREDICTION_TYPE}\"\n",
"BUCKET_NAME = MY_STAGING_BUCKET.split(\"gs://\")[1]\n",
"GCS_PREFIX = TASK_NAME\n",
"\n",
"print(f\"Bucket Name: {BUCKET_NAME}\")\n",
"print(f\"Task Name: {TASK_NAME}\")"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "compact-engagement"
},
"source": [
"# HMDB: a large human motion database\n",
"We prepared some training data and prediction data for the demo using the [HMDB Dataset](https://serre-lab.clps.brown.edu/resource/hmdb-a-large-human-motion-database).\n",
"\n",
"The HMDB Dataset is licensed under the Creative Commons Attribution 4.0 International License. To view a copy of this license, visit https://creativecommons.org/licenses/by/4.0/\n",
"\n",
"For more information about this dataset please visit: https://serre-lab.clps.brown.edu/resource/hmdb-a-large-human-motion-database/"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "SPDHQoFRD-vM"
},
"outputs": [],
"source": [
"automl_video_demo_train_data = (\n",
" \"gs://automl-video-demo-data/hmdb_split1_5classes_all.csv\"\n",
")\n",
"automl_video_demo_batch_prediction_data = (\n",
" \"gs://automl-video-demo-data/hmdb_split1_predict.jsonl\"\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "professional-bulletin"
},
"source": [
"### Copy AutoML Video Demo Train Data for Creating Managed Dataset"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "accurate-producer"
},
"outputs": [],
"source": [
"gcs_source_train = f\"gs://{BUCKET_NAME}/{TASK_NAME}/data/video_classification.csv\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "sticky-casino"
},
"outputs": [],
"source": [
"!gsutil cp $automl_video_demo_train_data $gcs_source_train"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "rough-alert"
},
"source": [
"# Run AutoML Video Training with Managed Video Dataset"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "adaptive-slovakia"
},
"source": [
"## Initialize Vertex SDK for Python\n",
"\n",
"Initialize the *client* for Vertex AI."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "figured-fellow"
},
"outputs": [],
"source": [
"from google.cloud import aiplatform\n",
"\n",
"aiplatform.init(project=MY_PROJECT, staging_bucket=MY_STAGING_BUCKET)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "pleasant-holmes"
},
"source": [
"## Create a Dataset on Vertex AI\n",
"We will now create a Vertex AI video dataset using the previously prepared csv files. Choose one of the options below. "
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "Ln-8NdHjTfbH"
},
"source": [
"Option 1: Using MBSDK VideoDataset class"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "uVBfL-0TTjNS"
},
"outputs": [],
"source": [
"dataset = aiplatform.VideoDataset.create(\n",
" display_name=f\"temp-{TASK_NAME}\",\n",
" gcs_source=gcs_source_train,\n",
" import_schema_uri=aiplatform.schema.dataset.ioformat.video.classification,\n",
" sync=False,\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "lXCA_nvHTp_I"
},
"source": [
"Option 2: Using MBSDK Dataset class\n",
"```\n",
"dataset = aiplatform.Dataset.create(\n",
" display_name=f'temp-{TASK_NAME}',\n",
" metadata_schema_uri=aiplatform.schema.dataset.metadata.video,\n",
" gcs_source=gcs_source_train, \n",
" import_schema_uri=aiplatform.schema.dataset.ioformat.video.classification,\n",
" sync=False\n",
")\n",
"```"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "3x4xuyIbVR_N"
},
"outputs": [],
"source": [
"dataset.wait()"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "mexican-spending"
},
"source": [
"## Launch a Training Job and Create a Model on Vertex AI"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dynamic-piece"
},
"source": [
"### Config a Training Job"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "continuous-circular"
},
"outputs": [],
"source": [
"job = aiplatform.AutoMLVideoTrainingJob(\n",
" display_name=f\"temp-{TASK_NAME}\",\n",
" prediction_type=PREDICTION_TYPE,\n",
" model_type=MODEL_TYPE,\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "juvenile-parameter"
},
"source": [
"### Run the Training Job"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "human-carrier"
},
"outputs": [],
"source": [
"model = job.run(\n",
" dataset=dataset,\n",
" training_fraction_split=0.8,\n",
" test_fraction_split=0.2,\n",
" model_display_name=f\"temp-{TASK_NAME}\",\n",
" sync=False,\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "abstract-textbook"
},
"outputs": [],
"source": [
"model.wait()"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "noted-usage"
},
"source": [
"# Batch Prediction Job on the Model"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "ruled-smith"
},
"source": [
"### Copy AutoML Video Demo Prediction Data for Creating Batch Prediction Job"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "polished-dispatch"
},
"outputs": [],
"source": [
"gcs_source_batch_prediction = (\n",
" f\"gs://{BUCKET_NAME}/{TASK_NAME}/data/video_classification_batch_prediction.jsonl\"\n",
")\n",
"gcs_destination_prefix_batch_prediction = (\n",
" f\"gs://{BUCKET_NAME}/{TASK_NAME}/batch_prediction\"\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "objective-soldier"
},
"outputs": [],
"source": [
"!gsutil cp $automl_video_demo_batch_prediction_data $gcs_source_batch_prediction"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "piano-middle"
},
"outputs": [],
"source": [
"batch_predict_job = model.batch_predict(\n",
" job_display_name=f\"temp-{TASK_NAME}\",\n",
" gcs_source=gcs_source_batch_prediction,\n",
" gcs_destination_prefix=gcs_destination_prefix_batch_prediction,\n",
" sync=False,\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "visible-scientist"
},
"outputs": [],
"source": [
"batch_predict_job.wait()\n",
"bp_iter_outputs = batch_predict_job.iter_outputs()\n",
"\n",
"prediction_results = list()\n",
"for blob in bp_iter_outputs:\n",
" if blob.name.split(\"/\")[-1].startswith(\"prediction\"):\n",
" prediction_results.append(blob.name)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "moving-geneva"
},
"outputs": [],
"source": [
"import json\n",
"\n",
"import tensorflow as tf\n",
"\n",
"tags = list()\n",
"for prediction_result in prediction_results:\n",
" gfile_name = f\"gs://{bp_iter_outputs.bucket.name}/{prediction_result}\"\n",
" with tf.io.gfile.GFile(name=gfile_name, mode=\"r\") as gfile:\n",
" for line in gfile.readlines():\n",
" line = json.loads(line)\n",
" break\n",
"\n",
"print(line)"
]
}
],
"metadata": {
"colab": {
"collapsed_sections": [],
"name": "AI_Platform_(Unified)_SDK_AutoML_Video_Classification.ipynb",
"toc_visible": true
},
"kernelspec": {
"display_name": "Python 3",
"name": "python3"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
@@ -23,6 +23,15 @@
"# limitations under the License."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "2d7a1a97d1ee"
},
"source": [
"# Vertex AI: SDK BigQuery Custom Container Training"
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -58,18 +67,61 @@
},
"source": [
"### Overview \n",
"To use this Jupyter notebook, copy the notebook to a Google Cloud Notebooks instance and open it. You can run each step, or cell, and see its results. To run a cell, use Shift+Enter. Jupyter automatically displays the return value of the last line in each cell. For more information about running notebooks in Google Cloud Notebook, see the Google Cloud Notebook guide.. \n",
"\n",
"### Objective \n",
"This Note book creates a custom container using bigquery dataset it will train container and crete ,train and Deploy the model to perform prediction. \n"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "989999fbdab3"
},
"source": [
"### Objective\n",
"\n",
"This notebook demonstrate how to create a Custom Model using Custom Container Training and a Big Query Dataset. It will require you provide a bucket where the dataset will be stored.\n",
"In this notebook, you will learn how to use Vertex AI Experiments to \n",
"\n",
"Costs \n",
"This tutorial uses billable components of Google Cloud: \n",
"* Log Pipeline Job\n",
"* Compare different Pipeline Jobs\n",
"\n",
"Vertex AI\n",
"Cloud Storage\n",
"Learn about Vertex AI pricing and Cloud Storage pricing, and use the Pricing Calculator to generate a cost estimate based on your projected usage."
"The steps covered include:\n",
"\n",
"* Formalize a training component\n",
"* Build a training a Model\n",
"* Run several Pipeline jobs and log their results\n",
"* Train the model for prediction\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "3d29af7e49d8"
},
"source": [
"### Dataset\n",
"\n",
"The dataset used for this tutorial is the [Iris dataset](https://www.tensorflow.org/datasets/catalog/iris) from [TensorFlow Datasets](https://www.tensorflow.org/datasets/catalog/overview). This dataset does not require any feature engineering. The version of the dataset you use in this tutorial is stored in a public Cloud Storage bucket. The trained model predicts the type of Iris flower species from a class of three species: setosa, virginica, or versicolor."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "e3e924989cce"
},
"source": [
"### Costs \n",
"\n",
"This tutorial uses billable components of Google Cloud:\n",
"\n",
"* Vertex AI\n",
"* Cloud Storage\n",
"\n",
"Learn about [Vertex AI\n",
"pricing](https://cloud.google.com/vertex-ai/pricing) [Bigquery\n",
"pricing](https://cloud.google.com/bigquery/pricing/) and [Cloud Storage\n",
"pricing](https://cloud.google.com/storage/pricing), and use the [Pricing\n",
"Calculator](https://cloud.google.com/products/calculator/)\n",
"to generate a cost estimate based on your projected usage."
]
},
{
@@ -139,10 +191,9 @@
"id": "xOMNWzTbftDr"
},
"source": [
"# Install Vertex AI SDK for Python\n",
"### Install additional packages\n",
"\n",
"\n",
"After the SDK installation the kernel will be automatically restarted."
"Install additional package dependencies not installed in your notebook environment, such as XGBoost, AdaNet, or TensorFlow Hub. Use the latest major GA version of each package."
]
},
{
@@ -161,6 +212,36 @@
"app.kernel.do_shutdown(True)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "d4f317591f55"
},
"source": [
"### Restart the kernel\n",
"\n",
"After you install the additional packages, you need to restart the notebook kernel so it can find the packages."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "f731803a16c0"
},
"outputs": [],
"source": [
"# Automatically restart kernel after installs\n",
"import os\n",
"\n",
"if not os.getenv(\"IS_TESTING\"):\n",
" # Automatically restart kernel after installs\n",
" import IPython\n",
"\n",
" app = IPython.Application.instance()\n",
" app.kernel.do_shutdown(True)"
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -172,6 +253,17 @@
"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."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "3c8049930470"
},
"outputs": [],
"source": [
"PROJECT_ID = \"[your-project-id]\" # @param {type:\"string\"}"
]
},
{
"cell_type": "code",
"execution_count": null,
@@ -183,14 +275,11 @@
"import os\n",
"\n",
"PROJECT_ID = \"\"\n",
"\n",
"# Get your Google Cloud project ID from gcloud\n",
"if not os.getenv(\"IS_TESTING\"):\n",
" shell_output = !gcloud config list --format 'value(core.project)' 2>/dev/null\n",
" PROJECT_ID = shell_output[0]\n",
" print(\"Project ID: \", PROJECT_ID)\n",
"\n",
"MY_STAGING_BUCKET = \"gs://YOUR BUCKET\" # bucket should be in same region as ucaip"
" print(\"Project ID: \", PROJECT_ID)"
]
},
{
@@ -218,21 +307,14 @@
{
"cell_type": "markdown",
"metadata": {
"id": "6x6CSodKjMmg"
"id": "ZaQd5jNwjP_0"
},
"source": [
"### Authenticate your Google Cloud account\n",
"\n",
"**If you are using Google Cloud Notebooks**, your environment is already\n",
"authenticated. Skip this step"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "ZaQd5jNwjP_0"
},
"source": [
"**If you are using Vertex AI Workbench Notebooks**, your environment is already\n",
"authenticated. Skip this step\n",
"\n",
"**If you are using Colab**, run the cell below and follow the instructions\n",
"when prompted to authenticate your account via oAuth.\n",
"\n",
@@ -296,9 +378,9 @@
"id": "r2lr6-MVpXLP"
},
"source": [
"#### Timestamp\n",
"#### UUID\n",
"\n",
"If you are in a live tutorial session, you might be using a shared test account or project. To avoid name collisions between users on resources created, you create a timestamp for each instance session, and append it onto the name of resources you create in this tutorial."
"If you are in a live tutorial session, you might be using a shared test account or project. To avoid name collisions between users on resources created, you create a uuid for each instance session, and append it onto the name of resources you create in this tutorial.\n"
]
},
{
@@ -309,9 +391,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()"
]
},
{
@@ -343,15 +432,24 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "GF076Vmoioll"
"id": "2f6f0f6ec383"
},
"outputs": [],
"source": [
"BUCKET_URI = \"gs://[your-bucket-name]\" # @param {type:\"string\"}\n",
"REGION = \"[your-region]\" # @param {type:\"string\"}\n",
"\n",
"REGION = \"[your-region]\" # @param {type:\"string\"}"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "GF076Vmoioll"
},
"outputs": [],
"source": [
"if BUCKET_URI == \"\" or BUCKET_URI is None or BUCKET_URI == \"gs://[your-bucket-name]\":\n",
" BUCKET_URI = \"gs://\" + PROJECT_ID + \"aip-\" + TIMESTAMP\n",
" BUCKET_URI = \"gs://\" + PROJECT_ID + \"aip-\" + UUID\n",
"\n",
"if REGION == \"[your-region]\":\n",
" REGION = \"us-central1\""
@@ -403,8 +501,9 @@
"id": "5T1d5uBoftDw"
},
"source": [
"# Copy Big Query Iris Dataset\n",
"We will make a Big Query dataset and copy Big Query's public iris table to that dataset. For more information about this dataset please visit: https://archive.ics.uci.edu/ml/datasets/iris "
"# Copy bigquery iris dataset\n",
"\n",
"You make a BigQuery dataset and copy BigQuery's public iris table to that dataset. For more information about this dataset please visit: https://archive.ics.uci.edu/ml/datasets/iris "
]
},
{
@@ -543,6 +642,15 @@
"### Write the entrypoint script to invoke trainer"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "c5cdc477cd73"
},
"source": [
"The entrypoint script train adn validates the data and also compiles the model."
]
},
{
"cell_type": "code",
"execution_count": null,
@@ -697,9 +805,9 @@
"id": "736ddff8408b"
},
"source": [
"# Create a Managed Tabular Dataset from Big Query Dataset\n",
"# Create a managed tabular dataset from bigquery dataset\n",
"\n",
"This section will create a managed Tabular dataset from the iris Big Query table we copied above."
"This section create a managed Tabular dataset from the iris BigQuery table we copied above.The param's used are BigQuery's public iris dataset."
]
},
{
@@ -723,7 +831,7 @@
"source": [
"# Launch The Training Job to Create a Model\n",
"\n",
"We will train a model with the container we built above."
"We will train a model with the container we built above.To train the model you use the CustomeContanier TrainingJob method with Container Image and Container_uri as parametrs."
]
},
{
@@ -753,9 +861,9 @@
"id": "a7fa9b59f919"
},
"source": [
"# Deploy The Model\n",
"# Deploy the model\n",
"\n",
"Deploy your model, then wait until the model FINISHES deployment before proceeding to prediction."
"Deploy your model, then wait until the model Finishes deployment before proceeding to prediction.For prediction deploy method takes machine_type as parameter."
]
},
{
@@ -778,6 +886,15 @@
"# Make a prediction\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "e4b04d246ba9"
},
"source": [
"Endpoint predict method publish the prediction based on length and width feature parameters."
]
},
{
"cell_type": "code",
"execution_count": null,
@@ -786,9 +903,11 @@
},
"outputs": [],
"source": [
"endpoint.predict(\n",
"prediction = endpoint.predict(\n",
" [{\"sepal_length\": 5.1, \"sepal_width\": 2.5, \"petal_length\": 3.0, \"petal_width\": 1.1}]\n",
")"
")\n",
"\n",
"print(prediction)"
]
},
{
@@ -797,12 +916,16 @@
"id": "MaoIczP8qu--"
},
"source": [
"## Cleaning up\n",
"# Cleaning up\n",
"\n",
"To clean up all Google Cloud resources used in this project, you can [delete the Google Cloud\n",
"project](https://cloud.google.com/resource-manager/docs/creating-managing-projects#shutting_down_projects) you used for the tutorial.\n",
"\n",
"Otherwise, you can delete the individual resources you created in this tutorial:"
"Otherwise, you can delete the individual resources you created in this tutorial:\n",
"\n",
"- Pipeline\n",
"- Endpoint\n",
"- Cloud Storage Bucket"
]
},
{
@@ -813,16 +936,28 @@
},
"outputs": [],
"source": [
"import os\n",
"delete_pipeline = True\n",
"delete_endpoint = True\n",
"\n",
"# Delete endpoint resource\n",
"! gcloud ai endpoints delete $ENDPOINT_NAME --quiet --region $REGION_NAME\n",
"\n",
"# Delete Cloud Storage objects that were created\n",
"! gsutil -m rm -r $JOB_DIR\n",
"if delete_pipeline:\n",
" job.delete()\n",
"\n",
"if os.getenv(\"IS_TESTING\"):\n",
"! gsutil -m rm -r $BUCKET_URI "
" if delete_endpoint and \"DISPLAY_NAME\" in globals():\n",
" endpoints = aip.Endpoint.list(\n",
" filter=f\"display_name={DISPLAY_NAME}_endpoint\", order_by=\"create_time\"\n",
" )\n",
" if endpoints:\n",
" endpoint = endpoints[0]\n",
" endpoint.undeploy_all()\n",
" aip.Endpoint.delete(endpoint.resource_name)\n",
" print(\"Deleted endpoint:\", endpoint)\n",
"\n",
"\n",
"# Delete bucket\n",
"delete_bucket = False\n",
"if delete_bucket or os.getenv(\"IS_TESTING\"):\n",
" ! gsutil rm -rf {BUCKET_URI}"
]
}
],
File diff suppressed because it is too large Load Diff
+57 -177
View File
@@ -43,7 +43,7 @@
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://raw.githubusercontent.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/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/notebook_template.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",
@@ -59,14 +59,15 @@
"source": [
"## Overview\n",
"\n",
"{TODO: Include a paragraph or two explaining what this example demonstrates, who should be interested in it, and what you need to know before you get started.}\n",
"\n",
"### Dataset\n",
"\n",
"{TODO: Include a paragraph with Dataset information and where to obtain it.} \n",
"\n",
"{TODO: Make sure the dataset is accessible to the public. **Googlers**: Add your dataset to the [public samples bucket](http://goto/cloudsamples#sample-storage-bucket) within gs://cloud-samples-data/vertex-ai, if it doesn't already exist there.}\n",
"\n",
"{TODO: Include a paragraph or two explaining what this example demonstrates, who should be interested in it, and what you need to know before you get started.}"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "d975e698c9a4"
},
"source": [
"### Objective\n",
"\n",
"In this tutorial, you learn how to {TODO: Complete the sentence explaining briefly what you will learn from the notebook, such as\n",
@@ -79,8 +80,28 @@
"\n",
"The steps performed include:\n",
"\n",
"- * {TODO: Add high level bullets for the steps of performed in the notebook}\n",
"- * {TODO: Add high level bullets for the steps of performed in the notebook}"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "08d289fa873f"
},
"source": [
"### Dataset\n",
"\n",
"{TODO: Include a paragraph with Dataset information and where to obtain it.} \n",
"\n",
"{TODO: Make sure the dataset is accessible to the public. **Googlers**: Add your dataset to the [public samples bucket](http://goto/cloudsamples#sample-storage-bucket) within gs://cloud-samples-data/vertex-ai, if it doesn't already exist there.}"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "aed92deeb4a0"
},
"source": [
"### Costs \n",
"\n",
"{TODO: Update the list of billable products that your tutorial uses.}\n",
@@ -154,7 +175,7 @@
"id": "i7EUnXsZhAGF"
},
"source": [
"### Install additional packages\n",
"## Installation\n",
"\n",
"Install the following packages required to execute this notebook. \n",
"\n",
@@ -241,7 +262,7 @@
"\n",
"1. [Enable the Vertex AI API](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com). {TODO: Update the APIs needed for your tutorial. Edit the API names, and update the link to append the API IDs, separating each one with a comma. For example, container.googleapis.com,cloudbuild.googleapis.com}\n",
"\n",
"1. If you are running this notebook locally, you will need to install the [Cloud SDK](https://cloud.google.com/sdk).\n",
"1. If you are running this notebook locally, you need to install the [Cloud SDK](https://cloud.google.com/sdk).\n",
"\n",
"1. Enter your project ID in the cell below. Then run the cell to make sure the\n",
"Cloud SDK uses the right project for all the commands in this notebook.\n",
@@ -268,22 +289,7 @@
},
"outputs": [],
"source": [
"PROJECT_ID = \"\"\n",
"\n",
"# Get your Google Cloud project ID from gcloud\n",
"if not os.getenv(\"IS_TESTING\"):\n",
" shell_output = !gcloud config list --format 'value(core.project)' 2>/dev/null\n",
" PROJECT_ID = shell_output[0]\n",
" print(\"Project ID: \", PROJECT_ID)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "qJYoRfYng0XZ"
},
"source": [
"Otherwise, set your project ID here."
"PROJECT_ID = \"[your-project-id]\" # @param {type:\"string\"}"
]
},
{
@@ -294,8 +300,11 @@
},
"outputs": [],
"source": [
"if PROJECT_ID == \"\" or PROJECT_ID is None:\n",
" PROJECT_ID = \"[your-project-id]\" # @param {type:\"string\"}"
"if PROJECT_ID == \"\" or PROJECT_ID is None or PROJECT_ID == \"[your-project-id]\":\n",
" # Get your GCP project id from gcloud\n",
" shell_output = ! gcloud config list --format 'value(core.project)' 2>/dev/null\n",
" PROJECT_ID = shell_output[0]\n",
" print(\"Project ID:\", PROJECT_ID)"
]
},
{
@@ -342,7 +351,7 @@
"#### Region\n",
"\n",
"You can also change the `REGION` variable, which is used for operations\n",
"throughout the rest of this notebook. Below are regions supported for Vertex AI. We recommend that you choose the region closest to you.\n",
"throughout the rest of this notebook. Below are regions supported for Vertex AI. It is recommended that you choose the region closest to you.\n",
"\n",
"- Americas: `us-central1`\n",
"- Europe: `europe-west4`\n",
@@ -373,9 +382,11 @@
"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 it onto the name of resources you create in this tutorial."
"If you are in a live tutorial session, you might be using a shared test account or project. To avoid name collisions between users on resources created, you create a uuid for each instance session, and append it onto the name of resources you create in this tutorial.\n",
"\n",
"{TODO: replace the `TIMESTAMP` with `UUID` in official notebooks}"
]
},
{
@@ -386,9 +397,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()"
]
},
{
@@ -511,7 +529,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 = f\"gs://{BUCKET_NAME}\""
]
},
@@ -671,145 +689,6 @@
"aiplatform.init(project=PROJECT_ID, location=REGION, staging_bucket=BUCKET_URI)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "E6ppE7imft-y"
},
"source": [
"## General style examples\n",
"\n",
"### Notebook heading\n",
"\n",
"- Include the collapsed license at the top (this uses Colab's \"Form\" mode to hide the cells).\n",
"- Only include a single H1 title.\n",
"- Include the button-bar immediately under the H1.\n",
"- Check that the Colab and GitHub links at the top are correct.\n",
"\n",
"### Notebook sections\n",
"\n",
"- Use H2 (##) and H3 (###) titles for notebook section headings.\n",
"- Use [sentence case to capitalize titles and headings](https://developers.google.com/style/capitalization#capitalization-in-titles-and-headings). (\"Train the model\" instead of \"Train the Model\")\n",
"- Include a brief text explanation before any code cells.\n",
"- Use short titles/headings: \"Download the data\", \"Build the model\", \"Train the model\".\n",
"\n",
"### Writing style\n",
"\n",
"- Use [present tense](https://developers.google.com/style/tense). (\"You receive a response\" instead of \"You will receive a response\")\n",
"- Use [active voice](https://developers.google.com/style/voice). (\"The service processes the request\" instead of \"The request is processed by the service\")\n",
"- Use [second person](https://developers.google.com/style/person) and an imperative style. \n",
" - Correct examples: \"Update the field\", \"You must update the field\"\n",
" - Incorrect examples: \"Let's update the field\", \"We'll update the field\", \"The user should update the field\"\n",
"- **Googlers**: Please follow our [branding guidelines](http://goto/cloud-branding).\n",
"\n",
"### Code\n",
"\n",
"- Put all your installs and imports in a setup section.\n",
"- Save the notebook with the Table of Contents open.\n",
"- Write Python 3 compatible code.\n",
"- Follow the [Google Python Style guide](https://github.com/google/styleguide/blob/gh-pages/pyguide.md) and write readable code.\n",
"- Keep cells small (max ~20 lines)."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "euaAioez2WyE"
},
"source": [
"## TensorFlow code style\n",
"\n",
"Use the highest level API that gets the job done (unless the goal is to demonstrate the low level API). For example, when using Tensorflow:\n",
"\n",
"- Use TF.keras.Sequential > keras functional api > keras model subclassing > ...\n",
"\n",
"- Use model.fit > model.train_on_batch > manual GradientTapes.\n",
"\n",
"- Use eager-style code.\n",
"\n",
"- Use tensorflow_datasets and tf.data where possible."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "reBCSTKOg47l"
},
"source": [
"### Notebook code style examples\n",
"\n",
" - Notebooks are for people. Write code optimized for clarity.\n",
"\n",
" - Demonstrate small parts before combining them into something more complex. Like below:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "MjJTYC86hPOZ"
},
"outputs": [],
"source": [
"# install needed for notebook ingestion test; otherwise not part of the example\n",
"! pip3 install --upgrade tensorflow\n",
"\n",
"# Build the model\n",
"import tensorflow as tf\n",
"\n",
"model = tf.keras.Sequential(\n",
" [\n",
" tf.keras.layers.Dense(10, activation=\"relu\", input_shape=(None, 5)),\n",
" tf.keras.layers.Dense(3),\n",
" ]\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "LWymd3KPhP_S"
},
"outputs": [],
"source": [
"# Run the model on a single batch of data, and inspect the output.\n",
"import numpy as np\n",
"\n",
"result = model(tf.constant(np.random.randn(10, 5), dtype=tf.float32)).numpy()\n",
"\n",
"print(\"min:\", result.min())\n",
"print(\"max:\", result.max())\n",
"print(\"mean:\", result.mean())\n",
"print(\"shape:\", result.shape)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "y-pQzaxnhR-0"
},
"outputs": [],
"source": [
"# Compile the model for training\n",
"model.compile(\n",
" optimizer=tf.keras.optimizers.Adam(), loss=tf.keras.losses.categorical_crossentropy\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "g0d8u7FmhUNf"
},
"source": [
"- Keep examples quick. Use small datasets, or small slices of datasets. You don't need to train to convergence, train until it's obvious it's making progress.\n",
"\n",
"- For a large example, don't try to fit all the code in the notebook. Add python files to tensorflow examples, and in the notebook run: \n",
"! pip3 install git+https://github.com/tensorflow/examples"
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -835,7 +714,7 @@
"outputs": [],
"source": [
"# Delete endpoint resource\n",
"! gcloud ai endpoints delete $ENDPOINT_NAME --quiet --region $REGION_NAME\n",
"! gcloud ai endpoints delete $ENDPOINT_NAME --quiet --region $REGION\n",
"\n",
"# Delete model resource\n",
"! gcloud ai models delete $MODEL_NAME --quiet\n",
@@ -843,7 +722,8 @@
"# Delete Cloud Storage objects that were created\n",
"! gsutil -m rm -r $JOB_DIR\n",
"\n",
"if os.getenv(\"IS_TESTING\"):\n",
"delete_bucket = False\n",
"if delete_bucket or os.getenv(\"IS_TESTING\"):\n",
" ! gsutil -m rm -r $BUCKET_URI"
]
}
+422
View File
@@ -0,0 +1,422 @@
import argparse
import json
import os
import urllib.request
parser = argparse.ArgumentParser()
parser.add_argument('--notebook-dir', dest='notebook_dir',
default=None, type=str, help='Notebook directory')
parser.add_argument('--notebook', dest='notebook',
default=None, type=str, help='Notebook to review')
parser.add_argument('--errors', dest='errors',
default=False, type=bool, help='Report errors')
parser.add_argument('--errors-csv', dest='errors_csv',
default=False, type=bool, help='Report errors as CSV')
parser.add_argument('--errors-codes', dest='errors_codes',
default=None, type=str, help='Report only specified errors')
parser.add_argument('--desc', dest='desc',
default=False, type=bool, help='Output description')
parser.add_argument('--uses', dest='uses',
default=False, type=bool, help='Output uses (resources)')
parser.add_argument('--steps', dest='steps',
default=False, type=bool, help='Ouput steps')
args = parser.parse_args()
if args.errors_codes:
args.errors_codes = args.errors_codes.split(',')
args.errors = True
if args.errors_csv:
args.errors = True
def parse_dir(directory):
entries = os.scandir(directory)
for entry in entries:
if entry.is_dir():
if entry.name[0] == '.':
continue
if entry.name == 'src' or entry.name == 'images':
continue
print("\n##", entry.name, "\n")
parse_dir(entry.path)
elif entry.name.endswith('.ipynb'):
parse_notebook(entry.path)
def parse_notebook(path):
with open(path, 'r') as f:
try:
content = json.load(f)
except:
print("Corrupted notebook:", path)
return
cells = content['cells']
# cell 1 is copyright
nth = 0
cell, nth = get_cell(path, cells, nth)
if not cell['source'][0].startswith('# Copyright'):
report_error(path, 0, "missing copyright cell")
# check for notices
cell, nth = get_cell(path, cells, nth)
if cell['source'][0].startswith('This notebook'):
cell, nth = get_cell(path, cells, nth)
# cell 2 is title and links
if not cell['source'][0].startswith('# '):
report_error(path, 1, "title cell must start with H1 heading")
else:
title = cell['source'][0][2:].strip()
check_sentence_case(path, title)
# check links.
source = ''
for line in cell['source']:
source += line
if '<a href="https://github.com' in line:
link = line.strip()[9:-2]
try:
code = urllib.request.urlopen(link).getcode()
except Exception as e:
report_error(path, 7, f"bad GitHub link: {link}")
if '<a href="https://colab.research.google.com/' in line:
link = 'https://github.com/' + line.strip()[50:-2]
try:
code = urllib.request.urlopen(link).getcode()
except Exception as e:
report_error(path, 8, f"bad Colab link: {link}")
if '<a href="https://console.cloud.google.com/vertex-ai/workbench/' in line:
link = line.strip()[91:-2]
try:
code = urllib.request.urlopen(link).getcode()
except Exception as e:
report_error(path, 9, f"bad Workbench link: {link}")
if 'View on GitHub' not in source:
report_error(path, 4, 'Missing link for GitHub')
if 'Open in Vertex AI Workbench' not in source:
report_error(path, 5, 'Missing link for Workbench')
if 'master' in source:
report_error(path, 6, 'Outdated branch (master) used in link')
# Overview
cell, nth = get_cell(path, cells, nth)
if not cell['source'][0].startswith("## Overview"):
report_error(path, 11, "Overview section not found")
# Objective
cell, nth = get_cell(path, cells, nth)
if not cell['source'][0].startswith("### Objective"):
report_error(path, 12, "Objective section not found")
costs = []
else:
desc, uses, steps, costs = parse_objective(path, cell)
add_index(path, title, desc, uses, steps)
# (optional) Recommendation
cell, nth = get_cell(path, cells, nth)
if cell['source'][0].startswith("### Recommendations"):
cell, nth = get_cell(path, cells, nth)
# Dataset
if not cell['source'][0].startswith("### Dataset") and not cell['source'][0].startswith("### Model") and not cell['source'][0].startswith("### Embedding"):
report_error(path, 13, "Dataset/Model section not found")
# Costs
cell, nth = get_cell(path, cells, nth)
if not cell['source'][0].startswith("### Costs"):
report_error(path, 14, "Costs section not found")
else:
text = ''
for line in cell['source']:
text += line
if 'BQ' in costs and 'BigQuery' not in text:
report_error(path, 20, 'Costs section missing reference to BiqQuery')
if 'Vertex' in costs and 'Vertex' not in text:
report_error(path, 20, 'Costs section missing reference to Vertex')
if 'Dataflow' in costs and 'Dataflow' not in text:
report_error(path, 20, 'Costs section missing reference to Dataflow')
# (optional) Setup local environment
cell, nth = get_cell(path, cells, nth)
if cell['source'][0].startswith('### Set up your local development environment'):
cell, nth = get_cell(path, cells, nth)
if cell['source'][0].startswith('**Otherwise**, make sure your environment meets'):
cell, nth = get_cell(path, cells, nth)
# (optional) Helper functions
if 'helper' in cell['source'][0]:
cell, nth = get_cell(path, cells, nth)
cell, nth = get_cell(path, cells, nth)
# Installation
if not cell['source'][0].startswith("## Install"):
if cell['source'][0].startswith("### Install"):
report_error(path, 27, "Installation section needs to be H2 heading")
else:
report_error(path, 21, "Installation section not found")
else:
cell, nth = get_cell(path, cells, nth)
if cell['cell_type'] != 'code':
report_error(path, 22, "Installation code section not found")
else:
if cell['source'][0].startswith('! mkdir'):
cell, nth = get_cell(path, cells, nth)
if 'requirements.txt' in cell['source'][0]:
cell, nth = get_cell(path, cells, nth)
text = ''
for line in cell['source']:
text += line
if 'pip ' in line:
if 'pip3' not in line:
report_error(path, 23, "Installation code section: use pip3")
if line.endswith('\\\n'):
continue
if '-q' not in line:
report_error(path, 23, "Installation code section: use -q with pip3")
if 'USER_FLAG' not in line and 'sh(' not in line:
report_error(path, 23, "Installation code section: use {USER_FLAG} with pip3")
if 'if IS_WORKBENCH_NOTEBOOK:' not in text:
report_error(path, 24, "Installation code section out of date (see template)")
# Restart kernel
while True:
cont = False
cell, nth = get_cell(path, cells, nth)
for line in cell['source']:
if 'pip' in line:
report_error(path, 25, f"All pip installations must be in a single code cell: {line}")
cont = True
break
if not cont:
break
if not cell['source'][0].startswith("### Restart the kernel"):
report_error(path, 26, "Restart the kernel section not found")
else:
cell, nth = get_cell(path, cells, nth) # code cell
if cell['cell_type'] != 'code':
report_error(path, 28, "Restart the kernel code section not found")
# (optional) Check package versions
cell, nth = get_cell(path, cells, nth)
if cell['source'][0].startswith('#### Check package versions'):
cell, nth = get_cell(path, cells, nth) # code cell
cell, nth = get_cell(path, cells, nth) # next text cell
# Before you begin
if not cell['source'][0].startswith("## Before you begin"):
report_error(path, 29, "Before you begin section not found")
else:
# maybe one or two cells
if len(cell['source']) < 2:
cell, nth = get_cell(path, cells, nth)
if not cell['source'][0].startswith("### Set up your Google Cloud project"):
report_error(path, 30, "Before you begin section incomplete")
# (optional) enable APIs
cell, nth = get_cell(path, cells, nth)
if cell['source'][0].startswith("### Enable APIs"):
cell, nth = get_cell(path, cells, nth) # code cell
cell, nth = get_cell(path, cells, nth) # next text cell
# Set project ID
if not cell['source'][0].startswith('#### Set your project ID'):
report_error(path, 31, "Set project ID section not found")
else:
cell, nth = get_cell(path, cells, nth)
if cell['cell_type'] != 'code':
report_error(path, 32, "Set project ID code section not found")
elif not cell['source'][0].startswith('PROJECT_ID = "[your-project-id]"'):
report_error(path, 33, f"Set project ID not match template: {line}")
cell, nth = get_cell(path, cells, nth)
if cell['cell_type'] != 'code' or 'or PROJECT_ID == "[your-project-id]":' not in cell['source'][0]:
report_error(path, 33, f"Set project ID not match template: {line}")
cell, nth = get_cell(path, cells, nth)
if cell['cell_type'] != 'code' or '! gcloud config set project' not in cell['source'][0]:
report_error(path, 33, f"Set project ID not match template: {line}")
'''
# Region
cell, nth = get_cell(path, cells, nth)
if cell['source'][0].startswith("### Region"):
report_error(path, 34, "Region section not found")
'''
def get_cell(path, cells, nth):
while empty_cell(path, cells, nth):
nth += 1
cell = cells[nth]
if cell['cell_type'] == 'markdown':
check_text_cell(path, cell)
return cell, nth + 1
def empty_cell(path, cells, nth):
if len(cells[nth]['source']) == 0:
report_error(path, 10, f'empty cell: cell #{nth}')
return True
else:
return False
def check_text_cell(path, cell):
branding = {
'Vertex SDK': 'Vertex AI SDK',
'Vertex Training': 'Vertex AI Training',
'Vertex Prediction': 'Vertex AI Prediction',
'Vertex Batch Prediction': 'Vertex AI Batch Prediction',
'Vertex XAI': 'Vertex Explainable AI',
'Vertex Experiments': 'Vertex AI Experiments',
'Vertex TensorBoard': 'Vertex AI TensorBoard',
'Vertex Pipelines': 'Vertex AI Pipelines',
'Vertex Hyperparameter Tuning': 'Vertex AI Hyperparameter Tuning',
'Vertex Metadata': 'Vertex ML Metadata',
'Vertex AI Metadata': 'Vertex ML Metadata',
'Vertex Vizier': 'Vertex AI Vizier',
'Vertex Dataset': 'Vertex AI Dataset',
'Vertex Model': 'Vertex AI Model',
'Vertex Endpoint': 'Vertex AI Endpoint',
'Vertex Private Endpoint': 'Vertex AI Private Endpoint',
'Tensorflow': 'TensorFlow',
'Tensorboard': 'TensorBoard',
'Google Cloud Notebooks': 'Vertex AI Workbench Notebooks'
}
for line in cell['source']:
if 'TODO' in line:
report_error(path, 14, f'TODO in cell: {line}')
if 'we ' in line.lower() or "let's" in line.lower() in line.lower():
report_error(path, 15, f'Do not use first person (e.g., we), replace with 2nd person (you): {line}')
if 'will' in line.lower() or 'would' in line.lower():
report_error(path, 16, f'Do not use future tense (e.g., will), replace with present tense: {line}')
for mistake, brand in branding.items():
if mistake in line:
report_error(path, 27, f"Branding {brand}: {line}")
def check_sentence_case(path, heading):
words = heading.split(' ')
if not words[0][0].isupper():
report_error(path, 2, f"heading must start with capitalized word: {words[0]}")
for word in words[1:]:
word = word.replace(':', '').replace('(', '').replace(')', '')
if word in ['E2E', 'Vertex', 'AutoML', 'ML', 'AI', 'GCP', 'API', 'R', 'CMEK', 'TFX', 'TFDV', 'SDK',
'VM', 'CPR', 'NVIDIA', 'ID', 'DASK']:
continue
if word.isupper():
report_error(path, 3, f"heading is not sentence case: {word}")
def report_error(notebook, code, msg):
if args.errors:
if args.errors_codes:
if str(code) not in args.errors_codes:
return
if args.errors_csv:
print(notebook, ',', code)
else:
print(f"{notebook}: ERROR ({code}): {msg}")
def parse_objective(path, cell):
desc = ''
in_desc = True
uses = ''
in_uses = False
steps = ''
in_steps = False
costs = []
for line in cell['source'][1:]:
if line.startswith('This tutorial uses'):
in_desc = False
in_steps = False
in_uses = True
uses += line
continue
elif line.startswith('The steps performed'):
in_desc = False
in_uses = False
in_steps = True
steps += line
continue
if in_desc:
desc += line
elif in_uses:
sline = line.strip()
if len(sline) == 0:
uses += '\n'
else:
ch = sline[0]
if ch in ['-', '*', '1', '2', '3', '4', '5', '6', '7', '8', '9']:
uses += line
elif in_steps:
sline = line.strip()
if len(sline) == 0:
steps += '\n'
else:
ch = sline[0]
if ch in ['-', '*', '1', '2', '3', '4', '5', '6', '7', '8', '9']:
steps += line
if desc == '':
report_error(path, 17, "Objective section missing desc")
if uses == '':
report_error(path, 18, "Objective section missing uses services list")
else:
if 'BigQuery' in uses:
costs.append('BQ')
if 'Vertex' in uses:
costs.append('Vertex')
if 'Dataflow' in uses:
costs.append('Dataflow')
if steps == '':
report_error(path, 19, "Objective section missing steps list")
return desc, uses, steps, costs
def add_index(path, title, desc, uses, steps):
if not args.desc and not args.uses and not args.steps:
return
title = title.split(':')[-1].strip()
title = title[0].upper() + title[1:]
print(f"\n[{title}]({path})\n")
if args.desc:
print(desc)
if args.uses:
print(uses)
if args.steps:
print(steps)
if args.notebook_dir:
if not os.path.isdir(args.notebook_dir):
print("Error: not a directory:", args.notebook_dir)
exit(1)
parse_dir(args.notebook_dir)
elif args.notebook:
if not os.path.isfile(args.notebook):
print("Error: not a notebook:", args.notebook)
exit(1)
parse_notebook(args.notebook)
else:
print("Error: must specify a directory or notebook")
exit(1)
@@ -0,0 +1,87 @@
## General style examples
### Notebook heading
- Include the collapsed license at the top (this uses Colab's "Form" mode to hide the cells).
- Only include a single H1 title.
- Include the button-bar immediately under the H1.
- Check that the Colab and GitHub links at the top are correct.
### Notebook sections
- Use H2 (##) and H3 (###) titles for notebook section headings.
- Use [sentence case to capitalize titles and headings](https://developers.google.com/style/capitalization#capitalization-in-titles-and-headings). ("Train the model" instead of "Train the Model")
- Include a brief text explanation before any code cells.
- Use short titles/headings: "Download the data", "Build the model", "Train the model".
### Writing style
- Use [present tense](https://developers.google.com/style/tense). ("You receive a response" instead of "You will receive a response")
- Use [active voice](https://developers.google.com/style/voice). ("The service processes the request" instead of "The request is processed by the service")
- Use [second person](https://developers.google.com/style/person) and an imperative style.
- Correct examples: "Update the field", "You must update the field"
- Incorrect examples: "Let's update the field", "We'll update the field", "The user should update the field"
- **Googlers**: Please follow our [branding guidelines](http://goto/cloud-branding).
### Code
- Put all your installs and imports in a setup section.
- Save the notebook with the Table of Contents open.
- Write Python 3 compatible code.
- Follow the [Google Python Style guide](https://github.com/google/styleguide/blob/gh-pages/pyguide.md) and write readable code.
- Keep cells small (max ~20 lines).
## TensorFlow code style
Use the highest level API that gets the job done (unless the goal is to demonstrate the low level API). For example, when using Tensorflow:
- Use TF.keras.Sequential > keras functional api > keras model subclassing > ...
- Use model.fit > model.train_on_batch > manual GradientTapes.
- Use eager-style code.
- Use tensorflow_datasets and tf.data where possible.
### Notebook code style examples
- Notebooks are for people. Write code optimized for clarity.
- Demonstrate small parts before combining them into something more complex. Like below:
```
# Build the model
import tensorflow as tf
model = tf.keras.Sequential(
[
tf.keras.layers.Dense(10, activation="relu", input_shape=(None, 5)),
tf.keras.layers.Dense(3),
]
)
```
```
# Run the model on a single batch of data, and inspect the output.
import numpy as np
result = model(tf.constant(np.random.randn(10, 5), dtype=tf.float32)).numpy()
print("min:", result.min())
print("max:", result.max())
print("mean:", result.mean())
print("shape:", result.shape)
```
```
# Compile the model for training
model.compile(
optimizer=tf.keras.optimizers.Adam(), loss=tf.keras.losses.categorical_crossentropy
)
```
- Keep examples quick. Use small datasets, or small slices of datasets. You don't need to train to convergence, train until it's obvious it's making progress.
- For a large example, don't try to fit all the code in the notebook. Add python files to tensorflow examples, and in the notebook run:
! pip3 install git+https://github.com/tensorflow/examples
+11 -7
View File
@@ -2,26 +2,30 @@
# the repo. Unless a later match takes precedence,
# @global-owner1 and @global-owner2 will be requested for
# review when someone opens a pull request.
* @vertex-ai-samples-contributors @GoogleCloudPlatform/cloudml-samples-owners
* @GoogleCloudPlatform/vertex-ai-samples-contributors @GoogleCloudPlatform/caiis-tw
# matching_engine folder
/matching_engine @shenzhimo2
/matching_engine @shenzhimo2 @ivanmkc
/tabnet/tabnet_vertex_tutorial.ipynb @longtle
/migration @aferlitsch
/explainabl_ai @aferlitsch
/pipelines @aferlitsch
/experiments @inardini
/migration @andrewferlitsch
/explainabl_ai
/pipelines @andrewferlitsch
/ml_metadata @andrewferlitsch
/model_monitoring @andrewferlitsch
/tensorboard @zbl94
/model_monitoring/model_monitoring.ipynb @mco-gh
/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
/feature_store/gapic-feature-store.ipynb @protorganizer @diemtvu
/feature_store/gapic-feature-store.ipynb @diemtvu
/managed_notebooks @GoogleCloudPlatform/notebooks-team
/pipelines/google_cloud_pipeline_components_bqml_text.ipynb @inardini
/pipelines/google_cloud_pipelines_dataproc_tabular @inardini
/automl/automl_forecasting_bqml_arima_plus_comparison.ipynb @TheMichaelHu
/automl/automl_tabular_on_vertex_pipelines.ipynb @helinwang
/custom/custom_training_tensorboard_profiler.ipynb @gericdong
/workbench/spark/spark_sample_notebook.ipynb @bradmiro
@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": null,
"execution_count": 54,
"metadata": {
"id": "ur8xi4C7S06n"
},
@@ -17,12 +17,21 @@
"# 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",
"# distributed under the Lice`nse 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": "0d2298941703"
},
"source": [
"# Vertex AI: Create, train, and deploy an AutoML text classification model"
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -43,8 +52,8 @@
" </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/official/automl/automl-text-classification.ipynb\">\n",
" <img src=\"https://lh3.googleusercontent.com/UiNooY4LUgW_oTvpsNhPpQzsstV5W8F7rYgxgGBD85cWJoLmrOzhVs_ksK_vgx40SHs7jCqkTkCk=e14-rj-sc0xffffff-h130-w32\" alt=\"Vertex AI logo\">\n",
" <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://raw.githubusercontent.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/automl/automl-text-classification.ipynb\">\n",
" <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",
@@ -54,19 +63,20 @@
{
"cell_type": "markdown",
"metadata": {
"id": "0259a7ce8120"
"id": "1adb10a59bc3"
},
"source": [
"# Vertex AI: Create, train, and deploy an AutoML text classification model\n",
"\n",
"## Overview\n",
"\n",
"This notebook walks you through the major phases of building and using an AutoML text classification model on [Vertex AI](https://cloud.google.com/vertex-ai/docs/). \n",
"\n",
"### Dataset\n",
"\n",
"In this notebook, you use the \"Happy Moments\" sample dataset to train a model. The resulting model classifies happy moments into categores that reflect the causes of happiness. \n",
"\n",
"This notebook walks you through the major phases of building and using an AutoML text classification model on [Vertex AI](https://cloud.google.com/vertex-ai/docs/). \n"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "9b9824ae2c91"
},
"source": [
"### Objective\n",
"\n",
"In this tutorial, you learn how to use `AutoML` to train a text classification model.\n",
@@ -84,8 +94,26 @@
"* Create an `Endpoint` resource.\n",
"* Deploy the `Model` resource to the `Endpoint` resource.\n",
"* Make an online prediction\n",
"* Make a batch prediction\n",
"* Make a batch prediction"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "f67c62885df4"
},
"source": [
"### Dataset\n",
"\n",
"In this notebook, you use the \"Happy Moments\" sample dataset to train a model. The resulting model classifies happy moments into categores that reflect the causes of happiness. "
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "0259a7ce8120"
},
"source": [
"### Costs\n",
"\n",
"This tutorial uses billable components of Google Cloud:\n",
@@ -173,7 +201,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 55,
"metadata": {
"id": "b75757581291"
},
@@ -188,6 +216,7 @@
")\n",
"\n",
"# Vertex AI Notebook requires dependencies to be installed with '--user'\n",
"\n",
"USER_FLAG = \"\"\n",
"if IS_WORKBENCH_NOTEBOOK:\n",
" USER_FLAG = \"--user\"\n",
@@ -208,7 +237,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 56,
"metadata": {
"id": "0c0b2427998a"
},
@@ -254,7 +283,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {
"id": "be175254a715"
},
@@ -311,7 +340,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {
"id": "ae43d96c4b1b"
},
@@ -336,7 +365,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {
"id": "953fa6e5ddda"
},
@@ -424,7 +453,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"metadata": {
"id": "d2de92accb67"
},
@@ -436,7 +465,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {
"id": "5ba09496accc"
},
@@ -478,7 +507,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 9,
"metadata": {
"id": "96ad3d416327"
},
@@ -498,7 +527,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 10,
"metadata": {
"id": "152013538e59"
},
@@ -521,7 +550,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 11,
"metadata": {
"id": "740cd5c67c79"
},
@@ -551,24 +580,15 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "6caf82e5e84e"
"id": "d35b8b6b94ae"
},
"outputs": [],
"source": [
"# Use a timestamp to ensure unique resources\n",
"src_uris = \"gs://cloud-ml-data/NL-classification/happiness.csv\"\n",
"display_name = f\"e2e-text-dataset-{TIMESTAMP}\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "d35b8b6b94ae"
},
"outputs": [],
"source": [
"ds = aiplatform.TextDataset.create(\n",
"display_name = f\"e2e-text-dataset-{TIMESTAMP}\"\n",
"\n",
"text_dataset = aiplatform.TextDataset.create(\n",
" display_name=display_name,\n",
" gcs_source=src_uris,\n",
" import_schema_uri=aiplatform.schema.dataset.ioformat.text.single_label_classification,\n",
@@ -582,53 +602,7 @@
"id": "5b3cc427353a"
},
"source": [
"## Train your text classification model\n",
"\n",
"Once your dataset has finished importing data, you are ready to train your model. To do this, you first need the full resource name of your dataset, where the full name has the format `projects/[YOUR_PROJECT]/locations/[YOUR_REGIO)N]/datasets/[YOUR_DATASET_ID]`. If you don't have the resource name handy, you can list all of the datasets in your project using `TextDataset.list()`. \n",
"\n",
"As shown in the following code block, you can pass in the display name of your dataset in the call to `list()` to filter the results.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "52cf56f1c8a9"
},
"outputs": [],
"source": [
"datasets = aiplatform.TextDataset.list(filter=f'display_name=\"{display_name}\"')\n",
"print(datasets)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "58df3e02df82"
},
"source": [
"When you create a new model, you need a reference to the `TextDataset` object that corresponds to your dataset. You can use the `ds` variable you created previously when you created the dataset or you can also list all of your datasets to get a reference to your dataset. Each item returned from `TextDataset.list()` is an instance of `TextDataset`.\n",
"\n",
"The following code block shows how to instantiate a `TextDataset` object using a dataset ID. Note that this code is intentionally verbose for demonstration purposes."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "aa667203da03"
},
"outputs": [],
"source": [
"# Get the dataset ID if it's not available\n",
"dataset_id = \"[your-dataset-id]\"\n",
"\n",
"if dataset_id == \"[your-dataset-id]\":\n",
" # Use the reference to the new dataset captured when we created it\n",
" dataset_id = ds.resource_name.split(\"/\")[-1]\n",
" print(f\"Dataset ID: {dataset_id}\")\n",
"\n",
"text_dataset = aiplatform.TextDataset(dataset_id)"
"## Train your text classification model\n"
]
},
{
@@ -653,7 +627,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 16,
"metadata": {
"id": "0aa0f01805ea"
},
@@ -682,8 +656,8 @@
"model = job.run(\n",
" dataset=text_dataset,\n",
" model_display_name=model_display_name,\n",
" training_fraction_split=0.7,\n",
" validation_fraction_split=0.2,\n",
" training_fraction_split=0.1,\n",
" validation_fraction_split=0.1,\n",
" test_fraction_split=0.1,\n",
" sync=True,\n",
")"
@@ -740,39 +714,11 @@
"deployed_model_display_name = f\"e2e-deployed-text-classification-model-{TIMESTAMP}\"\n",
"\n",
"endpoint = model.deploy(\n",
" deployed_model_display_name=deployed_model_display_name, sync=True\n",
" deployed_model_display_name=deployed_model_display_name, \n",
" sync=True\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "531da446035b"
},
"source": [
"In case you didn't record the name of the new endpoint, you can get a list of all your endpoints as you did before with datasets and models. For each endpoint, you can list the models deployed to that endpoint. To get a reference to the model that you just deployed, you can check the `display_name` of each model deployed to the endpoint against the model you're looking for."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "f61fb44181b4"
},
"outputs": [],
"source": [
"endpoints = aiplatform.Endpoint.list()\n",
"\n",
"endpoint_with_deployed_model = []\n",
"\n",
"for endpoint_ in endpoints:\n",
" for model in endpoint_.list_models():\n",
" if model.display_name.find(deployed_model_display_name) == 0:\n",
" endpoint_with_deployed_model.append(endpoint_)\n",
"\n",
"print(endpoint_with_deployed_model)"
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -781,7 +727,7 @@
"source": [
"## Get online predictions from your model\n",
"\n",
"Now that you have your endpoint's resource name, you can get online predictions from the text classification model. To get the online prediction, you send a prediction request to your endpoint."
"Now that you have your endpoint, you can get online predictions from the text classification model. To get the online prediction, you send a prediction request to your endpoint."
]
},
{
@@ -792,13 +738,6 @@
},
"outputs": [],
"source": [
"endpoint_name = \"[your-endpoint-name]\"\n",
"if endpoint_name == \"[your-endpoint-name]\":\n",
" endpoint_name = endpoint.resource_name\n",
"\n",
"print(f\"Endpoint name: {endpoint_name}\")\n",
"\n",
"endpoint = aiplatform.Endpoint(endpoint_name)\n",
"content = \"I got a high score on my math final!\"\n",
"\n",
"response = endpoint.predict(instances=[{\"content\": content}])\n",
@@ -835,7 +774,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 23,
"metadata": {
"id": "e4b838cbcd99"
},
@@ -858,7 +797,7 @@
"\n",
"+ All of your prediction instances as individual files on Google Cloud Storage, as TXT files for your instances\n",
"+ A JSONL file that lists the URIs of all your prediction instances\n",
"+ A Google Cloud Storage bucket to hold the output from batch prediction\n",
"+ A Cloud Storage bucket to hold the output from batch prediction\n",
"\n",
"For this tutorial, the following cells create a new Storage bucket, upload individual prediction instances as text files to the bucket, and then create the JSONL file with the URIs of your prediction instances."
]
@@ -872,16 +811,15 @@
"outputs": [],
"source": [
"# Instantiate the Storage client and create the new bucket\n",
"storage = storage.Client()\n",
"bucket = storage.bucket(BUCKET_URI)\n",
"\n",
"# from google.cloud import storage\n",
"storage_client = storage.Client()\n",
"bucket = storage_client.bucket(BUCKET_NAME)\n",
"# Iterate over the prediction instances, creating a new TXT file\n",
"# for each.\n",
"input_file_data = []\n",
"for count, instance in enumerate(instances):\n",
" instance_name = f\"input_{count}.txt\"\n",
" instance_file_uri = f\"{BUCKET_URI}/{instance_name}\"\n",
"\n",
" # Add the data to store in the JSONL input file.\n",
" tmp_data = {\"content\": instance_file_uri, \"mimeType\": \"text/plain\"}\n",
" input_file_data.append(tmp_data)\n",
@@ -901,7 +839,7 @@
"id": "31c262320610"
},
"source": [
"Now that you have the bucket with the prediction instances ready, you can send a batch prediction request to Vertex AI. When you send a request to the service, you must provide the URI of your JSONL file and your output bucket, including the `gs://` protocols.\n",
"Now that you have the bucket with the prediction instances ready, you can send a batch prediction rhttps://storage.googleapis.com/upload/storage/v1/b/gs://vertex-ai-devaip-20220728004429/o?uploadType=multipartequest to Vertex AI. When you send a request to the service, you must provide the URI of your JSONL file and your output bucket, including the `gs://` protocols.\n",
"\n",
"With the Python SDK, you can create a batch prediction job by calling `Model.batch_predict()`."
]
@@ -915,15 +853,13 @@
"outputs": [],
"source": [
"job_display_name = \"e2e-text-classification-batch-prediction-job\"\n",
"model = aiplatform.Model(model_name=model_name)\n",
"\n",
"# model = aiplatform.Model(model_name=model.name)\n",
"batch_prediction_job = model.batch_predict(\n",
" job_display_name=job_display_name,\n",
" gcs_source=f\"{BUCKET_URI}/{input_file_name}\",\n",
" gcs_destination_prefix=f\"{BUCKET_URI}/output\",\n",
" sync=True,\n",
")\n",
"\n",
"batch_prediction_job_name = batch_prediction_job.resource_name"
]
},
@@ -938,6 +874,15 @@
"The following code snippet demonstrates how to create an instance of the `BatchPredictionJob` class to review its status. Note that you need the full resource name printed out from the Python SDK for this snippet.\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "cd014de40e2f"
},
"source": [
"## BatchPredictionJob"
]
},
{
"cell_type": "code",
"execution_count": null,
@@ -999,6 +944,8 @@
},
"outputs": [],
"source": [
"import os\n",
"\n",
"RESULTS_DIRECTORY = \"prediction_results\"\n",
"RESULTS_DIRECTORY_FULL = f\"{RESULTS_DIRECTORY}/output\"\n",
"\n",
@@ -1020,6 +967,15 @@
"print(f\"Local results folder: {latest_directory}\")"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "e375109b7e40"
},
"source": [
"## JsonLines"
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -1094,9 +1050,9 @@
" ! gsutil rm -r $BUCKET_URI\n",
"\n",
"batch_job.delete()\n",
"\n",
"endpoint.undeploy_all()\n",
"# `force` parameter ensures that models are undeployed before deletion\n",
"endpoint.delete(force=True)\n",
"endpoint.delete()\n",
"\n",
"model.delete()\n",
"\n",
@@ -238,7 +238,7 @@
"\n",
"|Service account email|Description|Roles|\n",
"|---|---|---|\n",
"|PROJECT_NUMBER-compute@developer.gserviceaccount.com|Compute Engine default service account|Dataflow Admin, Dataflow Worker, Storage Admin, BigQuery Admin, Vertex AI User|\n",
"|PROJECT_NUMBER-compute@developer.gserviceaccount.com|Compute Engine default service account|Dataflow Developer, Dataflow Worker, Storage Admin, BigQuery Data Editor, Vertex AI User, Service Account User|\n",
"|service-PROJECT_NUMBER@gcp-sa-aiplatform.iam.gserviceaccount.com|AI Platform Service Agent|Vertex AI Service Agent|\n",
"\n",
"\n",
@@ -756,7 +756,7 @@
"# Fully qualified subnetwork name is in the form of\n",
"# https://www.googleapis.com/compute/v1/projects/HOST_PROJECT_ID/regions/REGION_NAME/subnetworks/SUBNETWORK_NAME\n",
"# reference: https://cloud.google.com/dataflow/docs/guides/specifying-networks#example_network_and_subnetwork_specifications\n",
"dataflow_subnetwork = \"\" # @param {type:\"string\"}\n",
"dataflow_subnetwork = None # @param {type:\"string\"}\n",
"# Specifies whether Dataflow workers use public IP addresses.\n",
"dataflow_use_public_ips = True # @param {type:\"boolean\"}"
]
@@ -853,6 +853,8 @@
" cv_trainer_worker_pool_specs_override=worker_pool_specs_override,\n",
" run_evaluation=run_evaluation,\n",
" run_distillation=run_distillation,\n",
" dataflow_subnetwork=dataflow_subnetwork,\n",
" dataflow_use_public_ips=dataflow_use_public_ips,\n",
")\n",
"\n",
"job_id = \"automl-tabular-{}\".format(uuid.uuid4())\n",
@@ -954,6 +956,8 @@
" test_fraction=test_fraction,\n",
" stage_1_tuning_result_artifact_uri=stage_1_tuning_result_artifact_uri,\n",
" run_evaluation=run_evaluation,\n",
" dataflow_subnetwork=dataflow_subnetwork,\n",
" dataflow_use_public_ips=dataflow_use_public_ips,\n",
")\n",
"\n",
"job_id = \"automl-tabular-skip-architecture-search-{}\".format(uuid.uuid4())\n",

Some files were not shown because too many files have changed in this diff Show More