Compare commits

..
Author SHA1 Message Date
ivanmkc d7591ed256 Improved git diff logic 2022-06-22 20:53:03 -04:00
Andrew FerlitschandGitHub 41fc83ad03 upgrade: current notebook standards (#655)
* update: current standards

* update: current standards

* Update sdk_custom_image_classification_batch_explain.ipynb

* fix: bucket nit
2022-06-22 16:59:39 -07:00
Andrew FerlitschandGitHub 9928276dc3 upgrade: current notebook standard (#653)
* upgrade: current notebook standard

* upgrade: current notebook standard

* Update sdk_automl_tabular_binary_classification_batch_explain.ipynb

* fix: bucket nit
2022-06-22 16:58:42 -07:00
Andrew FerlitschandGitHub 6607f93f5e upgrade: updated curated notebook to current standards (#648)
* upgrade: current standards

* upgrade: current standards

* fix: missed nits

* fix: missed nits

* Update automl-text-classification.ipynb

* Update automl-text-classification.ipynb

* rm extra comma
2022-06-22 16:56:38 -07:00
Andrew FerlitschandGitHub dcc0cfe06e upgrade: current notebook standards (#686)
* upgrade: notebook standard

* upgrade: notebook standard
2022-06-22 16:50:13 -07:00
Andrew FerlitschandGitHub 00d5c5c4bf Update README.md 2022-06-22 15:34:01 -07:00
Andrew FerlitschandGitHub f8152dde19 Update README.md 2022-06-22 15:24:14 -07:00
Andrew FerlitschandGitHub 0586e04c21 upgrade: current notebook standards (#656)
* update: current standards

* update: current standards

* fix: bucket nit
2022-06-22 15:06:01 -07:00
Andrew FerlitschandGitHub 3de18a7fab upgrade: current notebook standards (#674)
* upgrade: current notebook standard

* upgrade: current notebook standard

* fix: bucket

* fix: bucket
2022-06-22 15:03:54 -07:00
Andrew FerlitschandGitHub dc0bf24cc5 Update README.md 2022-06-22 14:58:28 -07:00
Andrew FerlitschandGitHub 8ce4c3070c Update README.md 2022-06-22 14:53:54 -07:00
Andrew FerlitschandGitHub 13c3acb976 Update README.md 2022-06-22 14:50:45 -07:00
Andrew FerlitschandGitHub c1150ff584 Update README.md 2022-06-22 14:39:06 -07:00
Andrew FerlitschandGitHub 4f11d70f7e Update README.md 2022-06-22 14:34:02 -07:00
Andrew FerlitschandGitHub 2bf9a2b317 Update README.md 2022-06-22 14:24:53 -07:00
Andrew FerlitschandGitHub b1e0ad0c4f Update README.md 2022-06-22 14:15:22 -07:00
Andrew FerlitschandGitHub 5624f92f02 Update README.md 2022-06-22 14:12:18 -07:00
Andrew FerlitschandGitHub 1335032954 Update README.md 2022-06-22 14:05:24 -07:00
Andrew FerlitschandGitHub 0b13c66e07 Update README.md 2022-06-22 14:01:55 -07:00
Andrew FerlitschandGitHub ef25b54926 update: add index (#684) 2022-06-22 13:58:06 -07:00
Andrew FerlitschandGitHub 064dbfeefa fix: bucket nit 2022-06-22 12:34:50 -07:00
Andrew FerlitschandGitHub 044c69e7a5 upgrade: current notebook standards (#654)
* update: current standards

* update: current standards
2022-06-22 12:33:26 -07:00
Andrew FerlitschandGitHub 32a46e7471 upgrade: current standards (#649)
* upgrade: current standards

* upgrade: current standards

* fix: missed nits

* fix: missed nits
2022-06-22 12:30:16 -07:00
Andrew FerlitschandGitHub b52d59822d upgrade: current notebook standards (#657)
* update: current standards

* update: current standards

* update: current standards

* update: current standards

* Update sdk_custom_tabular_regression_batch_explain.ipynb

* fix: indent issue

* fix: indent issue

* fix: bucket

* fix: bucket

* fix: image

* fix: image

* fix: cleanup

* fix: cleanup

* fix: cleanup
2022-06-22 11:47:17 -07:00
Andrew FerlitschandGitHub 529995ecde upgrade: current notebook standard (#671)
* upgrade: current notebook standard

* upgrade: current notebook standard

* Update google_cloud_pipeline_components_automl_tabular.ipynb

* fix: bucket

* fix: bucket
2022-06-22 11:35:38 -07:00
Andrew FerlitschandGitHub 0726328c92 upgrade: current notebook standard (#667)
* upgrade: current notebook standard

* upgrade: current notebook standard

* Update model_monitoring.ipynb

* Update model_monitoring.ipynb
2022-06-22 11:21:32 -07:00
Andrew FerlitschandGitHub 090e83c286 fix: more broken links 2022-06-22 11:19:17 -07:00
Andrew FerlitschandGitHub c3802626b9 fix: links issue 672 2022-06-22 11:18:08 -07:00
Andrew FerlitschandGitHub 9570c2477f upgrade: current notebook standards (#682)
* upgrade: current notebook standards

* upgrade: current notebook standards
2022-06-22 11:09:27 -07:00
Andrew FerlitschandGitHub 2b1a898b2a upgrade: current notebook standards (#680)
* upgrade: current notebook standards

* upgrade: current notebook standards
2022-06-22 11:09:04 -07:00
Andrew FerlitschandGitHub f2a42aa66e upgrade: current notebook standard (#679)
* upgrade: notebook standard

* upgrade: notebook standard

* fix: bucket

* fix: bucket
2022-06-22 11:08:37 -07:00
Andrew FerlitschandGitHub 30a03f1fd1 upgrade: current notebook standards (#678)
* upgrade: notebook standard

* upgrade: notebook standard

* Update google_cloud_pipeline_components_model_train_upload_deploy.ipynb

* fix: bucket nits

* fix: bucket
2022-06-22 11:08:08 -07:00
Andrew FerlitschandGitHub ca25448f59 upgrade: current notebook standard (#673)
* upgrade: current notebook standard

* upgrade: current notebook standard

* fix: bucket nit

* fix: bucket nit
2022-06-22 11:07:37 -07:00
Andrew FerlitschandGitHub 8f922710b0 upgrade: current notebook standard (#670)
* upgrade: current notebook standard

* upgrade: current notebook standard

* Update google_cloud_pipeline_components_automl_images.ipynb

* fix: bucket

* fix: bucket
2022-06-22 11:06:31 -07:00
Andrew FerlitschandGitHub 9509c6ab9d upgrade: current notebook standard (#669)
* upgrade: current notebook standard

* upgrade: current notebook standard

* Update lightweight_functions_component_io_kfp.ipynb

* fix: nits

* fix: nits

* fix: nits

* fix: nits
2022-06-22 11:05:47 -07:00
Andrew FerlitschandGitHub ccba176979 upgrade: current notebook standard (#665)
* upgrade: notebook standard

* upgrade: notebook standard

* Update sdk-feature-store.ipynb

* Update sdk-feature-store.ipynb

* Update sdk-feature-store.ipynb

* fix: aip reference

* fix: nits

* fix: nits
2022-06-22 11:05:07 -07:00
Andrew FerlitschandGitHub 1b8f383897 upgrade: current notebook standard (#663)
* update: current standards

* update: current standards

* fix: bucket

* fix: bucket
2022-06-22 09:36:49 -07:00
Andrew FerlitschandGitHub e5cd9e86d2 upgrade: notebook to latest standard (#651)
* fix: missed nits

* fix: missed nits
2022-06-22 08:56:10 -07:00
Andrew FerlitschandGitHub a7e86a4f26 upgrade: current notebook standard (#668)
* upgrade: current notebook standard

* upgrade: current notebook standard

* Update sdk-metric-parameter-tracking-for-locally-trained-models.ipynb
2022-06-21 20:23:18 -07:00
Ivan CheungandGitHub 8f0c73b32c Fixed cleanup scripts (#676) 2022-06-21 20:13:37 -07:00
Andrew FerlitschandGitHub c7d7b48a91 upgrade: notebook to current standards (#650)
* upgrade: current standards

* upgrade: current standards
2022-06-21 18:25:25 -07:00
Karl WeinmeisterandGitHub 583eb90f07 fix: CONTRIBUTING.md did not have nbfmt as final step 2022-06-20 13:56:49 -05:00
c3a9249c0c Workaround tensorboard/GCS issue for Cloud Shell (#386)
* Workaround tensorboard/GCS issue for Cloud Shell

Without `--load_fast=false` there will be `401 Unauthorized` for GCS log loads. 
See https://github.com/tensorflow/tensorboard/issues/4784#issuecomment-868945650

* PR #386: Fix missing import

`import json` was missing.

Co-authored-by: Karl Weinmeister <11586922+kweinmeister@users.noreply.github.com>
Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-06-19 10:07:09 -05:00
Karl WeinmeisterandGitHub 81b70e779c ci: Remove protobuf from requirements.txt 2022-06-19 09:38:45 -05:00
Karl WeinmeisterandGitHub 085713a818 ci: Add protobuf to requirements.txt 2022-06-18 17:20:45 -05:00
Karl WeinmeisterandGitHub 5af7c851dc Fix: update typo in GAPIC Feature Store notebook 2022-06-18 17:10:49 -05:00
691312d467 Add import feature analysis config sample code into gapic-feature-sto… (#548)
* Add import feature analysis config sample code into gapic-feature-store.ipynb

* Fixing linter for gapic-feature-store.ipynb

Co-authored-by: Ivan Cheung <ivans.mailbox@gmail.com>
Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
Co-authored-by: Karl Weinmeister <11586922+kweinmeister@users.noreply.github.com>
2022-06-18 17:09:37 -05:00
650c256c13 Fixes link to colab (#627)
Co-authored-by: Karl Weinmeister <11586922+kweinmeister@users.noreply.github.com>
2022-06-18 16:26:36 -05:00
9b00c4380b chore(deps): update actions/setup-python action to v4 (#622)
Co-authored-by: Karl Weinmeister <11586922+kweinmeister@users.noreply.github.com>
2022-06-18 16:21:49 -05:00
Karl WeinmeisterandGitHub 4851457e93 ci: Add Python version to support setup-python v4 2022-06-18 16:19:09 -05:00
dependabot[bot]GitHubdependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>Karl Weinmeister
1c54878fab build(deps): bump tensorflow (#595)
Bumps [tensorflow](https://github.com/tensorflow/tensorflow) from 2.5.3 to 2.7.2.
- [Release notes](https://github.com/tensorflow/tensorflow/releases)
- [Changelog](https://github.com/tensorflow/tensorflow/blob/master/RELEASE.md)
- [Commits](https://github.com/tensorflow/tensorflow/compare/v2.5.3...v2.7.2)

---
updated-dependencies:
- dependency-name: tensorflow
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Karl Weinmeister <11586922+kweinmeister@users.noreply.github.com>
2022-06-18 16:08:07 -05:00
dependabot[bot]GitHubdependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
c139b84454 build(deps): bump tensorflow (#593)
Bumps [tensorflow](https://github.com/tensorflow/tensorflow) from 2.5.3 to 2.7.2.
- [Release notes](https://github.com/tensorflow/tensorflow/releases)
- [Changelog](https://github.com/tensorflow/tensorflow/blob/master/RELEASE.md)
- [Commits](https://github.com/tensorflow/tensorflow/compare/v2.5.3...v2.7.2)

---
updated-dependencies:
- dependency-name: tensorflow
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-06-18 16:02:53 -05:00
15c38b4ca6 chore(deps): update dependency pyupgrade to v2.34.0 (#457)
Co-authored-by: Karl Weinmeister <11586922+kweinmeister@users.noreply.github.com>
2022-06-18 15:59:54 -05:00
Ivan CheungandGitHub 271c949a71 Update README.md (#642) 2022-06-17 14:59:05 -07:00
Andrew FerlitschandGitHub 09b5401434 update: fine-tuning notebook (#641)
* feat: add example of import from dataframe

* feat: add example of import from dataframe

* update: change in required perms

* update: change in required perms

* review: updates from review

* review: updates from review

* updates: fine tuning
2022-06-17 13:41:10 -07:00
dad76547f0 inardini - mobile gaming feature store blog review (#635)
* review content and image

* linter test passed

* andy review fixes

* linter test passed

Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-06-17 10:39:18 -07:00
Andrew FerlitschandGitHub c14a110c81 Update get_started_with_custom_training_pipeline_components.ipynb 2022-06-16 14:24:08 -07:00
Andrew FerlitschandGitHub d1e16546cc Update get_started_with_bqml_pipeline_components.ipynb 2022-06-16 14:23:29 -07:00
Andrew FerlitschandGitHub f91bc3d0c9 Update get_started_with_bq_tfdv_pipeline_components.ipynb 2022-06-16 14:22:56 -07:00
Andrew FerlitschandGitHub 5168808b6c fix: colab link 2022-06-16 14:22:23 -07:00
Andrew FerlitschandGitHub 501cca7b5e fix: colab link 2022-06-16 14:21:31 -07:00
Andrew FerlitschandGitHub f19d40d858 Update mlops_experimentation.ipynb 2022-06-16 13:49:17 -07:00
Andrew FerlitschandGitHub 5a721ce01d Update get_started_with_visionapi_and_automl.ipynb 2022-06-16 13:48:31 -07:00
Andrew FerlitschandGitHub 66421fb4d8 fix: colab link 2022-06-16 13:47:47 -07:00
Andrew FerlitschandGitHub 3658ee8c88 Update get_started_with_tabnet.ipynb 2022-06-16 13:46:10 -07:00
Andrew FerlitschandGitHub afaab4bb02 Update get_started_with_cmek_training.ipynb 2022-06-16 13:45:08 -07:00
Andrew FerlitschandGitHub c1e004bdff fix: colab link 2022-06-16 13:44:22 -07:00
Andrew FerlitschandGitHub 874e5a3ef5 Update get_started_vertex_training_xgboost.ipynb 2022-06-16 13:43:11 -07:00
Andrew FerlitschandGitHub 51529f370c fix: broken table 2022-06-16 13:41:01 -07:00
Andrew FerlitschandGitHub 5ddf98866c Update get_started_vertex_training_sklearn.ipynb 2022-06-16 13:40:22 -07:00
Andrew FerlitschandGitHub fbb6830876 fix: colab link 2022-06-16 13:30:01 -07:00
Andrew FerlitschandGitHub ee1bb281da fix: colab link 2022-06-16 13:28:16 -07:00
Andrew FerlitschandGitHub da2f7e88fe fix: update location of public dataset bucket 2022-06-16 12:43:15 -07:00
Andrew FerlitschandGitHub 3fb28e353f fix: remove internal link 2022-06-16 12:40:02 -07:00
Andrew FerlitschandGitHub c8e7f44f0a fix: updates from review (#640)
* feat: add example of import from dataframe

* feat: add example of import from dataframe

* update: change in required perms

* update: change in required perms

* review: updates from review

* review: updates from review
2022-06-16 12:36:28 -07:00
3d9049aeeb remove old hard-coded instances for prediction (#633)
Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-06-16 11:50:01 -07:00
Andrew FerlitschandGitHub 7b8726af24 fix: perms for using MR in BQML (#634)
* feat: add example of import from dataframe

* feat: add example of import from dataframe

* update: change in required perms

* update: change in required perms
2022-06-15 14:55:17 -07:00
Andrew FerlitschandGitHub 0443b05360 feat: add create tabular dataset from dataframe example (#632)
* feat: add example of import from dataframe

* feat: add example of import from dataframe
2022-06-14 11:44:30 -07:00
Ivan CheungandGitHub e422dbdef2 Added official version of tabular regression batch bq (#331)
* Added official version of tabular regression batch bq

* Ran linter

* Fixed cleanup

* Additional cleanup

* Added working version

* Refactored and made work

* Ran linter and cleaned up

* Renamed aip to aiplatform

* Replaced online with batch

* Renamed notebook

* Ran linter and cleaned up

* Fixed bug

* Fixed SQL by adding backticks

* Install google-cloud-bigquery[all]

* Refactored datasets

* Ran linter

* Removed GCS cells

* Fixed import file

* Fixed SQL issues and added cleanup of training dataset

* Fixed hardcorded table

* Fixed brand names

* Fixed header

* Fixed results table

* Addressed tech writing review comments

* Ran linter
2022-06-14 14:14:06 -04:00
Andrew FerlitschandGitHub ec5fc0b1c8 Update get_started_vertex_training_r.ipynb 2022-06-14 10:05:36 -07:00
Andrew FerlitschandGitHub c52e3f20ba Update get_started_vertex_training_pytorch.ipynb 2022-06-14 10:04:45 -07:00
Andrew FerlitschandGitHub e367dceceb Update get_started_vertex_training_lightgbm.ipynb 2022-06-14 10:04:11 -07:00
Andrew FerlitschandGitHub 19b8666808 Update get_started_vertex_training.ipynb 2022-06-14 10:03:24 -07:00
Andrew FerlitschandGitHub a2df0e9fca Update get_started_vertex_tensorboard.ipynb 2022-06-14 10:01:52 -07:00
Andrew FerlitschandGitHub 73b094550e Update get_started_vertex_feature_store.ipynb 2022-06-14 09:59:24 -07:00
Andrew FerlitschandGitHub d05ae109e1 Update get_started_vertex_experiments.ipynb 2022-06-14 09:57:55 -07:00
Andrew FerlitschandGitHub fdb25791d5 Update get_started_vertex_distributed_training.ipynb 2022-06-14 09:57:19 -07:00
Andrew FerlitschandGitHub 5a88492498 Update get_started_bqml_training.ipynb 2022-06-14 09:56:34 -07:00
Andrew FerlitschandGitHub f19a12b829 Update get_started_automl_training.ipynb 2022-06-14 09:55:53 -07:00
Andrew FerlitschandGitHub 3ed0ea73f4 Update get_started_bq_datasets.ipynb 2022-06-14 09:08:47 -07:00
Andrew FerlitschandGitHub b98fd24a72 Update get_started_bq_datasets.ipynb 2022-06-13 21:29:41 -07:00
Andrew FerlitschandGitHub eb4e9a0f91 Update get_started_vertex_datasets.ipynb 2022-06-13 21:27:16 -07:00
Andrew FerlitschandGitHub ec7c136b0a Update get_started_vertex_datasets.ipynb 2022-06-13 21:26:24 -07:00
Andrew FerlitschandGitHub ee7e43cc1a Update mlops_data_management.ipynb 2022-06-13 20:24:57 -07:00
Andrew FerlitschandGitHub ea9f5f3c5c Update get_started_with_data_labeling.ipynb 2022-06-13 20:24:22 -07:00
Andrew FerlitschandGitHub bd44798412 Update get_started_vertex_datasets.ipynb 2022-06-13 20:23:37 -07:00
Andrew FerlitschandGitHub 2af0cc0f80 fix: test for local execution 2022-06-13 20:22:57 -07:00
Andrew FerlitschandGitHub 5c0fa14d2d Update get_started_bq_datasets.ipynb 2022-06-13 20:21:44 -07:00
Andrew FerlitschandGitHub 7cc50d3203 Update README.md 2022-06-13 13:58:20 -07:00
Andrew FerlitschandGitHub 9c7da13177 Update gapic-vizier-multi-objective-optimization.ipynb 2022-06-13 08:39:33 -07:00
Andrew FerlitschandGitHub 45e0645f0b Update gapic-vizier-multi-objective-optimization.ipynb 2022-06-13 08:38:55 -07:00
Andrew FerlitschandGitHub cb884cc74a Update gapic-vizier-multi-objective-optimization.ipynb 2022-06-13 08:38:22 -07:00
Ivan CheungandGitHub d3a6475580 Fixed mistake in batch prediction request section (#617)
* Fixed mistake in batch prediction request section

* Fixed linter requirements
2022-06-10 17:13:45 -04:00
4e7061b2db added MLPerf benchmark reference and updated Criteo sample to use GRPC for stock containers (#630)
* added MLPerf benchmark reference and updated Criteo sample to use GRPC for stock containers

* addressed feedback for BERT sample and did similar changes to Criteo sample

Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-06-10 12:06:25 -07:00
Ivan CheungandGitHub 0250879f65 Added notebook substitution for common case of 1 notebook (#625) 2022-06-10 14:44:43 -04:00
Andrew FerlitschandGitHub 5cee23ae68 Update get_started_with_autoscaling.ipynb 2022-06-09 15:02:28 -07:00
Andrew FerlitschandGitHub d518558b3d Update README.md 2022-06-09 15:01:55 -07:00
Andrew FerlitschandGitHub 5c085c843f feat: notebook on autoscaling (#629)
* feat: XAI + custom server

* feat: add DIY MLMD for AutoML

* feat: add DIY MLMD for AutoML

* fix: replace BLAH

* fix: replace BLAH

* update: AutoML + MLMD

* update: AutoML + MLMD

* co-hosting

* co-hosting

* feat: new R notebook

* feat: new R notebook

* feat: airflow+vertex

* feat: airflow+vertex

* feat: notebook on autoscaling

* feat: notebook on autoscaling
2022-06-09 14:57:41 -07:00
Michael HuandGitHub 936b434ac4 fix: typo in links in bqml arima notebook (#616)
Notebook used as template had incorrect link format. Apply the same fixes as #514 to the arima notebook.
2022-06-09 17:52:12 -04:00
Michael HuandGitHub 43059c9fd9 fix: pin protobuf version to 3.19.0 (#621) 2022-06-09 12:49:45 -07:00
Andrew FerlitschandGitHub 19f72d426d fix: typos 2022-06-08 11:59:37 -07:00
Andrew FerlitschandGitHub 14ecaf3023 Update README.md 2022-06-08 11:58:18 -07:00
Andrew FerlitschandGitHub 80c93a9b6d feat: airflow with vertex pipelines (#624)
* feat: XAI + custom server

* feat: add DIY MLMD for AutoML

* feat: add DIY MLMD for AutoML

* fix: replace BLAH

* fix: replace BLAH

* update: AutoML + MLMD

* update: AutoML + MLMD

* co-hosting

* co-hosting

* feat: new R notebook

* feat: new R notebook

* feat: airflow+vertex

* feat: airflow+vertex
2022-06-08 11:55:11 -07:00
Andrew FerlitschandGitHub 06a1b4dc57 Update README.md 2022-06-07 09:48:16 -07:00
Andrew FerlitschandGitHub 4e779eedf1 Update README.md 2022-06-07 09:45:10 -07:00
Andrew FerlitschandGitHub afb341f5fd feat: new R notebook (#618)
* feat: XAI + custom server

* feat: add DIY MLMD for AutoML

* feat: add DIY MLMD for AutoML

* fix: replace BLAH

* fix: replace BLAH

* update: AutoML + MLMD

* update: AutoML + MLMD

* co-hosting

* co-hosting

* feat: new R notebook

* feat: new R notebook
2022-06-07 09:39:44 -07:00
e34b0fa115 chore(deps): pin dependency protobuf to v (#606)
Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-06-06 18:13:56 -07:00
dependabot[bot]GitHubdependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
6fa0345f25 build(deps): bump tensorflow (#596)
Bumps [tensorflow](https://github.com/tensorflow/tensorflow) from 2.5.3 to 2.7.2.
- [Release notes](https://github.com/tensorflow/tensorflow/releases)
- [Changelog](https://github.com/tensorflow/tensorflow/blob/master/RELEASE.md)
- [Commits](https://github.com/tensorflow/tensorflow/compare/v2.5.3...v2.7.2)

---
updated-dependencies:
- dependency-name: tensorflow
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-06-06 18:09:52 -07:00
dependabot[bot]GitHubdependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>Andrew Ferlitsch
dd43ae6639 build(deps): bump tensorflow (#594)
Bumps [tensorflow](https://github.com/tensorflow/tensorflow) from 2.5.3 to 2.7.2.
- [Release notes](https://github.com/tensorflow/tensorflow/releases)
- [Changelog](https://github.com/tensorflow/tensorflow/blob/master/RELEASE.md)
- [Commits](https://github.com/tensorflow/tensorflow/compare/v2.5.3...v2.7.2)

---
updated-dependencies:
- dependency-name: tensorflow
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-06-06 18:08:37 -07:00
dependabot[bot]GitHubdependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>Ivan CheungAndrew Ferlitsch
840385e0a7 build(deps): bump tensorflow (#592)
Bumps [tensorflow](https://github.com/tensorflow/tensorflow) from 2.5.3 to 2.7.2.
- [Release notes](https://github.com/tensorflow/tensorflow/releases)
- [Changelog](https://github.com/tensorflow/tensorflow/blob/master/RELEASE.md)
- [Commits](https://github.com/tensorflow/tensorflow/compare/v2.5.3...v2.7.2)

---
updated-dependencies:
- dependency-name: tensorflow
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Ivan Cheung <ivans.mailbox@gmail.com>
Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-06-06 18:07:48 -07:00
Michael HuandGitHub 9daaf51a1f add bqml arima and vertex forecasting comparison notebook (#581)
Adds a notebook that demonstrates how to compare a Vertex Forecasting model against a BQML ARIMA+ model trained using a first-party GCPC pipeline.
2022-06-06 20:48:30 -04:00
Andrew FerlitschandGitHub 9b2511e54e Update README.md 2022-06-06 13:38:55 -07:00
Andrew FerlitschandGitHub b6674e6540 feat: notebook for co-hosting models (#615)
* feat: XAI + custom server

* feat: add DIY MLMD for AutoML

* feat: add DIY MLMD for AutoML

* fix: replace BLAH

* fix: replace BLAH

* update: AutoML + MLMD

* update: AutoML + MLMD

* co-hosting

* co-hosting
2022-06-06 13:35:47 -07:00
Ivan CheungandGitHub a109cb6d44 fix: Added explanations output to forecasting notebook (#613)
* Added explanations output to forecasting notebook

* Simplified and added XAI

* Fix conflicts

* Ran linter

* Fixed batch prediction request explanation
2022-06-06 10:00:07 -07:00
Ivan CheungandGitHub f730d6b9de Added ability to test a single notebook (#608)
* Added ability to test a single notebook

* Added output_url to table

* Removed ML Ops notebooks
2022-06-06 10:30:31 -04:00
0947f2792d Made some minor changes to Sdk big query custom container training (#522)
* minor changes done

* ran linter test

Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-06-05 12:58:45 -07:00
dbf19acde4 Adds the updated telecom-subscriber-churn-prediction notebook to official and removes from community (#506)
* updates and adds the telecom-subscriber-churn-prediction notebook to official and removes from the community

* ran linter test

Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-06-05 12:53:21 -07:00
1aaa833153 Adds manual-scaling config and explanation to the Automl-forecasting-batch notebook in official folder (#514)
* adds manual-scaling config and explanation to the notebook

* ran linter test after installing linter requirement updates

Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-06-05 12:50:23 -07:00
c73d995680 Made minor changes to sdk_automl_image_object_detection_batch.ipynb file (#513)
* modified notebook

* ran linter test

Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-06-05 12:45:55 -07:00
3fe5028724 Malansari automl vision api notebook update (#612)
* Delete revised version

* Copy notebook from /notebooks/official

* Renamed base notebook

* Added first version by mansari@

* Updated to revised version by andrewferlitsch@

* Added author / reviewer information

Added sample files

* Updated CODEOWNERS

* Fixed links for opening the notebook in Colab/Github/Vertex

Removed installation of and references to pandas

Fixed gcs_annotation_file_name string reference

* Fixed the links for opening notebook (again!)

* Added attribution and references

* Removed references as covered at top

* Updated installation commands to match

* Updated Vertex AI region name to be more clear

* Added db-types dependency for pandas operations
that are now failing

* Minor edits

* Combined package installation and
added a note to ignore the errors

* Minor edit to message

* Added special thanks to andrewferlitsch@

* Updated andrewferlitsch@ GithHub profile link

* Updated sample files URLs to absolute URLs

* Removed empty code block

* Added additional attribution (and the one that did not make it into previous commit!)

* Fixed multi-package import formatting
Switched to pandas instead of db-dtypes

* Fixed isort issue

* Removed unnecessary pandas import

* Formatted the notebook with nbfmt

* Additional notebook formatting

* Updated link to open in Vertex AI Workbench
to point to raw .ipynb file

* Fixed lint issues

* Formatting changes

Added additional APIs to be enabled

* Fixed sample dataset link to point to public version

* Fixed linting issues

Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-06-04 09:14:23 -07:00
Andrew FerlitschandGitHub 44dd24f910 Update README.md 2022-06-02 15:57:04 -07:00
Andrew FerlitschandGitHub c20a9c4e63 update: AutoML + MLMD (#605)
* feat: XAI + custom server

* feat: add DIY MLMD for AutoML

* feat: add DIY MLMD for AutoML

* fix: replace BLAH

* fix: replace BLAH

* update: AutoML + MLMD

* update: AutoML + MLMD
2022-06-02 15:50:05 -07:00
Ivan CheungandGitHub edffdf34b7 Pin protobuf version to avoid broken dependencies. 2022-06-02 17:25:28 -04:00
340c24c5b4 Added custom container explainability notebook (#564)
* Commit for lint

* Commit after name change

* Commit of notebook and CODEOWNERS

Added custom container with xai notebook, and explainable_ai folder in the community folder

* Removed extra copy of file

* Remove extra file

* Updated per review from DPE

* Lint test updates

* linter ran

Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-06-02 12:28:15 -07:00
Andrew FerlitschandGitHub 11f20f3f08 fix: replace BLAH (#600)
* feat: XAI + custom server

* feat: add DIY MLMD for AutoML

* feat: add DIY MLMD for AutoML

* fix: replace BLAH

* fix: replace BLAH
2022-06-01 11:19:02 -07:00
Andrew FerlitschandGitHub 199b330aa5 Update get_started_automl_mlmd.ipynb 2022-05-31 18:37:05 -07:00
Andrew FerlitschandGitHub 5143db1024 feat: Add DIY MLMD with AutoML (#598)
* feat: XAI + custom server

* feat: add DIY MLMD for AutoML

* feat: add DIY MLMD for AutoML
2022-05-31 18:35:23 -07:00
Andrew FerlitschandGitHub 2f0bd3de15 fix: correct reference to service 2022-05-31 13:50:51 -07:00
Andrew FerlitschandGitHub 4d6c541967 feat: XAI + custom server (#597) 2022-05-31 13:31:20 -07:00
Andrew FerlitschandGitHub 5228a5c978 Update README.md 2022-05-31 12:47:16 -07:00
Andrew FerlitschandGitHub c6118bd17d feat: start stage 7 (#591)
* fix: enable apis

* fix: enable apis

* fix: enable apis

* fix: enable apis

* fix: enable apis

* fix: enable apis

* fix: enable apis

* fix: enable apis

* fix: enable apis

* fix: enable apis

* fix: enable apis

* fix: enable apis

* feat: swivel and matching engine

* feat: swivel and matching engine

* feat: LightGBM

* feat: LightGBM

* feat: start stage7

* feat: start stage8
2022-05-31 09:48:49 -07:00
Andrew FerlitschandGitHub d2c9e84af4 Add files via upload 2022-05-26 09:30:17 -07:00
Andrew FerlitschandGitHub fe0a0ff055 Update README.md 2022-05-26 09:30:04 -07:00
Andrew FerlitschandGitHub 40e287245d Delete stage5v2.png 2022-05-26 09:29:50 -07:00
Andrew FerlitschandGitHub c79646a537 Add files via upload 2022-05-26 09:26:24 -07:00
Andrew FerlitschandGitHub e293e1c2fb Update README.md 2022-05-26 09:26:09 -07:00
Andrew FerlitschandGitHub f2ab65bd03 Delete stage4v2.png 2022-05-26 09:25:51 -07:00
Andrew FerlitschandGitHub aa686516d3 Add files via upload 2022-05-25 14:42:01 -07:00
Andrew FerlitschandGitHub 11c80a0251 Update README.md 2022-05-25 14:41:45 -07:00
Andrew FerlitschandGitHub c5e9e5812b Delete stage3v2.png 2022-05-25 14:41:29 -07:00
Andrew FerlitschandGitHub 98b126fa0b Update README.md 2022-05-25 14:34:29 -07:00
Andrew FerlitschandGitHub 55553f9e69 Update README.md 2022-05-25 14:33:56 -07:00
Andrew FerlitschandGitHub 563013c745 Add files via upload 2022-05-25 14:33:10 -07:00
Andrew FerlitschandGitHub fefb9778a7 Update README.md 2022-05-25 14:32:53 -07:00
Andrew FerlitschandGitHub be1831082c Update README.md 2022-05-25 14:11:47 -07:00
Andrew FerlitschandGitHub 9e15ee2e8a Add files via upload 2022-05-25 14:11:21 -07:00
Andrew FerlitschandGitHub ceff7d7271 Delete stage2v2.png 2022-05-25 14:10:51 -07:00
Andrew FerlitschandGitHub df9b5cd6f0 Add files via upload 2022-05-24 16:17:27 -07:00
Andrew FerlitschandGitHub bc57801525 Update README.md 2022-05-24 16:17:06 -07:00
Andrew FerlitschandGitHub 1b403373d3 Delete stage1.png 2022-05-24 16:16:49 -07:00
Andrew FerlitschandGitHub 987fb74ca6 Add files via upload 2022-05-24 15:13:15 -07:00
Andrew FerlitschandGitHub 65a209bc7b Update README.md 2022-05-24 15:12:55 -07:00
Andrew FerlitschandGitHub 16e6d9e90f Delete stage6c.png 2022-05-24 15:12:32 -07:00
Andrew FerlitschandGitHub 7ce6bee763 Delete stage6b.png 2022-05-24 15:12:18 -07:00
Andrew FerlitschandGitHub 6d7ca3eb55 Delete stage6a.png 2022-05-24 15:12:05 -07:00
Andrew FerlitschandGitHub 8e9f205e9a Add files via upload 2022-05-24 14:58:15 -07:00
Andrew FerlitschandGitHub 5fdb6c4368 Update README.md 2022-05-24 14:57:50 -07:00
Andrew FerlitschandGitHub 71ebfd402c Delete stage5.png 2022-05-24 14:57:33 -07:00
Andrew FerlitschandGitHub 6e4ca83531 Update README.md 2022-05-24 14:43:12 -07:00
Andrew FerlitschandGitHub 05793d6a3c Add files via upload 2022-05-24 14:42:39 -07:00
Andrew FerlitschandGitHub 3dc374b7db Delete stage4.png 2022-05-24 14:42:13 -07:00
Andrew FerlitschandGitHub 3ac8a4f617 Add files via upload 2022-05-24 14:22:20 -07:00
Andrew FerlitschandGitHub 21b4b5b063 Delete stage3v3.png 2022-05-24 14:22:11 -07:00
Andrew FerlitschandGitHub 9ffd921ca4 Update README.md 2022-05-24 14:21:38 -07:00
Andrew FerlitschandGitHub 14e6ebbb95 Add files via upload 2022-05-24 14:21:08 -07:00
Andrew FerlitschandGitHub 277b685a39 Delete stage3.png 2022-05-24 14:20:58 -07:00
Andrew FerlitschandGitHub 67e7715ed9 Update README.md 2022-05-24 13:59:19 -07:00
Andrew FerlitschandGitHub bb87900209 Add files via upload 2022-05-24 13:58:51 -07:00
Andrew FerlitschandGitHub 96ebe7286b Delete stage2.png 2022-05-24 13:58:24 -07:00
Andrew FerlitschandGitHub 0b3a5dde09 Add files via upload 2022-05-24 13:57:41 -07:00
Andrew FerlitschandGitHub 17a30360b4 Delete stage2.png 2022-05-24 13:57:24 -07:00
Andrew FerlitschandGitHub b386f51916 Update README.md 2022-05-24 13:40:25 -07:00
Andrew FerlitschandGitHub dd4f40c7f4 Add files via upload 2022-05-24 13:39:51 -07:00
Andrew FerlitschandGitHub d402fc085a Delete stage1.jpg 2022-05-24 13:39:38 -07:00
Andrew FerlitschandGitHub a12b9cd60f Add files via upload 2022-05-24 13:38:11 -07:00
Andrew FerlitschandGitHub bf1032d550 Delete stage1.jpg 2022-05-24 13:38:01 -07:00
Andrew FerlitschandGitHub dea05e1e36 Add files via upload 2022-05-24 13:36:59 -07:00
Andrew FerlitschandGitHub a9f0117c82 Update README.md 2022-05-23 17:09:39 -07:00
Andrew FerlitschandGitHub 83f1fe9ecd Add files via upload 2022-05-23 17:08:06 -07:00
Andrew FerlitschandGitHub 7344274037 Add files via upload 2022-05-23 17:06:53 -07:00
Andrew FerlitschandGitHub e36bfa9a3b Add files via upload 2022-05-23 17:03:27 -07:00
Andrew FerlitschandGitHub 950aa245b8 Update README.md 2022-05-23 16:55:52 -07:00
Andrew FerlitschandGitHub ac47b2e370 Update README.md 2022-05-20 13:01:42 -07:00
Andrew FerlitschandGitHub 6662fc809b Update README.md 2022-05-20 13:00:49 -07:00
Andrew FerlitschandGitHub 12b3171d5e feat: LightGBM (#583)
* fix: enable apis

* fix: enable apis

* fix: enable apis

* fix: enable apis

* fix: enable apis

* fix: enable apis

* fix: enable apis

* fix: enable apis

* fix: enable apis

* fix: enable apis

* fix: enable apis

* fix: enable apis

* feat: swivel and matching engine

* feat: swivel and matching engine

* feat: LightGBM

* feat: LightGBM
2022-05-20 12:58:37 -07:00
Andrew FerlitschandGitHub 579d4751bd Update README.md 2022-05-20 12:41:10 -07:00
Andrew FerlitschandGitHub d4c607323d feat: swivel + ME (#582)
* fix: enable apis

* fix: enable apis

* fix: enable apis

* fix: enable apis

* fix: enable apis

* fix: enable apis

* fix: enable apis

* fix: enable apis

* fix: enable apis

* fix: enable apis

* fix: enable apis

* fix: enable apis

* feat: swivel and matching engine

* feat: swivel and matching engine
2022-05-20 12:39:42 -07:00
nayaknishantandGitHub 3ad30738a7 docs: fixing CODEOWNERS and instructions hyperlinks (#580)
When opening a PR, the CODEOWNERS and instructions hyperlinks throw a 404 error because they point to a URL that has been changed. Fixing these hyperlinks.
2022-05-19 13:20:23 -07:00
Andrew FerlitschandGitHub 119273ae7e Ml.googleapis fix (#579)
* fix: enable apis

* fix: enable apis

* fix: enable apis

* fix: enable apis

* fix: enable apis

* fix: enable apis

* fix: enable apis

* fix: enable apis

* fix: enable apis

* fix: enable apis

* fix: enable apis

* fix: enable apis
2022-05-19 12:42:55 -07:00
Andrew FerlitschandGitHub 95bc39a685 fix: enable APIs stage5 (#578)
* fix: enable apis

* fix: enable apis

* fix: enable apis

* fix: enable apis

* fix: enable apis

* fix: enable apis

* fix: enable apis

* fix: enable apis

* fix: enable apis

* fix: enable apis
2022-05-19 12:30:11 -07:00
Andrew FerlitschandGitHub b054104851 fix: enable APIs stage4 (#577)
* fix: enable apis

* fix: enable apis

* fix: enable apis

* fix: enable apis

* fix: enable apis

* fix: enable apis

* fix: enable apis

* fix: enable apis
2022-05-19 12:23:49 -07:00
Andrew FerlitschandGitHub e0e0cf849a fix: enable APIs stage3 (#576)
* fix: enable apis

* fix: enable apis

* fix: enable apis

* fix: enable apis

* fix: enable apis

* fix: enable apis
2022-05-19 12:15:29 -07:00
Andrew FerlitschandGitHub c95b3d7088 fix : enable APIs stage2 (#575)
* fix: enable apis

* fix: enable apis

* fix: enable apis

* fix: enable apis
2022-05-19 11:51:49 -07:00
Andrew FerlitschandGitHub 19c2bdb008 fix: enable APIs stage1 (#574)
* fix: enable apis

* fix: enable apis
2022-05-19 11:36:12 -07:00
Andrew FerlitschandGitHub 3c815f3888 update: new template edition (#572)
* fix: new template review updates

* fix: new template review updates

* mport -> import

* fix: dummy code sample required an import

dummy code samples (not otherwise part of template) -- should be self contained since they will be deleted by the template user.

* fix: added install for self-contained code passes ingestion test

* fix: example code (not otherwise part of template) not self-contained.

* fix: continue update so code example is self-contained

* update: numpy already installed in test env
2022-05-19 11:24:19 -07:00
cfcd9b29fd Malansari automl vision api notebook (#573)
* Delete revised version

* Copy notebook from /notebooks/official

* Renamed base notebook

* Added first version by mansari@

* Updated to revised version by andrewferlitsch@

* Added author / reviewer information

Added sample files

* Updated CODEOWNERS

* Fixed links for opening the notebook in Colab/Github/Vertex

Removed installation of and references to pandas

Fixed gcs_annotation_file_name string reference

* Fixed the links for opening notebook (again!)

* Added attribution and references

* Removed references as covered at top

* Updated installation commands to match

* Updated Vertex AI region name to be more clear

* Added db-types dependency for pandas operations
that are now failing

* Minor edits

* Combined package installation and
added a note to ignore the errors

* Minor edit to message

* Added special thanks to andrewferlitsch@

* Updated andrewferlitsch@ GithHub profile link

* Updated sample files URLs to absolute URLs

* Removed empty code block

* Added additional attribution (and the one that did not make it into previous commit!)

* Fixed multi-package import formatting
Switched to pandas instead of db-dtypes

* Fixed isort issue

* Removed unnecessary pandas import

* Formatted the notebook with nbfmt

* Additional notebook formatting

* Updated link to open in Vertex AI Workbench
to point to raw .ipynb file

* Fixed lint issues

* Formatting changes

Added additional APIs to be enabled

Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-05-19 11:14:17 -07:00
Ivan CheungandGitHub 4fca7d98b2 Increases notebook concurrency and linted CI files (#512)
* Fixed private pool issues

* Ran linter

* Added worker timeouts

* Tweaked timeout

* Removed gcloud requirement

* Removed unneeded file
2022-05-18 18:58:54 -04:00
Andrew FerlitschandGitHub dea950bcb6 fix: DPE styling (#570)
* fix: DPE-style tuning

* fix: DPE-style tuning

* fix: DPE-style tuning

* fix: DPE-style tuning

* fix: DPE-style tuning
2022-05-18 14:32:30 -07:00
Andrew FerlitschandGitHub 4c43755fb6 Mlops 8v3 (#569)
* fix: DPE-style tuning

* fix: DPE-style tuning

* fix: DPE-style tuning
2022-05-18 14:11:31 -07:00
Andrew FerlitschandGitHub 374942a9e9 fix: DPE-style tuning (#568) 2022-05-18 14:01:13 -07:00
Andrew FerlitschandGitHub 8add418428 Mlops 8v2 (#567)
* fix: two towers

* fix: two towers

* fix: typos in twotowers

* fix: typos in twotowers

* fix: DPE-style tuning

* fix: DPE-style tuning

* fix: DPE-style tuning

* fix: DPE-style tuning

* fix: DPE-style tuning

* fix: DPE-style tuning
2022-05-18 13:46:24 -07:00
Andrew FerlitschandGitHub 9d73cc4574 fix: DPE style tuning (#566)
* fix: two towers

* fix: two towers

* fix: typos in twotowers

* fix: typos in twotowers

* fix: DPE-style tuning

* fix: DPE-style tuning

* fix: DPE-style tuning

* fix: DPE-style tuning
2022-05-18 13:29:45 -07:00
Andrew FerlitschandGitHub 5edb4bb1bf fix: DPE-styling (#565)
* fix: two towers

* fix: two towers

* fix: typos in twotowers

* fix: typos in twotowers

* fix: DPE-style tuning

* fix: DPE-style tuning
2022-05-18 12:29:01 -07:00
Andrew FerlitschandGitHub 0e811868d3 fix: links 2022-05-18 11:33:56 -07:00
Andrew FerlitschandGitHub 9efcfa25e8 fix: links 2022-05-18 11:27:11 -07:00
48036cf581 vision api notebook - updated link to open in Vertex AI Workbench (#562)
* Delete revised version

* Copy notebook from /notebooks/official

* Renamed base notebook

* Added first version by mansari@

* Updated to revised version by andrewferlitsch@

* Added author / reviewer information

Added sample files

* Updated CODEOWNERS

* Fixed links for opening the notebook in Colab/Github/Vertex

Removed installation of and references to pandas

Fixed gcs_annotation_file_name string reference

* Fixed the links for opening notebook (again!)

* Added attribution and references

* Removed references as covered at top

* Updated installation commands to match

* Updated Vertex AI region name to be more clear

* Added db-types dependency for pandas operations
that are now failing

* Minor edits

* Combined package installation and
added a note to ignore the errors

* Minor edit to message

* Added special thanks to andrewferlitsch@

* Updated andrewferlitsch@ GithHub profile link

* Updated sample files URLs to absolute URLs

* Removed empty code block

* Added additional attribution (and the one that did not make it into previous commit!)

* Fixed multi-package import formatting
Switched to pandas instead of db-dtypes

* Fixed isort issue

* Removed unnecessary pandas import

* Formatted the notebook with nbfmt

* Additional notebook formatting

* Updated link to open in Vertex AI Workbench
to point to raw .ipynb file

* Fixed lint issues

Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-05-18 11:20:39 -07:00
Andrew FerlitschandGitHub 79fd9b4049 Update README.md 2022-05-17 11:05:54 -07:00
Andrew FerlitschandGitHub 46b2181a4e fix: typos in two towers (#563)
* fix: two towers

* fix: two towers

* fix: typos in twotowers

* fix: typos in twotowers
2022-05-17 11:04:01 -07:00
Andrew FerlitschandGitHub d04f25a8bd Update README.md 2022-05-16 15:13:45 -07:00
Andrew FerlitschandGitHub 9f341c350c fix: two towers (#561)
* fix: two towers

* fix: two towers
2022-05-16 15:11:44 -07:00
Ivan CheungandGitHub f22f97f680 fix: Updated matching engine dependency and fixed cases (#557)
* fix: Updated dependency and fixed cases

* Ran linter

* Renamed to Vertex AI Workbench notebook

* Additional text fixes
2022-05-16 13:06:04 -04:00
Andrew FerlitschandGitHub fe75745d44 feat: WIP: twotowers+matching engine (#560)
* feat: using Vision API for preprocessing data

* feat: using Vision API for preprocessing data

* feat: component vs job resource settings

* feat: component vs job resource settings

* feat: triton server

* feat: triton server

* feat: triton server

* feat: triton server

* fix: check for workbench

* fix: check for workbench

* fix: check for workbench

* fix: check for workbench

* fix: check for workbench

* fix: check for workbench

* fix: check for workbench

* fix: check for workbench

* fix: check for workbench

* fix: check for workbench

* fix: check for workbench

* fix: check for workbench

* fix: check for workbench

* fix: check for workbench

* update: ModelEvaluation SDK

* update: ModelEvaluation SDK

* feat: matching engine

* feat: matching engine

* feat: wip: twotowers

* feat: wip: twotowers
2022-05-13 14:03:43 -07:00
Andrew FerlitschandGitHub bbc9f1337e Update README.md 2022-05-13 08:56:39 -07:00
Andrew FerlitschandGitHub eb1fa9213a feat: add notebook for matching engine (#559)
* feat: using Vision API for preprocessing data

* feat: using Vision API for preprocessing data

* feat: component vs job resource settings

* feat: component vs job resource settings

* feat: triton server

* feat: triton server

* feat: triton server

* feat: triton server

* fix: check for workbench

* fix: check for workbench

* fix: check for workbench

* fix: check for workbench

* fix: check for workbench

* fix: check for workbench

* fix: check for workbench

* fix: check for workbench

* fix: check for workbench

* fix: check for workbench

* fix: check for workbench

* fix: check for workbench

* fix: check for workbench

* fix: check for workbench

* update: ModelEvaluation SDK

* update: ModelEvaluation SDK

* feat: matching engine

* feat: matching engine
2022-05-12 15:55:21 -07:00
Mohammad Al-AnsariandGitHub a7033a6527 Updates to visionapi notebook (#556)
* Delete revised version

* Copy notebook from /notebooks/official

* Renamed base notebook

* Added first version by mansari@

* Updated to revised version by andrewferlitsch@

* Added author / reviewer information

Added sample files

* Updated CODEOWNERS

* Fixed links for opening the notebook in Colab/Github/Vertex

Removed installation of and references to pandas

Fixed gcs_annotation_file_name string reference

* Fixed the links for opening notebook (again!)

* Added attribution and references

* Removed references as covered at top

* Updated installation commands to match

* Updated Vertex AI region name to be more clear

* Added db-types dependency for pandas operations
that are now failing

* Minor edits

* Combined package installation and
added a note to ignore the errors

* Minor edit to message

* Added special thanks to andrewferlitsch@

* Updated andrewferlitsch@ GithHub profile link

* Updated sample files URLs to absolute URLs

* Removed empty code block

* Added additional attribution (and the one that did not make it into previous commit!)

* Fixed multi-package import formatting
Switched to pandas instead of db-dtypes

* Fixed isort issue

* Removed unnecessary pandas import

* Formatted the notebook with nbfmt

* Additional notebook formatting
2022-05-11 11:23:50 -07:00
Andrew FerlitschandGitHub 7e6c2d69c8 update: ModelEval as SDK (#555)
* feat: using Vision API for preprocessing data

* feat: using Vision API for preprocessing data

* feat: component vs job resource settings

* feat: component vs job resource settings

* feat: triton server

* feat: triton server

* feat: triton server

* feat: triton server

* fix: check for workbench

* fix: check for workbench

* fix: check for workbench

* fix: check for workbench

* fix: check for workbench

* fix: check for workbench

* fix: check for workbench

* fix: check for workbench

* fix: check for workbench

* fix: check for workbench

* fix: check for workbench

* fix: check for workbench

* fix: check for workbench

* fix: check for workbench

* update: ModelEvaluation SDK

* update: ModelEvaluation SDK
2022-05-10 15:33:52 -07:00
Andrew FerlitschandGitHub 1a21b81804 fix: stage5 DPE style (#554)
* feat: using Vision API for preprocessing data

* feat: using Vision API for preprocessing data

* feat: component vs job resource settings

* feat: component vs job resource settings

* feat: triton server

* feat: triton server

* feat: triton server

* feat: triton server

* fix: check for workbench

* fix: check for workbench

* fix: check for workbench

* fix: check for workbench

* fix: check for workbench

* fix: check for workbench

* fix: check for workbench

* fix: check for workbench

* fix: check for workbench

* fix: check for workbench

* fix: check for workbench

* fix: check for workbench
2022-05-10 14:11:31 -07:00
Andrew FerlitschandGitHub 2bbd520613 fix: stage4 DPE styling (#553)
* feat: using Vision API for preprocessing data

* feat: using Vision API for preprocessing data

* feat: component vs job resource settings

* feat: component vs job resource settings

* feat: triton server

* feat: triton server

* feat: triton server

* feat: triton server

* fix: check for workbench

* fix: check for workbench

* fix: check for workbench

* fix: check for workbench

* fix: check for workbench

* fix: check for workbench

* fix: check for workbench

* fix: check for workbench

* fix: check for workbench

* fix: check for workbench
2022-05-10 13:58:44 -07:00
Andrew FerlitschandGitHub 8285e4ebd1 Mlops 8 (#552)
* feat: using Vision API for preprocessing data

* feat: using Vision API for preprocessing data

* feat: component vs job resource settings

* feat: component vs job resource settings

* feat: triton server

* feat: triton server

* feat: triton server

* feat: triton server

* fix: check for workbench

* fix: check for workbench

* fix: check for workbench

* fix: check for workbench

* fix: check for workbench

* fix: check for workbench

* fix: check for workbench

* fix: check for workbench
2022-05-10 12:56:43 -07:00
Andrew FerlitschandGitHub 859849894e fix: stage3 workbench (#551)
* feat: using Vision API for preprocessing data

* feat: using Vision API for preprocessing data

* feat: component vs job resource settings

* feat: component vs job resource settings

* feat: triton server

* feat: triton server

* feat: triton server

* feat: triton server

* fix: check for workbench

* fix: check for workbench

* fix: check for workbench

* fix: check for workbench

* fix: check for workbench

* fix: check for workbench
2022-05-10 12:38:52 -07:00
Andrew FerlitschandGitHub e74dd48ae0 fix: 2nd round workbench (#550)
* feat: using Vision API for preprocessing data

* feat: using Vision API for preprocessing data

* feat: component vs job resource settings

* feat: component vs job resource settings

* feat: triton server

* feat: triton server

* feat: triton server

* feat: triton server

* fix: check for workbench

* fix: check for workbench

* fix: check for workbench

* fix: check for workbench
2022-05-10 12:12:27 -07:00
Andrew FerlitschandGitHub a14eb71210 fix: check for workbench (#549)
* feat: using Vision API for preprocessing data

* feat: using Vision API for preprocessing data

* feat: component vs job resource settings

* feat: component vs job resource settings

* feat: triton server

* feat: triton server

* feat: triton server

* feat: triton server

* fix: check for workbench

* fix: check for workbench
2022-05-10 11:37:44 -07:00
Mohammad Al-AnsariandGitHub 0b6a9718ff Added author / reviewer informationAdded sample files (#544)
* Delete revised version

* Copy notebook from /notebooks/official

* Renamed base notebook

* Added first version by mansari@

* Updated to revised version by andrewferlitsch@

* Added author / reviewer information

Added sample files

* Updated CODEOWNERS

* Fixed links for opening the notebook in Colab/Github/Vertex

Removed installation of and references to pandas

Fixed gcs_annotation_file_name string reference
2022-05-09 13:59:59 -07:00
Andrew FerlitschandGitHub 6ac0d8a029 Update README.md 2022-05-09 13:48:00 -07:00
Andrew FerlitschandGitHub 2ee013bcab Delete get_started_nvidia_triton_serving.ipynb 2022-05-09 13:47:18 -07:00
Andrew FerlitschandGitHub 1ebb3f5714 Mlops 8 (#547)
* feat: using Vision API for preprocessing data

* feat: using Vision API for preprocessing data

* feat: component vs job resource settings

* feat: component vs job resource settings

* feat: triton server

* feat: triton server

* feat: triton server

* feat: triton server
2022-05-09 13:46:35 -07:00
Andrew FerlitschandGitHub 11c5134961 Update README.md 2022-05-09 13:40:51 -07:00
Andrew FerlitschandGitHub e328b7268f feat: triton server (#546)
* feat: using Vision API for preprocessing data

* feat: using Vision API for preprocessing data

* feat: component vs job resource settings

* feat: component vs job resource settings

* feat: triton server

* feat: triton server
2022-05-09 13:38:37 -07:00
Andrew FerlitschandGitHub d297e99e5a Update get_started_with_machine_management.ipynb 2022-05-09 12:20:03 -07:00
Andrew FerlitschandGitHub 48c7a4c82e fix: spelling 2022-05-09 12:15:07 -07:00
Andrew FerlitschandGitHub eb3b52f863 Update README.md 2022-05-09 12:10:40 -07:00
Andrew FerlitschandGitHub 4e58cca127 Update get_started_with_machine_management.ipynb 2022-05-09 12:09:07 -07:00
Andrew FerlitschandGitHub 182a98768f feat: machine resource settings (#545)
* feat: using Vision API for preprocessing data

* feat: using Vision API for preprocessing data

* feat: component vs job resource settings

* feat: component vs job resource settings
2022-05-09 12:06:56 -07:00
Andrew FerlitschandGitHub f483447235 Update README.md 2022-05-06 19:07:16 -07:00
Andrew FerlitschandGitHub c59050608b feat: vision api and automl (#543)
* feat: using Vision API for preprocessing data

* feat: using Vision API for preprocessing data
2022-05-06 19:04:43 -07:00
Andrew FerlitschandGitHub 3b9844f92c update: add co-author (#542)
* feat: add colab code for docker

* feat: add colab code for docker

* fix: add colab support for docker

* fix: add colab support for docker

* fix: delete tmp BQ model

* fix: delete tmp BQ model

* feat: GAPIC->SDK for private endpoints

* feat: GAPIC->SDK for private endpoints

* fix: add IS_COLAB flag

* fix: add IS_COLAB flag

* fix: add IS_COLAB flag

* fix: add IS_COLAB flag

* fix: add IS_COLAB flag

* fix: add IS_COLAB flag

* fix: IS_COLAB

* fix: IS_COLAB

* fix: IS_COLAB

* fix: IS_COLAB

* fix: IS_COLAB

* feat: more model eval work

* feat: more model eval work

* fix: IS_COLAB

* fix: IS_COLAB

* fix: IS_COLAB

* fix: IS_COLABA

* feat: add notebook for TFX

* feat: add notebook for TFX

* feat: add notebook for TFX

* fix: mistakes

* fix: mistakes

* fix: vertex ai compatibility

* fix: vertex ai compatibility

* fix: workbench auth

* fix: workbench auth

* update: add co-author

* update: add co-author
2022-05-06 15:27:05 -07:00
Andrew FerlitschandGitHub ee301a22f6 clean: remove BLAH 2022-05-06 12:38:30 -07:00
Andrew FerlitschandGitHub b7d16f66aa fix: workbench auth (#541)
* feat: add colab code for docker

* feat: add colab code for docker

* fix: add colab support for docker

* fix: add colab support for docker

* fix: delete tmp BQ model

* fix: delete tmp BQ model

* feat: GAPIC->SDK for private endpoints

* feat: GAPIC->SDK for private endpoints

* fix: add IS_COLAB flag

* fix: add IS_COLAB flag

* fix: add IS_COLAB flag

* fix: add IS_COLAB flag

* fix: add IS_COLAB flag

* fix: add IS_COLAB flag

* fix: IS_COLAB

* fix: IS_COLAB

* fix: IS_COLAB

* fix: IS_COLAB

* fix: IS_COLAB

* feat: more model eval work

* feat: more model eval work

* fix: IS_COLAB

* fix: IS_COLAB

* fix: IS_COLAB

* fix: IS_COLABA

* feat: add notebook for TFX

* feat: add notebook for TFX

* feat: add notebook for TFX

* fix: mistakes

* fix: mistakes

* fix: vertex ai compatibility

* fix: vertex ai compatibility

* fix: workbench auth

* fix: workbench auth
2022-05-06 10:18:06 -07:00
Andrew FerlitschandGitHub 57aad5b802 fix: compat issue with Vertex AI and TFX Transform (#540)
* feat: add colab code for docker

* feat: add colab code for docker

* fix: add colab support for docker

* fix: add colab support for docker

* fix: delete tmp BQ model

* fix: delete tmp BQ model

* feat: GAPIC->SDK for private endpoints

* feat: GAPIC->SDK for private endpoints

* fix: add IS_COLAB flag

* fix: add IS_COLAB flag

* fix: add IS_COLAB flag

* fix: add IS_COLAB flag

* fix: add IS_COLAB flag

* fix: add IS_COLAB flag

* fix: IS_COLAB

* fix: IS_COLAB

* fix: IS_COLAB

* fix: IS_COLAB

* fix: IS_COLAB

* feat: more model eval work

* feat: more model eval work

* fix: IS_COLAB

* fix: IS_COLAB

* fix: IS_COLAB

* fix: IS_COLABA

* feat: add notebook for TFX

* feat: add notebook for TFX

* feat: add notebook for TFX

* fix: mistakes

* fix: mistakes

* fix: vertex ai compatibility

* fix: vertex ai compatibility
2022-05-05 19:04:13 -07:00
Andrew FerlitschandGitHub 9e311433ba fix: mistakes in tfx notebook (#539)
* feat: add colab code for docker

* feat: add colab code for docker

* fix: add colab support for docker

* fix: add colab support for docker

* fix: delete tmp BQ model

* fix: delete tmp BQ model

* feat: GAPIC->SDK for private endpoints

* feat: GAPIC->SDK for private endpoints

* fix: add IS_COLAB flag

* fix: add IS_COLAB flag

* fix: add IS_COLAB flag

* fix: add IS_COLAB flag

* fix: add IS_COLAB flag

* fix: add IS_COLAB flag

* fix: IS_COLAB

* fix: IS_COLAB

* fix: IS_COLAB

* fix: IS_COLAB

* fix: IS_COLAB

* feat: more model eval work

* feat: more model eval work

* fix: IS_COLAB

* fix: IS_COLAB

* fix: IS_COLAB

* fix: IS_COLABA

* feat: add notebook for TFX

* feat: add notebook for TFX

* feat: add notebook for TFX

* fix: mistakes

* fix: mistakes
2022-05-05 14:58:04 -07:00
Andrew FerlitschandGitHub 04b310927a Update README.md 2022-05-05 13:36:36 -07:00
Andrew FerlitschandGitHub 2fed3ad014 feat: add TFX pipeline (#538)
* feat: add colab code for docker

* feat: add colab code for docker

* fix: add colab support for docker

* fix: add colab support for docker

* fix: delete tmp BQ model

* fix: delete tmp BQ model

* feat: GAPIC->SDK for private endpoints

* feat: GAPIC->SDK for private endpoints

* fix: add IS_COLAB flag

* fix: add IS_COLAB flag

* fix: add IS_COLAB flag

* fix: add IS_COLAB flag

* fix: add IS_COLAB flag

* fix: add IS_COLAB flag

* fix: IS_COLAB

* fix: IS_COLAB

* fix: IS_COLAB

* fix: IS_COLAB

* fix: IS_COLAB

* feat: more model eval work

* feat: more model eval work

* fix: IS_COLAB

* fix: IS_COLAB

* fix: IS_COLAB

* fix: IS_COLABA

* feat: add notebook for TFX

* feat: add notebook for TFX

* feat: add notebook for TFX
2022-05-05 13:34:22 -07:00
Andrew FerlitschandGitHub 0ec94e0af6 fix: IS_COLAB (#535)
* feat: add colab code for docker

* feat: add colab code for docker

* fix: add colab support for docker

* fix: add colab support for docker

* fix: delete tmp BQ model

* fix: delete tmp BQ model

* feat: GAPIC->SDK for private endpoints

* feat: GAPIC->SDK for private endpoints

* fix: add IS_COLAB flag

* fix: add IS_COLAB flag

* fix: add IS_COLAB flag

* fix: add IS_COLAB flag

* fix: add IS_COLAB flag

* fix: add IS_COLAB flag

* fix: IS_COLAB

* fix: IS_COLAB

* fix: IS_COLAB

* fix: IS_COLAB

* fix: IS_COLAB

* feat: more model eval work

* feat: more model eval work

* fix: IS_COLAB

* fix: IS_COLAB

* fix: IS_COLAB

* fix: IS_COLABA
2022-05-04 13:55:11 -07:00
9470be0900 adds the updated service-account code to mlops/stage3/get_started_with_dataproc_serverless_pipeline_components notebook (#529)
* adds the updated service-account setting code to notebook

* ran linter test

Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-05-04 10:04:55 -07:00
479a0c6271 adds the updated service-account code to mlops/stage3/get_started_with_automl_pipeline_components notebook (#528)
* adds the updated service-account setting code to the notebook

* ran linter test

Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-05-04 10:04:13 -07:00
053f9c397f adds the updated service-account code to mlops/stage3/get_started_with_kubeflow_pipelines notebook (#527)
* adds updated service-account setting code to the notebook

* ran linter test

Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-05-04 10:03:39 -07:00
Andrew FerlitschandGitHub 2c82469756 fix: service account 2022-05-03 08:33:17 -07:00
Andrew FerlitschandGitHub fdfc7009d0 fix: correct IS_COLAB (#531)
* feat: add colab code for docker

* feat: add colab code for docker

* fix: add colab support for docker

* fix: add colab support for docker

* fix: delete tmp BQ model

* fix: delete tmp BQ model

* feat: GAPIC->SDK for private endpoints

* feat: GAPIC->SDK for private endpoints

* fix: add IS_COLAB flag

* fix: add IS_COLAB flag

* fix: add IS_COLAB flag

* fix: add IS_COLAB flag

* fix: add IS_COLAB flag

* fix: add IS_COLAB flag

* fix: IS_COLAB

* fix: IS_COLAB

* fix: IS_COLAB

* fix: IS_COLAB

* fix: IS_COLAB

* feat: more model eval work

* feat: more model eval work

* fix: IS_COLAB

* fix: IS_COLAB
2022-05-02 14:25:08 -07:00
Andrew FerlitschandGitHub 59fcfe137d fix: typo in stage 2022-05-02 14:00:16 -07:00
Andrew FerlitschandGitHub 9b434b32bc feat: more eval examples (#530)
* feat: add colab code for docker

* feat: add colab code for docker

* fix: add colab support for docker

* fix: add colab support for docker

* fix: delete tmp BQ model

* fix: delete tmp BQ model

* feat: GAPIC->SDK for private endpoints

* feat: GAPIC->SDK for private endpoints

* fix: add IS_COLAB flag

* fix: add IS_COLAB flag

* fix: add IS_COLAB flag

* fix: add IS_COLAB flag

* fix: add IS_COLAB flag

* fix: add IS_COLAB flag

* fix: IS_COLAB

* fix: IS_COLAB

* fix: IS_COLAB

* fix: IS_COLAB

* fix: IS_COLAB

* feat: more model eval work

* feat: more model eval work
2022-05-02 13:19:07 -07:00
fc27cd8628 Added service account fetch code for colab in get_started_with_rapid_prototyping_bqml_automl file (#520)
* made changes

* ran linter test

* added minor changes

* ran linter test

* made changes

* ran linter test

Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-05-02 09:21:45 -07:00
a62f03c396 Added service account fetch code for colab in get_started_with_custom_training_pipeline_components file (#519)
* made changes

* ran linter test

* made minor changes

* ran linter test

* made changes

* ran linter test

Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-05-02 09:21:08 -07:00
a270439814 Added service account fetch code for colab in get_started_with_bqml_pipeline_components file (#518)
* changes made

* ran linter test

* made minor changes

* ran linter test

* made changes

* ran linter test

Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-05-02 09:20:18 -07:00
sudarshan-SpringMLandGitHub a97af4a078 Added service account fetch code for colab in get_started_with_bq_tfdv_pipeline_components file (#517)
* added service account code for colab

* ran linter test

* made changes

* ran linter test
2022-05-02 09:19:29 -07:00
Andrew FerlitschandGitHub d7127cc22f fix: IS_COLAB (#526)
* feat: add colab code for docker

* feat: add colab code for docker

* fix: add colab support for docker

* fix: add colab support for docker

* fix: delete tmp BQ model

* fix: delete tmp BQ model

* feat: GAPIC->SDK for private endpoints

* feat: GAPIC->SDK for private endpoints

* fix: add IS_COLAB flag

* fix: add IS_COLAB flag

* fix: add IS_COLAB flag

* fix: add IS_COLAB flag

* fix: add IS_COLAB flag

* fix: add IS_COLAB flag

* fix: IS_COLAB

* fix: IS_COLAB

* fix: IS_COLAB

* fix: IS_COLAB

* fix: IS_COLAB
2022-04-29 15:25:49 -07:00
Andrew FerlitschandGitHub 802ab4edd8 fix: DPE-styling (#525)
* feat: add colab code for docker

* feat: add colab code for docker

* fix: add colab support for docker

* fix: add colab support for docker

* fix: delete tmp BQ model

* fix: delete tmp BQ model

* feat: GAPIC->SDK for private endpoints

* feat: GAPIC->SDK for private endpoints

* fix: add IS_COLAB flag

* fix: add IS_COLAB flag

* fix: add IS_COLAB flag

* fix: add IS_COLAB flag

* fix: add IS_COLAB flag

* fix: add IS_COLAB flag

* fix: IS_COLAB

* fix: IS_COLAB

* fix: IS_COLAB
2022-04-29 15:10:19 -07:00
Andrew FerlitschandGitHub ae7f28fb31 fix: DPE-styling updates (#524)
* feat: add colab code for docker

* feat: add colab code for docker

* fix: add colab support for docker

* fix: add colab support for docker

* fix: delete tmp BQ model

* fix: delete tmp BQ model

* feat: GAPIC->SDK for private endpoints

* feat: GAPIC->SDK for private endpoints

* fix: add IS_COLAB flag

* fix: add IS_COLAB flag

* fix: add IS_COLAB flag

* fix: add IS_COLAB flag

* fix: add IS_COLAB flag

* fix: add IS_COLAB flag
2022-04-29 14:06:59 -07:00
f63e3e6e4c Added colab link and made changes in the code in such a way that docker commands can run on colab environment for the file get_started_vertex_training_pytorch (#508)
* Added colab in the notebook

* Ran linter test

Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-04-29 11:55:51 -07:00
Andrew FerlitschandGitHub b9bb497ebc fix: IS_COLAB (#523)
* feat: add colab code for docker

* feat: add colab code for docker

* fix: add colab support for docker

* fix: add colab support for docker

* fix: delete tmp BQ model

* fix: delete tmp BQ model

* feat: GAPIC->SDK for private endpoints

* feat: GAPIC->SDK for private endpoints

* fix: add IS_COLAB flag

* fix: add IS_COLAB flag

* fix: add IS_COLAB flag

* fix: add IS_COLAB flag
2022-04-29 11:54:21 -07:00
Andrew FerlitschandGitHub 4368b9e7f8 feat: GAPIC->SDK for private endpoint (#516)
* feat: add colab code for docker

* feat: add colab code for docker

* fix: add colab support for docker

* fix: add colab support for docker

* fix: delete tmp BQ model

* fix: delete tmp BQ model

* feat: GAPIC->SDK for private endpoints

* feat: GAPIC->SDK for private endpoints
2022-04-28 09:59:49 -07:00
2e9cb5d2cf minor change for 'Get started with dataflow pipeline components' (#500)
* Add minor changes to get_started_with_dataflow_pipeline_components

* minor changes and tested

* remove variable dataflow_wait_op, since not used in other places.

* remove variable dataflow_wait_op, since not used in other places

* removed unused import

* Run linter test

* Add gcloud project set when using colab

* Run linter

* correct anem toColab logo Run in Colab

* run linter

* correct the list of items to remove

* Run linter

* Run liinter

Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-04-27 16:45:20 -07:00
9ec8a93e05 Minor changes has been done to pipelines_intro_kfp (#494)
* minor changes done

* ran linter test

* chnanged the as per review coments

* ran linter test

Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-04-27 09:42:34 -07:00
3ed8778656 Made few changes to sdk-feature-store (#486)
* Added vertexai notebook

* Ran the linter test

* Made the required changes based on the comments

* Ran linter test again

Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-04-27 09:39:03 -07:00
Andrew FerlitschandGitHub bf5e3cf870 fix: delete tmp BQ model (#510)
* feat: add colab code for docker

* feat: add colab code for docker

* fix: add colab support for docker

* fix: add colab support for docker

* fix: delete tmp BQ model

* fix: delete tmp BQ model
2022-04-27 09:30:35 -07:00
c23215893d minor changes on stage1 ml ops - Get started vertex datasets (#474)
* Add minor changes to get_started_vertex_datasets notebook

* run linter

* Run Linter test

* Add google authentication cell for colab execution

* run linter

* correct the project id definition

* Run linter

* Add project id cell

* run liner

* Added imports that are required

* run linter test

* Add gcloud project set

* Run linter

* add linter run

* Running linter test

* run linter test

Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-04-25 10:11:27 -07:00
Andrew FerlitschandGitHub 1c96f7ca71 fix: notebook run in colab (#505)
* feat: add colab code for docker

* feat: add colab code for docker

* fix: add colab support for docker

* fix: add colab support for docker
2022-04-22 18:50:29 -07:00
Andrew FerlitschandGitHub 0d5661835b feat: add docker support in Colab (#504)
* feat: add colab code for docker

* feat: add colab code for docker
2022-04-22 13:54:29 -07:00
fe1a3c0bc9 Adds Colab part and minor changes to ml_ops/stage2/get_started_bqml_training notebook (#491)
* adds the ml_ops/stage2/get_Started_bqml_training notebook to official and removes the same from community folder

* ran linter test

* updates the textual content

* ran linter test

* moves the updated stage2/get-started-bqml notebook back to the communit folder

* ran linter test

* updates the header according to the template

* ran linter test

* adds colab part and minor changes

* ran linter test

* retains the newly added code lost in conflicts

* ran linter test

* converts vertex to vertex ai

* ran linter test

* moves deletion of temporary BQ table outside delete_storage condition

* ran linter test

* adds bigquery-storage dependency to the notebook tested on Colab

* ran linter test

Co-authored-by: Karl Weinmeister <11586922+kweinmeister@users.noreply.github.com>
Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-04-22 11:09:49 -07:00
82bffb87f1 Made some minor changes to sdk-metric-parameter-tracking-for-locally-trained-models (#480)
* Added to correct path

* Ran linter test

* Made some changes

* Ran linter test

Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-04-22 00:05:57 -07:00
sudarshan-SpringMLandGitHub 741c6732f1 Made minor changes to sdk-metric-parameter-tracking-for-custom-jobs file (#479)
* modified file

* modified file

* ran linter test

* deleted file in community folder

* ran linter test

* changed folder name in links

* ran linter test

* resolved comments

* ran linter test

* modified file

* ran linter test
2022-04-22 00:05:07 -07:00
9d8caf7888 Added markup text mentioning the role provided to service account used by notebook instance & provided key-version value while destroying it in notebook get_started_with_cmek_training (#495)
* Changes made to notebook

* Ran linter test

Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-04-21 23:37:19 -07:00
e63d354413 Made minor changes to rapid_prototyping_bqml_automl file and moved file from community to official (#496)
* added file

* modified notebook

* ran linter test

Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-04-21 22:44:18 -07:00
831c515477 Adding official version for Fraud detection notebook (#321)
* deleted file in community folder

* modified notebook

* ran linter test

* renamed managed_notebooks folder to workbench

* ran linter

* resolved comments

* ran linter test

* pulled new version of branch

* ran linter again

* resolved comments

* ran linter test

* removed %%time and added --user flag to all pip installs

* ran linter test

* added debug statements

* ran linter test

* added verbose

* ran linter test

Co-authored-by: Karl Weinmeister <11586922+kweinmeister@users.noreply.github.com>
Co-authored-by: Andrew Ferlitsch <aferlitsch@google.com>
2022-04-21 22:07:58 -07:00
Andrew FerlitschandGitHub 06ba5d6804 fix: SaraRob installation updates (#501)
* feat: improve notebook for metric compare

* feat: improve notebook for metric compare

* feat: improve notebook for metric compare

* feat: improve notebook for metric compare

* feat: improve notebook for metric compare
2022-04-21 11:37:44 -07:00
158 changed files with 45962 additions and 12608 deletions
+29 -25
View File
@@ -1,45 +1,49 @@
from typing import List
from ratemate import RateLimit
from resource_cleanup_manager import (
ResourceCleanupManager,
DatasetResourceCleanupManager,
EndpointResourceCleanupManager,
ModelResourceCleanupManager,
DatasetResourceCleanupManager,
ModelResourceCleanupManager,
EndpointResourceCleanupManager,
ResourceCleanupManager,
)
rate_limit = RateLimit(max_count=25, per=60, greedy=False)
def run_cleanup_managers(managers: List[ResourceCleanupManager], is_dry_run: bool):
for manager in managers:
type_name = manager.type_name
for manager in managers:
type_name = manager.type_name
print(f"Fetching {type_name}'s...")
resources = manager.list()
print(f"Found {len(resources)} {type_name}'s")
for resource in resources:
if not manager.is_deletable(resource):
continue
print(f"Fetching {type_name}'s...")
resources = manager.list()
print(f"Found {len(resources)} {type_name}'s")
for resource in resources:
try:
if not manager.is_deletable(resource):
continue
if is_dry_run:
resource_name = manager.resource_name(resource)
print(f"Will delete '{type_name}': {resource_name}")
else:
try:
manager.delete(resource)
except Exception as exception:
print(exception)
if is_dry_run:
resource_name = manager.resource_name(resource)
print(f"Will delete '{type_name}': {resource_name}")
else:
rate_limit.wait() # wait before deleting
manager.delete(resource)
except Exception as exception:
print(exception)
print("")
print("")
is_dry_run = False
if is_dry_run:
print("Starting cleanup in dry run mode...")
print("Starting cleanup in dry run mode...")
# List of all cleanup managers
managers = [
DatasetResourceCleanupManager(),
EndpointResourceCleanupManager(),
ModelResourceCleanupManager(),
DatasetResourceCleanupManager(),
EndpointResourceCleanupManager(),
ModelResourceCleanupManager(), # ModelResourceCleanupManager must follow EndpointResourceCleanupManager due to deployed models blocking model deletion.
]
run_cleanup_managers(managers=managers, is_dry_run=is_dry_run)
@@ -1,8 +1,9 @@
import abc
from typing import Any, Type
from google.cloud import aiplatform
from typing import Any
from proto.datetime_helpers import DatetimeWithNanoseconds
from google.cloud.aiplatform import base
from proto.datetime_helpers import DatetimeWithNanoseconds
# If a resource was updated within this number of seconds, do not delete.
RESOURCE_UPDATE_BUFFER_IN_SECONDS = 60 * 60 * 8
@@ -40,7 +41,7 @@ class ResourceCleanupManager(abc.ABC):
# Check that it wasn't created too recently, to prevent race conditions
if time_difference <= RESOURCE_UPDATE_BUFFER_IN_SECONDS:
print(
f"Skipping '{resource}' due update_time being '{time_difference}', which is less than '{RESOURCE_UPDATE_BUFFER_IN_SECONDS}'."
f"Skipping '{resource}' due to update_time being '{time_difference}', which is less than '{RESOURCE_UPDATE_BUFFER_IN_SECONDS}'."
)
return False
@@ -50,7 +51,7 @@ class ResourceCleanupManager(abc.ABC):
class VertexAIResourceCleanupManager(ResourceCleanupManager):
@property
@abc.abstractmethod
def vertex_ai_resource(self) -> base.VertexAiResourceNounWithFutureManager:
def vertex_ai_resource(self) -> Type[base.VertexAiResourceNounWithFutureManager]:
pass
@property
@@ -60,7 +61,9 @@ class VertexAIResourceCleanupManager(ResourceCleanupManager):
def list(self) -> Any:
return self.vertex_ai_resource.list()
def resource_name(self, resource: Any) -> str:
def resource_name(
self, resource: Type[base.VertexAiResourceNounWithFutureManager]
) -> str:
return resource.display_name
def delete(self, resource):
@@ -74,12 +77,33 @@ class VertexAIResourceCleanupManager(ResourceCleanupManager):
class DatasetResourceCleanupManager(VertexAIResourceCleanupManager):
vertex_ai_resource = aiplatform.datasets._Dataset
dataset_types = [
aiplatform.ImageDataset,
aiplatform.TabularDataset,
aiplatform.TextDataset,
aiplatform.TimeSeriesDataset,
aiplatform.VideoDataset,
]
def list(self) -> Any:
return [
dataset
for dataset_type in self.dataset_types
for dataset in dataset_type.list()
]
class EndpointResourceCleanupManager(VertexAIResourceCleanupManager):
vertex_ai_resource = aiplatform.Endpoint
def delete(self, resource):
# TODO: Remove this once https://github.com/googleapis/python-aiplatform/issues/1441 is fixed
resource._sync_gca_resource()
for deployed_model_id in [
models.id for models in resource._gca_resource.deployed_models
]:
resource._undeploy(deployed_model_id=deployed_model_id)
resource.delete(force=True)
+10 -1
View File
@@ -17,6 +17,7 @@
import argparse
import pathlib
import execute_changed_notebooks_helper
@@ -73,6 +74,13 @@ parser.add_argument(
help="The GCP directory for storing executed notebooks.",
required=True,
)
parser.add_argument(
"--timeout",
type=int,
help="Timeout in seconds",
default=86400,
required=False,
)
parser.add_argument(
"--private_pool_id",
type=str,
@@ -102,6 +110,7 @@ execute_changed_notebooks_helper.process_and_execute_notebooks(
artifacts_bucket=args.artifacts_bucket,
variable_project_id=args.variable_project_id,
variable_region=args.variable_region,
private_pool_id=args.private_pool_id if not "default" else None,
private_pool_id=args.private_pool_id,
should_parallelize=args.should_parallelize,
timeout=args.timeout,
)
+122 -51
View File
@@ -17,18 +17,24 @@ import concurrent
import dataclasses
import datetime
import functools
import git
import operator
import os
import pathlib
import nbformat
import re
import subprocess
from typing import List, Optional
from tabulate import tabulate
import operator
import execute_notebook_helper
import execute_notebook_remote
from utils import util, NotebookProcessors
import nbformat
from google.cloud.devtools.cloudbuild_v1.types import BuildOperationMetadata
from ratemate import RateLimit
from tabulate import tabulate
from utils import NotebookProcessors, util
# A buffer so that workers finish before the orchestrating job
WORKER_TIMEOUT_BUFFER_IN_SECONDS: int = 60 * 60
def format_timedelta(delta: datetime.timedelta) -> str:
@@ -103,6 +109,9 @@ def _create_tag(filepath: str) -> str:
return tag
rate_limit = RateLimit(max_count=50, per=60, greedy=True)
def process_and_execute_notebook(
container_uri: str,
staging_bucket: str,
@@ -110,9 +119,12 @@ def process_and_execute_notebook(
variable_project_id: str,
variable_region: str,
private_pool_id: Optional[str],
deadline: datetime,
notebook: str,
should_get_tail_logs: bool = False,
) -> NotebookExecutionResult:
rate_limit.wait() # wait before creating the task
print(f"Running notebook: {notebook}")
# Create paths
@@ -145,14 +157,20 @@ def process_and_execute_notebook(
# Upload the pre-processed code to a GCS bucket
code_archive_uri = util.archive_code_and_upload(staging_bucket=staging_bucket)
# Calculate timeout in seconds
timeout_in_seconds = max(
int((deadline - datetime.datetime.now()).total_seconds()), 1
)
operation = execute_notebook_remote.execute_notebook_remote(
code_archive_uri=code_archive_uri,
notebook_uri=notebook,
notebook_output_uri=notebook_output_uri,
container_uri=container_uri,
tag=tag,
region=variable_region,
private_pool_id=private_pool_id,
private_pool_region=variable_region,
timeout_in_seconds=timeout_in_seconds,
)
operation_metadata = BuildOperationMetadata(mapping=operation.metadata)
@@ -215,20 +233,39 @@ def get_changed_notebooks(
# Find notebooks
notebooks = []
# Instantiate GitPython objects
repo = git.Repo(os.getcwd())
index = repo.index
if base_branch:
print(f"Looking for notebooks that changed from branch: {base_branch}")
notebooks = subprocess.check_output(
["git", "diff", "--name-only", f"origin/{base_branch}..."] + test_paths
)
# Get the point at which this branch branches off from main
branching_commits = repo.merge_base("HEAD", f"origin/{base_branch}")
if len(branching_commits) > 0:
branching_commit = branching_commits[0]
print(f"Looking for notebooks that changed from branch: {branching_commit}")
notebooks = [
diff.b_path
for diff in index.diff(branching_commit, paths=test_paths)
if diff.b_path is not None
]
else:
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 = [notebook for notebook in notebooks if notebook.endswith(".ipynb")]
notebooks = [notebook for notebook in notebooks if len(notebook) > 0]
notebooks = [notebook for notebook in notebooks if pathlib.Path(notebook).exists()]
if len(notebooks) > 0:
print(f"Found {len(notebooks)} notebooks:")
for notebook in notebooks:
print(f"\t{notebook}")
return notebooks
@@ -241,6 +278,7 @@ def process_and_execute_notebooks(
variable_region: str,
private_pool_id: Optional[str],
should_parallelize: bool,
timeout: int,
):
"""
Run the notebooks that exist under the folders defined in the test_paths_file.
@@ -267,17 +305,27 @@ def process_and_execute_notebooks(
Required. The value for REGION to inject into notebooks.
should_parallelize (bool):
Required. Should run notebooks in parallel using a thread pool as opposed to in sequence.
timeout (str):
Required. Timeout string according to https://cloud.google.com/build/docs/build-config-file-schema#timeout.
"""
notebook_execution_results: List[NotebookExecutionResult] = []
if len(notebooks) > 0:
# Calculate deadline
deadline = datetime.datetime.now() + datetime.timedelta(
seconds=max(timeout - WORKER_TIMEOUT_BUFFER_IN_SECONDS, 0)
)
if len(notebooks) > 1:
notebook_execution_results: List[NotebookExecutionResult] = []
print(f"Found {len(notebooks)} modified notebooks: {notebooks}")
if should_parallelize and len(notebooks) > 1:
print(
"Running notebooks in parallel, so no logs will be displayed. Please wait..."
)
with concurrent.futures.ThreadPoolExecutor(max_workers=None) as executor:
with concurrent.futures.ThreadPoolExecutor(max_workers=100) as executor:
print(f"Max workers: {executor._max_workers}")
notebook_execution_results = list(
executor.map(
functools.partial(
@@ -288,6 +336,7 @@ def process_and_execute_notebooks(
variable_project_id,
variable_region,
private_pool_id,
deadline,
),
notebooks,
)
@@ -301,47 +350,69 @@ def process_and_execute_notebooks(
variable_project_id=variable_project_id,
variable_region=variable_region,
private_pool_id=private_pool_id,
deadline=deadline,
notebook=notebook,
)
for notebook in notebooks
]
print("\n=== RESULTS ===\n")
results_sorted = sorted(
notebook_execution_results,
key=lambda result: result.is_pass,
reverse=True,
)
# Print results
print(
tabulate(
[
[
result.name,
"PASSED" if result.is_pass else "FAILED",
format_timedelta(result.duration),
result.log_url,
result.output_uri,
]
for result in results_sorted
],
headers=["build_tag", "status", "duration", "log_url", "output_url"],
)
)
print("\n=== END RESULTS===\n")
total_notebook_duration = functools.reduce(
operator.add,
[datetime.timedelta(seconds=0)]
+ [result.duration for result in results_sorted],
)
print(
f"Cumulative notebook duration: {format_timedelta(total_notebook_duration)}"
)
# Raise error if any notebooks failed
if not all([result.is_pass for result in results_sorted]):
raise RuntimeError("Notebook failures detected. See logs for details")
elif len(notebooks) == 1:
notebook = notebooks[0]
# Pre-process notebook by substituting variable names
_process_notebook(
notebook_path=notebook,
variable_project_id=variable_project_id,
variable_region=variable_region,
)
execute_notebook_helper.execute_notebook(
notebook_source=notebook,
output_file_or_uri="/".join(
[artifacts_bucket, pathlib.Path(notebook).name]
),
should_log_output=True,
)
else:
print("No notebooks modified in this pull request.")
print("\n=== RESULTS ===\n")
results_sorted = sorted(
notebook_execution_results,
key=lambda result: result.is_pass,
reverse=True,
)
# Print results
print(
tabulate(
[
[
result.name,
"PASSED" if result.is_pass else "FAILED",
format_timedelta(result.duration),
result.log_url,
]
for result in results_sorted
],
headers=["build_tag", "status", "duration", "log_url"],
)
)
print("\n=== END RESULTS===\n")
total_notebook_duration = functools.reduce(
operator.add,
[datetime.timedelta(seconds=0)]
+ [result.duration for result in results_sorted],
)
print(f"Cumulative notebook duration: {format_timedelta(total_notebook_duration)}")
# Raise error if any notebooks failed
if not all([result.is_pass for result in results_sorted]):
raise RuntimeError("Notebook failures detected. See logs for details")
+1
View File
@@ -16,6 +16,7 @@
"""A CLI to download (optional) and run a single notebook locally"""
import argparse
import execute_notebook_helper
parser = argparse.ArgumentParser(description="Run a single notebook locally.")
+4 -4
View File
@@ -15,14 +15,14 @@
"""Methods to run a notebook locally"""
import sys
import os
import errno
import papermill as pm
import os
import shutil
import sys
from utils import util
import papermill as pm
from google.cloud.aiplatform import utils
from utils import util
# This script is used to execute a notebook and write out the output notebook.
+18 -19
View File
@@ -16,22 +16,18 @@
"""Methods to run a notebook on Google Cloud Build"""
from re import sub
from typing import Optional
import google.auth
import yaml
from google.api_core import client_options, operation
from google.cloud.aiplatform import utils
from google.cloud.devtools import cloudbuild_v1
from google.cloud.devtools.cloudbuild_v1.types import Source, StorageSource
from google.protobuf import duration_pb2
from yaml.loader import FullLoader
import google.auth
from google.cloud.devtools import cloudbuild_v1
from google.cloud.devtools.cloudbuild_v1.types import Source, StorageSource
from typing import Optional
import yaml
from google.cloud.aiplatform import utils
from google.api_core import operation, client_options
CLOUD_BUILD_FILEPATH = ".cloud-build/notebook-execution-test-cloudbuild-single.yaml"
TIMEOUT_IN_SECONDS = 86400
SERVICE_BASE_PATH = "cloudbuild.googleapis.com"
@@ -40,12 +36,14 @@ def execute_notebook_remote(
notebook_uri: str,
notebook_output_uri: str,
container_uri: str,
region: str,
private_pool_id: Optional[str],
private_pool_region: Optional[str],
tag: Optional[str],
timeout_in_seconds: Optional[int] = None,
) -> operation.Operation:
"""Create and execute a single notebook on Google Cloud Build"""
# Load build steps from YAML
cloudbuild_config = yaml.load(open(CLOUD_BUILD_FILEPATH), Loader=FullLoader)
substitutions = {
@@ -57,13 +55,14 @@ def execute_notebook_remote(
build = cloudbuild_v1.Build()
options: Optional[client_options.ClientOptions] = None
if private_pool_id:
substitutions["_PRIVATE_POOL_NAME"] = private_pool_id
build.options = cloudbuild_config["options"]
if private_pool_id and private_pool_region:
# substitutions["_PRIVATE_POOL_NAME"] = private_pool_id
build.options = cloudbuild_config.get("options")
build.options.pool = {"name": private_pool_id}
# Switch to the regional endpoint of the pool
options = client_options.ClientOptions(
api_endpoint=f"{region}-{SERVICE_BASE_PATH}"
api_endpoint=f"{private_pool_region}-{SERVICE_BASE_PATH}"
)
# Authorize the client with Google defaults
@@ -85,8 +84,8 @@ def execute_notebook_remote(
build.steps = cloudbuild_config["steps"]
build.substitutions = substitutions
build.timeout = duration_pb2.Duration(seconds=TIMEOUT_IN_SECONDS)
build.queue_ttl = duration_pb2.Duration(seconds=TIMEOUT_IN_SECONDS)
build.timeout = duration_pb2.Duration(seconds=timeout_in_seconds)
build.queue_ttl = duration_pb2.Duration(seconds=timeout_in_seconds)
if tag:
build.tags = [tag]
@@ -25,7 +25,4 @@ steps:
- 'python3 -m pip install -U pip && python3 -m pip freeze && 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
options:
pool:
name: ${_PRIVATE_POOL_NAME}
timeout: 86400s
@@ -11,12 +11,9 @@ steps:
args:
- -c
- 'python3 .cloud-build/CheckPythonVersion.py'
# Fetch base branch if required
- name: ${_PYTHON_IMAGE}
entrypoint: /bin/sh
args:
- -c
- 'if [ -n "${_BASE_BRANCH}" ]; then git fetch origin "${_BASE_BRANCH}":refs/remotes/origin/"${_BASE_BRANCH}"; else echo "Skipping fetch."; fi'
# Fetch full repo for diff purposes
- name: gcr.io/cloud-builders/git
args: [fetch, --unshallow]
# Install Python dependencies
- name: ${_PYTHON_IMAGE}
entrypoint: /bin/sh
+2 -1
View File
@@ -9,4 +9,5 @@ tabulate
google-cloud-aiplatform
google-cloud-storage
google-cloud-build
gcloud
ratemate
GitPython
-1
View File
@@ -1,3 +1,2 @@
notebooks/official
notebooks/notebook_template.ipynb
notebooks/community/ml_ops
+4 -2
View File
@@ -13,8 +13,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from nbconvert.preprocessors import Preprocessor
from typing import Dict
from nbconvert.preprocessors import Preprocessor
from . import UpdateNotebookVariables as update_notebook_variables
@@ -60,4 +62,4 @@ class UpdateVariablesPreprocessor(Preprocessor):
executable_cells.append(cell)
notebook.cells = executable_cells
return notebook, resources
return notebook, resources
@@ -78,4 +78,4 @@ def test_region():
variable_name="REGION",
variable_value="us-central1",
)
assert new_content == 'REGION = "us-central1" # @param {type:"string"}'
assert new_content == 'REGION = "us-central1" # @param {type:"string"}'
+7 -7
View File
@@ -1,13 +1,13 @@
from datetime import datetime
from typing import Optional
from google.cloud import storage
from google.cloud.aiplatform import utils
from google.auth import credentials as auth_credentials
import os
import subprocess
import tarfile
import uuid
from datetime import datetime
from typing import Optional
from google.auth import credentials as auth_credentials
from google.cloud import storage
from google.cloud.aiplatform import utils
def download_file(bucket_name: str, blob_name: str, destination_file: str) -> str:
@@ -57,4 +57,4 @@ def archive_code_and_upload(staging_bucket: str):
print(f"Uploaded source code archive to {source_archived_file_gcs}")
return source_archived_file_gcs
return source_archived_file_gcs
+6 -6
View File
@@ -2,17 +2,17 @@ If you are opening a PR for `Official Notebooks` under the [notebooks/official](
- [ ] 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.
- [ ] Passes all the required automated checks. You can locally test for formatting and linting with these [instructions](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/docs/contributing.md#code-quality-checks).
- [ ] Passes all the required automated checks. You can locally test for formatting and linting with these [instructions](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/CONTRIBUTING.md#code-quality-checks).
- [ ] You have consulted with a tech writer to see if tech writer review is necessary. If so, the notebook has been reviewed by a tech writer, and they have approved it.
- [ ] This notebook has been added to the [CODEOWNERS](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/docs/CODEOWNERS) file under `# Official Notebooks` section, pointing to the author or the author's team.
- [ ] 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.
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/docs/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/docs/contributing.md#code-quality-checks).
- [ ] 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:
- [ ] 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/docs/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/docs/contributing.md#code-quality-checks).
- [ ] 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).
+3 -1
View File
@@ -7,7 +7,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Set up Python
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Fetch pull request branch
uses: actions/checkout@v3
with:
+2 -1
View File
@@ -3,7 +3,8 @@ ipython
jupyter
nbconvert
black==22.3.0
pyupgrade==2.31.1
pyupgrade==2.34.0
isort==5.10.1
flake8==4.0.1
nbqa==1.3.1
+1 -1
View File
@@ -48,8 +48,8 @@ then you will need to manually address them before submitting your PR.
nbqa black "$notebook"
nbqa pyupgrade "$notebook"
nbqa isort "$notebook"
python3 -m tensorflow_docs.tools.nbfmt --remove_outputs "$notebook"
nbqa flake8 "$notebook" --extend-ignore=W391,E501,F821,E402,F404,W503,E203,E722,W293,W291
python3 -m tensorflow_docs.tools.nbfmt --remove_outputs "$notebook"
```
## Code Reviews
@@ -1,4 +1,4 @@
google-cloud-bigquery==2.20.0
tensorflow==2.5.3
tensorflow==2.7.2
pillow==9.0.1
tf-agents==0.8.0
@@ -1,4 +1,4 @@
google-cloud-pubsub==2.5.0
pillow==9.0.1
tf-agents==0.8.0
tensorflow==2.5.3
tensorflow==2.7.2
@@ -1,5 +1,5 @@
dataclasses==0.6
google-cloud-aiplatform==1.8.1
tensorflow==2.5.3
tensorflow==2.7.2
pillow==9.0.1
tf-agents==0.8.0
@@ -1 +1 @@
tensorflow==2.5.3
tensorflow==2.7.2
+2 -2
View File
@@ -1,5 +1,5 @@
The [official](https://github.com/GoogleCloudPlatform/vertex-ai-samples/tree/main/notebooks/official) folder contains notebooks organized by Google Cloud product.
The [official](https://github.com/GoogleCloudPlatform/vertex-ai-samples/tree/main/notebooks/official) folder contains notebooks organized by Google Cloud product. These are tested weekly and maintained by Google.
The [community](https://github.com/GoogleCloudPlatform/vertex-ai-samples/tree/main/notebooks/community) folder contains notebooks that aren't officially supported by Google.
The [community](https://github.com/GoogleCloudPlatform/vertex-ai-samples/tree/main/notebooks/community) folder contains notebooks that may be created by Google or external contributors. They are not necessary maintained.
Contributions to the repo should use the [notebook template](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/notebook_template.ipynb) as a starting point.
+2
View File
@@ -12,6 +12,7 @@
/managed_notebooks/
/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
/matching_engine/sdk_matching_engine_for_indexing.ipynb @ivanmkc
/matching_engine/matching_engine_for_indexing.ipynb @yinghsienwu
/sdk/pytorch_lightning_custom_container_training.ipynb @brianchunkang
@@ -20,3 +21,4 @@
/vertex_endpoints/tf_hub_obj_detection/deploy_tfhub_object_detection_on_vertex_endpoints.ipynb @entrpn
/vertex_endpoints/nvidia-triton/nvidia-triton-custom-container-prediction.ipynb @RajeshThallam
/vertex_endpoints/optimized_tensorflow_runtime @vlasenkoalexey
/notebooks/community/ml_ops/stage2/get_started_with_visionapi_and_automl.ipynb @mansari
File diff suppressed because it is too large Load Diff
Binary file not shown.

Before

Width:  |  Height:  |  Size: 122 KiB

After

Width:  |  Height:  |  Size: 140 KiB

@@ -32,18 +32,18 @@
"<table align=\"left\">\n",
"\n",
" <td>\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/notebook_template.ipynb\">\n",
" <a href=\"https://colab.research.google.com/github/vertex-ai-samples/blob/main/notebooks/community/feature_store/mobile_gaming/mobile_gaming_feature_store.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/colab-logo-32px.png\" alt=\"Colab logo\"> Run in Colab\n",
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/notebook_template.ipynb\">\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/feature_store/mobile_gaming/mobile_gaming_feature_store.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/github-logo-32px.png\" alt=\"GitHub logo\">\n",
" View on GitHub\n",
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/notebook_template.ipynb\">\n",
" <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://raw.githubusercontent.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/feature_store/mobile_gaming/mobile_gaming_feature_store.ipynb\">\n",
" <img src=\"https://lh3.googleusercontent.com/UiNooY4LUgW_oTvpsNhPpQzsstV5W8F7rYgxgGBD85cWJoLmrOzhVs_ksK_vgx40SHs7jCqkTkCk=e14-rj-sc0xffffff-h130-w32\" alt=\"Vertex AI logo\">\n",
" Open in Vertex AI Workbench\n",
" </a>\n",
@@ -54,52 +54,52 @@
{
"cell_type": "markdown",
"metadata": {
"id": "7FZeBEwdXS4d"
"id": "tvgnzT1CKxrO"
},
"source": [
"## Overview\n",
"\n",
"Imagine you are a member of the Data Science team working on the same Mobile Gaming application reported in the [Churn prediction for game developers using Google Analytics 4 (GA4) and BigQuery ML](https://cloud.google.com/blog/topics/developers-practitioners/churn-prediction-game-developers-using-google-analytics-4-ga4-and-bigquery-ml) blog post. \n",
"\n",
"Business wants to use that information in real-time to take immediate intervention actions in-game to prevent churn. In particular, for each player, they want to provide gaming incentives like new items or bonus packs depending on the customer demographic, behavioral information and the resulting propensity of return. \n",
"\n",
"Last year, Google Cloud announced Vertex AI, a managed machine learning (ML) platform that allows data science teams to accelerate the deployment and maintenance of ML models. One of the platform building blocks is Vertex AI Feature store which provides a managed service for low latency scalable feature serving. Also it is a centralized feature repository with easy APIs to search & discover features and feature monitoring capabilities to track drift and other quality issues. \n",
"\n",
"In this notebook, we will show how the role of Vertex AI Feature Store in a ready to production scenario when the user's activities within the first 24 hours of last engagment and the gaming platform would consume in order to improver UX. Below you can find the high level picture of the system\n",
"\n",
" \n",
"Imagine you are a member of the Data Science team working on the same Mobile Gaming application reported in the [Churn prediction for game developers using Google Analytics 4 (GA4) and BigQuery ML](https://cloud.google.com/blog/topics/developers-practitioners/churn-prediction-game-developers-using-google-analytics-4-ga4-and-bigquery-ml) blog post.\n",
" \n",
"Business wants to use that information in real-time to take immediate intervention actions in-game to prevent churn. In particular, for each player, they want to provide gaming incentives like new items or bonus packs depending on the customer demographic, behavioral information and the resulting propensity of return.\n",
" \n",
"Last year, Google Cloud announced Vertex AI, a managed machine learning (ML) platform that allows data science teams to accelerate the deployment and maintenance of ML models. One of the platform building blocks is Vertex AI Feature store which provides a managed service for low latency scalable feature serving. Also it is a centralized feature repository with easy APIs to search & discover features and feature monitoring capabilities to track drift and other quality issues.\n",
" \n",
"In this notebook, we will show how the role of Vertex AI Feature Store in a ready to production scenario when the user's activities within the first 24 hours of last engagement and the gaming platform would consume in order to improve UX. Below you can find the high level picture of the system\n",
" \n",
"<img src=\"./assets/mobile_gaming_architecture_1.png\">\n",
"\n",
"\n",
" \n",
" \n",
"### Dataset\n",
"\n",
" \n",
"The dataset is the public sample export data from an actual mobile game app called \"Flood It!\" (Android, iOS)\n",
"\n",
" \n",
"### Objective\n",
"\n",
" \n",
"In the following notebook, you will learn how Vertex AI Feature store\n",
"\n",
"1. Provide a centralized feature repository with easy APIs to search & discover features and fetch them for training/serving. \n",
"\n",
"2. Simplify deployments of models for Online Prediction, via low latency scalable feature serving.\n",
"\n",
"3. Mitigate training serving skew and data leakage by performing point in time lookups to fetch historical data for training.\n",
"\n",
" \n",
"1. Provide a centralized feature repository with easy APIs to search & discover features and fetch them for training/serving.\n",
" \n",
"2. Simplify deployments of models for Online Prediction, via low latency scalable feature serving.\n",
" \n",
"3. Mitigate training serving skew and data leakage by performing point in time lookups to fetch historical data for training.\n",
" \n",
"**Notice that we assume that already know how to set up a Vertex AI Feature store. In case you are not, please check out [this detailed notebook](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/feature_store/gapic-feature-store.ipynb).**\n",
"\n",
"\n",
"### Costs \n",
"\n",
" \n",
" \n",
"### Costs\n",
" \n",
"This tutorial uses billable components of Google Cloud:\n",
"\n",
" \n",
"* Vertex AI\n",
"* BigQuery\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."
"to generate a cost estimate based on your projected usage.\n"
]
},
{
@@ -110,7 +110,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."
]
},
@@ -159,7 +159,7 @@
"source": [
"### Install additional packages\n",
"\n",
"Install additional package dependencies not installed in your notebook environment, such as {XGBoost, AdaNet, or TensorFlow Hub TODO: Replace with relevant packages for the tutorial}. Use the latest major GA version of each package."
"Install additional package dependencies not installed in your notebook environment, such as XGBoost. Use the latest major GA version of each package."
]
},
{
@@ -172,12 +172,15 @@
"source": [
"import os\n",
"\n",
"# The Google Cloud Notebook product has specific requirements\n",
"IS_GOOGLE_CLOUD_NOTEBOOK = os.path.exists(\"/opt/deeplearning/metadata/env_version\")\n",
"# The Vertex AI Workbench Notebook product has specific requirements\n",
"IS_WORKBENCH_NOTEBOOK = os.getenv(\"DL_ANACONDA_HOME\")\n",
"IS_USER_MANAGED_WORKBENCH_NOTEBOOK = os.path.exists(\n",
" \"/opt/deeplearning/metadata/env_version\"\n",
")\n",
"\n",
"# Google Cloud Notebook requires dependencies to be installed with '--user'\n",
"# Vertex AI Notebook requires dependencies to be installed with '--user'\n",
"USER_FLAG = \"\"\n",
"if IS_GOOGLE_CLOUD_NOTEBOOK:\n",
"if IS_WORKBENCH_NOTEBOOK:\n",
" USER_FLAG = \"--user\""
]
},
@@ -185,11 +188,11 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "SzEo6DeE2GOP"
"id": "_vr6BYED_5my"
},
"outputs": [],
"source": [
"! pip3 install {USER_FLAG} --upgrade pip\n",
"! pip3 install {USER_FLAG} --upgrade pip -q\n",
"! pip3 install {USER_FLAG} --upgrade google-cloud-aiplatform==1.11.0 -q --no-warn-conflicts\n",
"! pip3 install {USER_FLAG} git+https://github.com/googleapis/python-aiplatform.git@main # For features monitoring\n",
"! pip3 install {USER_FLAG} --upgrade google-cloud-bigquery==2.24.0 -q --no-warn-conflicts\n",
@@ -249,7 +252,7 @@
"\n",
"1. [Make sure that billing is enabled for your project](https://cloud.google.com/billing/docs/how-to/modify-project).\n",
"\n",
"1. [Enable the Vertex AI API and Compute Engine API](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com,compute_component). \n",
"1. [Enable the APIs](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com,notebooks.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",
"\n",
@@ -307,18 +310,76 @@
"outputs": [],
"source": [
"if PROJECT_ID == \"\" or PROJECT_ID is None:\n",
" PROJECT_ID = \"\" # @param {type:\"string\"}"
" PROJECT_ID = \"[your-project-id]\" # @param {type:\"string\"}"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "dEjRdjxBuDsi"
"id": "set_gcloud_project_id"
},
"outputs": [],
"source": [
"!gcloud config set project $PROJECT_ID #change it"
"! gcloud config set project $PROJECT_ID"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "23988890fef6"
},
"source": [
"#### Get your project number (Optional)\n",
"\n",
"Now that the project ID is set, you get your corresponding project number."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "2d6950574e1d"
},
"outputs": [],
"source": [
"shell_output = ! gcloud projects list --filter=\"PROJECT_ID:'{PROJECT_ID}'\" --format='value(PROJECT_NUMBER)'\n",
"PROJECT_NUMBER = shell_output[0]\n",
"print(\"Project Number:\", PROJECT_NUMBER)"
]
},
{
"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": "jIcZV7-C2RrX"
},
"outputs": [],
"source": [
"REGION = \"[your-region]\" # @param {type: \"string\"}\n",
"\n",
"if REGION == \"[your-region]\":\n",
" REGION = \"us-central1\""
]
},
{
@@ -353,7 +414,7 @@
"source": [
"### Authenticate your Google Cloud account\n",
"\n",
"**If you are using Google Cloud Notebooks**, your environment is already\n",
"**If you are using Vertex AI Workbench Notebooks**, your environment is already\n",
"authenticated. Skip this step."
]
},
@@ -376,9 +437,13 @@
"3. In the **Service account name** field, enter a name, and\n",
" click **Create**.\n",
"\n",
"4. In the **Grant this service account access to project** section, click the **Role** drop-down list. Type \"Vertex AI\"\n",
"into the filter box, and select\n",
" **Vertex AI Administrator**. Type \"Storage Object Admin\" into the filter box, and select **Storage Object Admin**.\n",
"4. In the **Grant this service account access to project** section, click the **Role** drop-down list and add the following roles:\n",
" - BigQuery Admin\n",
" - Storage Admin\n",
" - Storage Object Admin\n",
" - Vertex AI Administrator\n",
" - Vertex AI Feature Store Admin\n",
"\n",
"\n",
"5. Click *Create*. A JSON file that contains your key downloads to your\n",
"local environment.\n",
@@ -395,19 +460,19 @@
},
"outputs": [],
"source": [
"import os\n",
"import sys\n",
"\n",
"# If you are running this notebook in Colab, run this cell and follow the\n",
"# instructions to authenticate your GCP account. This provides access to your\n",
"# Cloud Storage bucket and lets you submit training jobs and prediction\n",
"# requests.\n",
"\n",
"# The Google Cloud Notebook product has specific requirements\n",
"IS_GOOGLE_CLOUD_NOTEBOOK = os.path.exists(\"/opt/deeplearning/metadata/env_version\")\n",
"import os\n",
"import sys\n",
"\n",
"# If on Google Cloud Notebooks, then don't execute this code\n",
"if not IS_GOOGLE_CLOUD_NOTEBOOK:\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",
@@ -447,8 +512,8 @@
},
"outputs": [],
"source": [
"BUCKET_URI = \"gs://[your-bucket-name]\" # @param {type:\"string\"}\n",
"REGION = \"[your-region]\" # @param {type:\"string\"}"
"BUCKET_NAME = \"[your-bucket-name]\" # @param {type:\"string\"}\n",
"BUCKET_URI = f\"gs://{BUCKET_NAME}\""
]
},
{
@@ -459,11 +524,9 @@
},
"outputs": [],
"source": [
"if BUCKET_URI == \"\" or BUCKET_URI is None or BUCKET_URI == \"gs://[your-bucket-name]\":\n",
" BUCKET_URI = \"gs://\" + PROJECT_ID + \"-aip-\" + TIMESTAMP\n",
"\n",
"if REGION == \"[your-region]\":\n",
" REGION = \"us-central1\""
"if BUCKET_NAME == \"\" or BUCKET_NAME is None or BUCKET_NAME == \"[your-bucket-name]\":\n",
" BUCKET_NAME = PROJECT_ID + \"-aip-\" + TIMESTAMP\n",
" BUCKET_URI = f\"gs://{BUCKET_NAME}\""
]
},
{
@@ -486,26 +549,6 @@
"! gsutil mb -l $REGION -p $PROJECT_ID $BUCKET_URI"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "994afa65eaa2"
},
"source": [
"Run the following cell to grant access to your Cloud Storage resources from Vertex AI Feature store"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "psP1rPU9TRnX"
},
"outputs": [],
"source": [
"! gsutil uniformbucketlevelaccess set on $BUCKET_URI"
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -526,6 +569,78 @@
"! gsutil ls -al $BUCKET_URI"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "set_service_account"
},
"source": [
"#### Service Account (Optional)\n",
"\n",
"If you do not want to use your project's Compute Engine service account, set `SERVICE_ACCOUNT` to another service account ID."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "MQVV9haf2Rra"
},
"outputs": [],
"source": [
"SERVICE_ACCOUNT = \"[your-service-account]\" # @param {type:\"string\"}"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "autoset_service_account"
},
"outputs": [],
"source": [
"if (\n",
" SERVICE_ACCOUNT == \"\"\n",
" or SERVICE_ACCOUNT is None\n",
" or SERVICE_ACCOUNT == \"[your-service-account]\"\n",
"):\n",
" # Get your service account from gcloud\n",
" if not IS_COLAB:\n",
" shell_output = !gcloud auth list 2>/dev/null\n",
" SERVICE_ACCOUNT = shell_output[2].replace(\"*\", \"\").strip()\n",
"\n",
" else: # IS_COLAB:\n",
" shell_output = ! gcloud projects describe $PROJECT_ID\n",
" project_number = shell_output[-1].split(\":\")[1].strip().replace(\"'\", \"\")\n",
" SERVICE_ACCOUNT = f\"{project_number}-compute@developer.gserviceaccount.com\"\n",
"\n",
" print(\"Service Account:\", SERVICE_ACCOUNT)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "set_service_account:pipelines"
},
"source": [
"#### Set service account access\n",
"\n",
"Run the following commands to grant your service account access. You only need to run this step once per service account."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "U4UpQThc2Rrb"
},
"outputs": [],
"source": [
"! gsutil iam ch serviceAccount:{SERVICE_ACCOUNT}:roles/storage.objectCreator $BUCKET_URI\n",
"\n",
"! gsutil iam ch serviceAccount:{SERVICE_ACCOUNT}:roles/storage.objectViewer $BUCKET_URI"
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -541,13 +656,22 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "G3G2BXqswb_J"
"id": "8615339fa4ca"
},
"outputs": [],
"source": [
"BQ_DATASET = \"Mobile_Gaming\" # @param {type:\"string\"}\n",
"LOCATION = \"US\"\n",
"\n",
"LOCATION = \"US\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "G3G2BXqswb_J"
},
"outputs": [],
"source": [
"!bq mk --location=$LOCATION --dataset $PROJECT_ID:$BQ_DATASET"
]
},
@@ -600,12 +724,9 @@
"outputs": [],
"source": [
"# Data Engineering and Feature Engineering\n",
"TODAY = \"2018-10-03\"\n",
"TOMORROW = \"2018-10-04\"\n",
"TODAY = \"2022-06-16\"\n",
"LABEL_TABLE = f\"label_table_{TODAY}\".replace(\"-\", \"\")\n",
"FEATURES_TABLE = \"wide_features_table\" # @param {type:\"string\"}\n",
"FEATURES_TABLE_TODAY = f\"wide_features_table_{TODAY}\".replace(\"-\", \"\")\n",
"FEATURES_TABLE_TOMORROW = f\"wide_features_table_{TOMORROW}\".replace(\"-\", \"\")\n",
"FEATURES_TABLE = f\"wide_features_table_{TODAY}\" # @param {type:\"string\"}\n",
"FEATURESTORE_ID = \"mobile_gaming\" # @param {type:\"string\"}\n",
"ENTITY_TYPE_ID = \"user\"\n",
"\n",
@@ -947,13 +1068,37 @@
"You will cover those steps in details below."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "init_aip:mbsdk,all"
},
"source": [
"### Initialize Vertex AI SDK for Python\n",
"\n",
"Initialize the Vertex AI SDK for Python for your project and corresponding bucket."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "poLJ0fV52Rrc"
},
"outputs": [],
"source": [
"vertex_ai.init(project=PROJECT_ID, location=REGION, staging_bucket=BUCKET_URI)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "4ffd54e97270"
},
"source": [
"## Initiate clients"
"### Initialize BigQuery SDK for Python\n",
"\n",
"Initialize the BigQuery AI SDK for Python for your project and corresponding bucket."
]
},
{
@@ -964,55 +1109,53 @@
},
"outputs": [],
"source": [
"bq_client = bigquery.Client(project=PROJECT_ID, location=LOCATION)\n",
"vertex_ai.init(project=PROJECT_ID, location=REGION, staging_bucket=BUCKET_URI)"
"bq_client = bigquery.Client(project=PROJECT_ID, location=LOCATION)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "zmMWIpCwsET9"
"id": "WnUQO2IHC9pZ"
},
"source": [
"## Identify users and build your features\n",
"\n",
"This section we will static features we want to fetch from Vertex AI Feature Store. In particular, we will cover the following steps:\n",
"\n",
" \n",
"This section we will have static features we want to fetch from Vertex AI Feature Store. In particular, we will cover the following steps:\n",
" \n",
"1. Identify users, process demographic features and process behavioral features within the last 24 hours using **BigQuery**\n",
"\n",
" \n",
"2. Set up the feature store\n",
"\n",
" \n",
"3. Register features using **Vertex AI Feature Store** and the SDK.\n",
"\n",
"Below you have a picture that shows the process. \n",
"\n",
" \n",
"Below you have a picture that shows the process.\n",
" \n",
"<img src=\"./assets/feature_store_ingestion_2.png\">\n",
"\n",
"\n",
"\n",
"The original dataset contains raw event data we cannot ingest in the feature store as they are. We need to pre-process the raw data in order to get user features. \n",
"\n",
"**Notice we simulate those transformations in different point of time (today and tomorrow).**\n"
" \n",
" \n",
"The original dataset contains raw event data we cannot ingest in the feature store as they are. We need to pre-process the raw data in order to get user features.\n",
" \n",
"**Notice we simulate those transformations in different points of time (today and tomorrow).**\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "8avYy5QOv02s"
"id": "e9zIrwhpDF2q"
},
"source": [
"### Label, Demographic and Behavioral Transformations\n",
"\n",
"This section is based on the [Churn prediction for game developers using Google Analytics 4 (GA4) and BigQuery ML](https://cloud.google.com/blog/topics/developers-practitioners/churn-prediction-game-developers-using-google-analytics-4-ga4-and-bigquery-ml?utm_source=linkedin&utm_medium=unpaidsoc&utm_campaign=FY21-Q2-Google-Cloud-Tech-Blog&utm_content=google-analytics-4&utm_term=-) blog article by Minhaz Kazi and Polong Lin. \n",
"\n",
"You will adapt it in order to turn a batch churn prediction (using features within the first 24h user of first engagment) in a real-time churn prediction (using features within the first 24h user of last engagment)."
" \n",
"This section is based on the [Churn prediction for game developers using Google Analytics 4 (GA4) and BigQuery ML](https://cloud.google.com/blog/topics/developers-practitioners/churn-prediction-game-developers-using-google-analytics-4-ga4-and-bigquery-ml?utm_source=linkedin&utm_medium=unpaidsoc&utm_campaign=FY21-Q2-Google-Cloud-Tech-Blog&utm_content=google-analytics-4&utm_term=-) blog article by Minhaz Kazi and Polong Lin.\n",
" \n",
"You will adapt it to turn a batch churn prediction (using features within the first 24h user of first engagement) into a real-time churn prediction (using features within the first 6h user of last engagement).\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "YO28RAITh6L-"
"id": "RQX5m8UiC_px"
},
"outputs": [],
"source": [
@@ -1039,27 +1182,27 @@
" SELECT\n",
" event_timestamp,\n",
" user_pseudo_id,\n",
" SUM(IF(event_name = 'user_engagement', 1, 0)) OVER (PARTITION BY user_pseudo_id ORDER BY event_timestamp ASC RANGE BETWEEN 86400000000 PRECEDING\n",
" SUM(IF(event_name = 'user_engagement', 1, 0)) OVER (PARTITION BY user_pseudo_id ORDER BY event_timestamp ASC RANGE BETWEEN 21600000000 PRECEDING\n",
" AND CURRENT ROW ) AS cnt_user_engagement,\n",
" SUM(IF(event_name = 'level_start_quickplay', 1, 0)) OVER (PARTITION BY user_pseudo_id ORDER BY event_timestamp ASC RANGE BETWEEN 86400000000 PRECEDING\n",
" SUM(IF(event_name = 'level_start_quickplay', 1, 0)) OVER (PARTITION BY user_pseudo_id ORDER BY event_timestamp ASC RANGE BETWEEN 21600000000 PRECEDING\n",
" AND CURRENT ROW ) AS cnt_level_start_quickplay,\n",
" SUM(IF(event_name = 'level_end_quickplay', 1, 0)) OVER (PARTITION BY user_pseudo_id ORDER BY event_timestamp ASC RANGE BETWEEN 86400000000 PRECEDING\n",
" SUM(IF(event_name = 'level_end_quickplay', 1, 0)) OVER (PARTITION BY user_pseudo_id ORDER BY event_timestamp ASC RANGE BETWEEN 21600000000 PRECEDING\n",
" AND CURRENT ROW ) AS cnt_level_end_quickplay,\n",
" SUM(IF(event_name = 'level_complete_quickplay', 1, 0)) OVER (PARTITION BY user_pseudo_id ORDER BY event_timestamp ASC RANGE BETWEEN 86400000000 PRECEDING\n",
" SUM(IF(event_name = 'level_complete_quickplay', 1, 0)) OVER (PARTITION BY user_pseudo_id ORDER BY event_timestamp ASC RANGE BETWEEN 21600000000 PRECEDING\n",
" AND CURRENT ROW ) AS cnt_level_complete_quickplay,\n",
" SUM(IF(event_name = 'level_reset_quickplay', 1, 0)) OVER (PARTITION BY user_pseudo_id ORDER BY event_timestamp ASC RANGE BETWEEN 86400000000 PRECEDING\n",
" SUM(IF(event_name = 'level_reset_quickplay', 1, 0)) OVER (PARTITION BY user_pseudo_id ORDER BY event_timestamp ASC RANGE BETWEEN 21600000000 PRECEDING\n",
" AND CURRENT ROW ) AS cnt_level_reset_quickplay,\n",
" SUM(IF(event_name = 'post_score', 1, 0)) OVER (PARTITION BY user_pseudo_id ORDER BY event_timestamp ASC RANGE BETWEEN 86400000000 PRECEDING\n",
" SUM(IF(event_name = 'post_score', 1, 0)) OVER (PARTITION BY user_pseudo_id ORDER BY event_timestamp ASC RANGE BETWEEN 21600000000 PRECEDING\n",
" AND CURRENT ROW ) AS cnt_post_score,\n",
" SUM(IF(event_name = 'spend_virtual_currency', 1, 0)) OVER (PARTITION BY user_pseudo_id ORDER BY event_timestamp ASC RANGE BETWEEN 86400000000 PRECEDING\n",
" SUM(IF(event_name = 'spend_virtual_currency', 1, 0)) OVER (PARTITION BY user_pseudo_id ORDER BY event_timestamp ASC RANGE BETWEEN 21600000000 PRECEDING\n",
" AND CURRENT ROW ) AS cnt_spend_virtual_currency,\n",
" SUM(IF(event_name = 'ad_reward', 1, 0)) OVER (PARTITION BY user_pseudo_id ORDER BY event_timestamp ASC RANGE BETWEEN 86400000000 PRECEDING\n",
" SUM(IF(event_name = 'ad_reward', 1, 0)) OVER (PARTITION BY user_pseudo_id ORDER BY event_timestamp ASC RANGE BETWEEN 21600000000 PRECEDING\n",
" AND CURRENT ROW ) AS cnt_ad_reward,\n",
" SUM(IF(event_name = 'challenge_a_friend', 1, 0)) OVER (PARTITION BY user_pseudo_id ORDER BY event_timestamp ASC RANGE BETWEEN 86400000000 PRECEDING\n",
" SUM(IF(event_name = 'challenge_a_friend', 1, 0)) OVER (PARTITION BY user_pseudo_id ORDER BY event_timestamp ASC RANGE BETWEEN 21600000000 PRECEDING\n",
" AND CURRENT ROW ) AS cnt_challenge_a_friend,\n",
" SUM(IF(event_name = 'completed_5_levels', 1, 0)) OVER (PARTITION BY user_pseudo_id ORDER BY event_timestamp ASC RANGE BETWEEN 86400000000 PRECEDING\n",
" SUM(IF(event_name = 'completed_5_levels', 1, 0)) OVER (PARTITION BY user_pseudo_id ORDER BY event_timestamp ASC RANGE BETWEEN 21600000000 PRECEDING\n",
" AND CURRENT ROW ) AS cnt_completed_5_levels,\n",
" SUM(IF(event_name = 'use_extra_steps', 1, 0)) OVER (PARTITION BY user_pseudo_id ORDER BY event_timestamp ASC RANGE BETWEEN 86400000000 PRECEDING\n",
" SUM(IF(event_name = 'use_extra_steps', 1, 0)) OVER (PARTITION BY user_pseudo_id ORDER BY event_timestamp ASC RANGE BETWEEN 21600000000 PRECEDING\n",
" AND CURRENT ROW ) AS cnt_use_extra_steps,\n",
" FROM (\n",
" SELECT\n",
@@ -1071,7 +1214,7 @@
"\n",
"SELECT\n",
" -- PARSE_TIMESTAMP('%Y-%m-%d %H:%M:%S', CONCAT('{TODAY}', ' ', STRING(TIME_TRUNC(CURRENT_TIME(), SECOND))), 'UTC') as timestamp,\n",
" PARSE_TIMESTAMP('%Y-%m-%d %H:%M:%S', FORMAT_TIMESTAMP('%Y-%m-%d %H:%M:%S', TIMESTAMP_MICROS(beh.event_timestamp))) AS timestamp,\n",
" TIMESTAMP_ADD(PARSE_TIMESTAMP('%Y-%m-%d %H:%M:%S', FORMAT_TIMESTAMP('%Y-%m-%d %H:%M:%S', TIMESTAMP_MICROS(beh.event_timestamp))), INTERVAL 1351 DAY) AS timestamp,\n",
" dem.*,\n",
" CAST(IFNULL(beh.cnt_user_engagement, 0) AS FLOAT64) AS cnt_user_engagement,\n",
" CAST(IFNULL(beh.cnt_level_start_quickplay, 0) AS FLOAT64) AS cnt_level_start_quickplay,\n",
@@ -1097,7 +1240,7 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "Z6CjIOmDsET-"
"id": "oGYxLCSnD068"
},
"outputs": [],
"source": [
@@ -1107,31 +1250,31 @@
{
"cell_type": "markdown",
"metadata": {
"id": "Lx__2-assET-"
"id": "xQLIlsTCD_nk"
},
"source": [
"## Create a Vertex AI Feature store and ingest your features\n",
"\n",
"Now you have the wide table of features. It is time to ingest them into the feature store. \n",
"\n",
" \n",
"Now you have a wide table of features. It is time to ingest them into the feature store.\n",
" \n",
"Before to moving on, you may have a question: **Why do I need a feature store**\n",
"in this scenario at that point?\n",
"\n",
"One of the reason would be to make those features accessable across team by calculating once and reuse them many times. And in order to make it possible you need also be able to monitor those features over time to guarantee freshness and in case have a new feature engineerign run to refresh them. \n",
"\n",
"If it is not your case, I will give even more reasons about why you should consider feature store in the following sections. Just keep following me for now.\n",
"\n",
"One of the most important thing is related to its data model. As you can see in the picture below, Vertex AI Feature Store organizes resources hierarchically in the following order: `Featurestore -> EntityType -> Feature`. You must create these resources before you can ingest data into Vertex AI Feature Store.\n",
"\n",
" \n",
"One of the reasons would be to make those features accessible across teams by calculating once and reuse them many times. And in order to make it possible you need also be able to monitor those features over time to guarantee freshness and in case have a new feature engineering run to refresh them.\n",
" \n",
"If it is not your case, I will give even more reasons about why you should consider a feature store in the following sections. Just keep following me for now.\n",
" \n",
"One of the most important things is related to its data model. As you can see in the picture below, Vertex AI Feature Store organizes resources hierarchically in the following order: `Featurestore -> EntityType -> Feature`. You must create these resources before you can ingest data into Vertex AI Feature Store.\n",
" \n",
"<img src=\"./assets/feature_store_data_model_3.png\">\n",
"\n",
"In our case we are going to create **mobile_gaming** featurestore resource containing **user** entity type and all its associated **features** such as country or the number of times a user challenged a friend (cnt_challenge_a_friend)."
" \n",
"In our case we are going to create **mobile_gaming** featurestore resource containing **user** entity type and all its associated **features** such as country or the number of times a user challenged a friend (cnt_challenge_a_friend).\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "8dNlxda2sET_"
"id": "VR7BJEozED_Q"
},
"source": [
"### Create featurestore, ```mobile_gaming```\n",
@@ -1143,7 +1286,7 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "t2en8I7TSe4b"
"id": "vUFqtYU-EDTR"
},
"outputs": [],
"source": [
@@ -1164,7 +1307,7 @@
{
"cell_type": "markdown",
"metadata": {
"id": "rN-vlvPUsET_"
"id": "mUlCwfdpEHJG"
},
"source": [
"### Create the ```User``` entity type and its features\n",
@@ -1176,7 +1319,7 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "CbZ2RQ5XbuRq"
"id": "PnCU1wBND3W7"
},
"outputs": [],
"source": [
@@ -1194,7 +1337,7 @@
{
"cell_type": "markdown",
"metadata": {
"id": "B2PIAprPmnhB"
"id": "bT9LXzu1EOvW"
},
"source": [
"### Set Feature Monitoring\n",
@@ -1208,7 +1351,7 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "N6im2c3ymiwC"
"id": "8WBlYUkOERaI"
},
"outputs": [],
"source": [
@@ -1231,7 +1374,7 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "gp9xaLQXn0CS"
"id": "92X4-7PFETj5"
},
"outputs": [],
"source": [
@@ -1254,18 +1397,18 @@
{
"cell_type": "markdown",
"metadata": {
"id": "ustwKOMle8Qp"
"id": "hxAuZjt3EWFo"
},
"source": [
"### Create features\n",
"\n",
"In order to ingest features, you need to provide feature configuration and create them as featurestore resources.\n"
"In order to ingest features, you need to provide feature configuration and create them as featurestore resources."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "ijeZCTKIfCRL"
"id": "hRXO2I5VEYwt"
},
"source": [
"#### Create Feature configuration\n",
@@ -1278,7 +1421,7 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "vX_uYmjUgd9x"
"id": "K26NEYZIEbvE"
},
"outputs": [],
"source": [
@@ -1359,7 +1502,7 @@
{
"cell_type": "markdown",
"metadata": {
"id": "ErkruXPJkPuy"
"id": "FjzMd1XbEfdo"
},
"source": [
"#### Create features using `batch_create_features` method\n",
@@ -1371,7 +1514,7 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "ZsCAO_IfsEUC"
"id": "nqlgCDI9pbCD"
},
"outputs": [],
"source": [
@@ -1388,19 +1531,19 @@
{
"cell_type": "markdown",
"metadata": {
"id": "9WisJk18qqgs"
"id": "7zpFV7wAppkC"
},
"source": [
"### Search features\n",
"\n",
"Vertex AI Feature store supports serching capabilities. Below you have a simple example that show how to filter a feature based on its name. "
"Vertex AI Feature store supports searching capabilities. Below you have a simple example that shows how to filter a feature based on its name. "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "JzqyarMZqvZS"
"id": "BJXYLLOfppCL"
},
"outputs": [],
"source": [
@@ -1412,7 +1555,7 @@
{
"cell_type": "markdown",
"metadata": {
"id": "ugtBfW5gsEUD"
"id": "is9C_6-QpxG3"
},
"source": [
"## Ingest features \n",
@@ -1447,7 +1590,7 @@
" entity_id_field=ENTITY_ID_FIELD,\n",
" disable_online_serving=False,\n",
" worker_count=10,\n",
" sync=True,\n",
" sync=False,\n",
" )\n",
"except RuntimeError as error:\n",
" print(error)"
@@ -1456,7 +1599,7 @@
{
"cell_type": "markdown",
"metadata": {
"id": "3Yv8MenWXrRX"
"id": "8lCMpDPGp-oQ"
},
"source": [
"# Train and deploy a real-time churn ML model using Vertex AI Training and Endpoints\n",
@@ -1467,34 +1610,34 @@
"\n",
"<img src=\"./assets/train_model_4.png\">\n",
"\n",
"Let's dive into each step of this process.\n"
"Let's dive into each step of this process."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "saZZ3zWKX1YK"
"id": "VMrvnuyjqGfY"
},
"source": [
"## Fetch training data with point-in-time query using BigQuery and Vertex AI Feature store \n",
"\n",
"As we mentioned above, in real time churn prediction, it is so important defining the label you want to predict with your model. \n",
"\n",
"Let's assume that you decide to predict the churn probability over the last 24 hr. So now you have your label. Next step is to define your training sample. But let's think about that for a second. \n",
"\n",
"In that churn real time system, you have a high volume of transactions you could use to calculate those features which keep floating and are collected constantly over time. It implies that you always get fresh data to reconstruct features. And depending on when you decide to calculate one feature or another you can end up with a set of features that are not aligned in time. \n",
"\n",
"## Fetch training data with point-in-time query using BigQuery and Vertex AI Feature store \n",
" \n",
"As we mentioned above, in real time churn prediction, it is so important defining the label you want to predict with your model.\n",
" \n",
"Let's assume that you decide to predict the churn probability over the next hour. So now you have your label. Next step is to define your training sample. But let's think about that for a second.\n",
" \n",
"In that churn real time system, you have a high volume of transactions you could use to calculate those features which keep floating and are collected constantly over time. It implies that you always get fresh data to reconstruct features. And depending on when you decide to calculate one feature or another you can end up with a set of features that are not aligned in time.\n",
" \n",
"When you have labels available, it would be incredibly difficult to say which set of features contains the most up to date historical information associated with the label you want to predict. And, when you are not able to guarantee that, the performance of your model would be badly affected because you serve no representative features of the data and the label from the field when it goes live. So you need a way to get the most updated features you calculated over time before the label becomes available in order to avoid this informational skew.\n",
"\n",
"**With the Vertex AI Feature store, you can fetch feature values corresponding to a particular timestamp thanks to point-in-time lookup capability.** In our case, it would be the timestamp associated to the label you want to predict with your model. In this way, you will avoid data leakage and you will get the most updated features to train your model. \n",
"\n",
"Let's see how to do that. \n"
" \n",
"**With the Vertex AI Feature store, you can fetch feature values corresponding to a particular timestamp thanks to point-in-time lookup capability.** In our case, it would be the timestamp associated with the label you want to predict with your model. In this way, you will avoid data leakage and you will get the most updated features to train your model.\n",
" \n",
"Let's see how to do that.\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "YHNbIHqFcQiM"
"id": "RE_Pvmu-qdDt"
},
"source": [
"### Define query for reading instances at a specific point in time\n",
@@ -1506,7 +1649,7 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "DGUm0bYqhVV4"
"id": "bUDVw7l-qF2x"
},
"outputs": [],
"source": [
@@ -1518,13 +1661,13 @@
" # get training threshold ----------------------------------------------------------------------------------\n",
" get_training_threshold AS (\n",
" SELECT\n",
" (MAX(event_timestamp) - 86400000000) AS training_thrs\n",
" (MAX(event_timestamp) - 10800000000) AS training_thrs\n",
" FROM\n",
" `firebase-public-project.analytics_153293282.events_*`\n",
" WHERE\n",
" event_name=\"user_engagement\"\n",
" AND\n",
" PARSE_TIMESTAMP('%Y-%m-%d %H:%M:%S', FORMAT_TIMESTAMP('%Y-%m-%d %H:%M:%S', TIMESTAMP_MICROS(event_timestamp))) < '{TODAY}'),\n",
" TIMESTAMP_ADD(PARSE_TIMESTAMP('%Y-%m-%d %H:%M:%S', FORMAT_TIMESTAMP('%Y-%m-%d %H:%M:%S', TIMESTAMP_MICROS(event_timestamp))), INTERVAL 1351 DAY) < '{TODAY}'),\n",
"\n",
" # query to create label -----------------------------------------------------------------------------------\n",
" get_label AS (\n",
@@ -1549,7 +1692,7 @@
" WHERE\n",
" event_name=\"user_engagement\"\n",
" AND\n",
" PARSE_TIMESTAMP('%Y-%m-%d %H:%M:%S', FORMAT_TIMESTAMP('%Y-%m-%d %H:%M:%S', TIMESTAMP_MICROS(event_timestamp))) < '{TODAY}'\n",
" TIMESTAMP_ADD(PARSE_TIMESTAMP('%Y-%m-%d %H:%M:%S', FORMAT_TIMESTAMP('%Y-%m-%d %H:%M:%S', TIMESTAMP_MICROS(event_timestamp))), INTERVAL 1351 DAY) < '{TODAY}'\n",
" GROUP BY\n",
" user_pseudo_id )\n",
" GROUP BY\n",
@@ -1669,7 +1812,7 @@
"source": [
"!mkdir -m 777 -p trainer data/ingest data/raw model config\n",
"!gsutil -m cp -r $GCS_DESTINATION_OUTPUT_URI/*.csv data/ingest\n",
"!head -n 1000 data/ingest/*.csv > data/raw/sample.csv"
"!head -n 2000 data/ingest/*.csv > data/raw/sample.csv"
]
},
{
@@ -2071,7 +2214,7 @@
},
"outputs": [],
"source": [
"TRAIN_JOB_RESOURCE_NAME = \"\" # @param {type:\"string\"}"
"TRAIN_JOB_RESOURCE_NAME = \"[your-train-job-resource-name]\" # @param {type:\"string\"}"
]
},
{
@@ -2166,32 +2309,32 @@
{
"cell_type": "markdown",
"metadata": {
"id": "7c9330928aa1"
"id": "1TNzL_EGrVUm"
},
"source": [
"# Serve ML features at scale with low latency\n",
"\n",
"At that time, you are ready **to deploy our simple model which would requires fetching preprocessed attributes as input features in real time**. \n",
"\n",
" \n",
"At that time, you are ready **to deploy our simple model which would requires fetching preprocessed attributes as input features in real time**.\n",
" \n",
"Below you can see how it works\n",
"\n",
"<img src=\"./assets/online_serving_5.png\" width=\"600\">\n",
"\n",
"But think about those features for a second. \n",
"\n",
"Your behavioral features used to trained your model, they cannot be computed when you are going to serve the model online. \n",
"\n",
"How could you compute the number of time a user challenged a friend withing the last 24 hours on the fly?\n",
"\n",
"You simply can't do that. You need to be computed this feature on the server side and serve it with low latency. And becuase Bigquery is not optimized for those read operations, we need a different service that allows singleton lookup where the result is a single row with many columns.\n",
"\n",
"Also, even if it was not the case, when you deploy a model that requires preprocessing your data, you need to be sure to reproduce the same preprocessing steps you had when you trained it. If you are not able to do that a skew between training and serving data would happen and it will affect badly your model performance (and in the worst scenario break your serving system). \n",
"\n",
"You need a way to mitigate that in a way you don't need to implement those preprocessing steps online but just serve the same aggregated features you already have for training to generate online prediction. \n",
"\n",
"These are other valuable reasons to introduce Vertex AI Feature Store. With it, you have a service which helps you to serve feature at scale with low latency as they were available at training time mitigating in that way possible training-serving skew.\n",
"\n",
"Now that you know **why you need a feature store**, let's closing this journey by deploying your model and use feature store to retrieve features online, pass them to endpoint and generate predictions.\n"
" \n",
"<center><img src=\"./assets/online_serving_5.png\" width=\"800\"/></center>\n",
" \n",
"But think about those features for a second.\n",
" \n",
"Your behavioral features used to train your model, they cannot be computed when you are going to serve the model online.\n",
" \n",
"How could you compute the number of times a user challenged a friend within the last 24 hours on the fly?\n",
" \n",
"You need to be computed this feature on the server side and serve it with low latency. And because Bigquery is not optimized for those read operations, we need a different service that allows singleton lookup where the result is a single row with many columns.\n",
" \n",
"Also, even if it was not the case, when you deploy a model that requires preprocessing your data, you need to be sure to reproduce the same preprocessing steps you had when you trained it. If you are not able to do that a skew between training and serving data would happen and it will badly affect your model performance (and in the worst scenario break your serving system).\n",
" \n",
"You need a way to mitigate that in a way you don't need to implement those preprocessing steps online but just serve the same aggregated features you already have for training to generate online prediction.\n",
" \n",
"These are other valuable reasons to introduce Vertex AI Feature Store. With it, you have a service which helps you to serve features at scale with low latency as they were available at training time mitigating in that way possible training-serving skew.\n",
" \n",
"Now that you know **why you need a feature store**, let's conclude this journey by deploying your model using a feature store to retrieve features online, pass them to the endpoint and generate predictions.\n"
]
},
{
@@ -2221,13 +2364,13 @@
},
"outputs": [],
"source": [
"simulate_prediction(endpoint=endpoint, n_requests=1000, latency=1)"
"simulate_prediction(endpoint=endpoint, n_requests=10, latency=1)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "TpV-iwP9qw9c"
"id": "8d3S1d1urZOy"
},
"source": [
"## Cleaning up\n",
@@ -2267,11 +2410,12 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "sx_vKniMq9ZX"
"id": "FMXT2akXrZOy"
},
"outputs": [],
"source": [
"# Delete bucket\n",
"delete_bucket = False\n",
"if (delete_bucket or os.getenv(\"IS_TESTING\")) and \"BUCKET_URI\" in globals():\n",
" ! gsutil -m rm -r $BUCKET_URI"
]
@@ -98,10 +98,10 @@
"## Before you begin\n",
"\n",
"* **Prepare a VPC network**. To reduce any network overhead that might lead to unnecessary increase in overhead latency, it is best to call the ANN endpoints from your VPC via a direct [VPC Peering](https://cloud.google.com/vertex-ai/docs/general/vpc-peering) connection. The following section describes how to setup a VPC Peering connection if you don't have one. This is a one-time initial setup task. You can also reuse existing VPC network and skip this section.\n",
"* **WARNING:** The match service gRPC API (to create online queries against your deployed index) has to be executed in a Google Cloud Notebook instance that is created with the following requirements:\n",
"* **WARNING:** The MatchingIndexEndpoint.match method (to create online queries against your deployed index) has to be executed in a Vertex AI Workbench notebook instance that is created with the following requirements:\n",
" * **In the same region as where your ANN service is deployed** (for example, if you set `REGION = \"us-central1\"` as same as the tutorial, the notebook instance has to be in `us-central1`).\n",
" * **Make sure you select the VPC network you created for ANN service** (instead of using the \"default\" one). That is, you will have to create the VPC network below and then create a new notebook instance that uses that VPC. \n",
" * If you run it in the colab or a Google Cloud Notebook instance in a different VPC network or region, the gRPC API will fail to peer the network (InactiveRPCError)."
" * If you run it in the colab or a Vertex AI Workbench notebook instance in a different VPC network or region, the gRPC API will fail to peer the network (InactiveRPCError)."
]
},
{
@@ -114,9 +114,9 @@
"source": [
"PROJECT_ID = \"<your_project_id>\" # @param {type:\"string\"}\n",
"\n",
"NETWORK_NAME = \"ucaip-haystack-vpc-network\" # @param {type:\"string\"}\n",
"NETWORK_NAME = \"my-vpc-network\" # @param {type:\"string\"}\n",
"\n",
"PEERING_RANGE_NAME = \"ucaip-haystack-range\""
"PEERING_RANGE_NAME = \"my-haystack-range\""
]
},
{
@@ -140,7 +140,7 @@
"! gcloud compute firewall-rules create {NETWORK_NAME}-allow-ssh --network {NETWORK_NAME} --priority 65534 --project {PROJECT_ID} --allow tcp:22\n",
"\n",
"# Reserve IP range\n",
"! gcloud compute addresses create {PEERING_RANGE_NAME} --global --prefix-length=16 --network={NETWORK_NAME} --purpose=VPC_PEERING --project={PROJECT_ID} --description=\"peering range for uCAIP Haystack.\"\n",
"! gcloud compute addresses create {PEERING_RANGE_NAME} --global --prefix-length=16 --network={NETWORK_NAME} --purpose=VPC_PEERING --project={PROJECT_ID} --description=\"peering range\"\n",
"\n",
"# Set up peering with service networking\n",
"! gcloud services vpc-peerings connect --service=servicenetworking.googleapis.com --network={NETWORK_NAME} --ranges={PEERING_RANGE_NAME} --project={PROJECT_ID}"
@@ -152,7 +152,7 @@
"id": "d3uj8x73nDX_"
},
"source": [
"* Authentication: `$ gcloud auth login` rerun this in Google Cloud Notebook terminal when you are logged out and need the credential again."
"* Authentication: Rerun the `gcloud auth login` command in the Vertex AI Workbench notebook terminal when you are logged out and need the credential again."
]
},
{
@@ -163,7 +163,7 @@
"source": [
"### Installation\n",
"\n",
"Download and install the latest (preview) version of the Vertex SDK for Python."
"Download and install the latest version of the Vertex SDK for Python."
]
},
{
@@ -174,7 +174,7 @@
},
"outputs": [],
"source": [
"! pip install -U git+https://github.com/ivanmkc/python-aiplatform.git@imkc--matching-engine"
"! pip install -U google-cloud-aiplatform"
]
},
{
@@ -333,7 +333,7 @@
"source": [
"### Authenticate your Google Cloud account\n",
"\n",
"**If you are using Google Cloud Notebooks**, your environment is already\n",
"**If you are using a Vertex AI Workbench notebook**, your environment is already\n",
"authenticated. Skip this step."
]
},
@@ -383,11 +383,13 @@
"# Cloud Storage bucket and lets you submit training jobs and prediction\n",
"# requests.\n",
"\n",
"# The Google Cloud Notebook product has specific requirements\n",
"IS_GOOGLE_CLOUD_NOTEBOOK = os.path.exists(\"/opt/deeplearning/metadata/env_version\")\n",
"# The Vertex AI Workbench notebook product has specific requirements\n",
"IS_VERTEX_AI_WORKBENCH_NOTEBOOK = os.path.exists(\n",
" \"/opt/deeplearning/metadata/env_version\"\n",
")\n",
"\n",
"# If on Google Cloud Notebooks, then don't execute this code\n",
"if not IS_GOOGLE_CLOUD_NOTEBOOK:\n",
"# If on a Vertex AI Workbench notebook, then don't execute this code\n",
"if not IS_VERTEX_AI_WORKBENCH_NOTEBOOK:\n",
" if \"google.colab\" in sys.modules:\n",
" from google.colab import auth as google_auth\n",
"\n",
@@ -539,12 +541,12 @@
"id": "lR6Wwv-hCCN-"
},
"source": [
"## Prepare the Data\n",
"## Prepare the data\n",
"\n",
"The GloVe dataset consists of a set of pre-trained embeddings. The embeddings are split into a \"train\" split, and a \"test\" split.\n",
"We will create a vector search index from the \"train\" split, and use the embedding vectors in the \"test\" split as query vectors to test the vector search index.\n",
"\n",
"NOTE: While the data split uses the term \"train\", these are pre-trained embeddings and thus are ready to be indexed for search. The terms \"train\" and \"test\" split are used just to be consistent with usual machine learning terminology.\n",
"**Note:** While the data split uses the term \"train\", these are pre-trained embeddings and therefore are ready to be indexed for search. The terms \"train\" and \"test\" split are used just to be consistent with machine learning terminology.\n",
"\n",
"Download the GloVe dataset.\n"
]
@@ -1,877 +0,0 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "ur8xi4C7S06n"
},
"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": "JAPoU8Sm5E6e"
},
"source": [
"<table align=\"left\">\n",
"\n",
" <td>\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/master/notebooks/community/ml_metadata/sdk-metric-parameter-tracking-for-locally-trained-models.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/colab-logo-32px.png\" alt=\"Colab logo\"> Run in Colab\n",
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/master/notebooks/community/ml_metadata/sdk-metric-parameter-tracking-for-locally-trained-models.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/github-logo-32px.png\" alt=\"GitHub logo\">\n",
" View on GitHub\n",
" </a>\n",
" </td>\n",
"</table>"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "WBFL9LagqmwT"
},
"source": [
"#Vertex AI: Track parameters and metrics for locally trained models"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "tvgnzT1CKxrO"
},
"source": [
"## Overview\n",
"\n",
"This notebook demonstrates how to track metrics and parameters for ML training jobs and analyze this metadata using Vertex SDK for Python.\n",
"\n",
"### Dataset\n",
"\n",
"In this notebook, we will train a simple distributed neural network (DNN) model to predict automobile's miles per gallon (MPG) based on automobile information in the [auto-mpg dataset](https://www.kaggle.com/devanshbesain/exploration-and-analysis-auto-mpg).\n",
"\n",
"### Objective\n",
"\n",
"In this notebook, you will learn how to use Vertex SDK for Python to:\n",
"\n",
" * Track parameters and metrics for a locally trainined model.\n",
" * Extract and perform analysis for all parameters and metrics within an Experiment.\n",
"\n",
"### Costs \n",
"\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": {
"id": "ze4-nDLfK4pw"
},
"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."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "gCuSR8GkAgzl"
},
"source": [
"**Otherwise**, make sure your environment meets this notebook's requirements.\n",
"You need the following:\n",
"\n",
"* The Google Cloud SDK\n",
"* Git\n",
"* Python 3\n",
"* virtualenv\n",
"* Jupyter notebook running in a virtual environment with Python 3\n",
"\n",
"The Google Cloud guide to [Setting up a Python development\n",
"environment](https://cloud.google.com/python/setup) and the [Jupyter\n",
"installation guide](https://jupyter.org/install) provide detailed instructions\n",
"for meeting these requirements. The following steps provide a condensed set of\n",
"instructions:\n",
"\n",
"1. [Install and initialize the Cloud SDK.](https://cloud.google.com/sdk/docs/)\n",
"\n",
"1. [Install Python 3.](https://cloud.google.com/python/setup#installing_python)\n",
"\n",
"1. [Install\n",
" virtualenv](https://cloud.google.com/python/setup#installing_and_using_virtualenv)\n",
" and create a virtual environment that uses Python 3. Activate the virtual environment.\n",
"\n",
"1. To install Jupyter, run `pip install jupyter` on the\n",
"command-line in a terminal shell.\n",
"\n",
"1. To launch Jupyter, run `jupyter notebook` on the command-line in a terminal shell.\n",
"\n",
"1. Open this notebook in the Jupyter Notebook Dashboard."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "i7EUnXsZhAGF"
},
"source": [
"### Install additional packages\n",
"\n",
"Run the following commands to install the Vertex SDK for Python."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "IaYsrh0Tc17L"
},
"outputs": [],
"source": [
"import sys\n",
"\n",
"if \"google.colab\" in sys.modules:\n",
" USER_FLAG = \"\"\n",
"else:\n",
" USER_FLAG = \"--user\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "wyy5Lbnzg5fi"
},
"outputs": [],
"source": [
"!python3 -m pip install {USER_FLAG} google-cloud-aiplatform --upgrade"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "hhq5zEbGg0XX"
},
"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": "EzrelQZ22IZj"
},
"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": {
"id": "lWEdiXsJg0XY"
},
"source": [
"## Before you begin\n",
"\n",
"### Select a GPU runtime\n",
"\n",
"**Make sure you're running this notebook in a GPU runtime if you have that option. In Colab, select \"Runtime --> Change runtime type > GPU\"**"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "BF1j6f9HApxa"
},
"source": [
"### 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 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",
"\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": "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,
"metadata": {
"id": "oM1iC_MfAts1"
},
"outputs": [],
"source": [
"import os\n",
"\n",
"PROJECT_ID = \"\"\n",
"\n",
"# Get your Google Cloud project ID from gcloud\n",
"if not os.getenv(\"IS_TESTING\"):\n",
" shell_output=!gcloud config list --format 'value(core.project)' 2>/dev/null\n",
" PROJECT_ID = shell_output[0]\n",
" print(\"Project ID: \", PROJECT_ID)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "qJYoRfYng0XZ"
},
"source": [
"Otherwise, set your project ID here."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "riG_qUokg0XZ"
},
"outputs": [],
"source": [
"if PROJECT_ID == \"\" or PROJECT_ID is None:\n",
" PROJECT_ID = \"[your-project-id]\" # @param {type:\"string\"}"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "06571eb4063b"
},
"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 it onto the name of resources you create in this tutorial."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "697568e92bd6"
},
"outputs": [],
"source": [
"from datetime import datetime\n",
"\n",
"TIMESTAMP = datetime.now().strftime(\"%Y%m%d%H%M%S\")"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dr--iN2kAylZ"
},
"source": [
"### Authenticate your Google Cloud account\n",
"\n",
"**If you are using Google Cloud Notebooks**, your environment is already\n",
"authenticated. Skip this step."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "sBCra4QMA2wR"
},
"source": [
"**If you are using Colab**, run the cell below and follow the instructions\n",
"when prompted to authenticate your account via oAuth.\n",
"\n",
"**Otherwise**, follow these steps:\n",
"\n",
"1. In the Cloud Console, go to the [**Create service account key**\n",
" page](https://console.cloud.google.com/apis/credentials/serviceaccountkey).\n",
"\n",
"2. Click **Create service account**.\n",
"\n",
"3. In the **Service account name** field, enter a name, and\n",
" click **Create**.\n",
"\n",
"4. In the **Grant this service account access to project** section, click the **Role** drop-down list. Type \"Vertex AI\"\n",
"into the filter box, and select\n",
" **Vertex AI Administrator**. Type \"Storage Object Admin\" into the filter box, and select **Storage Object Admin**.\n",
"\n",
"5. Click *Create*. A JSON file that contains your key downloads to your\n",
"local environment.\n",
"\n",
"6. Enter the path to your service account key as the\n",
"`GOOGLE_APPLICATION_CREDENTIALS` variable in the cell below and run the cell."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "PyQmSRbKA8r-"
},
"outputs": [],
"source": [
"import os\n",
"import sys\n",
"\n",
"# If you are running this notebook in Colab, run this cell and follow the\n",
"# instructions to authenticate your GCP account. This provides access to your\n",
"# Cloud Storage bucket and lets you submit training jobs and prediction\n",
"# requests.\n",
"\n",
"# If on Google Cloud Notebooks, then don't execute this code\n",
"if not os.path.exists(\"/opt/deeplearning/metadata/env_version\"):\n",
" 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": "XoEqT2Y4DJmf"
},
"source": [
"### Import libraries and define constants"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "Y9Uo3tifg1kx"
},
"source": [
"Import required libraries."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "pRUOFELefqf1"
},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
"import pandas as pd\n",
"from google.cloud import aiplatform\n",
"from tensorflow.python.keras import Sequential, layers\n",
"from tensorflow.python.keras.utils import data_utils"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "xtXZWmYqJ1bh"
},
"source": [
"Define some constants"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "JIOrI-hoJ46P"
},
"outputs": [],
"source": [
"EXPERIMENT_NAME = \"\" # @param {type:\"string\"}\n",
"REGION = \"[your-region]\" # @param {type:\"string\"}"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "jWQLXXNVN4Lv"
},
"source": [
"If EXEPERIMENT_NAME is not set, set a default one below:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "Q1QInYWOKsmo"
},
"outputs": [],
"source": [
"if EXPERIMENT_NAME == \"\" or EXPERIMENT_NAME is None:\n",
" EXPERIMENT_NAME = \"my-experiment-\" + TIMESTAMP"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "Xuny18aMcWDb"
},
"source": [
"## Concepts\n",
"\n",
"To better understanding how parameters and metrics are stored and organized, we'd like to introduce the following concepts:\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "NThDci5bp0Uw"
},
"source": [
"### Experiment\n",
"Experiments describe a context that groups your runs and the artifacts you create into a logical session. For example, in this notebook you create an Experiment and log data to that experiment."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "SAyRR3Ydp4X5"
},
"source": [
"### Run\n",
"A run represents a single path/avenue that you executed while performing an experiment. A run includes artifacts that you used as inputs or outputs, and parameters that you used in this execution. An Experiment can contain multiple runs. "
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "l1YW2pgyegFP"
},
"source": [
"## Getting started tracking parameters and metrics\n",
"\n",
"You can use the Vertex SDK for Python to track metrics and parameters for models trained locally. \n",
"\n",
"In the following example, you train a simple distributed neural network (DNN) model to predict automobile's miles per gallon (MPG) based on automobile information in the [auto-mpg dataset](https://www.kaggle.com/devanshbesain/exploration-and-analysis-auto-mpg)."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "KPY41M9_AhZU"
},
"source": [
"### Load and process the training dataset"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "bfMQSmRuUuX-"
},
"source": [
"Download and process the dataset."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "RiQuMv4bmpuV"
},
"outputs": [],
"source": [
"def read_data(uri):\n",
" dataset_path = data_utils.get_file(\"auto-mpg.data\", uri)\n",
" column_names = [\n",
" \"MPG\",\n",
" \"Cylinders\",\n",
" \"Displacement\",\n",
" \"Horsepower\",\n",
" \"Weight\",\n",
" \"Acceleration\",\n",
" \"Model Year\",\n",
" \"Origin\",\n",
" ]\n",
" raw_dataset = pd.read_csv(\n",
" dataset_path,\n",
" names=column_names,\n",
" na_values=\"?\",\n",
" comment=\"\\t\",\n",
" sep=\" \",\n",
" skipinitialspace=True,\n",
" )\n",
" dataset = raw_dataset.dropna()\n",
" dataset[\"Origin\"] = dataset[\"Origin\"].map(\n",
" lambda x: {1: \"USA\", 2: \"Europe\", 3: \"Japan\"}.get(x)\n",
" )\n",
" dataset = pd.get_dummies(dataset, prefix=\"\", prefix_sep=\"\")\n",
" return dataset\n",
"\n",
"\n",
"dataset = read_data(\n",
" \"http://archive.ics.uci.edu/ml/machine-learning-databases/auto-mpg/auto-mpg.data\"\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "Y06J7A7yU21t"
},
"source": [
"Split dataset for training and testing."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "p5JBCBKyH-NC"
},
"outputs": [],
"source": [
"def train_test_split(dataset, split_frac=0.8, random_state=0):\n",
" train_dataset = dataset.sample(frac=split_frac, random_state=random_state)\n",
" test_dataset = dataset.drop(train_dataset.index)\n",
" train_labels = train_dataset.pop(\"MPG\")\n",
" test_labels = test_dataset.pop(\"MPG\")\n",
"\n",
" return train_dataset, test_dataset, train_labels, test_labels\n",
"\n",
"\n",
"train_dataset, test_dataset, train_labels, test_labels = train_test_split(dataset)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "gaNNTFPaU7KT"
},
"source": [
"Normalize the features in the dataset for better model performance."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "VGq5QCoyIEWJ"
},
"outputs": [],
"source": [
"def normalize_dataset(train_dataset, test_dataset):\n",
" train_stats = train_dataset.describe()\n",
" train_stats = train_stats.transpose()\n",
"\n",
" def norm(x):\n",
" return (x - train_stats[\"mean\"]) / train_stats[\"std\"]\n",
"\n",
" normed_train_data = norm(train_dataset)\n",
" normed_test_data = norm(test_dataset)\n",
"\n",
" return normed_train_data, normed_test_data\n",
"\n",
"\n",
"normed_train_data, normed_test_data = normalize_dataset(train_dataset, test_dataset)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "UBXUgxgqA_GB"
},
"source": [
"### Define ML model and training function"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "66odBYKrIN4q"
},
"outputs": [],
"source": [
"def train(\n",
" train_data,\n",
" train_labels,\n",
" num_units=64,\n",
" activation=\"relu\",\n",
" dropout_rate=0.0,\n",
" validation_split=0.2,\n",
" epochs=1000,\n",
"):\n",
"\n",
" model = Sequential(\n",
" [\n",
" layers.Dense(\n",
" num_units,\n",
" activation=activation,\n",
" input_shape=[len(train_dataset.keys())],\n",
" ),\n",
" layers.Dropout(rate=dropout_rate),\n",
" layers.Dense(num_units, activation=activation),\n",
" layers.Dense(1),\n",
" ]\n",
" )\n",
"\n",
" model.compile(loss=\"mse\", optimizer=\"adam\", metrics=[\"mae\", \"mse\"])\n",
" print(model.summary())\n",
"\n",
" history = model.fit(\n",
" train_data, train_labels, epochs=epochs, validation_split=validation_split\n",
" )\n",
"\n",
" return model, history"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "O8XJZB3gR8eL"
},
"source": [
"### Initialize the Vertex AI SDK for Python and create an Experiment\n",
"\n",
"Initialize the *client* for Vertex AI and create an experiment."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "o_wnT10RJ7-W"
},
"outputs": [],
"source": [
"aiplatform.init(project=PROJECT_ID, location=REGION, experiment=EXPERIMENT_NAME)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "u-iTnzt3B6Z_"
},
"source": [
"### Start several model training runs\n",
"\n",
"Training parameters and metrics are logged for each run."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "i2wnpu8_7JfV"
},
"outputs": [],
"source": [
"parameters = [\n",
" {\"num_units\": 16, \"epochs\": 3, \"dropout_rate\": 0.1},\n",
" {\"num_units\": 16, \"epochs\": 10, \"dropout_rate\": 0.1},\n",
" {\"num_units\": 16, \"epochs\": 10, \"dropout_rate\": 0.2},\n",
" {\"num_units\": 32, \"epochs\": 10, \"dropout_rate\": 0.1},\n",
" {\"num_units\": 32, \"epochs\": 10, \"dropout_rate\": 0.2},\n",
"]\n",
"\n",
"for i, params in enumerate(parameters):\n",
" aiplatform.start_run(run=f\"auto-mpg-local-run-{i}\")\n",
" aiplatform.log_params(params)\n",
" model, history = train(\n",
" normed_train_data,\n",
" train_labels,\n",
" num_units=params[\"num_units\"],\n",
" activation=\"relu\",\n",
" epochs=params[\"epochs\"],\n",
" dropout_rate=params[\"dropout_rate\"],\n",
" )\n",
" aiplatform.log_metrics(\n",
" {metric: values[-1] for metric, values in history.history.items()}\n",
" )\n",
"\n",
" loss, mae, mse = model.evaluate(normed_test_data, test_labels, verbose=2)\n",
" aiplatform.log_metrics({\"eval_loss\": loss, \"eval_mae\": mae, \"eval_mse\": mse})"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "jZLrJZTfL7tE"
},
"source": [
"### Extract parameters and metrics into a dataframe for analysis"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "A1PqKxlpOZa2"
},
"source": [
"We can also extract all parameters and metrics associated with any Experiment into a dataframe for further analysis."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "jbRf1WoH_vbY"
},
"outputs": [],
"source": [
"experiment_df = aiplatform.get_experiment_df()\n",
"experiment_df"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "EYuYgqVCMKU1"
},
"source": [
"### Visualizing an experiment's parameters and metrics"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "r8orCj8iJuO1"
},
"outputs": [],
"source": [
"plt.rcParams[\"figure.figsize\"] = [15, 5]\n",
"\n",
"ax = pd.plotting.parallel_coordinates(\n",
" experiment_df.reset_index(level=0),\n",
" \"run_name\",\n",
" cols=[\n",
" \"param.num_units\",\n",
" \"param.dropout_rate\",\n",
" \"param.epochs\",\n",
" \"metric.loss\",\n",
" \"metric.val_loss\",\n",
" \"metric.eval_loss\",\n",
" ],\n",
" color=[\"blue\", \"green\", \"pink\", \"red\"],\n",
")\n",
"ax.set_yscale(\"symlog\")\n",
"ax.legend(bbox_to_anchor=(1.0, 0.5))"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "WTHvPMweMlP1"
},
"source": [
"## Visualizing experiments in Cloud Console"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "F19_5lw0MqXv"
},
"source": [
"Run the following to get the URL of Vertex AI Experiments for your project.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "GmN9vE9pqqzt"
},
"outputs": [],
"source": [
"print(\"Vertex AI Experiments:\")\n",
"print(\n",
" f\"https://console.cloud.google.com/ai/platform/experiments/experiments?folder=&organizationId=&project={PROJECT_ID}\"\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "TpV-iwP9qw9c"
},
"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."
]
}
],
"metadata": {
"colab": {
"collapsed_sections": [],
"name": "sdk-metric-parameter-tracking-for-locally-trained-models.ipynb",
"toc_visible": true
},
"kernelspec": {
"display_name": "Python 3",
"name": "python3"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
+2 -2
View File
@@ -22,7 +22,7 @@ The first stage in MLOps is the collection and preparation for the purpose of de
- Data is preprocessed for training and evaluation using Dataflow.
- Data augmentation is performed on-the-fly and is coupled with model feeding.
<img src='stage1.jpg'>
<img src='stage1v2.png'>
## Notebooks
@@ -76,7 +76,7 @@ The steps performed include:
- image data
```
[Get Started with Data Labeling](get_started_data_labeling.ipynb)
[Get Started with Data Labeling](get_started_with_data_labeling.ipynb)
```
The steps performed include:
@@ -34,17 +34,16 @@
"<table align=\"left\">\n",
" <td>\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage1/get_started_bq_datasets.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/github-logo-32px.png\" alt=\"GitHub logo\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/colab-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/stage1/get_started_bq_datasets.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/colab-logo-32px.png\\\" alt=\"Colab logo\"> Run in Colab\n",
" </a>\n",
" <td>\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage1/get_started_bq_datasets.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/colab-logo-32px.png\" alt=\"Colab logo\"> Run in Colab\n",
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage1/get_started_bq_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_bq_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",
@@ -174,20 +173,24 @@
"source": [
"import os\n",
"\n",
"# The Google Cloud Notebook product has specific requirements\n",
"IS_GOOGLE_CLOUD_NOTEBOOK = os.path.exists(\"/opt/deeplearning/metadata/env_version\")\n",
"# The Vertex AI Workbench Notebook product has specific requirements\n",
"IS_WORKBENCH_NOTEBOOK = os.getenv(\"DL_ANACONDA_HOME\") and not os.getenv(\"VIRTUAL_ENV\")\n",
"IS_USER_MANAGED_WORKBENCH_NOTEBOOK = os.path.exists(\n",
" \"/opt/deeplearning/metadata/env_version\"\n",
")\n",
"\n",
"# Google Cloud Notebook requires dependencies to be installed with '--user'\n",
"# Vertex AI Notebook requires dependencies to be installed with '--user'\n",
"USER_FLAG = \"\"\n",
"if IS_GOOGLE_CLOUD_NOTEBOOK:\n",
"if IS_WORKBENCH_NOTEBOOK:\n",
" USER_FLAG = \"--user\"\n",
"\n",
"# Install the packages\n",
"! pip3 install --upgrade pyarrow $USER_FLAG\n",
"! pip3 install --upgrade google-cloud-bigquery $USER_FLAG\n",
"! pip3 install --upgrade google-cloud-aiplatform[tensorboard] $USER_FLAG\n",
"! pip3 install -U xgboost $USER_FLAG\n",
"! pip3 install -U tensorflow-io==0.18 $USER_FLAG"
"! pip3 install --upgrade pyarrow $USER_FLAG -q\n",
"! pip3 install --upgrade google-cloud-bigquery $USER_FLAG -q\n",
"! pip3 install --upgrade google-cloud-aiplatform $USER_FLAG -q\n",
"! pip3 install -U xgboost $USER_FLAG -q\n",
"! pip3 install -U tensorflow $USER_FLAG -q\n",
"! pip3 install -U tensorflow-io==0.18 $USER_FLAG -q"
]
},
{
@@ -219,21 +222,14 @@
" app.kernel.do_shutdown(True)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "a47846030fef"
},
"source": [
"## Before you begin"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "84cd83853240"
},
"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",
@@ -366,7 +362,7 @@
"source": [
"### Authenticate your Google Cloud account\n",
"\n",
"**If you are using Google Cloud Notebooks**, your environment is already authenticated. Skip this step.\n",
"**If you are using Vertex AI Workbench Notebooks**, your environment is already authenticated. 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",
@@ -393,20 +389,21 @@
},
"outputs": [],
"source": [
"import os\n",
"import sys\n",
"\n",
"# If you are running this notebook in Colab, run this cell and follow the\n",
"# instructions to authenticate your GCP account. This provides access to your\n",
"# Cloud Storage bucket and lets you submit training jobs and prediction\n",
"# requests.\n",
"\n",
"# The Google Cloud Notebook product has specific requirements\n",
"IS_GOOGLE_CLOUD_NOTEBOOK = os.path.exists(\"/opt/deeplearning/metadata/env_version\")\n",
"import os\n",
"import sys\n",
"\n",
"# If on Google Cloud Notebooks, then don't execute this code\n",
"if not IS_GOOGLE_CLOUD_NOTEBOOK:\n",
"# If on Vertex AI Workbench, then don't execute this code\n",
"IS_COLAB = False\n",
"if not os.path.exists(\"/opt/deeplearning/metadata/env_version\") and not os.getenv(\n",
" \"DL_ANACONDA_HOME\"\n",
"):\n",
" if \"google.colab\" in sys.modules:\n",
" IS_COLAB = True\n",
" from google.colab import auth as google_auth\n",
"\n",
" google_auth.authenticate_user()\n",
@@ -441,7 +438,8 @@
},
"outputs": [],
"source": [
"BUCKET_URI = \"gs://[your-bucket-name]\" # @param {type:\"string\"}"
"BUCKET_NAME = \"[your-bucket-name]\" # @param {type:\"string\"}\n",
"BUCKET_URI = f\"gs://{BUCKET_NAME}\""
]
},
{
@@ -453,7 +451,8 @@
"outputs": [],
"source": [
"if BUCKET_URI == \"\" or BUCKET_URI is None or BUCKET_URI == \"gs://[your-bucket-name]\":\n",
" BUCKET_URI = \"gs://\" + PROJECT_ID + \"aip-\" + TIMESTAMP"
" BUCKET_NAME = PROJECT_ID + \"aip-\" + TIMESTAMP\n",
" BUCKET_URI = \"gs://\" + BUCKET_NAME"
]
},
{
@@ -1133,7 +1132,7 @@
"source": [
"dataframe[\"station_number\"] = pd.to_numeric(dataframe[\"station_number\"])\n",
"labels = dataframe[\"mean_temp\"]\n",
"data = dataframe.drop(4)\n",
"data = dataframe.drop([\"mean_temp\"], axis=1)\n",
"\n",
"dtrain = xgb.DMatrix(data, label=labels)"
]
@@ -1194,6 +1193,7 @@
"\n",
"# Delete the dataset using the Vertex dataset object\n",
"dataset.delete()\n",
"\n",
"# Delete the temporary BigQuery dataset\n",
"! bq rm -r -f $PROJECT_ID:$DATASET_ID\n",
"\n",
@@ -39,8 +39,14 @@
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://console.cloud.google.com/ai/platform/notebooks/deploy-notebook?download_url=https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage1/get_started_dataflow.ipynb\">\n",
" Open in Google Cloud Notebooks\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage1/get_started_dataflow.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://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage1/get_started_dataflow.ipynb\">\n",
" <img src=\"https://lh3.googleusercontent.com/UiNooY4LUgW_oTvpsNhPpQzsstV5W8F7rYgxgGBD85cWJoLmrOzhVs_ksK_vgx40SHs7jCqkTkCk=e14-rj-sc0xffffff-h130-w32\" alt=\"Vertex AI logo\">\n",
" Open in Vertex AI Workbench\n",
" </a>\n",
" </td>\n",
"</table>\n",
@@ -139,7 +145,7 @@
"source": [
"## Installations\n",
"\n",
"Install *one time* the packages for executing the MLOps notebooks."
"Install the following packages to execute this notebook."
]
},
{
@@ -150,20 +156,26 @@
},
"outputs": [],
"source": [
"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"
"import os\n",
"\n",
"# The Vertex AI Workbench Notebook product has specific requirements\n",
"IS_WORKBENCH_NOTEBOOK = os.getenv(\"DL_ANACONDA_HOME\") and not os.getenv(\"VIRTUAL_ENV\")\n",
"IS_USER_MANAGED_WORKBENCH_NOTEBOOK = os.path.exists(\n",
" \"/opt/deeplearning/metadata/env_version\"\n",
")\n",
"\n",
"# Vertex AI Notebook requires dependencies to be installed with '--user'\n",
"USER_FLAG = \"\"\n",
"if IS_WORKBENCH_NOTEBOOK:\n",
" USER_FLAG = \"--user\"\n",
"\n",
"! pip3 install -U tensorflow==2.5 $USER_FLAG -q\n",
"! pip3 install -U tensorflow-data-validation==1.2 $USER_FLAG -q\n",
"! pip3 install -U tensorflow-transform==1.2 $USER_FLAG -q\n",
"! pip3 install -U tensorflow-io==0.18 $USER_FLAG -q\n",
"! pip3 install --upgrade google-cloud-aiplatform $USER_FLAG -q\n",
"! pip3 install --upgrade google-cloud-bigquery $USER_FLAG -q\n",
"! pip3 install --upgrade apache-beam[gcp] $USER_FLAG -q"
]
},
{
@@ -195,6 +207,32 @@
" app.kernel.do_shutdown(True)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "84cd83853240"
},
"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, BigQuery, Compute Engine and Cloud Storage APIs](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com,bigquery,compute_component,storage_component).\n",
"\n",
"1. If you are running this notebook locally, you need to install the [Cloud SDK](https://cloud.google.com/sdk).\n",
"\n",
"1. Enter your project ID in the cell below. Then run the cell to make sure the\n",
"Cloud SDK uses the right project for all the commands in this notebook.\n",
"\n",
"**Note**: Jupyter runs lines prefixed with `!` as shell commands, and it interpolates Python variables prefixed with `$` into these commands."
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -271,7 +309,10 @@
},
"outputs": [],
"source": [
"REGION = \"us-central1\" # @param {type: \"string\"}"
"REGION = \"[your-region]\" # @param {type: \"string\"}\n",
"\n",
"if REGION == \"[your-region]\":\n",
" REGION = \"us-central1\""
]
},
{
@@ -298,6 +339,67 @@
"TIMESTAMP = datetime.now().strftime(\"%Y%m%d%H%M%S\")"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "77c385f0db59"
},
"source": [
"### Authenticate your Google Cloud account\n",
"\n",
"**If you are using Vertex AI Workbench Notebooks**, your environment is already authenticated. Skip this step.\n",
"\n",
"**If you are using Colab**, run the cell below and follow the instructions when prompted to authenticate your account via oAuth.\n",
"\n",
"**Otherwise**, follow these steps:\n",
"\n",
"In the Cloud Console, go to the [Create service account key](https://console.cloud.google.com/apis/credentials/serviceaccountkey) page.\n",
"\n",
"1. **Click Create service account**.\n",
"\n",
"2. In the **Service account name** field, enter a name, and click **Create**.\n",
"\n",
"3. In the **Grant this service account access to project** section, click the Role drop-down list. Type \"Vertex AI\" into the filter box, and select **Vertex AI Administrator**. Type \"Storage Object Admin\" into the filter box, and select **Storage Object Admin**.\n",
"\n",
"4. Click Create. A JSON file that contains your key downloads to your local environment.\n",
"\n",
"5. Enter the path to your service account key as the GOOGLE_APPLICATION_CREDENTIALS variable in the cell below and run the cell."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "535223fa4b84"
},
"outputs": [],
"source": [
"# If you are running this notebook in Colab, run this cell and follow the\n",
"# instructions to authenticate your GCP account. This provides access to your\n",
"# Cloud Storage bucket and lets you submit training jobs and prediction\n",
"# requests.\n",
"\n",
"import os\n",
"import sys\n",
"\n",
"# If on Vertex AI Workbench, then don't execute this code\n",
"IS_COLAB = False\n",
"if not os.path.exists(\"/opt/deeplearning/metadata/env_version\") and not os.getenv(\n",
" \"DL_ANACONDA_HOME\"\n",
"):\n",
" if \"google.colab\" in sys.modules:\n",
" IS_COLAB = True\n",
" from google.colab import auth as google_auth\n",
"\n",
" google_auth.authenticate_user()\n",
"\n",
" # If you are running this notebook locally, replace the string below with the\n",
" # path to your service account key and run this cell to authenticate your GCP\n",
" # account.\n",
" elif not os.getenv(\"IS_TESTING\"):\n",
" %env GOOGLE_APPLICATION_CREDENTIALS ''"
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -326,7 +428,8 @@
},
"outputs": [],
"source": [
"BUCKET_NAME = \"gs://[your-bucket-name]\" # @param {type:\"string\"}"
"BUCKET_NAME = \"[your-bucket-name]\" # @param {type:\"string\"}\n",
"BUCKET_URI = f\"gs://{BUCKET_NAME}\""
]
},
{
@@ -337,8 +440,9 @@
},
"outputs": [],
"source": [
"if BUCKET_NAME == \"\" or BUCKET_NAME is None or BUCKET_NAME == \"gs://[your-bucket-name]\":\n",
" BUCKET_NAME = \"gs://\" + PROJECT_ID + \"aip-\" + TIMESTAMP"
"if BUCKET_NAME == \"\" or BUCKET_NAME is None or BUCKET_NAME == \"[your-bucket-name]\":\n",
" BUCKET_NAME = PROJECT_ID + \"aip-\" + TIMESTAMP\n",
" BUCKET_URI = \"gs://\" + BUCKET_NAME"
]
},
{
@@ -358,7 +462,7 @@
},
"outputs": [],
"source": [
"! gsutil mb -l $REGION $BUCKET_NAME"
"! gsutil mb -l $REGION $BUCKET_URI"
]
},
{
@@ -378,7 +482,7 @@
},
"outputs": [],
"source": [
"! gsutil ls -al $BUCKET_NAME"
"! gsutil ls -al $BUCKET_URI"
]
},
{
@@ -401,7 +505,7 @@
},
"outputs": [],
"source": [
"import google.cloud.aiplatform as aip"
"import google.cloud.aiplatform as aiplatform"
]
},
{
@@ -555,7 +659,7 @@
},
"outputs": [],
"source": [
"aip.init(project=PROJECT_ID, location=REGION)"
"aiplatform.init(project=PROJECT_ID, location=REGION)"
]
},
{
@@ -1004,7 +1108,7 @@
},
"outputs": [],
"source": [
"SCHEMA_LOCATION = BUCKET_NAME + \"/schema.txt\"\n",
"SCHEMA_LOCATION = BUCKET_URI + \"/schema.txt\"\n",
"\n",
"# When running Apache Beam directly (file is directly accessed)\n",
"tfdv.write_schema_text(output_path=SCHEMA_LOCATION, schema=schema)\n",
@@ -1149,7 +1253,7 @@
" )\n",
"\n",
"\n",
"EXPORTED_DATA_PREFIX = os.path.join(BUCKET_NAME, \"exported_data\")\n",
"EXPORTED_DATA_PREFIX = os.path.join(BUCKET_URI, \"exported_data\")\n",
"\n",
"QUERY_STRING = \"SELECT {},{} FROM {} LIMIT 500\".format(\n",
" \"CAST(station_number as STRING) AS station_number,year,month,day\",\n",
@@ -1162,7 +1266,7 @@
" \"runner\": RUNNER,\n",
" \"raw_data_query\": QUERY_STRING,\n",
" \"exported_data_prefix\": EXPORTED_DATA_PREFIX,\n",
" \"temp_location\": os.path.join(BUCKET_NAME, \"temp\"),\n",
" \"temp_location\": os.path.join(BUCKET_URI, \"temp\"),\n",
" \"project\": PROJECT_ID,\n",
" \"region\": REGION,\n",
" \"setup_file\": \"./setup.py\",\n",
@@ -1187,17 +1291,7 @@
"To clean up all Google Cloud resources used in this project, you can [delete the Google Cloud\n",
"project](https://cloud.google.com/resource-manager/docs/creating-managing-projects#shutting_down_projects) you used for the tutorial.\n",
"\n",
"Otherwise, you can delete the individual resources you created in this tutorial:\n",
"\n",
"- Dataset\n",
"- Pipeline\n",
"- Model\n",
"- Endpoint\n",
"- AutoML Training Job\n",
"- Batch Job\n",
"- Custom Job\n",
"- Hyperparameter Tuning Job\n",
"- Cloud Storage Bucket"
"Otherwise, you can delete the individual resources you created in this tutorial."
]
},
{
@@ -1208,61 +1302,11 @@
},
"outputs": [],
"source": [
"delete_all = True\n",
"delete_storage = True\n",
"\n",
"if delete_all:\n",
" # Delete the dataset using the Vertex dataset object\n",
" try:\n",
" if \"dataset\" in globals():\n",
" dataset.delete()\n",
" except Exception as e:\n",
" print(e)\n",
"\n",
" # Delete the model using the Vertex model object\n",
" try:\n",
" if \"model\" in globals():\n",
" model.delete()\n",
" except Exception as e:\n",
" print(e)\n",
"\n",
" # Delete the endpoint using the Vertex endpoint object\n",
" try:\n",
" if \"endpoint\" in globals():\n",
" endpoint.undeploy_all()\n",
" endpoint.delete()\n",
" except Exception as e:\n",
" print(e)\n",
"\n",
" # Delete the AutoML or Pipeline training job\n",
" try:\n",
" if \"dag\" in globals():\n",
" dag.delete()\n",
" except Exception as e:\n",
" print(e)\n",
"\n",
" # Delete the custom training job\n",
" try:\n",
" if \"job\" in globals():\n",
" job.delete()\n",
" except Exception as e:\n",
" print(e)\n",
"\n",
" # Delete the batch prediction job using the Vertex batch prediction object\n",
" try:\n",
" if \"batch_predict_job\" in globals():\n",
" batch_predict_job.delete()\n",
" except Exception as e:\n",
" print(e)\n",
"\n",
" # Delete the hyperparameter tuning job using the Vertex hyperparameter tuning object\n",
" try:\n",
" if \"hpt_job\" in globals():\n",
" hpt_job.delete()\n",
" except Exception as e:\n",
" print(e)\n",
"\n",
" if \"BUCKET_NAME\" in globals():\n",
" ! gsutil rm -r $BUCKET_NAME"
"if delete_storage or os.getenv(\"IS_TESTING\"):\n",
" if \"BUCKET_URI\" in globals():\n",
" ! gsutil rm -r $BUCKET_URI"
]
}
],
@@ -8,7 +8,7 @@
},
"outputs": [],
"source": [
"# Copyright 2021 Google LLC\n",
"# Copyright 2022 Google LLC\n",
"#\n",
"# Licensed under the Apache License, Version 2.0 (the \"License\");\n",
"# you may not use this file except in compliance with the License.\n",
@@ -34,15 +34,21 @@
"<table align=\"left\">\n",
" <td>\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage1/get_started_vertex_datasets.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/github-logo-32px.png\" alt=\"GitHub logo\">\n",
" View on GitHub\n",
" <img src=\"https://cloud.google.com/ml-engine/images/colab-logo-32px.png\" alt=\"Colab logo\"> Run in Colab\n",
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://console.cloud.google.com/ai/platform/notebooks/deploy-notebook?download_url=https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage1/get_started_vertex_datasets.ipynb\">\n",
" Open in Google Cloud Notebooks\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/stage1/get_started_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",
" </td> \n",
"</table>\n",
"<br/><br/><br/>"
]
@@ -130,7 +136,17 @@
" - 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."
" - Create a tf.data.Dataset from the TFRecords.\n",
"\n",
" \n",
"### 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."
]
},
{
@@ -141,7 +157,7 @@
"source": [
"## Installations\n",
"\n",
"Install *one time* the packages for executing the MLOps notebooks."
"Install the packages required for executing this notebook."
]
},
{
@@ -152,20 +168,27 @@
},
"outputs": [],
"source": [
"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"
"import os\n",
"\n",
"# The Vertex AI Workbench Notebook product has specific requirements\n",
"IS_WORKBENCH_NOTEBOOK = os.getenv(\"DL_ANACONDA_HOME\") and not os.getenv(\"VIRTUAL_ENV\")\n",
"IS_USER_MANAGED_WORKBENCH_NOTEBOOK = os.path.exists(\n",
" \"/opt/deeplearning/metadata/env_version\"\n",
")\n",
"\n",
"# Vertex AI Notebook requires dependencies to be installed with '--user'\n",
"USER_FLAG = \"\"\n",
"if IS_WORKBENCH_NOTEBOOK:\n",
" USER_FLAG = \"--user\"\n",
"\n",
"! pip3 install -U tensorflow $USER_FLAG -q\n",
"! pip3 install -U tensorflow-data-validation $USER_FLAG -q\n",
"! pip3 install -U tensorflow-transform $USER_FLAG -q\n",
"! pip3 install -U tensorflow-io $USER_FLAG -q\n",
"! pip3 install --upgrade google-cloud-aiplatform $USER_FLAG -q\n",
"! pip3 install --upgrade google-cloud-bigquery $USER_FLAG -q\n",
"! pip3 install -U tensorflow-io==0.18 $USER_FLAG -q\n",
"! pip3 install --upgrade db-dtypes $USER_FLAG -q! pip3 install --upgrade future $USER_FLAG -q"
]
},
{
@@ -197,6 +220,30 @@
" app.kernel.do_shutdown(True)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "cb082379ed5b"
},
"source": [
"### 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 API](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com). \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": {
@@ -216,7 +263,24 @@
},
"outputs": [],
"source": [
"PROJECT_ID = \"[your-project-id]\" # @param {type:\"string\"}"
"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."
]
},
{
@@ -227,18 +291,15 @@
},
"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)"
"if PROJECT_ID == \"\" or PROJECT_ID is None:\n",
" PROJECT_ID = \"[your-project-id]\" # @param {type:\"string\"}"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "set_gcloud_project_id"
"id": "c021ca495967"
},
"outputs": [],
"source": [
@@ -273,7 +334,10 @@
},
"outputs": [],
"source": [
"REGION = \"us-central1\" # @param {type: \"string\"}"
"REGION = \"[your-region]\" # @param {type: \"string\"}\n",
"\n",
"if REGION == \"[your-region]\":\n",
" REGION = \"us-central1\""
]
},
{
@@ -300,6 +364,66 @@
"TIMESTAMP = datetime.now().strftime(\"%Y%m%d%H%M%S\")"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "927085b84a07"
},
"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",
"**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": "89788a802687"
},
"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": {
@@ -328,7 +452,7 @@
},
"outputs": [],
"source": [
"BUCKET_NAME = \"gs://[your-bucket-name]\" # @param {type:\"string\"}"
"BUCKET_URI = \"gs://[your-bucket-name]\" # @param {type:\"string\"}"
]
},
{
@@ -339,8 +463,8 @@
},
"outputs": [],
"source": [
"if BUCKET_NAME == \"\" or BUCKET_NAME is None or BUCKET_NAME == \"gs://[your-bucket-name]\":\n",
" BUCKET_NAME = \"gs://\" + PROJECT_ID + \"aip-\" + TIMESTAMP"
"if BUCKET_URI == \"\" or BUCKET_URI is None or BUCKET_URI == \"gs://[your-bucket-name]\":\n",
" BUCKET_URI = \"gs://\" + PROJECT_ID + \"aip-\" + TIMESTAMP"
]
},
{
@@ -360,7 +484,7 @@
},
"outputs": [],
"source": [
"! gsutil mb -l $REGION $BUCKET_NAME"
"! gsutil mb -l $REGION $BUCKET_URI"
]
},
{
@@ -380,7 +504,7 @@
},
"outputs": [],
"source": [
"! gsutil ls -al $BUCKET_NAME"
"! gsutil ls -al $BUCKET_URI"
]
},
{
@@ -392,7 +516,11 @@
"### Set up variables\n",
"\n",
"Next, set up some variables used throughout the tutorial.\n",
"### Import libraries and define constants"
"### Import libraries and define constants\n",
"\n",
"Import the BigQuery package, TensorFlow Data Validation (TFDV) package and TensorFlow Data Validation package into your Python environment. \n",
"\n",
"Import TensorFlow Transform (TFT) package and pandas into your Python environment."
]
},
{
@@ -403,97 +531,13 @@
},
"outputs": [],
"source": [
"import google.cloud.aiplatform as aip"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "import_bq"
},
"source": [
"#### Import BigQuery\n",
"\n",
"Import the BigQuery package into your Python environment."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "import_bq"
},
"outputs": [],
"source": [
"import google.cloud.aiplatform as aip\n",
"import pandas as pd\n",
"import tensorflow_data_validation as tfdv\n",
"import tensorflow_transform as tft\n",
"from google.cloud import bigquery"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "import_tfdv"
},
"source": [
"#### Import TensorFlow Data Validation\n",
"\n",
"Import the TensorFlow Data Validation (TFDV) package into your Python environment."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "import_tfdv"
},
"outputs": [],
"source": [
"import tensorflow_data_validation as tfdv"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "import_tft"
},
"source": [
"#### Import TensorFlow Transform\n",
"\n",
"Import the TensorFlow Transform (TFT) package into your Python environment."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "import_tft"
},
"outputs": [],
"source": [
"import tensorflow_transform as tft"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "import_pandas"
},
"source": [
"#### Import pandas\n",
"\n",
"Import the pandas package into your Python environment."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "import_pandas"
},
"outputs": [],
"source": [
"import pandas as pd"
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -513,7 +557,7 @@
},
"outputs": [],
"source": [
"aip.init(project=PROJECT_ID, location=REGION)"
"aip.init(project=PROJECT_ID, location=REGION, staging_bucket=BUCKET_URI)"
]
},
{
@@ -567,26 +611,13 @@
"Learn more about [All dataset documentation](https://cloud.google.com/vertex-ai/docs/datasets/datasets)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "import_file:flowers,csv,icn"
},
"outputs": [],
"source": [
"IMPORT_FILE = (\n",
" \"gs://cloud-samples-data/vision/automl_classification/flowers/all_data_v2.csv\"\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "create_dataset:image,icn"
},
"source": [
"### Create the Dataset\n",
"### Create an Image Dataset\n",
"\n",
"Next, create the `Dataset` resource using the `create` method for the `ImageDataset` class, which takes the following parameters:\n",
"\n",
@@ -601,6 +632,19 @@
"Learn more about [ImageDataset](https://cloud.google.com/vertex-ai/docs/datasets/prepare-image)."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "import_file:flowers,csv,icn"
},
"outputs": [],
"source": [
"IMPORT_FILE = (\n",
" \"gs://cloud-samples-data/vision/automl_classification/flowers/all_data_v2.csv\"\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
@@ -618,24 +662,13 @@
"print(dataset.resource_name)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "import_file:hmdb,csv,vcn"
},
"outputs": [],
"source": [
"IMPORT_FILE = \"gs://automl-video-demo-data/hmdb_split1_5classes_train_inf.csv\""
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "create_dataset:video,vcn"
},
"source": [
"### Create the Dataset\n",
"### Create a Video Dataset\n",
"\n",
"Next, create the `Dataset` resource using the `create` method for the `VideoDataset` class, which takes the following parameters:\n",
"\n",
@@ -649,6 +682,17 @@
"Learn more about [VideoDataset](https://cloud.google.com/vertex-ai/docs/datasets/prepare-video)."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "import_file:hmdb,csv,vcn"
},
"outputs": [],
"source": [
"IMPORT_FILE = \"gs://automl-video-demo-data/hmdb_split1_5classes_train_inf.csv\""
]
},
{
"cell_type": "code",
"execution_count": null,
@@ -666,24 +710,13 @@
"print(dataset.resource_name)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "import_file:happydb,csv,tcn"
},
"outputs": [],
"source": [
"IMPORT_FILE = \"gs://cloud-ml-data/NL-classification/happiness.csv\""
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "create_dataset:text,tcn"
},
"source": [
"### Create the Dataset\n",
"### Create a Text Dataset\n",
"\n",
"Next, create the `Dataset` resource using the `create` method for the `TextDataset` class, which takes the following parameters:\n",
"\n",
@@ -698,6 +731,17 @@
"Learn more about [TextDataset](https://cloud.google.com/vertex-ai/docs/datasets/prepare-text)."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "import_file:happydb,csv,tcn"
},
"outputs": [],
"source": [
"IMPORT_FILE = \"gs://cloud-ml-data/NL-classification/happiness.csv\""
]
},
{
"cell_type": "code",
"execution_count": null,
@@ -715,6 +759,24 @@
"print(dataset.resource_name)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "create_dataset:tabular,bq,lrg,v2"
},
"source": [
"### Create a Tabular Dataset\n",
"\n",
"#### CSV input data\n",
"\n",
"Next, create the `Dataset` resource using the `create` method for the `TabularDataset` class for CSV input data, which takes the following parameters:\n",
"\n",
"- `display_name`: The human readable name for the `Dataset` resource.\n",
"- `gcs_source`: A list of one or more dataset index files to import the data items into the `Dataset` resource.\n",
"\n",
"Learn more about [TabularDataset from CSV files](https://cloud.google.com/vertex-ai/docs/datasets/create-dataset-api#aiplatform_create_dataset_tabular_gcs_sample-python)"
]
},
{
"cell_type": "code",
"execution_count": null,
@@ -723,27 +785,50 @@
},
"outputs": [],
"source": [
"IMPORT_FILE = \"bq://bigquery-public-data.samples.gsod\"\n",
"BQ_TABLE = \"bigquery-public-data.samples.gsod\""
"IMPORT_FILE = \"gs://cloud-samples-data/tables/iris_1000.csv\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "create_dataset:tabular,bq,lrg,v2"
},
"outputs": [],
"source": [
"dataset = aip.TabularDataset.create(\n",
" display_name=\"example\" + \"_\" + TIMESTAMP, gcs_source=[IMPORT_FILE]\n",
")\n",
"\n",
"print(dataset.resource_name)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "create_dataset:tabular,bq,lrg,v2"
"id": "854dd1e0195c"
},
"source": [
"### Create the Dataset\n",
"#### BigQuery input data\n",
"\n",
"#### CSV input data\n",
"\n",
"Next, create the `Dataset` resource using the `create` method for the `TabularDataset` class, which takes the following parameters:\n",
"Next, create the `Dataset` resource using the `create` method for the `TabularDataset` class for BigQuery table input, which takes the following parameters:\n",
"\n",
"- `display_name`: The human readable name for the `Dataset` resource.\n",
"- `gcs_source`: A list of one or more dataset index files to import the data items into the `Dataset` resource.\n",
"- `labels`: User defined metadata. In this example, you store the location of the Cloud Storage bucket containing the user defined data.\n",
"- `bq_source`: A list of one or more BigQuery tables to import the data items into the `Dataset` resource.\n",
"\n",
"Learn more about [TabularDataset from CSV files](https://cloud.google.com/vertex-ai/docs/datasets/create-dataset-api#aiplatform_create_dataset_tabular_gcs_sample-python)"
"Learn more about [TabularDataset from BigQuery table](https://cloud.google.com/vertex-ai/docs/datasets/create-dataset-api#aiplatform_create_dataset_tabular_bigquery_sample-pythonn)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "86343c146300"
},
"outputs": [],
"source": [
"IMPORT_FILE = \"bq://bigquery-public-data.samples.gsod\"\n",
"BQ_TABLE = \"bigquery-public-data.samples.gsod\""
]
},
{
@@ -761,15 +846,63 @@
"print(dataset.resource_name)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "82e9fe20ce71"
},
"source": [
"#### Dataframe input data\n",
"\n",
"Next, create the `Dataset` resource using the `create_from_dataframe` method for the `TabularDataset` class for pandas dataframe input, which takes the following parameters:\n",
"\n",
"- `display_name`: The human readable name for the `Dataset` resource.\n",
"- `df_source`: The pandas dataframe to import the data items into the `Dataset` resource.\n",
"- `staging_path`: The BigQuery table to store the imported data."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "import_file:covid,csv,forecast"
"id": "3805f945ffdd"
},
"outputs": [],
"source": [
"IMPORT_FILE = \"gs://cloud-samples-data/ai-platform/covid/bigquery-public-covid-nyt-us-counties-train.csv\""
"# Download the table.\n",
"table = bigquery.TableReference.from_string(BQ_TABLE)\n",
"\n",
"rows = bqclient.list_rows(\n",
" table,\n",
" max_results=10000,\n",
" selected_fields=[\n",
" bigquery.SchemaField(\"station_number\", \"STRING\"),\n",
" bigquery.SchemaField(\"year\", \"INTEGER\"),\n",
" bigquery.SchemaField(\"month\", \"INTEGER\"),\n",
" bigquery.SchemaField(\"day\", \"INTEGER\"),\n",
" bigquery.SchemaField(\"mean_temp\", \"FLOAT\"),\n",
" ],\n",
")\n",
"\n",
"dataframe = rows.to_dataframe()\n",
"print(dataframe.head())"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "create_dataset:tabular,bq,lrg,v2"
},
"outputs": [],
"source": [
"dataset = aip.TabularDataset.create_from_dataframe(\n",
" display_name=\"example\" + \"_\" + TIMESTAMP,\n",
" df_source=dataframe,\n",
" staging_path=f\"bq://{PROJECT_ID}.samples.gsod\",\n",
")\n",
"\n",
"print(dataset.resource_name)"
]
},
{
@@ -778,7 +911,7 @@
"id": "create_dataset:tabular,forecast,v2"
},
"source": [
"### Create the Dataset\n",
"### Create a Time Series Dataset\n",
"\n",
"Next, create the `Dataset` resource using the `create` method for the `TimeSeriesDataset` class, which takes the following parameters:\n",
"\n",
@@ -789,6 +922,17 @@
"Learn more about [TimeSeriesDataset](https://cloud.google.com/vertex-ai/docs/datasets/prepare-tabular)."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "import_file:covid,csv,forecast"
},
"outputs": [],
"source": [
"IMPORT_FILE = \"gs://cloud-samples-data/ai-platform/covid/bigquery-public-covid-nyt-us-counties-train.csv\""
]
},
{
"cell_type": "code",
"execution_count": null,
@@ -1149,9 +1293,9 @@
"comps = BQ_TABLE.split(\".\")\n",
"BQ_PROJECT_DATASET_TABLE = comps[0] + \":\" + comps[1] + \".\" + comps[2]\n",
"\n",
"! bq --location=us extract --destination_format CSV $BQ_PROJECT_DATASET_TABLE $BUCKET_NAME/mydata*.csv\n",
"! bq --location=us extract --destination_format CSV $BQ_PROJECT_DATASET_TABLE $BUCKET_URI/mydata*.csv\n",
"\n",
"IMPORT_FILES = ! gsutil ls $BUCKET_NAME/mydata*.csv\n",
"IMPORT_FILES = ! gsutil ls $BUCKET_URI/mydata*.csv\n",
"\n",
"print(IMPORT_FILES)\n",
"\n",
@@ -1209,6 +1353,38 @@
"To create a dataframe from multiple CSV sources, you read each CSV file and concatenate the dataframes together."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "bcd2e4e0703b"
},
"source": [
"If you are running this notebook on Colab, run the following cell to install packages fsspec and gcsfs."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "927bd3f92268"
},
"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 Workbench AI Notebook, then don't execute this code\n",
"if not os.path.exists(\"/opt/deeplearning/metadata/env_version\"):\n",
" if \"google.colab\" in sys.modules:\n",
" ! pip3 install fsspec\n",
" ! pip3 install gcsfs"
]
},
{
"cell_type": "code",
"execution_count": null,
@@ -1269,7 +1445,7 @@
},
"outputs": [],
"source": [
"EXPORTED_DIR = f\"{BUCKET_NAME}/exported\"\n",
"EXPORTED_DIR = f\"{BUCKET_URI}/exported\"\n",
"exported_files = dataset.export_data(output_dir=EXPORTED_DIR)\n",
"\n",
"! gsutil ls $EXPORTED_DIR"
@@ -1498,7 +1674,7 @@
" data = f.readlines()\n",
"\n",
"# The path to the TFRecord cached file.\n",
"GCS_TFRECORD_URI = BUCKET_NAME + \"/flowers.tfrecord\"\n",
"GCS_TFRECORD_URI = BUCKET_URI + \"/flowers.tfrecord\"\n",
"\n",
"# Create the TFRecord cached file\n",
"with tf.io.TFRecordWriter(GCS_TFRECORD_URI) as writer:\n",
@@ -1532,14 +1708,7 @@
"Otherwise, you can delete the individual resources you created in this tutorial:\n",
"\n",
"- Dataset\n",
"- Pipeline\n",
"- Model\n",
"- Endpoint\n",
"- AutoML Training Job\n",
"- Batch Job\n",
"- Custom Job\n",
"- Hyperparameter Tuning Job\n",
"- Cloud Storage Bucket"
"- Bucket"
]
},
{
@@ -1550,61 +1719,16 @@
},
"outputs": [],
"source": [
"delete_all = True\n",
"delete_bucket = False\n",
"\n",
"if delete_all:\n",
" # Delete the dataset using the Vertex dataset object\n",
" try:\n",
" if \"dataset\" in globals():\n",
" dataset.delete()\n",
" except Exception as e:\n",
" print(e)\n",
"# Delete the dataset using the Vertex dataset object\n",
"datasets = aip.TabularDataset.list(filter=f'display_name=\"example_{TIMESTAMP}\"')\n",
"for dataset in datasets:\n",
" dataset.delete()\n",
"\n",
" # Delete the model using the Vertex model object\n",
" try:\n",
" if \"model\" in globals():\n",
" model.delete()\n",
" except Exception as e:\n",
" print(e)\n",
"\n",
" # Delete the endpoint using the Vertex endpoint object\n",
" try:\n",
" if \"endpoint\" in globals():\n",
" endpoint.undeploy_all()\n",
" endpoint.delete()\n",
" except Exception as e:\n",
" print(e)\n",
"\n",
" # Delete the AutoML or Pipeline training job\n",
" try:\n",
" if \"dag\" in globals():\n",
" dag.delete()\n",
" except Exception as e:\n",
" print(e)\n",
"\n",
" # Delete the custom training job\n",
" try:\n",
" if \"job\" in globals():\n",
" job.delete()\n",
" except Exception as e:\n",
" print(e)\n",
"\n",
" # Delete the batch prediction job using the Vertex batch prediction object\n",
" try:\n",
" if \"batch_predict_job\" in globals():\n",
" batch_predict_job.delete()\n",
" except Exception as e:\n",
" print(e)\n",
"\n",
" # Delete the hyperparameter tuning job using the Vertex hyperparameter tuning object\n",
" try:\n",
" if \"hpt_job\" in globals():\n",
" hpt_job.delete()\n",
" except Exception as e:\n",
" print(e)\n",
"\n",
" if \"BUCKET_NAME\" in globals():\n",
" ! gsutil rm -r $BUCKET_NAME"
"# Delete the bucket\n",
"if delete_bucket or os.getenv(\"IS_TESTING\"):\n",
" ! gsutil rm -r $BUCKET_URI"
]
}
],
@@ -44,7 +44,7 @@
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage1/get_started_with_data_labeling.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_data_labeling.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",
@@ -145,17 +145,20 @@
"source": [
"import os\n",
"\n",
"# The Google Cloud Notebook product has specific requirements\n",
"IS_GOOGLE_CLOUD_NOTEBOOK = os.path.exists(\"/opt/deeplearning/metadata/env_version\")\n",
"# The Vertex AI Workbench Notebook product has specific requirements\n",
"IS_WORKBENCH_NOTEBOOK = os.getenv(\"DL_ANACONDA_HOME\") and not os.getenv(\"VIRTUAL_ENV\")\n",
"IS_USER_MANAGED_WORKBENCH_NOTEBOOK = os.path.exists(\n",
" \"/opt/deeplearning/metadata/env_version\"\n",
")\n",
"\n",
"# Google Cloud Notebook requires dependencies to be installed with '--user'\n",
"# Vertex AI Notebook requires dependencies to be installed with '--user'\n",
"USER_FLAG = \"\"\n",
"if IS_GOOGLE_CLOUD_NOTEBOOK:\n",
"if IS_WORKBENCH_NOTEBOOK:\n",
" USER_FLAG = \"--user\"\n",
"\n",
"# Install the packages\n",
"! pip3 install --upgrade google-cloud-aiplatform $USER_FLAG\n",
"! pip3 install --upgrade google-cloud-storage $USER_FLAG"
"! pip3 install --upgrade google-cloud-aiplatform $USER_FLAG -q\n",
"! pip3 install --upgrade google-cloud-storage $USER_FLAG -q"
]
},
{
@@ -207,7 +210,7 @@
"\n",
"2. [Make sure that billing is enabled for your project.](https://cloud.google.com/billing/docs/how-to/modify-project)\n",
"\n",
"3. [Enable the Vertex AI APIs and Compute Engine APIs.](https://console.cloud.google.com/flows/enableapi?apiid=ml.googleapis.com,compute_component)\n",
"3. [Enable the Vertex AI APIs and Compute Engine APIs.](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com,compute_component)\n",
"\n",
"4. [Google Cloud SDK](https://cloud.google.com/sdk) is already installed in Google Cloud Notebooks.\n",
"\n",
@@ -359,7 +362,7 @@
"source": [
"### Authenticate your Google Cloud account\n",
"\n",
"**If you are using Google Cloud Notebooks**, your environment is already\n",
"**If you are using Vertex AI Workbench Notebooks**, your environment is already\n",
"authenticated. Skip this step."
]
},
@@ -401,20 +404,21 @@
},
"outputs": [],
"source": [
"import os\n",
"import sys\n",
"\n",
"# If you are running this notebook in Colab, run this cell and follow the\n",
"# instructions to authenticate your GCP account. This provides access to your\n",
"# Cloud Storage bucket and lets you submit training jobs and prediction\n",
"# requests.\n",
"\n",
"# The Google Cloud Notebook product has specific requirements\n",
"IS_GOOGLE_CLOUD_NOTEBOOK = os.path.exists(\"/opt/deeplearning/metadata/env_version\")\n",
"import os\n",
"import sys\n",
"\n",
"# If on Google Cloud Notebooks, then don't execute this code\n",
"if not IS_GOOGLE_CLOUD_NOTEBOOK:\n",
"# If on Vertex AI Workbench, then don't execute this code\n",
"IS_COLAB = False\n",
"if not os.path.exists(\"/opt/deeplearning/metadata/env_version\") and not os.getenv(\n",
" \"DL_ANACONDA_HOME\"\n",
"):\n",
" if \"google.colab\" in sys.modules:\n",
" IS_COLAB = True\n",
" from google.colab import auth as google_auth\n",
"\n",
" google_auth.authenticate_user()\n",
@@ -462,7 +466,8 @@
"outputs": [],
"source": [
"if BUCKET_URI == \"\" or BUCKET_URI is None or BUCKET_URI == \"gs://[your-bucket-name]\":\n",
" BUCKET_URI = \"gs://\" + PROJECT_ID + \"aip-\" + TIMESTAMP"
" BUCKET_NAME = PROJECT_ID + \"aip-\" + TIMESTAMP\n",
" BUCKET_URI = \"gs://\" + BUCKET_NAME"
]
},
{
@@ -39,8 +39,14 @@
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://console.cloud.google.com/ai/platform/notebooks/deploy-notebook?download_url=https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage1/mlops_data_management.ipynb\">\n",
" Open in Google Cloud Notebooks\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage1/mlops_data_management.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/colab-logo-32px.png\\\" alt=\"Colab logo\"> Run in Colab\n",
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://raw.githubusercontent.com/GoogleCloudPlatform/vertex-ai-samples/main/notebooks/community/ml_ops/stage1/mlops_data_management.ipynb\">\n",
" <img src=\"https://lh3.googleusercontent.com/UiNooY4LUgW_oTvpsNhPpQzsstV5W8F7rYgxgGBD85cWJoLmrOzhVs_ksK_vgx40SHs7jCqkTkCk=e14-rj-sc0xffffff-h130-w32\" alt=\"Vertex AI logo\">\n",
" Open in Vertex AI Workbench\n",
" </a>\n",
" </td>\n",
"</table>\n",
@@ -133,7 +139,20 @@
},
"outputs": [],
"source": [
"ONCE_ONLY = False\n",
"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",
"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",
@@ -178,6 +197,32 @@
" app.kernel.do_shutdown(True)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "84cd83853240"
},
"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, BigQuery, Compute Engine and Cloud Storage APIs](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com,bigquery,compute_component,storage_component).\n",
"\n",
"1. If you are running this notebook locally, you need to install the [Cloud SDK](https://cloud.google.com/sdk).\n",
"\n",
"1. Enter your project ID in the cell below. Then run the cell to make sure the\n",
"Cloud SDK uses the right project for all the commands in this notebook.\n",
"\n",
"**Note**: Jupyter runs lines prefixed with `!` as shell commands, and it interpolates Python variables prefixed with `$` into these commands."
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -254,7 +299,10 @@
},
"outputs": [],
"source": [
"REGION = \"us-central1\" # @param {type: \"string\"}"
"REGION = \"[your-region]\" # @param {type: \"string\"}\n",
"\n",
"if REGION == \"[your-region]\":\n",
" REGION = \"us-central1\""
]
},
{
@@ -281,6 +329,67 @@
"TIMESTAMP = datetime.now().strftime(\"%Y%m%d%H%M%S\")"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "77c385f0db59"
},
"source": [
"### Authenticate your Google Cloud account\n",
"\n",
"**If you are using Vertex AI Workbench Notebooks**, your environment is already authenticated. Skip this step.\n",
"\n",
"**If you are using Colab**, run the cell below and follow the instructions when prompted to authenticate your account via oAuth.\n",
"\n",
"**Otherwise**, follow these steps:\n",
"\n",
"In the Cloud Console, go to the [Create service account key](https://console.cloud.google.com/apis/credentials/serviceaccountkey) page.\n",
"\n",
"1. **Click Create service account**.\n",
"\n",
"2. In the **Service account name** field, enter a name, and click **Create**.\n",
"\n",
"3. In the **Grant this service account access to project** section, click the Role drop-down list. Type \"Vertex AI\" into the filter box, and select **Vertex AI Administrator**. Type \"Storage Object Admin\" into the filter box, and select **Storage Object Admin**.\n",
"\n",
"4. Click Create. A JSON file that contains your key downloads to your local environment.\n",
"\n",
"5. Enter the path to your service account key as the GOOGLE_APPLICATION_CREDENTIALS variable in the cell below and run the cell."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "535223fa4b84"
},
"outputs": [],
"source": [
"# If you are running this notebook in Colab, run this cell and follow the\n",
"# instructions to authenticate your GCP account. This provides access to your\n",
"# Cloud Storage bucket and lets you submit training jobs and prediction\n",
"# requests.\n",
"\n",
"import os\n",
"import sys\n",
"\n",
"# If on Vertex AI Workbench, then don't execute this code\n",
"IS_COLAB = False\n",
"if not os.path.exists(\"/opt/deeplearning/metadata/env_version\") and not os.getenv(\n",
" \"DL_ANACONDA_HOME\"\n",
"):\n",
" if \"google.colab\" in sys.modules:\n",
" IS_COLAB = True\n",
" from google.colab import auth as google_auth\n",
"\n",
" google_auth.authenticate_user()\n",
"\n",
" # If you are running this notebook locally, replace the string below with the\n",
" # path to your service account key and run this cell to authenticate your GCP\n",
" # account.\n",
" elif not os.getenv(\"IS_TESTING\"):\n",
" %env GOOGLE_APPLICATION_CREDENTIALS ''"
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -309,7 +418,8 @@
},
"outputs": [],
"source": [
"BUCKET_NAME = \"gs://[your-bucket-name]\" # @param {type:\"string\"}"
"BUCKET_NAME = \"[your-bucket-name]\" # @param {type:\"string\"}\n",
"BUCKET_URI = f\"gs://{BUCKET_NAME}\""
]
},
{
@@ -320,8 +430,9 @@
},
"outputs": [],
"source": [
"if BUCKET_NAME == \"\" or BUCKET_NAME is None or BUCKET_NAME == \"gs://[your-bucket-name]\":\n",
" BUCKET_NAME = \"gs://\" + PROJECT_ID + \"aip-\" + TIMESTAMP"
"if BUCKET_NAME == \"\" or BUCKET_NAME is None or BUCKET_NAME == \"[your-bucket-name]\":\n",
" BUCKET_NAME = PROJECT_ID + \"aip-\" + TIMESTAMP\n",
" BUCKET_URI = \"gs://\" + BUCKET_NAME"
]
},
{
@@ -341,7 +452,7 @@
},
"outputs": [],
"source": [
"! gsutil mb -l $REGION $BUCKET_NAME"
"! gsutil mb -l $REGION $BUCKET_URI"
]
},
{
@@ -361,7 +472,7 @@
},
"outputs": [],
"source": [
"! gsutil ls -al $BUCKET_NAME"
"! gsutil ls -al $BUCKET_URI"
]
},
{
@@ -516,7 +627,7 @@
},
"outputs": [],
"source": [
"aip.init(project=PROJECT_ID, staging_bucket=BUCKET_NAME)"
"aip.init(project=PROJECT_ID, staging_bucket=BUCKET_URI)"
]
},
{
@@ -757,7 +868,7 @@
"dataset = aip.TabularDataset.create(\n",
" display_name=\"Chicago Taxi\" + \"_\" + TIMESTAMP,\n",
" bq_source=[IMPORT_FILE],\n",
" labels={\"user_metadata\": BUCKET_NAME[5:]},\n",
" labels={\"user_metadata\": BUCKET_NAME},\n",
")\n",
"\n",
"label_column = \"tip_bin\"\n",
@@ -949,9 +1060,9 @@
},
"outputs": [],
"source": [
"STATISTICS_SCHEMA = BUCKET_NAME + \"/statistics.jsonl\"\n",
"STATISTICS_SCHEMA = BUCKET_URI + \"/statistics.jsonl\"\n",
"\n",
"tfdv.write_stats_text(stats, BUCKET_NAME + \"/statistics.jsonl\")\n",
"tfdv.write_stats_text(stats, BUCKET_URI + \"/statistics.jsonl\")\n",
"\n",
"with tf.io.gfile.GFile(\n",
" \"gs://\" + dataset.labels[\"user_metadata\"] + \"/metadata.jsonl\", \"r\"\n",
@@ -964,7 +1075,7 @@
") as f:\n",
" json.dump(metadata, f)\n",
"\n",
"!gsutil cat $BUCKET_NAME/metadata.jsonl"
"! gsutil cat $BUCKET_URI/metadata.jsonl"
]
},
{
@@ -1011,7 +1122,7 @@
},
"outputs": [],
"source": [
"SCHEMA_LOCATION = BUCKET_NAME + \"/schema.txt\"\n",
"SCHEMA_LOCATION = BUCKET_URI + \"/schema.txt\"\n",
"\n",
"# When running Apache Beam directly (file is directly accessed)\n",
"tfdv.write_schema_text(output_path=SCHEMA_LOCATION, schema=schema)\n",
@@ -1049,7 +1160,7 @@
") as f:\n",
" json.dump(metadata, f)\n",
"\n",
"!gsutil cat $BUCKET_NAME/metadata.jsonl"
"! gsutil cat $BUCKET_URI/metadata.jsonl"
]
},
{
@@ -1372,10 +1483,10 @@
" )\n",
"\n",
"\n",
"EXPORTED_JSONL_PREFIX = os.path.join(BUCKET_NAME, \"exported_data/jsonl\")\n",
"EXPORTED_TFREC_PREFIX = os.path.join(BUCKET_NAME, \"exported_data/tfrec\")\n",
"TRANSFORMED_DATA_PREFIX = os.path.join(BUCKET_NAME, \"transformed_data\")\n",
"TRANSFORM_ARTIFACTS_DIR = os.path.join(BUCKET_NAME, \"transformed_artifacts\")\n",
"EXPORTED_JSONL_PREFIX = os.path.join(BUCKET_URI, \"exported_data/jsonl\")\n",
"EXPORTED_TFREC_PREFIX = os.path.join(BUCKET_URI, \"exported_data/tfrec\")\n",
"TRANSFORMED_DATA_PREFIX = os.path.join(BUCKET_URI, \"transformed_data\")\n",
"TRANSFORM_ARTIFACTS_DIR = os.path.join(BUCKET_URI, \"transformed_artifacts\")\n",
"\n",
"QUERY_STRING = \"SELECT * FROM {} LIMIT 300000\".format(BQ_TABLE)\n",
"JOB_NAME = \"chicago\" + TIMESTAMP\n",
@@ -1388,7 +1499,7 @@
" \"transform_artifact_dir\": TRANSFORM_ARTIFACTS_DIR,\n",
" \"exported_jsonl_prefix\": EXPORTED_JSONL_PREFIX,\n",
" \"exported_tfrec_prefix\": EXPORTED_TFREC_PREFIX,\n",
" \"temp_location\": os.path.join(BUCKET_NAME, \"temp\"),\n",
" \"temp_location\": os.path.join(BUCKET_URI, \"temp\"),\n",
" \"project\": PROJECT_ID,\n",
" \"region\": REGION,\n",
" \"setup_file\": \"./setup.py\",\n",
@@ -1459,7 +1570,7 @@
") as f:\n",
" json.dump(metadata, f)\n",
"\n",
"!gsutil cat $BUCKET_NAME/metadata.jsonl"
"! gsutil cat $BUCKET_URI/metadata.jsonl"
]
},
{
@@ -1473,17 +1584,9 @@
"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",
"Otherwise, you can delete the individual resources you created in this tutorial.\n",
"\n",
"- Dataset\n",
"- Pipeline\n",
"- Model\n",
"- Endpoint\n",
"- AutoML Training Job\n",
"- Batch Job\n",
"- Custom Job\n",
"- Hyperparameter Tuning Job\n",
"- Cloud Storage Bucket"
"*Note:* stage2/mlops_experimentation is dependent on the resources created by this stage1 notebook."
]
},
{
@@ -1504,8 +1607,8 @@
" except Exception as e:\n",
" print(e)\n",
"\n",
" if \"BUCKET_NAME\" in globals():\n",
" ! gsutil rm -r $BUCKET_NAME"
" if \"BUCKET_URI\" in globals():\n",
" ! gsutil rm -r $BUCKET_URI"
]
}
],
Binary file not shown.

Before

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

+41 -10
View File
@@ -25,7 +25,11 @@ The second stage in MLOps is experimenting in developing one or more baseline mo
- Use the What-if-Tool (WIT) to explore how the trained model would make predictions in different scenarios.
<img src='stage2.png'>
<img src='stage2v3.png'>
<br/>
<br/>
<br/>
<img src='stage2.2v1.png'>
## Notebooks
@@ -115,6 +119,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)
```
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.
- 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)
```
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)
```
@@ -214,18 +244,19 @@ The steps performed include:
- Hyperparameter tuning the Vertex AI TabNet model.
- Train the model using Vertex AI Training using BigQuery table.
```
[Get Started with Vertex AI TabNet builtin algorithm](get_started_with_tabnet.ipynb)
[Get Started with Vision API and AutoML](get_started_with_visionapi_and_automl.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.
- 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.
- Train the model.
- View the model evaluation.
- Deploy the `Vertex AI Model` resource to a serving `Endpoint` resource.
- Make a prediction.
- Undeploy the `Model`.
```
@@ -38,13 +38,13 @@
" View on GitHub\n",
" </a>\n",
" </td>\n",
" <td>\n",
" <td>\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage2/get_started_automl_training.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/colab-logo-32px.png\\\" alt=\"Colab logo\"> Run in Colab\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://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage2/get_started_automl_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_automl_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",
@@ -173,7 +173,7 @@
"source": [
"## Installations\n",
"\n",
"Install the following packages for executing the MLOps notebooks."
"Install the packages required for executing this notebook."
]
},
{
@@ -186,16 +186,21 @@
"source": [
"import os\n",
"\n",
"# The Google Cloud Notebook product has specific requirements\n",
"IS_GOOGLE_CLOUD_NOTEBOOK = os.path.exists(\"/opt/deeplearning/metadata/env_version\")\n",
"# The Vertex AI Workbench Notebook product has specific requirements\n",
"IS_WORKBENCH_NOTEBOOK = os.getenv(\"DL_ANACONDA_HOME\") and not os.getenv(\"VIRTUAL_ENV\")\n",
"IS_USER_MANAGED_WORKBENCH_NOTEBOOK = os.path.exists(\n",
" \"/opt/deeplearning/metadata/env_version\"\n",
")\n",
"\n",
"# Google Cloud Notebook requires dependencies to be installed with '--user'\n",
"# Vertex AI Notebook requires dependencies to be installed with '--user'\n",
"USER_FLAG = \"\"\n",
"if IS_GOOGLE_CLOUD_NOTEBOOK:\n",
"if IS_WORKBENCH_NOTEBOOK:\n",
" USER_FLAG = \"--user\"\n",
"\n",
"! pip3 install --upgrade google-cloud-aiplatform $USER_FLAG\n",
"! pip3 install --upgrade google-cloud-storage $USER_FLAG"
"# Install the packages\n",
"\n",
"! pip3 install --upgrade google-cloud-aiplatform $USER_FLAG -q\n",
"! pip3 install --upgrade google-cloud-storage $USER_FLAG -q"
]
},
{
@@ -358,7 +363,7 @@
"source": [
"### Authenticate your Google Cloud account\n",
"\n",
"**If you are using Google Cloud Notebooks**, your environment is already authenticated. Skip this step.\n",
"**If you are using Vertex AI Workbench Notebooks**, your environment is already authenticated. 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",
@@ -393,9 +398,13 @@
"import os\n",
"import sys\n",
"\n",
"# If on Google Cloud Notebook, then don't execute this code\n",
"if not os.path.exists(\"/opt/deeplearning/metadata/env_version\"):\n",
"# If on Vertex AI Workbench, then don't execute this code\n",
"IS_COLAB = False\n",
"if not os.path.exists(\"/opt/deeplearning/metadata/env_version\") and not os.getenv(\n",
" \"DL_ANACONDA_HOME\"\n",
"):\n",
" if \"google.colab\" in sys.modules:\n",
" IS_COLAB = True\n",
" from google.colab import auth as google_auth\n",
"\n",
" google_auth.authenticate_user()\n",
@@ -762,9 +771,8 @@
},
"source": [
"## Review model evaluation scores\n",
"After your model training has finished, you can review the evaluation scores for it.\n",
"\n",
"First, you need to get a reference to the new model. As with datasets, you can either use the reference to the model variable you created when you deployed the model or you can list all of the models in your project."
"After your model training has finished, you can review the evaluation scores for it using the `list_model_evaluations()` method. This method will return an iterator for each evaluation slice."
]
},
{
@@ -775,20 +783,10 @@
},
"outputs": [],
"source": [
"# Get model resource ID\n",
"models = aiplatform.Model.list(filter=\"display_name=flowers_\" + TIMESTAMP)\n",
"model_evaluations = model.list_model_evaluations()\n",
"\n",
"# Get a reference to the Model Service client\n",
"client_options = {\"api_endpoint\": f\"{REGION}-aiplatform.googleapis.com\"}\n",
"model_service_client = aiplatform.gapic.ModelServiceClient(\n",
" client_options=client_options\n",
")\n",
"\n",
"model_evaluations = model_service_client.list_model_evaluations(\n",
" parent=models[0].resource_name\n",
")\n",
"model_evaluation = list(model_evaluations)[0]\n",
"print(model_evaluation)"
"for model_evaluation in model_evaluations:\n",
" print(model_evaluation.to_dict())"
]
},
{
@@ -1263,9 +1261,8 @@
},
"source": [
"## Review model evaluation scores\n",
"After your model has finished training, you can review the evaluation scores for it.\n",
"\n",
"First, you need to get a reference to the new model. As with datasets, you can either use the reference to the model variable you created when you deployed the model or you can list all of the models in your project."
"After your model training has finished, you can review the evaluation scores for it using the `list_model_evaluations()` method. This method will return an iterator for each evaluation slice."
]
},
{
@@ -1276,20 +1273,10 @@
},
"outputs": [],
"source": [
"# Get model resource ID\n",
"models = aiplatform.Model.list(filter=\"display_name=gsod_\" + TIMESTAMP)\n",
"model_evaluations = model.list_model_evaluations()\n",
"\n",
"# Get a reference to the Model Service client\n",
"client_options = {\"api_endpoint\": f\"{REGION}-aiplatform.googleapis.com\"}\n",
"model_service_client = aiplatform.gapic.ModelServiceClient(\n",
" client_options=client_options\n",
")\n",
"\n",
"model_evaluations = model_service_client.list_model_evaluations(\n",
" parent=models[0].resource_name\n",
")\n",
"model_evaluation = list(model_evaluations)[0]\n",
"print(model_evaluation)"
"for model_evaluation in model_evaluations:\n",
" print(model_evaluation.to_dict())"
]
},
{
@@ -1627,9 +1614,8 @@
},
"source": [
"## Review model evaluation scores\n",
"After your model has finished training, you can review the evaluation scores for it.\n",
"\n",
"First, you need to get a reference to the new model. As with datasets, you can either use the reference to the model variable you created when you deployed the model or you can list all of the models in your project."
"After your model training has finished, you can review the evaluation scores for it using the `list_model_evaluations()` method. This method will return an iterator for each evaluation slice."
]
},
{
@@ -1640,20 +1626,10 @@
},
"outputs": [],
"source": [
"# Get model resource ID\n",
"models = aiplatform.Model.list(filter=\"display_name=happydb_\" + TIMESTAMP)\n",
"model_evaluations = model.list_model_evaluations()\n",
"\n",
"# Get a reference to the Model Service client\n",
"client_options = {\"api_endpoint\": f\"{REGION}-aiplatform.googleapis.com\"}\n",
"model_service_client = aiplatform.gapic.ModelServiceClient(\n",
" client_options=client_options\n",
")\n",
"\n",
"model_evaluations = model_service_client.list_model_evaluations(\n",
" parent=models[0].resource_name\n",
")\n",
"model_evaluation = list(model_evaluations)[0]\n",
"print(model_evaluation)"
"for model_evaluation in model_evaluations:\n",
" print(model_evaluation.to_dict())"
]
},
{
@@ -1954,9 +1930,8 @@
},
"source": [
"## Review model evaluation scores\n",
"After your model has finished training, you can review the evaluation scores for it.\n",
"\n",
"First, you need to get a reference to the new model. As with datasets, you can either use the reference to the model variable you created when you deployed the model or you can list all of the models in your project."
"After your model training has finished, you can review the evaluation scores for it using the `list_model_evaluations()` method. This method will return an iterator for each evaluation slice."
]
},
{
@@ -1967,20 +1942,10 @@
},
"outputs": [],
"source": [
"# Get model resource ID\n",
"models = aiplatform.Model.list(filter=\"display_name=human_motion_\" + TIMESTAMP)\n",
"model_evaluations = model.list_model_evaluations()\n",
"\n",
"# Get a reference to the Model Service client\n",
"client_options = {\"api_endpoint\": f\"{REGION}-aiplatform.googleapis.com\"}\n",
"model_service_client = aiplatform.gapic.ModelServiceClient(\n",
" client_options=client_options\n",
")\n",
"\n",
"model_evaluations = model_service_client.list_model_evaluations(\n",
" parent=models[0].resource_name\n",
")\n",
"model_evaluation = list(model_evaluations)[0]\n",
"print(model_evaluation)"
"for model_evaluation in model_evaluations:\n",
" print(model_evaluation.to_dict())"
]
},
{
@@ -38,8 +38,13 @@
" 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/stage2/get_started_bqml_training.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://github.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/blob/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",
@@ -128,18 +133,20 @@
"source": [
"import os\n",
"\n",
"# The Google Cloud Notebook product has specific requirements\n",
"IS_GOOGLE_CLOUD_NOTEBOOK = os.path.exists(\"/opt/deeplearning/metadata/env_version\")\n",
"# The Vertex AI Workbench Notebook product has specific requirements\n",
"IS_WORKBENCH_NOTEBOOK = os.getenv(\"DL_ANACONDA_HOME\") and not os.getenv(\"VIRTUAL_ENV\")\n",
"IS_USER_MANAGED_WORKBENCH_NOTEBOOK = os.path.exists(\"/opt/deeplearning/metadata/env_version\")\n",
"\n",
"# Google Cloud Notebook requires dependencies to be installed with '--user'\n",
"# Vertex AI Notebook requires dependencies to be installed with '--user'\n",
"USER_FLAG = \"\"\n",
"if IS_GOOGLE_CLOUD_NOTEBOOK:\n",
"if IS_WORKBENCH_NOTEBOOK:\n",
" USER_FLAG = \"--user\"\n",
"\n",
"# Install the packages\n",
"! pip3 install --upgrade pyarrow $USER_FLAG\n",
"! pip3 install --upgrade google-cloud-aiplatform $USER_FLAG\n",
"! pip3 install --upgrade google-cloud-bigquery $USER_FLAG"
"! pip3 install --upgrade pyarrow \\\n",
" google-cloud-aiplatform \\\n",
" google-cloud-bigquery \\\n",
" google-cloud-bigquery-storage $USER_FLAG -q"
]
},
{
@@ -177,6 +184,23 @@
"id": "project_id"
},
"source": [
"### Set up your Google Cloud project\n",
"\n",
"**The following steps are required, regardless of your notebook environment.**\n",
"\n",
"1. [Select or create a Google Cloud project](https://console.cloud.google.com/cloud-resource-manager). When you first create an account, you get a $300 free credit towards your compute/storage costs.\n",
"\n",
"1. [Make sure that billing is enabled for your project](https://cloud.google.com/billing/docs/how-to/modify-project).\n",
"\n",
"1. [Enable the Vertex AI, BigQuery, Compute Engine and Cloud Storage APIs](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com,bigquery,compute_component,storage_component).\n",
"\n",
"1. If you are running this notebook locally, you need to install the [Cloud SDK](https://cloud.google.com/sdk).\n",
"\n",
"1. Enter your project ID in the cell below. Then run the cell to make sure the\n",
"Cloud SDK uses the right project for all the commands in this notebook.\n",
"\n",
"**Note**: Jupyter runs lines prefixed with `!` as shell commands, and it interpolates Python variables prefixed with `$` into these commands.\n",
"\n",
"#### 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`."
@@ -277,6 +301,67 @@
"TIMESTAMP = datetime.now().strftime(\"%Y%m%d%H%M%S\")"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "f3bd8c0d0469"
},
"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": "e0953a00668e"
},
"outputs": [],
"source": [
"# If you are running this notebook in Colab, run this cell and follow the\n",
"# instructions to authenticate your GCP account. This provides access to your\n",
"# Cloud Storage bucket and lets you submit training jobs and prediction\n",
"# requests.\n",
"\n",
"import os\n",
"import sys\n",
"\n",
"# If on Vertex AI Workbench, then don't execute this code\n",
"IS_COLAB = False\n",
"if not os.path.exists(\"/opt/deeplearning/metadata/env_version\") and not os.getenv(\n",
" \"DL_ANACONDA_HOME\"\n",
"):\n",
" if \"google.colab\" in sys.modules:\n",
" IS_COLAB = True\n",
" from google.colab import auth as google_auth\n",
"\n",
" google_auth.authenticate_user()\n",
"\n",
" # If you are running this notebook locally, replace the string below with the\n",
" # path to your service account key and run this cell to authenticate your GCP\n",
" # account.\n",
" elif not os.getenv(\"IS_TESTING\"):\n",
" %env GOOGLE_APPLICATION_CREDENTIALS ''"
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -300,7 +385,8 @@
},
"outputs": [],
"source": [
"BUCKET_NAME = \"gs://[your-bucket-name]\" # @param {type:\"string\"}"
"BUCKET_NAME = \"[your-bucket-name]\" # @param {type:\"string\"}\n",
"BUCKET_URI = f\"gs://{BUCKET_NAME}\""
]
},
{
@@ -311,8 +397,9 @@
},
"outputs": [],
"source": [
"if BUCKET_NAME == \"\" or BUCKET_NAME is None or BUCKET_NAME == \"gs://[your-bucket-name]\":\n",
" BUCKET_NAME = \"gs://\" + PROJECT_ID + \"aip-\" + TIMESTAMP"
"if BUCKET_NAME == \"\" or BUCKET_NAME is None or BUCKET_NAME == \"[your-bucket-name]\":\n",
" BUCKET_NAME = PROJECT_ID + \"aip-\" + TIMESTAMP\n",
" BUCKET_URI = f\"gs://{BUCKET_NAME}\""
]
},
{
@@ -332,7 +419,7 @@
},
"outputs": [],
"source": [
"! gsutil mb -l $REGION $BUCKET_NAME"
"! gsutil mb -l $REGION $BUCKET_URI"
]
},
{
@@ -352,7 +439,55 @@
},
"outputs": [],
"source": [
"! gsutil ls -al $BUCKET_NAME"
"! gsutil ls -al $BUCKET_URI"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "set_service_account"
},
"source": [
"#### Service Account\n",
"\n",
"You use a service account to create Vertex AI Pipeline jobs. If you do not want to use your project's Compute Engine service account, set `SERVICE_ACCOUNT` to another service account ID."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "set_service_account"
},
"outputs": [],
"source": [
"SERVICE_ACCOUNT = \"[your-service-account]\" # @param {type:\"string\"}"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "autoset_service_account"
},
"outputs": [],
"source": [
"if (\n",
" SERVICE_ACCOUNT == \"\"\n",
" or SERVICE_ACCOUNT is None\n",
" or SERVICE_ACCOUNT == \"[your-service-account]\"\n",
"):\n",
" # Get your service account from gcloud\n",
" if not IS_COLAB:\n",
" shell_output = !gcloud auth list 2>/dev/null\n",
" SERVICE_ACCOUNT = shell_output[2].replace(\"*\", \"\").strip()\n",
"\n",
" if IS_COLAB:\n",
" shell_output = ! gcloud projects describe $PROJECT_ID\n",
" project_number = shell_output[-1].split(\":\")[1].strip().replace(\"'\", \"\")\n",
" SERVICE_ACCOUNT = f\"{project_number}-compute@developer.gserviceaccount.com\"\n",
"\n",
" print(\"Service Account:\", SERVICE_ACCOUNT)"
]
},
{
@@ -395,7 +530,7 @@
},
"outputs": [],
"source": [
"aiplatform.init(project=PROJECT_ID, staging_bucket=BUCKET_NAME)"
"aiplatform.init(project=PROJECT_ID, staging_bucket=BUCKET_URI)"
]
},
{
@@ -695,10 +830,10 @@
},
"outputs": [],
"source": [
"param = f\"{PROJECT_ID}:{BQ_DATASET_NAME}.{MODEL_NAME} {BUCKET_NAME}/{MODEL_NAME}\"\n",
"param = f\"{PROJECT_ID}:{BQ_DATASET_NAME}.{MODEL_NAME} {BUCKET_URI}/{MODEL_NAME}\"\n",
"! bq extract -m $param\n",
"\n",
"MODEL_DIR = f\"{BUCKET_NAME}/{BQ_DATASET_NAME}\"\n",
"MODEL_DIR = f\"{BUCKET_URI}/{BQ_DATASET_NAME}\"\n",
"! gsutil ls $MODEL_DIR"
]
},
@@ -829,7 +964,7 @@
"id": "model_delete:mbsdk"
},
"source": [
"#### Delete the model\n",
"#### Delete the `Vertex AI Model` resource\n",
"\n",
"The method 'delete()' deletes the model."
]
@@ -845,6 +980,32 @@
"model.delete()"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "7890ae6f6410"
},
"source": [
"### Delete the `BigQuery ML` model\n",
"\n",
"Next, delete the `BigQuery ML` instance of the model."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "f0b6163e70c0"
},
"outputs": [],
"source": [
"MODEL_QUERY = f\"\"\"\n",
"DROP MODEL `{BQ_DATASET_NAME}.{MODEL_NAME}`\n",
"\"\"\"\n",
"\n",
"job = bqclient.query(MODEL_QUERY)"
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -933,6 +1094,32 @@
"print(results)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "3f3cee1236b1"
},
"source": [
"### Delete the `BigQuery ML` model\n",
"\n",
"Next, delete the `BigQuery ML` instance of the model."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "957b7d841502"
},
"outputs": [],
"source": [
"MODEL_QUERY = f\"\"\"\n",
"DROP MODEL `{BQ_DATASET_NAME}.{MODEL_NAME}`\n",
"\"\"\"\n",
"\n",
"job = bqclient.query(MODEL_QUERY)"
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -985,7 +1172,33 @@
{
"cell_type": "markdown",
"metadata": {
"id": "1bb996026c94"
"id": "4def8aaf3398"
},
"source": [
"### Delete the `BigQuery ML` model\n",
"\n",
"Next, delete the `BigQuery ML` instance of the model."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "ff5b32618018"
},
"outputs": [],
"source": [
"MODEL_QUERY = f\"\"\"\n",
"DROP MODEL `{BQ_DATASET_NAME}.{MODEL_NAME}`\n",
"\"\"\"\n",
"\n",
"job = bqclient.query(MODEL_QUERY)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "2b4498ca6fea"
},
"source": [
"## Model Registry\n",
@@ -994,30 +1207,27 @@
"\n",
"### Setting permissions to automatically register the model\n",
"\n",
"You need to set some additional IAM permissions for BigQuery ML to automatically upload and register the model after training. Depending on your service account, the setting of the permissions below may fail. In this case, we recommend executing the permissions in a Cloud Shell."
"You need to set some additional IAM permissions for BigQuery ML to automatically upload and register the model after training. Depending on your service account, the setting of the permissions below may fail. In this case, we recommend executing the permissions in a Cloud Shell.\n",
"\n",
"Learn more about [Setting permissions for Model Registry](https://cloud.devsite.corp.google.com/bigquery-ml/docs/managing-models-vertex\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "eaaf24146aad"
"id": "29229f72d13d"
},
"outputs": [],
"source": [
"! gcloud projects add-iam-policy-binding $PROJECT_ID \\\n",
" --member='serviceAccount:cloud-dataengine@system.gserviceaccount.com' \\\n",
" --role='roles/aiplatform.admin'\n",
"\n",
"! gcloud projects add-iam-policy-binding $PROJECT_ID \\\n",
" --member='user:cloud-dataengine@prod.google.com' \\\n",
" --role='roles/aiplatform.admin'"
" --member=serviceAccount:$SERVICE_ACCOUNT --role=roles/aiplatform.admin --condition=None"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "8bfc0b26155f"
"id": "6c390ee7c11a"
},
"source": [
"### Training and registering the model\n",
@@ -1033,7 +1243,7 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "3ff1d4ef4df2"
"id": "57db464f4c42"
},
"outputs": [],
"source": [
@@ -1070,7 +1280,7 @@
{
"cell_type": "markdown",
"metadata": {
"id": "a243d86f9d22"
"id": "5b4970272040"
},
"source": [
"### Find the model in the `Vertex Model Registry`\n",
@@ -1082,7 +1292,7 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "4fd9a143d900"
"id": "76c22674ba99"
},
"outputs": [],
"source": [
@@ -1092,6 +1302,46 @@
"print(model.gca_resource)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "48e6ef5d5ffa"
},
"outputs": [],
"source": [
"models = aiplatform.Model.list()\n",
"for model in models:\n",
" if model.gca_resource.display_name.startswith(\"bqml\"):\n",
" print(model.gca_resource.display_name)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "ef61354b1a5f"
},
"source": [
"### Delete the `BigQuery ML` model\n",
"\n",
"Next, delete the `BigQuery ML` instance of the model."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "f6004d1ce59d"
},
"outputs": [],
"source": [
"MODEL_QUERY = f\"\"\"\n",
"DROP MODEL `{BQ_DATASET_NAME}.{MODEL_NAME}`\n",
"\"\"\"\n",
"\n",
"job = bqclient.query(MODEL_QUERY)"
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -1103,12 +1353,9 @@
"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",
"Otherwise, you can delete the individual resources you created in this tutorial.\n",
"\n",
"- Model\n",
"- Endpoint\n",
"- Dataset\n",
"- Cloud Storage Bucket"
"Set `delete_storage` to `True` to delete the Cloud Storage bucket used in this notebook."
]
},
{
@@ -1129,11 +1376,13 @@
"except Exception as e:\n",
" print(e)\n",
"\n",
"if os.getenv(\"IS_TESTING\"):\n",
"# Delete the created BigQuery dataset\n",
"! bq rm -r -f $PROJECT_ID:$BQ_DATASET_NAME\n",
"\n",
"delete_storage = False\n",
"if delete_storage or os.getenv(\"IS_TESTING\"):\n",
" # Delete the created GCS bucket\n",
" ! gsutil rm -r $BUCKET_NAME\n",
" # Delete the created BigQuery dataset\n",
" ! bq rm -r -f $PROJECT_ID:$BQ_DATASET_NAME"
" ! gsutil rm -r $BUCKET_URI"
]
}
],
@@ -33,7 +33,7 @@
"\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/stage2/get_started_vertex_distributed_training.ipynb\">\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage2/get_started_vertex_distributed_training.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",
@@ -44,7 +44,7 @@
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage2/get_started_vertex_distributed_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_vertex_distributed_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",
@@ -146,7 +146,7 @@
"source": [
"### Install additional packages\n",
"\n",
"Install the latest version of Vertex SDK for Python."
"Install the packages required for executing this notebook."
]
},
{
@@ -159,23 +159,17 @@
"source": [
"import os\n",
"\n",
"# The Google Cloud Notebook product has specific requirements\n",
"IS_GOOGLE_CLOUD_NOTEBOOK = os.path.exists(\"/opt/deeplearning/metadata/env_version\")\n",
"# The Vertex AI Workbench Notebook product has specific requirements\n",
"IS_WORKBENCH_NOTEBOOK = os.getenv(\"DL_ANACONDA_HOME\") and not os.getenv(\"VIRTUAL_ENV\")\n",
"IS_USER_MANAGED_WORKBENCH_NOTEBOOK = os.path.exists(\n",
" \"/opt/deeplearning/metadata/env_version\"\n",
")\n",
"\n",
"# Google Cloud Notebook requires dependencies to be installed with '--user'\n",
"# Vertex AI Notebook requires dependencies to be installed with '--user'\n",
"USER_FLAG = \"\"\n",
"if IS_GOOGLE_CLOUD_NOTEBOOK:\n",
" USER_FLAG = \"--user\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "TjOXHg2VyajN"
},
"outputs": [],
"source": [
"if IS_WORKBENCH_NOTEBOOK:\n",
" USER_FLAG = \"--user\"\n",
"\n",
"! pip3 install {USER_FLAG} --upgrade google-cloud-aiplatform"
]
},
@@ -209,6 +203,32 @@
" app.kernel.do_shutdown(True)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "84cd83853240"
},
"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, BigQuery, Compute Engine and Cloud Storage APIs](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com,bigquery,compute_component,storage_component).\n",
"\n",
"1. If you are running this notebook locally, you need to install the [Cloud SDK](https://cloud.google.com/sdk).\n",
"\n",
"1. Enter your project ID in the cell below. Then run the cell to make sure the\n",
"Cloud SDK uses the right project for all the commands in this notebook.\n",
"\n",
"**Note**: Jupyter runs lines prefixed with `!` as shell commands, and it interpolates Python variables prefixed with `$` into these commands."
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -287,7 +307,10 @@
},
"outputs": [],
"source": [
"REGION = \"us-central1\" # @param {type: \"string\"}"
"REGION = \"[your-region]\" # @param {type: \"string\"}\n",
"\n",
"if REGION == \"[your-region]\":\n",
" REGION = \"us-central1\""
]
},
{
@@ -322,7 +345,7 @@
"source": [
"### Authenticate your Google Cloud account\n",
"\n",
"**If you are using Google Cloud Notebooks**, your environment is already\n",
"**If you are using Vertex AI Workbench Notebooks**, your environment is already\n",
"authenticated. Skip this step."
]
},
@@ -364,20 +387,21 @@
},
"outputs": [],
"source": [
"import os\n",
"import sys\n",
"\n",
"# If you are running this notebook in Colab, run this cell and follow the\n",
"# instructions to authenticate your GCP account. This provides access to your\n",
"# Cloud Storage bucket and lets you submit training jobs and prediction\n",
"# requests.\n",
"\n",
"# The Google Cloud Notebook product has specific requirements\n",
"IS_GOOGLE_CLOUD_NOTEBOOK = os.path.exists(\"/opt/deeplearning/metadata/env_version\")\n",
"import os\n",
"import sys\n",
"\n",
"# If on Google Cloud Notebooks, then don't execute this code\n",
"if not IS_GOOGLE_CLOUD_NOTEBOOK:\n",
"# If on Vertex AI Workbench, then don't execute this code\n",
"IS_COLAB = False\n",
"if not os.path.exists(\"/opt/deeplearning/metadata/env_version\") and not os.getenv(\n",
" \"DL_ANACONDA_HOME\"\n",
"):\n",
" if \"google.colab\" in sys.modules:\n",
" IS_COLAB = True\n",
" from google.colab import auth as google_auth\n",
"\n",
" google_auth.authenticate_user()\n",
@@ -412,7 +436,8 @@
},
"outputs": [],
"source": [
"BUCKET_NAME = \"gs://[your-bucket-name]\" # @param {type:\"string\"}"
"BUCKET_NAME = \"[your-bucket-name]\" # @param {type:\"string\"}\n",
"BUCKET_URI = f\"gs://{BUCKET_NAME}\""
]
},
{
@@ -423,8 +448,9 @@
},
"outputs": [],
"source": [
"if BUCKET_NAME == \"\" or BUCKET_NAME is None or BUCKET_NAME == \"gs://[your-bucket-name]\":\n",
" BUCKET_NAME = \"gs://\" + PROJECT_ID + \"aip-\" + TIMESTAMP"
"if BUCKET_NAME == \"\" or BUCKET_NAME is None or BUCKET_NAME == \"[your-bucket-name]\":\n",
" BUCKET_NAME = PROJECT_ID + \"aip-\" + TIMESTAMP\n",
" BUCKET_URI = f\"gs://{BUCKET_NAME}\""
]
},
{
@@ -444,7 +470,7 @@
},
"outputs": [],
"source": [
"! gsutil mb -l $REGION $BUCKET_NAME"
"! gsutil mb -l $REGION $BUCKET_URI"
]
},
{
@@ -464,7 +490,7 @@
},
"outputs": [],
"source": [
"! gsutil ls -al $BUCKET_NAME"
"! gsutil ls -al $BUCKET_URI"
]
},
{
@@ -509,7 +535,7 @@
},
"outputs": [],
"source": [
"aip.init(project=PROJECT_ID, staging_bucket=BUCKET_NAME)"
"aip.init(project=PROJECT_ID, staging_bucket=BUCKET_URI)"
]
},
{
@@ -587,7 +613,7 @@
"if os.getenv(\"IS_TESTING_TF\"):\n",
" TF = os.getenv(\"IS_TESTING_TF\")\n",
"else:\n",
" TF = \"2.1\".replace(\".\", \"-\")\n",
" TF = \"2.5\".replace(\".\", \"-\")\n",
"\n",
"if TF[0] == \"2\":\n",
" if TRAIN_GPU:\n",
@@ -718,7 +744,7 @@
"\n",
"job = aip.CustomPythonPackageTrainingJob(\n",
" display_name=DISPLAY_NAME,\n",
" python_package_gcs_uri=f\"{BUCKET_NAME}/trainer_boston.tar.gz\",\n",
" python_package_gcs_uri=f\"{BUCKET_URI}/trainer_boston.tar.gz\",\n",
" python_module_name=\"trainer.task\",\n",
" container_uri=TRAIN_IMAGE,\n",
" model_serving_container_image_uri=DEPLOY_IMAGE,\n",
@@ -974,7 +1000,7 @@
"! rm -f custom.tar custom.tar.gz\n",
"! tar cvf custom.tar custom\n",
"! gzip custom.tar\n",
"! gsutil cp custom.tar.gz $BUCKET_NAME/trainer_boston.tar.gz"
"! gsutil cp custom.tar.gz $BUCKET_URI/trainer_boston.tar.gz"
]
},
{
@@ -996,7 +1022,7 @@
},
"outputs": [],
"source": [
"MODEL_DIR = BUCKET_NAME\n",
"MODEL_DIR = BUCKET_URI\n",
"\n",
"CMDARGS = [\"--epochs=5\", \"--batch_size=16\", \"--distribute=mirrored\"]\n",
"\n",
@@ -1168,7 +1194,7 @@
"\n",
"job = aip.CustomPythonPackageTrainingJob(\n",
" display_name=DISPLAY_NAME,\n",
" python_package_gcs_uri=f\"{BUCKET_NAME}/trainer_boston.tar.gz\",\n",
" python_package_gcs_uri=f\"{BUCKET_URI}/trainer_boston.tar.gz\",\n",
" python_module_name=\"trainer.task\",\n",
" container_uri=TRAIN_IMAGE,\n",
" model_serving_container_image_uri=DEPLOY_IMAGE,\n",
@@ -1195,7 +1221,7 @@
},
"outputs": [],
"source": [
"MODEL_DIR = BUCKET_NAME\n",
"MODEL_DIR = BUCKET_URI\n",
"\n",
"CMDARGS = [\"--epochs=5\", \"--batch_size=16\", \"--distribute=multiworker\"]\n",
"\n",
@@ -1338,7 +1364,11 @@
},
"outputs": [],
"source": [
"! docker build custom -t $TRAIN_IMAGE"
"if not IS_COLAB:\n",
" ! docker build custom -t $TRAIN_IMAGE\n",
"else:\n",
" # install docker daemon\n",
" ! apt-get -qq install docker.io"
]
},
{
@@ -1360,7 +1390,8 @@
},
"outputs": [],
"source": [
"! docker run $TRAIN_IMAGE --epochs=5 --model-dir=./"
"if not IS_COLAB:\n",
" ! docker run $TRAIN_IMAGE --epochs=5 --model-dir=./"
]
},
{
@@ -1382,7 +1413,38 @@
},
"outputs": [],
"source": [
"! docker push $TRAIN_IMAGE"
"if not IS_COLAB:\n",
" ! docker push $TRAIN_IMAGE"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "f50e9c553fb7"
},
"source": [
"*Executes in Colab*"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "a7e8c98f1e56"
},
"outputs": [],
"source": [
"%%bash -s $IS_COLAB $TRAIN_IMAGE\n",
"if [ $1 == \"False\" ]; then\n",
" exit 0\n",
"fi\n",
"set -x\n",
"dockerd -b none --iptables=0 -l warn &\n",
"for i in $(seq 5); do [ ! -S \"/var/run/docker.sock\" ] && sleep 2 || break; done\n",
"docker build custom -t $2\n",
"docker run $2 --epochs=5 --model-dir=./\n",
"docker push $2\n",
"kill $(jobs -p)"
]
},
{
@@ -1408,7 +1470,7 @@
"source": [
"PRIMARY_COMPUTE = \"n2-highcpu-64\"\n",
"\n",
"MODEL_DIR = BUCKET_NAME\n",
"MODEL_DIR = BUCKET_URI\n",
"\n",
"CMDARGS = [\n",
" \"--model-dir=\" + MODEL_DIR,\n",
@@ -40,11 +40,11 @@
" </td>\n",
" <td>\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage2/get_started_vertex_experiments.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/colab-logo-32px.png\\\" alt=\"Colab logo\"> Run in Colab\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://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage2/get_started_vertex_experiments.ipynb\">\n",
" <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://raw.githubusercontent.com/GoogleCloudPlatform/vertex-ai-samples/main/notebooks/community/ml_ops/stage2/get_started_vertex_experiments.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",
@@ -142,15 +142,18 @@
"source": [
"import os\n",
"\n",
"# The Google Cloud Notebook product has specific requirements\n",
"IS_GOOGLE_CLOUD_NOTEBOOK = os.path.exists(\"/opt/deeplearning/metadata/env_version\")\n",
"# The Vertex AI Workbench Notebook product has specific requirements\n",
"IS_WORKBENCH_NOTEBOOK = os.getenv(\"DL_ANACONDA_HOME\") and not os.getenv(\"VIRTUAL_ENV\")\n",
"IS_USER_MANAGED_WORKBENCH_NOTEBOOK = os.path.exists(\n",
" \"/opt/deeplearning/metadata/env_version\"\n",
")\n",
"\n",
"# Google Cloud Notebook requires dependencies to be installed with '--user'\n",
"# Vertex AI Notebook requires dependencies to be installed with '--user'\n",
"USER_FLAG = \"\"\n",
"if IS_GOOGLE_CLOUD_NOTEBOOK:\n",
"if IS_WORKBENCH_NOTEBOOK:\n",
" USER_FLAG = \"--user\"\n",
"\n",
"! pip3 install --upgrade google-cloud-logging $USER_FLAG"
"! pip3 install --upgrade google-cloud-logging $USER_FLAG -q"
]
},
{
@@ -314,7 +317,7 @@
"source": [
"### Authenticate your Google Cloud account\n",
"\n",
"**If you are using Google Cloud Notebooks**, your environment is already authenticated. Skip this step.\n",
"**If you are using Vertex AI Workbench Notebooks**, your environment is already authenticated. 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",
@@ -349,9 +352,13 @@
"import os\n",
"import sys\n",
"\n",
"# If on Google Cloud Notebook, then don't execute this code\n",
"if not os.path.exists(\"/opt/deeplearning/metadata/env_version\"):\n",
"# If on Vertex AI Workbench, then don't execute this code\n",
"IS_COLAB = False\n",
"if not os.path.exists(\"/opt/deeplearning/metadata/env_version\") and not os.getenv(\n",
" \"DL_ANACONDA_HOME\"\n",
"):\n",
" if \"google.colab\" in sys.modules:\n",
" IS_COLAB = True\n",
" from google.colab import auth as google_auth\n",
"\n",
" google_auth.authenticate_user()\n",
@@ -41,12 +41,12 @@
" \n",
" <td>\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage2/get_started_vertex_feature_store.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/colab-logo-32px.png\\\" alt=\"Colab logo\"> Run in Colab\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",
" \n",
" <td>\n",
" <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage2/get_started_vertex_feature_store.ipynb\">\n",
" <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://raw.githubusercontent.com/GoogleCloudPlatform/vertex-ai-samples/main/notebooks/community/ml_ops/stage2/get_started_vertex_feature_store.ipynb\">\n",
" <img src=\"https://lh3.googleusercontent.com/UiNooY4LUgW_oTvpsNhPpQzsstV5W8F7rYgxgGBD85cWJoLmrOzhVs_ksK_vgx40SHs7jCqkTkCk=e14-rj-sc0xffffff-h130-w32\" alt=\"Vertex AI logo\">\n",
" Open in Vertex AI Workbench\n",
" </a>\n",
@@ -144,12 +144,15 @@
"source": [
"import os\n",
"\n",
"# The Google Cloud Notebook product has specific requirements\n",
"IS_GOOGLE_CLOUD_NOTEBOOK = os.path.exists(\"/opt/deeplearning/metadata/env_version\")\n",
"# The Vertex AI Workbench Notebook product has specific requirements\n",
"IS_WORKBENCH_NOTEBOOK = os.getenv(\"DL_ANACONDA_HOME\") and not os.getenv(\"VIRTUAL_ENV\")\n",
"IS_USER_MANAGED_WORKBENCH_NOTEBOOK = os.path.exists(\n",
" \"/opt/deeplearning/metadata/env_version\"\n",
")\n",
"\n",
"# Google Cloud Notebook requires dependencies to be installed with '--user'\n",
"# Vertex AI Notebook requires dependencies to be installed with '--user'\n",
"USER_FLAG = \"\"\n",
"if IS_GOOGLE_CLOUD_NOTEBOOK:\n",
"if IS_WORKBENCH_NOTEBOOK:\n",
" USER_FLAG = \"--user\"\n",
"\n",
"# Install the dependecies\n",
@@ -185,6 +188,30 @@
" app.kernel.do_shutdown(True)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "project_id"
},
"source": [
"### 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, Cloud Storage and Cloud Logging APIs](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com,compute_component,storage_component,logging).\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": {
@@ -299,7 +326,7 @@
"source": [
"### Authenticate your Google Cloud account\n",
"\n",
"**If you are using Google Cloud Notebooks**, your environment is already authenticated. Skip this step.\n",
"**If you are using Vertex AI Workbench Notebooks**, your environment is already authenticated. 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",
@@ -334,8 +361,11 @@
"import os\n",
"import sys\n",
"\n",
"# If on Google Cloud Notebook, then don't execute this code\n",
"if not os.path.exists(\"/opt/deeplearning/metadata/env_version\"):\n",
"# If on Vertex AI Workbench, then don't execute this code\n",
"IS_COLAB = \"google.colab\" in sys.modules\n",
"if not os.path.exists(\"/opt/deeplearning/metadata/env_version\") and not os.getenv(\n",
" \"DL_ANACONDA_HOME\"\n",
"):\n",
" if \"google.colab\" in sys.modules:\n",
" from google.colab import auth as google_auth\n",
"\n",
@@ -459,7 +489,7 @@
"outputs": [],
"source": [
"# Represents featurestore resource path.\n",
"FEATURESTORE_NAME = \"movies\"\n",
"FEATURESTORE_NAME = \"movies_\" + TIMESTAMP\n",
"\n",
"featurestore = aiplatform.Featurestore.create(\n",
" featurestore_id=FEATURESTORE_NAME,\n",
@@ -29,7 +29,7 @@
"id": "title:generic,gcp"
},
"source": [
"# E2E ML on GCP: MLOps stage 2 : experimentation: get started with Vertex Tensorboard\n",
"# E2E ML on GCP: MLOps stage 2 : experimentation: get started with Vertex AI Tensorboard\n",
"\n",
"<table align=\"left\">\n",
" <td>\n",
@@ -44,7 +44,7 @@
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/notebook_template.ipynb\">\n",
" <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://raw.githubusercontent.com/GoogleCloudPlatform/vertex-ai-samples/main/notebooks/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",
@@ -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 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."
]
},
{
@@ -110,21 +110,14 @@
{
"cell_type": "markdown",
"metadata": {
"id": "94a148f11da5"
"id": "56cb7f08a9e8"
},
"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."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "56cb7f08a9e8"
},
"source": [
"all the requirements to run this notebook. You can skip this step.\n",
"\n",
"**Otherwise**, make sure your environment meets this notebook's requirements.\n",
"You need the following:\n",
"\n",
@@ -187,7 +180,7 @@
"source": [
"## Installations\n",
"\n",
"Install *one time* the packages for executing the MLOps notebooks."
"Install the following packages for executing this notebook."
]
},
{
@@ -200,25 +193,19 @@
"source": [
"import os\n",
"\n",
"# The Google Cloud Notebook product has specific requirements\n",
"IS_GOOGLE_CLOUD_NOTEBOOK = os.path.exists(\"/opt/deeplearning/metadata/env_version\")\n",
"# The Vertex AI Workbench Notebook product has specific requirements\n",
"IS_WORKBENCH_NOTEBOOK = os.getenv(\"DL_ANACONDA_HOME\") and not os.getenv(\"VIRTUAL_ENV\")\n",
"IS_USER_MANAGED_WORKBENCH_NOTEBOOK = os.path.exists(\n",
" \"/opt/deeplearning/metadata/env_version\"\n",
")\n",
"\n",
"# Google Cloud Notebook requires dependencies to be installed with '--user'\n",
"# Vertex AI Notebook requires dependencies to be installed with '--user'\n",
"USER_FLAG = \"\"\n",
"if IS_GOOGLE_CLOUD_NOTEBOOK:\n",
" USER_FLAG = \"--user\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "install_mlops"
},
"outputs": [],
"source": [
"! pip3 install -U tensorflow==2.8 $USER_FLAG\n",
"! pip3 install --upgrade google-cloud-aiplatform[tensorboard] $USER_FLAG"
"if IS_WORKBENCH_NOTEBOOK:\n",
" USER_FLAG = \"--user\"\n",
"\n",
"! pip3 install -U tensorflow==2.8 $USER_FLAG -q\n",
"! pip3 install --upgrade google-cloud-aiplatform[tensorboard] $USER_FLAG -q"
]
},
{
@@ -250,21 +237,14 @@
" app.kernel.do_shutdown(True)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "d6a00c14b087"
},
"source": [
"## Before you begin"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "2721ef0202d9"
},
"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",
@@ -273,7 +253,7 @@
"\n",
"1. [Make sure that billing is enabled for your project](https://cloud.google.com/billing/docs/how-to/modify-project).\n",
"\n",
"1. [Enable the Vertex AI API](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com). {TODO: Update the APIs needed for your tutorial. Edit the API names, and update the link to append the API IDs, separating each one with a comma. For example, container.googleapis.com,cloudbuild.googleapis.com}\n",
"1. [Enable the Vertex AI API](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com). \n",
"\n",
"1. If you are running this notebook locally, you will need to install the [Cloud SDK](https://cloud.google.com/sdk).\n",
"\n",
@@ -359,7 +339,10 @@
},
"outputs": [],
"source": [
"REGION = \"us-central1\" # @param {type: \"string\"}"
"REGION = \"[your-region]\" # @param {type: \"string\"}\n",
"\n",
"if REGION == \"[your-region]\":\n",
" REGION = \"us-central1\""
]
},
{
@@ -394,7 +377,7 @@
"source": [
"### Authenticate your Google Cloud account\n",
"\n",
"**If you are using Google Cloud Notebooks**, your environment is already\n",
"**If you are using Vertex AI Workbench Notebooks**, your environment is already\n",
"authenticated. Skip this step."
]
},
@@ -436,20 +419,21 @@
},
"outputs": [],
"source": [
"import os\n",
"import sys\n",
"\n",
"# If you are running this notebook in Colab, run this cell and follow the\n",
"# instructions to authenticate your GCP account. This provides access to your\n",
"# Cloud Storage bucket and lets you submit training jobs and prediction\n",
"# requests.\n",
"\n",
"# The Google Cloud Notebook product has specific requirements\n",
"IS_GOOGLE_CLOUD_NOTEBOOK = os.path.exists(\"/opt/deeplearning/metadata/env_version\")\n",
"import os\n",
"import sys\n",
"\n",
"# If on Google Cloud Notebooks, then don't execute this code\n",
"if not IS_GOOGLE_CLOUD_NOTEBOOK:\n",
"# If on Vertex AI Workbench, then don't execute this code\n",
"IS_COLAB = False\n",
"if not os.path.exists(\"/opt/deeplearning/metadata/env_version\") and not os.getenv(\n",
" \"DL_ANACONDA_HOME\"\n",
"):\n",
" if \"google.colab\" in sys.modules:\n",
" IS_COLAB = True\n",
" from google.colab import auth as google_auth\n",
"\n",
" google_auth.authenticate_user()\n",
@@ -574,9 +558,16 @@
" or SERVICE_ACCOUNT is None\n",
" or SERVICE_ACCOUNT == \"[your-service-account]\"\n",
"):\n",
" # Get your GCP project id from gcloud\n",
" shell_output = !gcloud auth list 2>/dev/null\n",
" SERVICE_ACCOUNT = shell_output[2].replace(\"*\", \"\").strip()\n",
" # Get your service account from gcloud\n",
" if not IS_COLAB:\n",
" shell_output = !gcloud auth list 2>/dev/null\n",
" SERVICE_ACCOUNT = shell_output[2].replace(\"*\", \"\").strip()\n",
"\n",
" if IS_COLAB:\n",
" shell_output = ! gcloud projects describe $PROJECT_ID\n",
" project_number = shell_output[-1].split(\":\")[1].strip().replace(\"'\", \"\")\n",
" SERVICE_ACCOUNT = f\"{project_number}-compute@developer.gserviceaccount.com\"\n",
"\n",
" print(\"Service Account:\", SERVICE_ACCOUNT)"
]
},
@@ -29,7 +29,7 @@
"id": "title:generic,gcp"
},
"source": [
"# E2E ML on GCP: MLOps stage 2 : experimentation: get started with Vertex Training\n",
"# E2E ML on GCP: MLOps stage 2 : experimentation: get started with Vertex AI Training\n",
"\n",
"<table align=\"left\">\n",
" <td>\n",
@@ -39,8 +39,14 @@
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://console.cloud.google.com/ai/platform/notebooks/deploy-notebook?download_url=https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage2/get_started_vertex_training.ipynb\">\n",
" Open in Google Cloud Notebooks\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage2/get_started_vertex_training.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/stage2/get_started_vertex_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",
" </td>\n",
"</table>\n",
@@ -127,7 +133,7 @@
"source": [
"## Installations\n",
"\n",
"Install *one time* the packages for executing the MLOps notebooks."
"Install the packages required for executing this notebook"
]
},
{
@@ -138,20 +144,20 @@
},
"outputs": [],
"source": [
"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"
"import os\n",
"\n",
"# The Vertex AI Workbench Notebook product has specific requirements\n",
"IS_WORKBENCH_NOTEBOOK = os.getenv(\"DL_ANACONDA_HOME\") and not os.getenv(\"VIRTUAL_ENV\")\n",
"IS_USER_MANAGED_WORKBENCH_NOTEBOOK = os.path.exists(\n",
" \"/opt/deeplearning/metadata/env_version\"\n",
")\n",
"\n",
"# Vertex AI Notebook requires dependencies to be installed with '--user'\n",
"USER_FLAG = \"\"\n",
"if IS_WORKBENCH_NOTEBOOK:\n",
" USER_FLAG = \"--user\"\n",
"\n",
"! pip3 install --upgrade google-cloud-aiplatform $USER_FLAG -q"
]
},
{
@@ -173,8 +179,6 @@
},
"outputs": [],
"source": [
"import os\n",
"\n",
"if not os.getenv(\"IS_TESTING\"):\n",
" # Automatically restart kernel after installs\n",
" import IPython\n",
@@ -183,6 +187,36 @@
" app.kernel.do_shutdown(True)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "before_you_begin"
},
"source": [
"## Before you begin\n",
"\n",
"### GPU runtime\n",
"\n",
"*Make sure you're running this notebook in a GPU runtime if you have that option. In Colab, select* **Runtime > Change Runtime Type > GPU**\n",
"\n",
"### Set up your Google Cloud project\n",
"\n",
"**The following steps are required, regardless of your notebook environment.**\n",
"\n",
"1. [Select or create a Google Cloud project](https://console.cloud.google.com/cloud-resource-manager). When you first create an account, you get a $300 free credit towards your compute/storage costs.\n",
"\n",
"2. [Make sure that billing is enabled for your project.](https://cloud.google.com/billing/docs/how-to/modify-project)\n",
"\n",
"3. [Enable the 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",
"\n",
"5. Enter your project ID in the cell below. Then run the cell to make sure the\n",
"Cloud SDK uses the right project for all the commands in this notebook.\n",
"\n",
"**Note**: Jupyter runs lines prefixed with `!` as shell commands, and it interpolates Python variables prefixed with `$`."
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -259,7 +293,10 @@
},
"outputs": [],
"source": [
"REGION = \"us-central1\" # @param {type: \"string\"}"
"REGION = \"[your-region]\" # @param {type: \"string\"}\n",
"\n",
"if REGION == \"[your-region]\":\n",
" REGION = \"us-central1\""
]
},
{
@@ -286,6 +323,67 @@
"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 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",
"**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 = False\n",
"if not os.path.exists(\"/opt/deeplearning/metadata/env_version\") and not os.getenv(\n",
" \"DL_ANACONDA_HOME\"\n",
"):\n",
" if \"google.colab\" in sys.modules:\n",
" IS_COLAB = True\n",
" from google.colab import auth as google_auth\n",
"\n",
" google_auth.authenticate_user()\n",
"\n",
" # If you are running this notebook locally, replace the string below with the\n",
" # path to your service account key and run this cell to authenticate your GCP\n",
" # account.\n",
" elif not os.getenv(\"IS_TESTING\"):\n",
" %env GOOGLE_APPLICATION_CREDENTIALS ''"
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -309,7 +407,8 @@
},
"outputs": [],
"source": [
"BUCKET_NAME = \"gs://[your-bucket-name]\" # @param {type:\"string\"}"
"BUCKET_NAME = \"[your-bucket-name]\" # @param {type:\"string\"}\n",
"BUCKET_URI = f\"gs://{BUCKET_NAME}\""
]
},
{
@@ -320,8 +419,9 @@
},
"outputs": [],
"source": [
"if BUCKET_NAME == \"\" or BUCKET_NAME is None or BUCKET_NAME == \"gs://[your-bucket-name]\":\n",
" BUCKET_NAME = \"gs://\" + PROJECT_ID + \"aip-\" + TIMESTAMP"
"if BUCKET_NAME == \"\" or BUCKET_NAME is None or BUCKET_NAME == \"[your-bucket-name]\":\n",
" BUCKET_NAME = PROJECT_ID + \"aip-\" + TIMESTAMP\n",
" BUCKET_URI = \"gs://\" + BUCKET_NAME"
]
},
{
@@ -341,7 +441,7 @@
},
"outputs": [],
"source": [
"! gsutil mb -l $REGION $BUCKET_NAME"
"! gsutil mb -l $REGION $BUCKET_URI"
]
},
{
@@ -361,7 +461,7 @@
},
"outputs": [],
"source": [
"! gsutil ls -al $BUCKET_NAME"
"! gsutil ls -al $BUCKET_URI"
]
},
{
@@ -384,7 +484,7 @@
},
"outputs": [],
"source": [
"import google.cloud.aiplatform as aip"
"import google.cloud.aiplatform as aiplatform"
]
},
{
@@ -406,7 +506,7 @@
},
"outputs": [],
"source": [
"aip.init(project=PROJECT_ID, staging_bucket=BUCKET_NAME)"
"aiplatform.init(project=PROJECT_ID, staging_bucket=BUCKET_URI)"
]
},
{
@@ -441,7 +541,7 @@
"source": [
"if os.getenv(\"IS_TESTING_TRAIN_GPU\"):\n",
" TRAIN_GPU, TRAIN_NGPU = (\n",
" aip.gapic.AcceleratorType.NVIDIA_TESLA_K80,\n",
" aiplatform.gapic.AcceleratorType.NVIDIA_TESLA_K80,\n",
" int(os.getenv(\"IS_TESTING_TRAIN_GPU\")),\n",
" )\n",
"else:\n",
@@ -449,7 +549,7 @@
"\n",
"if os.getenv(\"IS_TESTING_DEPLOY_GPU\"):\n",
" DEPLOY_GPU, DEPLOY_NGPU = (\n",
" aip.gapic.AcceleratorType.NVIDIA_TESLA_K80,\n",
" aiplatform.gapic.AcceleratorType.NVIDIA_TESLA_K80,\n",
" int(os.getenv(\"IS_TESTING_DEPLOY_GPU\")),\n",
" )\n",
"else:\n",
@@ -484,7 +584,7 @@
"if os.getenv(\"IS_TESTING_TF\"):\n",
" TF = os.getenv(\"IS_TESTING_TF\")\n",
"else:\n",
" TF = \"2.1\".replace(\".\", \"-\")\n",
" TF = \"2.5\".replace(\".\", \"-\")\n",
"\n",
"if TF[0] == \"2\":\n",
" if TRAIN_GPU:\n",
@@ -602,7 +702,7 @@
"DISPLAY_NAME = \"boston_\" + TIMESTAMP\n",
"REQUIREMENTS = [\"tensorflow==2.3\"]\n",
"\n",
"job = aip.CustomTrainingJob(\n",
"job = aiplatform.CustomTrainingJob(\n",
" display_name=DISPLAY_NAME,\n",
" script_path=\"task.py\",\n",
" requirements=REQUIREMENTS,\n",
@@ -693,12 +793,12 @@
"outputs": [],
"source": [
"CMDARGS = [\n",
" \"--model-dir=\" + BUCKET_NAME,\n",
" \"--model-dir=\" + BUCKET_URI,\n",
"]\n",
"\n",
"job.run(args=CMDARGS, replica_count=1, machine_type=TRAIN_COMPUTE, sync=True)\n",
"\n",
"! gsutil cat {BUCKET_NAME}/test.txt"
"! gsutil cat {BUCKET_URI}/test.txt"
]
},
{
@@ -768,9 +868,9 @@
"source": [
"DISPLAY_NAME = \"boston_\" + TIMESTAMP\n",
"\n",
"job = aip.CustomPythonPackageTrainingJob(\n",
"job = aiplatform.CustomPythonPackageTrainingJob(\n",
" display_name=DISPLAY_NAME,\n",
" python_package_gcs_uri=f\"{BUCKET_NAME}/trainer_boston.tar.gz\",\n",
" python_package_gcs_uri=f\"{BUCKET_URI}/trainer_boston.tar.gz\",\n",
" python_module_name=\"trainer.task\",\n",
" container_uri=TRAIN_IMAGE,\n",
")"
@@ -900,7 +1000,7 @@
"! rm -f custom.tar custom.tar.gz\n",
"! tar cvf custom.tar custom\n",
"! gzip custom.tar\n",
"! gsutil cp custom.tar.gz $BUCKET_NAME/trainer_boston.tar.gz"
"! gsutil cp custom.tar.gz $BUCKET_URI/trainer_boston.tar.gz"
]
},
{
@@ -922,11 +1022,11 @@
},
"outputs": [],
"source": [
"CMDARGS = [\"--model-dir=\" + BUCKET_NAME, \"--epochs=5\"]\n",
"CMDARGS = [\"--model-dir=\" + BUCKET_URI, \"--epochs=5\"]\n",
"\n",
"job.run(args=CMDARGS, replica_count=1, machine_type=TRAIN_COMPUTE, sync=True)\n",
"\n",
"! gsutil cat {BUCKET_NAME}/test.txt"
"! gsutil cat {BUCKET_URI}/test.txt"
]
},
{
@@ -1151,7 +1251,11 @@
},
"outputs": [],
"source": [
"! docker build custom -t $TRAIN_IMAGE"
"if not IS_COLAB:\n",
" ! docker build custom -t $TRAIN_IMAGE\n",
"else:\n",
" # install docker daemon\n",
" ! apt-get -qq install docker.io"
]
},
{
@@ -1173,7 +1277,8 @@
},
"outputs": [],
"source": [
"! docker run $TRAIN_IMAGE --epochs=5 --model-dir=./"
"if not IS_COLAB:\n",
" ! docker run $TRAIN_IMAGE --epochs=5 --model-dir=./"
]
},
{
@@ -1195,7 +1300,38 @@
},
"outputs": [],
"source": [
"! docker push $TRAIN_IMAGE"
"if not IS_COLAB:\n",
" ! docker push $TRAIN_IMAGE"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "f50e9c553fb7"
},
"source": [
"*Executes in Colab*"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "a7e8c98f1e56"
},
"outputs": [],
"source": [
"%%bash -s $IS_COLAB $TRAIN_IMAGE\n",
"if [ $1 == \"False\" ]; then\n",
" exit 0\n",
"fi\n",
"set -x\n",
"dockerd -b none --iptables=0 -l warn &\n",
"for i in $(seq 5); do [ ! -S \"/var/run/docker.sock\" ] && sleep 2 || break; done\n",
"docker build custom -t $2\n",
"docker run $2 --epochs=5 --model-dir=./\n",
"docker push $2\n",
"kill $(jobs -p)"
]
},
{
@@ -1229,7 +1365,7 @@
},
"outputs": [],
"source": [
"job = aip.CustomContainerTrainingJob(\n",
"job = aiplatform.CustomContainerTrainingJob(\n",
" display_name=\"boston_\" + TIMESTAMP,\n",
" container_uri=TRAIN_IMAGE,\n",
" command=[\"python3\", \"trainer/task.py\"],\n",
@@ -1257,11 +1393,11 @@
},
"outputs": [],
"source": [
"CMDARGS = [\"--model-dir=\" + BUCKET_NAME, \"--epochs=5\"]\n",
"CMDARGS = [\"--model-dir=\" + BUCKET_URI, \"--epochs=5\"]\n",
"\n",
"job.run(args=CMDARGS, replica_count=1, machine_type=TRAIN_COMPUTE, sync=True)\n",
"\n",
"! gsutil cat {BUCKET_NAME}/test.txt"
"! gsutil cat {BUCKET_URI}/test.txt"
]
},
{
@@ -1466,7 +1602,7 @@
"! rm -f custom.tar custom.tar.gz\n",
"! tar cvf custom.tar custom\n",
"! gzip custom.tar\n",
"! gsutil cp custom.tar.gz $BUCKET_NAME/trainer_boston.tar.gz"
"! gsutil cp custom.tar.gz $BUCKET_URI/trainer_boston.tar.gz"
]
},
{
@@ -1496,7 +1632,7 @@
"if os.getenv(\"IS_TESTING_TF\"):\n",
" TF = os.getenv(\"IS_TESTING_TF\")\n",
"else:\n",
" TF = \"2.1\".replace(\".\", \"-\")\n",
" TF = \"2.5\".replace(\".\", \"-\")\n",
"\n",
"if TF[0] == \"2\":\n",
" if TRAIN_GPU:\n",
@@ -1551,9 +1687,9 @@
"source": [
"DISPLAY_NAME = \"boston_\" + TIMESTAMP\n",
"\n",
"job = aip.CustomPythonPackageTrainingJob(\n",
"job = aiplatform.CustomPythonPackageTrainingJob(\n",
" display_name=DISPLAY_NAME,\n",
" python_package_gcs_uri=f\"{BUCKET_NAME}/trainer_boston.tar.gz\",\n",
" python_package_gcs_uri=f\"{BUCKET_URI}/trainer_boston.tar.gz\",\n",
" python_module_name=\"trainer.task\",\n",
" container_uri=TRAIN_IMAGE,\n",
" model_serving_container_image_uri=DEPLOY_IMAGE,\n",
@@ -1587,12 +1723,12 @@
},
"outputs": [],
"source": [
"MODEL_DIR = \"{}/{}\".format(BUCKET_NAME, TIMESTAMP)\n",
"MODEL_DIR = \"{}/{}\".format(BUCKET_URI, TIMESTAMP)\n",
"\n",
"EPOCHS = 20\n",
"STEPS = 100\n",
"\n",
"DIRECT = True\n",
"DIRECT = False\n",
"if DIRECT:\n",
" CMDARGS = [\n",
" \"--model-dir=\" + MODEL_DIR,\n",
@@ -1758,17 +1894,7 @@
"To clean up all Google Cloud resources used in this project, you can [delete the Google Cloud\n",
"project](https://cloud.google.com/resource-manager/docs/creating-managing-projects#shutting_down_projects) you used for the tutorial.\n",
"\n",
"Otherwise, you can delete the individual resources you created in this tutorial:\n",
"\n",
"- Dataset\n",
"- Pipeline\n",
"- Model\n",
"- Endpoint\n",
"- AutoML Training Job\n",
"- Batch Job\n",
"- Custom Job\n",
"- Hyperparameter Tuning Job\n",
"- Cloud Storage Bucket"
"Otherwise, you can delete the individual resources you created in this tutorial."
]
},
{
@@ -1779,61 +1905,24 @@
},
"outputs": [],
"source": [
"delete_all = True\n",
"delete_bucket = False\n",
"delete_model = True\n",
"delete_job = True\n",
"\n",
"if delete_all:\n",
" # Delete the dataset using the Vertex dataset object\n",
"if delete_model:\n",
" try:\n",
" if \"dataset\" in globals():\n",
" dataset.delete()\n",
" model.delete()\n",
" except Exception as e:\n",
" print(e)\n",
"\n",
" # Delete the model using the Vertex model object\n",
"if delete_job:\n",
" try:\n",
" if \"model\" in globals():\n",
" model.delete()\n",
" job.delete()\n",
" except Exception as e:\n",
" print(e)\n",
"\n",
" # Delete the endpoint using the Vertex endpoint object\n",
" try:\n",
" if \"endpoint\" in globals():\n",
" endpoint.undeploy_all()\n",
" endpoint.delete()\n",
" except Exception as e:\n",
" print(e)\n",
"\n",
" # Delete the AutoML or Pipeline training job\n",
" try:\n",
" if \"dag\" in globals():\n",
" dag.delete()\n",
" except Exception as e:\n",
" print(e)\n",
"\n",
" # Delete the custom training job\n",
" try:\n",
" if \"job\" in globals():\n",
" job.delete()\n",
" except Exception as e:\n",
" print(e)\n",
"\n",
" # Delete the batch prediction job using the Vertex batch prediction object\n",
" try:\n",
" if \"batch_predict_job\" in globals():\n",
" batch_predict_job.delete()\n",
" except Exception as e:\n",
" print(e)\n",
"\n",
" # Delete the hyperparameter tuning job using the Vertex hyperparameter tuning object\n",
" try:\n",
" if \"hpt_job\" in globals():\n",
" hpt_job.delete()\n",
" except Exception as e:\n",
" print(e)\n",
"\n",
" if \"BUCKET_NAME\" in globals():\n",
" ! gsutil rm -r $BUCKET_NAME"
"if delete_bucket or os.getenv(\"IS_TESTING\"):\n",
" ! gsutil rm -rf {BUCKET_URI}"
]
}
],
File diff suppressed because it is too large Load Diff
@@ -33,13 +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/stage2/get_started_vertex_training_pytorch.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/stage2/get_started_vertex_training_pytorch.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/github-logo-32px.png\" alt=\"GitHub logo\">\n",
" View on GitHub\n",
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/notebook_template.ipynb\">\n",
" <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://raw.githubusercontent.com/GoogleCloudPlatform/vertex-ai-samples/main/notebooks/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",
@@ -172,7 +177,7 @@
"source": [
"## Installations\n",
"\n",
"Install *one time* the packages for executing the MLOps notebooks."
"Install the following packages to execute this notebook."
]
},
{
@@ -183,10 +188,22 @@
},
"outputs": [],
"source": [
"! pip3 install --upgrade google-cloud-aiplatform[tensorboard] $USER_FLAG\n",
"! pip3 install --upgrade google-cloud-pipeline-components $USER_FLAG\n",
"! pip3 install --upgrade cloudml-hypertune $USER_FLAG\n",
"! pip3 install --upgrade torchvision $USER_FLAG"
"import os\n",
"\n",
"# The Vertex AI Workbench Notebook product has specific requirements\n",
"IS_WORKBENCH_NOTEBOOK = os.getenv(\"DL_ANACONDA_HOME\") and not os.getenv(\"VIRTUAL_ENV\")\n",
"IS_USER_MANAGED_WORKBENCH_NOTEBOOK = os.path.exists(\n",
" \"/opt/deeplearning/metadata/env_version\"\n",
")\n",
"\n",
"# Vertex AI Notebook requires dependencies to be installed with '--user'\n",
"USER_FLAG = \"\"\n",
"if IS_WORKBENCH_NOTEBOOK:\n",
" USER_FLAG = \"--user\"\n",
"\n",
"! pip3 install --upgrade google-cloud-aiplatform $USER_FLAG -q\n",
"! pip3 install --upgrade cloudml-hypertune $USER_FLAG -q\n",
"! pip3 install --upgrade torchvision $USER_FLAG -q"
]
},
{
@@ -218,6 +235,32 @@
" app.kernel.do_shutdown(True)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "84cd83853240"
},
"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, BigQuery, Compute Engine and Cloud Storage APIs](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com,bigquery,compute_component,storage_component).\n",
"\n",
"1. If you are running this notebook locally, you need to install the [Cloud SDK](https://cloud.google.com/sdk).\n",
"\n",
"1. Enter your project ID in the cell below. Then run the cell to make sure the\n",
"Cloud SDK uses the right project for all the commands in this notebook.\n",
"\n",
"**Note**: Jupyter runs lines prefixed with `!` as shell commands, and it interpolates Python variables prefixed with `$` into these commands."
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -294,7 +337,10 @@
},
"outputs": [],
"source": [
"REGION = \"us-central1\" # @param {type: \"string\"}"
"REGION = \"[your-region]\" # @param {type: \"string\"}\n",
"\n",
"if REGION == \"[your-region]\":\n",
" REGION = \"us-central1\""
]
},
{
@@ -321,6 +367,67 @@
"TIMESTAMP = datetime.now().strftime(\"%Y%m%d%H%M%S\")"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "77c385f0db59"
},
"source": [
"### Authenticate your Google Cloud account\n",
"\n",
"**If you are using Vertex AI Workbench Notebooks**, your environment is already authenticated. Skip this step.\n",
"\n",
"**If you are using Colab**, run the cell below and follow the instructions when prompted to authenticate your account via oAuth.\n",
"\n",
"**Otherwise**, follow these steps:\n",
"\n",
"In the Cloud Console, go to the [Create service account key](https://console.cloud.google.com/apis/credentials/serviceaccountkey) page.\n",
"\n",
"1. **Click Create service account**.\n",
"\n",
"2. In the **Service account name** field, enter a name, and click **Create**.\n",
"\n",
"3. In the **Grant this service account access to project** section, click the Role drop-down list. Type \"Vertex AI\" into the filter box, and select **Vertex AI Administrator**. Type \"Storage Object Admin\" into the filter box, and select **Storage Object Admin**.\n",
"\n",
"4. Click Create. A JSON file that contains your key downloads to your local environment.\n",
"\n",
"5. Enter the path to your service account key as the GOOGLE_APPLICATION_CREDENTIALS variable in the cell below and run the cell."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "535223fa4b84"
},
"outputs": [],
"source": [
"# If you are running this notebook in Colab, run this cell and follow the\n",
"# instructions to authenticate your GCP account. This provides access to your\n",
"# Cloud Storage bucket and lets you submit training jobs and prediction\n",
"# requests.\n",
"\n",
"import os\n",
"import sys\n",
"\n",
"# If on Vertex AI Workbench, then don't execute this code\n",
"IS_COLAB = False\n",
"if not os.path.exists(\"/opt/deeplearning/metadata/env_version\") and not os.getenv(\n",
" \"DL_ANACONDA_HOME\"\n",
"):\n",
" if \"google.colab\" in sys.modules:\n",
" IS_COLAB = True\n",
" from google.colab import auth as google_auth\n",
"\n",
" google_auth.authenticate_user()\n",
"\n",
" # If you are running this notebook locally, replace the string below with the\n",
" # path to your service account key and run this cell to authenticate your GCP\n",
" # account.\n",
" elif not os.getenv(\"IS_TESTING\"):\n",
" %env GOOGLE_APPLICATION_CREDENTIALS ''"
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -994,11 +1101,52 @@
"source": [
"APP_NAME = \"cifar10\"\n",
"DEPLOY_IMAGE = f\"gcr.io/{PROJECT_ID}/pytorch_predict_{APP_NAME}\"\n",
"print(DEPLOY_IMAGE)\n",
"\n",
"! docker build --tag=$DEPLOY_IMAGE ./\n",
"\n",
"! docker push $DEPLOY_IMAGE"
"print(DEPLOY_IMAGE)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "85739262f629"
},
"outputs": [],
"source": [
"if not IS_COLAB:\n",
" ! docker build --tag=$DEPLOY_IMAGE ./\n",
" ! docker push $DEPLOY_IMAGE\n",
"else:\n",
" # install docker daemon\n",
" ! apt-get -qq install docker.io"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "f50e9c553fb7"
},
"source": [
"*Executes in Colab*"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "a7e8c98f1e56"
},
"outputs": [],
"source": [
"%%bash -s $IS_COLAB $DEPLOY_IMAGE\n",
"if [ $1 == \"False\" ]; then\n",
" exit 0\n",
"fi\n",
"set -x\n",
"dockerd -b none --iptables=0 -l warn &\n",
"for i in $(seq 5); do [ ! -S \"/var/run/docker.sock\" ] && sleep 2 || break; done\n",
"docker build --tag=$2 ./\n",
"docker push $2\n",
"kill $(jobs -p)"
]
},
{
@@ -1211,7 +1359,6 @@
"Otherwise, you can delete the individual resources you created in this tutorial:\n",
"\n",
"- Model\n",
"- Custom Job (Custom job deleted in previous cell)\n",
"- Cloud Storage Bucket"
]
},
@@ -1226,8 +1373,8 @@
"# Delete the model using the Vertex model object\n",
"model.delete()\n",
"\n",
"\n",
"if os.getenv(\"IS_TESTING\"):\n",
"delete_bucket = False\n",
"if delete_bucket or os.getenv(\"IS_TESTING\"):\n",
" ! gsutil rm -r $BUCKET_URI"
]
}
@@ -39,7 +39,12 @@
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage2/get_started_vertex_training_r.ipynb\">\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage2/get_started_vertex_training_r.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/stage2/get_started_vertex_training_r.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",
@@ -129,7 +134,7 @@
"source": [
"## Installations\n",
"\n",
"Install *one time* the packages for executing the MLOps notebooks."
"Install the packages required for executing this notebook."
]
},
{
@@ -142,25 +147,19 @@
"source": [
"import os\n",
"\n",
"# The Google Cloud Notebook product has specific requirements\n",
"IS_GOOGLE_CLOUD_NOTEBOOK = os.path.exists(\"/opt/deeplearning/metadata/env_version\")\n",
"# The Vertex AI Workbench Notebook product has specific requirements\n",
"IS_WORKBENCH_NOTEBOOK = os.getenv(\"DL_ANACONDA_HOME\") and not os.getenv(\"VIRTUAL_ENV\")\n",
"IS_USER_MANAGED_WORKBENCH_NOTEBOOK = os.path.exists(\n",
" \"/opt/deeplearning/metadata/env_version\"\n",
")\n",
"\n",
"# Google Cloud Notebook requires dependencies to be installed with '--user'\n",
"# Vertex AI Notebook requires dependencies to be installed with '--user'\n",
"USER_FLAG = \"\"\n",
"if IS_GOOGLE_CLOUD_NOTEBOOK:\n",
" USER_FLAG = \"--user\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "install_mlops"
},
"outputs": [],
"source": [
"! pip3 install --upgrade google-cloud-aiplatform[tensorboard] $USER_FLAG\n",
"! pip3 install --upgrade rpy2 $USER_FLAG"
"if IS_WORKBENCH_NOTEBOOK:\n",
" USER_FLAG = \"--user\"\n",
"\n",
"! pip3 install --upgrade google-cloud-aiplatform[tensorboard] $USER_FLAG -q\n",
"! pip3 install --upgrade rpy2 $USER_FLAG -q"
]
},
{
@@ -215,7 +214,7 @@
"\n",
"1. [Make sure that billing is enabled for your project](https://cloud.google.com/billing/docs/how-to/modify-project).\n",
"\n",
"1. [Enable the Vertex AI API](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com). {TODO: Update the APIs needed for your tutorial. Edit the API names, and update the link to append the API IDs, separating each one with a comma. For example, container.googleapis.com,cloudbuild.googleapis.com}\n",
"1. [Enable the Vertex AI API](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com). \n",
"\n",
"1. If you are running this notebook locally, you will need to install the [Cloud SDK](https://cloud.google.com/sdk).\n",
"\n",
@@ -332,6 +331,67 @@
"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 = False\n",
"if not os.path.exists(\"/opt/deeplearning/metadata/env_version\") and not os.getenv(\n",
" \"DL_ANACONDA_HOME\"\n",
"):\n",
" if \"google.colab\" in sys.modules:\n",
" IS_COLAB = True\n",
" from google.colab import auth as google_auth\n",
"\n",
" google_auth.authenticate_user()\n",
"\n",
" # If you are running this notebook locally, replace the string below with the\n",
" # path to your service account key and run this cell to authenticate your GCP\n",
" # account.\n",
" elif not os.getenv(\"IS_TESTING\"):\n",
" %env GOOGLE_APPLICATION_CREDENTIALS ''"
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -1366,7 +1426,9 @@
},
"outputs": [],
"source": [
"if os.getenv(\"IS_TESTING\"):\n",
"delete_bucket = False\n",
"\n",
"if delete_bucket or os.getenv(\"IS_TESTING\"):\n",
" ! gsutil rm -r $BUCKET_URI"
]
}
@@ -33,21 +33,23 @@
"\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/stage2/get_started_vertex_training_sklearn.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/stage2/get_started_vertex_training_sklearn.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/github-logo-32px.png\" alt=\"GitHub logo\">\n",
" View on GitHub\n",
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://console.cloud.google.com/ai/platform/notebooks/deploy-notebook?download_url=https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage2/get_started_vertex_training_sklearn.ipynb\">\n",
" <a href=\"https://console.cloud.google.com/ai/platform/notebooks/deploy-notebook?download_url=https://raw.githubusercontent.com/GoogleCloudPlatform/vertex-ai-samples/main/notebooks/community/ml_ops/stage2/get_started_vertex_training_sklearn.ipynb\">\n",
" <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",
" </a>\n",
" </td>\n",
"</table>\n",
"<br/><br/><br/>"
]
},
@@ -60,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 Training for Scikit-Learn."
"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."
]
},
{
@@ -97,15 +99,156 @@
"- Create a `Vertex AI Model` resource."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "b132d4ef86d6"
},
"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) 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": {
"id": "94a148f11da5"
},
"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",
"\n",
"**Otherwise**, make sure your environment meets this notebook's requirements.\n",
"You need the following:\n",
"\n",
"* The Google Cloud SDK\n",
"* Git\n",
"* Python 3\n",
"* virtualenv\n",
"* Jupyter notebook running in a virtual environment with Python 3\n",
"\n",
"The Google Cloud guide to [Setting up a Python development\n",
"environment](https://cloud.google.com/python/setup) and the [Jupyter\n",
"installation guide](https://jupyter.org/install) provide detailed instructions\n",
"for meeting these requirements. The following steps provide a condensed set of\n",
"instructions:\n",
"\n",
"1. [Install and initialize the Cloud SDK.](https://cloud.google.com/sdk/docs/)\n",
"\n",
"1. [Install Python 3.](https://cloud.google.com/python/setup#installing_python)\n",
"\n",
"1. [Install\n",
" virtualenv](https://cloud.google.com/python/setup#installing_and_using_virtualenv)\n",
" and create a virtual environment that uses Python 3. Activate the virtual environment.\n",
"\n",
"1. To install Jupyter, run `pip3 install jupyter` on the\n",
"command-line in a terminal shell.\n",
"\n",
"1. To launch Jupyter, run `jupyter notebook` on the command-line in a terminal shell.\n",
"\n",
"1. Open this notebook in the Jupyter Notebook Dashboard.\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "install_mlops"
},
"source": [
"## Installations\n",
"### Install additional packages\n",
"\n",
"You will not need special packages for this notebook."
"Install the following packages for executing this notebook."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "78168417490e"
},
"outputs": [],
"source": [
"import os\n",
"\n",
"# The Vertex AI Workbench Notebook product has specific requirements\n",
"IS_WORKBENCH_NOTEBOOK = os.getenv(\"DL_ANACONDA_HOME\") and not os.getenv(\"VIRTUAL_ENV\")\n",
"IS_USER_MANAGED_WORKBENCH_NOTEBOOK = os.path.exists(\n",
" \"/opt/deeplearning/metadata/env_version\"\n",
")\n",
"\n",
"# Vertex AI Notebook requires dependencies to be installed with '--user'\n",
"USER_FLAG = \"\"\n",
"if IS_WORKBENCH_NOTEBOOK:\n",
" USER_FLAG = \"--user\"\n",
"\n",
"! pip3 install {USER_FLAG} --upgrade google-cloud-aiplatform -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": "2721ef0202d9"
},
"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 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",
"\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."
]
},
{
@@ -184,7 +327,10 @@
},
"outputs": [],
"source": [
"REGION = \"us-central1\" # @param {type: \"string\"}"
"REGION = \"[your-region]\" # @param {type: \"string\"}\n",
"\n",
"if REGION == \"[your-region]\":\n",
" REGION = \"us-central1\""
]
},
{
@@ -211,6 +357,67 @@
"TIMESTAMP = datetime.now().strftime(\"%Y%m%d%H%M%S\")"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "77c385f0db59"
},
"source": [
"### Authenticate your Google Cloud account\n",
"\n",
"**If you are using Vertex AI Workbench Notebooks**, your environment is already authenticated. Skip this step.\n",
"\n",
"**If you are using Colab**, run the cell below and follow the instructions when prompted to authenticate your account via oAuth.\n",
"\n",
"**Otherwise**, follow these steps:\n",
"\n",
"In the Cloud Console, go to the [Create service account key](https://console.cloud.google.com/apis/credentials/serviceaccountkey) page.\n",
"\n",
"1. **Click Create service account**.\n",
"\n",
"2. In the **Service account name** field, enter a name, and click **Create**.\n",
"\n",
"3. In the **Grant this service account access to project** section, click the Role drop-down list. Type \"Vertex AI\" into the filter box, and select **Vertex AI Administrator**. Type \"Storage Object Admin\" into the filter box, and select **Storage Object Admin**.\n",
"\n",
"4. Click Create. A JSON file that contains your key downloads to your local environment.\n",
"\n",
"5. Enter the path to your service account key as the GOOGLE_APPLICATION_CREDENTIALS variable in the cell below and run the cell."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "535223fa4b84"
},
"outputs": [],
"source": [
"# If you are running this notebook in Colab, run this cell and follow the\n",
"# instructions to authenticate your GCP account. This provides access to your\n",
"# Cloud Storage bucket and lets you submit training jobs and prediction\n",
"# requests.\n",
"\n",
"import os\n",
"import sys\n",
"\n",
"# If on Vertex AI Workbench, then don't execute this code\n",
"IS_COLAB = False\n",
"if not os.path.exists(\"/opt/deeplearning/metadata/env_version\") and not os.getenv(\n",
" \"DL_ANACONDA_HOME\"\n",
"):\n",
" if \"google.colab\" in sys.modules:\n",
" IS_COLAB = True\n",
" from google.colab import auth as google_auth\n",
"\n",
" google_auth.authenticate_user()\n",
"\n",
" # If you are running this notebook locally, replace the string below with the\n",
" # path to your service account key and run this cell to authenticate your GCP\n",
" # account.\n",
" elif not os.getenv(\"IS_TESTING\"):\n",
" %env GOOGLE_APPLICATION_CREDENTIALS ''"
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -468,9 +675,9 @@
"id": "sklearn_intro"
},
"source": [
"## Introduction to Scikit-learn training\n",
"## Introduction to scikit-learn training\n",
"\n",
"Once you have trained a Scikit-learn model, you will want to save it at a Cloud Storage location, so it can subsequently be uploaded to a `Vertex AI Model` resource. The Scikit-learn package does not have support to save the model to a Cloud Storage location. Instead, you will do the following steps to save to a Cloud Storage location.\n",
"Once you have trained a scikit-learn model, you will want to save it at a Cloud Storage location, so it can subsequently be uploaded to a `Vertex AI Model` resource. The Scikit-learn package does not have support to save the model to a Cloud Storage location. Instead, you will do the following steps to save to a Cloud Storage location.\n",
"\n",
"1. Save the in-memory model to the local filesystem in pickle format (e.g., model.pkl).\n",
"2. Create a Cloud Storage storage client.\n",
@@ -955,7 +1162,6 @@
"\n",
"\n",
"- Model\n",
"- Custom Job (already deleted in previous cell)\n",
"- Cloud Storage Bucket"
]
},
@@ -970,7 +1176,8 @@
"# Delete the model using the Vertex model object\n",
"model.delete()\n",
"\n",
"if os.getenv(\"IS_TESTING\"):\n",
"delete_bucket = False\n",
"if delete_bucket or os.getenv(\"IS_TESTING\"):\n",
" ! gsutil rm -r $BUCKET_URI"
]
}
@@ -45,7 +45,7 @@
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage2/get_started_vertex_training_xgboost.ipynb\">\n",
" <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://raw.githubusercontent.com/GoogleCloudPlatform/vertex-ai-samples/main/notebooks/community/ml_ops/stage2/get_started_vertex_training_xgboost.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",
@@ -122,7 +122,7 @@
"source": [
"## Installations\n",
"\n",
"Install *one time* the packages for executing the MLOps notebooks."
"Install the following packages to execute this notebook."
]
},
{
@@ -133,20 +133,46 @@
},
"outputs": [],
"source": [
"# ! 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"
"import os\n",
"\n",
"# The Vertex AI Workbench Notebook product has specific requirements\n",
"IS_WORKBENCH_NOTEBOOK = os.getenv(\"DL_ANACONDA_HOME\") and not os.getenv(\"VIRTUAL_ENV\")\n",
"IS_USER_MANAGED_WORKBENCH_NOTEBOOK = os.path.exists(\n",
" \"/opt/deeplearning/metadata/env_version\"\n",
")\n",
"\n",
"# Vertex AI Notebook requires dependencies to be installed with '--user'\n",
"USER_FLAG = \"\"\n",
"if IS_WORKBENCH_NOTEBOOK:\n",
" USER_FLAG = \"--user\"\n",
"\n",
"! pip3 install --upgrade google-cloud-aiplatform $USER_FLAG -q"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "2721ef0202d9"
},
"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 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",
"\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."
]
},
{
@@ -255,6 +281,33 @@
"TIMESTAMP = datetime.now().strftime(\"%Y%m%d%H%M%S\")"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "77c385f0db59"
},
"source": [
"### Authenticate your Google Cloud account\n",
"\n",
"**If you are using Vertex AI Workbench Notebooks**, your environment is already authenticated. Skip this step.\n",
"\n",
"**If you are using Colab**, run the cell below and follow the instructions when prompted to authenticate your account via oAuth.\n",
"\n",
"**Otherwise**, follow these steps:\n",
"\n",
"In the Cloud Console, go to the [Create service account key](https://console.cloud.google.com/apis/credentials/serviceaccountkey) page.\n",
"\n",
"1. **Click Create service account**.\n",
"\n",
"2. In the **Service account name** field, enter a name, and click **Create**.\n",
"\n",
"3. In the **Grant this service account access to project** section, click the Role drop-down list. Type \"Vertex AI\" into the filter box, and select **Vertex AI Administrator**. Type \"Storage Object Admin\" into the filter box, and select **Storage Object Admin**.\n",
"\n",
"4. Click Create. A JSON file that contains your key downloads to your local environment.\n",
"\n",
"5. Enter the path to your service account key as the GOOGLE_APPLICATION_CREDENTIALS variable in the cell below and run the cell."
]
},
{
"cell_type": "code",
"execution_count": null,
@@ -263,20 +316,21 @@
},
"outputs": [],
"source": [
"import os\n",
"import sys\n",
"\n",
"# If you are running this notebook in Colab, run this cell and follow the\n",
"# instructions to authenticate your GCP account. This provides access to your\n",
"# Cloud Storage bucket and lets you submit training jobs and prediction\n",
"# requests.\n",
"\n",
"# The Google Cloud Notebook product has specific requirements\n",
"IS_GOOGLE_CLOUD_NOTEBOOK = os.path.exists(\"/opt/deeplearning/metadata/env_version\")\n",
"import os\n",
"import sys\n",
"\n",
"# If on Google Cloud Notebooks, then don't execute this code\n",
"if not IS_GOOGLE_CLOUD_NOTEBOOK:\n",
"# If on Vertex AI Workbench, then don't execute this code\n",
"IS_COLAB = False\n",
"if not os.path.exists(\"/opt/deeplearning/metadata/env_version\") and not os.getenv(\n",
" \"DL_ANACONDA_HOME\"\n",
"):\n",
" if \"google.colab\" in sys.modules:\n",
" IS_COLAB = True\n",
" from google.colab import auth as google_auth\n",
"\n",
" google_auth.authenticate_user()\n",
@@ -1004,7 +1058,9 @@
},
"outputs": [],
"source": [
"if os.getenv(\"IS_TESTING\"):\n",
"delete_bucket = False\n",
"\n",
"if delete_bucket or os.getenv(\"IS_TESTING\"):\n",
" ! gsutil rm -r $BUCKET_URI"
]
}
@@ -29,7 +29,7 @@
"id": "title:generic,gcp"
},
"source": [
"# E2E ML on GCP: MLOps stage 2 : experimentation: get started with Vertex Vizier\n",
"# E2E ML on GCP: MLOps stage 2 : experimentation: get started with Vertex AI Vizier\n",
"\n",
"<table align=\"left\">\n",
" <td>\n",
@@ -39,7 +39,12 @@
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage2/get_started_vertex_vizier.ipynb\">\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage2/get_started_vertex_vizier.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/colab-logo-32px.png\" alt=\"Colab logo\"> Run in Colab\n",
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://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_vizier.ipynb\">\n",
" <img src=\"https://lh3.googleusercontent.com/UiNooY4LUgW_oTvpsNhPpQzsstV5W8F7rYgxgGBD85cWJoLmrOzhVs_ksK_vgx40SHs7jCqkTkCk=e14-rj-sc0xffffff-h130-w32\" alt=\"Vertex AI logo\">\n",
" Open in Vertex AI Workbench\n",
" </a>\n",
@@ -137,7 +142,7 @@
"source": [
"## Installations\n",
"\n",
"Install *one time* the packages for executing the MLOps notebooks."
"Install the packages required for executing this notebook."
]
},
{
@@ -150,25 +155,18 @@
"source": [
"import os\n",
"\n",
"# The Google Cloud Notebook product has specific requirements\n",
"IS_GOOGLE_CLOUD_NOTEBOOK = os.path.exists(\"/opt/deeplearning/metadata/env_version\")\n",
"# The Vertex AI Workbench Notebook product has specific requirements\n",
"IS_WORKBENCH_NOTEBOOK = os.getenv(\"DL_ANACONDA_HOME\") and not os.getenv(\"VIRTUAL_ENV\")\n",
"IS_USER_MANAGED_WORKBENCH_NOTEBOOK = os.path.exists(\n",
" \"/opt/deeplearning/metadata/env_version\"\n",
")\n",
"\n",
"# Google Cloud Notebook requires dependencies to be installed with '--user'\n",
"# Vertex AI Notebook requires dependencies to be installed with '--user'\n",
"USER_FLAG = \"\"\n",
"if IS_GOOGLE_CLOUD_NOTEBOOK:\n",
" USER_FLAG = \"--user\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "install_mlops"
},
"outputs": [],
"source": [
"! pip3 install --upgrade google-cloud-aiplatform[tensorboard] $USER_FLAG\n",
" "
"if IS_WORKBENCH_NOTEBOOK:\n",
" USER_FLAG = \"--user\"\n",
"\n",
"! pip3 install --upgrade google-cloud-aiplatform[tensorboard] $USER_FLAG"
]
},
{
@@ -200,6 +198,32 @@
" app.kernel.do_shutdown(True)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "2721ef0202d9"
},
"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 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",
"\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": {
@@ -305,6 +329,67 @@
"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 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",
"**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 = False\n",
"if not os.path.exists(\"/opt/deeplearning/metadata/env_version\") and not os.getenv(\n",
" \"DL_ANACONDA_HOME\"\n",
"):\n",
" if \"google.colab\" in sys.modules:\n",
" IS_COLAB = True\n",
" from google.colab import auth as google_auth\n",
"\n",
" google_auth.authenticate_user()\n",
"\n",
" # If you are running this notebook locally, replace the string below with the\n",
" # path to your service account key and run this cell to authenticate your GCP\n",
" # account.\n",
" elif not os.getenv(\"IS_TESTING\"):\n",
" %env GOOGLE_APPLICATION_CREDENTIALS ''"
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -1598,6 +1683,8 @@
},
"outputs": [],
"source": [
"delete_bucket = False\n",
"\n",
"if os.getenv(\"IS_TESTING\"):\n",
" ! gsutil rm -r $BUCKET_URI"
]
@@ -38,8 +38,14 @@
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://console.cloud.google.com/ai/platform/notebooks/deploy-notebook?download_url=https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage2/get_started_with_cmek_training.ipynb\">\n",
" Open in Google Cloud Notebooks\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage2/get_started_with_cmek_training.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/stage2/get_started_with_cmek_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",
" </td>\n",
"</table>\n",
@@ -91,6 +97,26 @@
"- Train an AutoML model with CMEK encryption."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "5e2eba58ad71"
},
"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) 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": {
@@ -110,10 +136,21 @@
},
"outputs": [],
"source": [
"USER_FLAG = \"--user\"\n",
"import os\n",
"\n",
"! pip3 install --upgrade google-cloud-aiplatform $USER_FLAG\n",
"! pip3 install --upgrade google-cloud-kms $USER_FLAG"
"# The Vertex AI Workbench Notebook product has specific requirements\n",
"IS_WORKBENCH_NOTEBOOK = os.getenv(\"DL_ANACONDA_HOME\") and not os.getenv(\"VIRTUAL_ENV\")\n",
"IS_USER_MANAGED_WORKBENCH_NOTEBOOK = os.path.exists(\n",
" \"/opt/deeplearning/metadata/env_version\"\n",
")\n",
"\n",
"# Vertex AI Notebook requires dependencies to be installed with '--user'\n",
"USER_FLAG = \"\"\n",
"if IS_WORKBENCH_NOTEBOOK:\n",
" USER_FLAG = \"--user\"\n",
"\n",
"! pip3 install --upgrade google-cloud-aiplatform $USER_FLAG -q\n",
"! pip3 install --upgrade google-cloud-kms $USER_FLAG -q"
]
},
{
@@ -145,6 +182,39 @@
" app.kernel.do_shutdown(True)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "013daf3de88e"
},
"source": [
"## Before you begin"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "d1afc945645f"
},
"source": [
"### 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 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",
"\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": {
@@ -248,6 +318,82 @@
"TIMESTAMP = datetime.now().strftime(\"%Y%m%d%H%M%S\")"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "d35af059208d"
},
"source": [
"### Authenticate your Google Cloud account\n",
"\n",
"**If you are using Vertex AI Workbench Notebooks**, your environment is already\n",
"authenticated. Skip this step."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "a00567d0660a"
},
"source": [
"**If you are using Colab**, run the cell below and follow the instructions\n",
"when prompted to authenticate your account via oAuth.\n",
"\n",
"**Otherwise**, follow these steps:\n",
"\n",
"1. In the Cloud Console, go to the [**Create service account key**\n",
" page](https://console.cloud.google.com/apis/credentials/serviceaccountkey).\n",
"\n",
"2. Click **Create service account**.\n",
"\n",
"3. In the **Service account name** field, enter a name, and\n",
" click **Create**.\n",
"\n",
"4. In the **Grant this service account access to project** section, click the **Role** drop-down list. Type \"Vertex AI\"\n",
"into the filter box, and select\n",
" **Vertex AI Administrator**. Type \"Storage Object Admin\" into the filter box, and select **Storage Object Admin**.\n",
"\n",
"5. Click *Create*. A JSON file that contains your key downloads to your\n",
"local environment.\n",
"\n",
"6. Enter the path to your service account key as the\n",
"`GOOGLE_APPLICATION_CREDENTIALS` variable in the cell below and run the cell."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "40160162ea4c"
},
"outputs": [],
"source": [
"# If you are running this notebook in Colab, run this cell and follow the\n",
"# instructions to authenticate your GCP account. This provides access to your\n",
"# Cloud Storage bucket and lets you submit training jobs and prediction\n",
"# requests.\n",
"\n",
"import os\n",
"import sys\n",
"\n",
"# If on Vertex AI Workbench, then don't execute this code\n",
"IS_COLAB = False\n",
"if not os.path.exists(\"/opt/deeplearning/metadata/env_version\") and not os.getenv(\n",
" \"DL_ANACONDA_HOME\"\n",
"):\n",
" if \"google.colab\" in sys.modules:\n",
" IS_COLAB = True\n",
" from google.colab import auth as google_auth\n",
"\n",
" google_auth.authenticate_user()\n",
"\n",
" # If you are running this notebook locally, replace the string below with the\n",
" # path to your service account key and run this cell to authenticate your GCP\n",
" # account.\n",
" elif not os.getenv(\"IS_TESTING\"):\n",
" %env GOOGLE_APPLICATION_CREDENTIALS ''"
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -271,7 +417,7 @@
},
"outputs": [],
"source": [
"BUCKET_NAME = \"gs://[your-bucket-name]\" # @param {type:\"string\"}"
"BUCKET_URI = \"gs://[your-bucket-name]\" # @param {type:\"string\"}"
]
},
{
@@ -282,8 +428,8 @@
},
"outputs": [],
"source": [
"if BUCKET_NAME == \"\" or BUCKET_NAME is None or BUCKET_NAME == \"gs://[your-bucket-name]\":\n",
" BUCKET_NAME = \"gs://\" + PROJECT_ID + \"aip-\" + TIMESTAMP"
"if BUCKET_URI == \"\" or BUCKET_URI is None or BUCKET_URI == \"gs://[your-bucket-name]\":\n",
" BUCKET_URI = \"gs://\" + PROJECT_ID + \"aip-\" + TIMESTAMP"
]
},
{
@@ -303,7 +449,7 @@
},
"outputs": [],
"source": [
"! gsutil mb -l $REGION $BUCKET_NAME"
"! gsutil mb -l $REGION $BUCKET_URI"
]
},
{
@@ -323,7 +469,7 @@
},
"outputs": [],
"source": [
"! gsutil ls -al $BUCKET_NAME"
"! gsutil ls -al $BUCKET_URI"
]
},
{
@@ -346,7 +492,7 @@
},
"outputs": [],
"source": [
"import google.cloud.aiplatform as aip\n",
"import google.cloud.aiplatform as aiplatform\n",
"from google.cloud import kms"
]
},
@@ -369,7 +515,7 @@
},
"outputs": [],
"source": [
"aip.init(project=PROJECT_ID, location=REGION, staging_bucket=BUCKET_NAME)"
"aiplatform.init(project=PROJECT_ID, location=REGION, staging_bucket=BUCKET_URI)"
]
},
{
@@ -384,7 +530,7 @@
"\n",
"### Enable KMS API\n",
"\n",
"First, you enble the [Cloud Key Management Service (KMS)](https://console.cloud.google.com/flows/enableapi?apiid=cloudkms.googleapis.com)\n",
"First, you enable the [Cloud Key Management Service (KMS)](https://console.cloud.google.com/flows/enableapi?apiid=cloudkms.googleapis.com)\n",
"\n",
"Learn more about [Customer managed encryption keys (CMEK)](https://cloud.google.com/vertex-ai/docs/general/cmek)"
]
@@ -549,6 +695,8 @@
"\n",
"Next, you set permissions for your Vertex AI service account to encrypt and decrypt resources using your key.\n",
"\n",
"Note: Compute Engine default service account which is used by this notebook instance for authentication purposes during Google API calls, should be granted the role of Cloud KMS Admin.\n",
"\n",
"Learn more about [Grant Vertex AI permissions](https://cloud.google.com/vertex-ai/docs/general/cmek#grant_permissions)"
]
},
@@ -638,9 +786,9 @@
},
"outputs": [],
"source": [
"aip.init(\n",
"aiplatform.init(\n",
" project=PROJECT_ID,\n",
" staging_bucket=BUCKET_NAME,\n",
" staging_bucket=BUCKET_URI,\n",
" location=REGION,\n",
" encryption_spec_key_name=ENCRYPTION_SPEC_KEY_NAME,\n",
")"
@@ -689,10 +837,10 @@
},
"outputs": [],
"source": [
"dataset = aip.ImageDataset.create(\n",
"dataset = aiplatform.ImageDataset.create(\n",
" display_name=\"flowers_\" + TIMESTAMP,\n",
" gcs_source=[IMPORT_FILE],\n",
" import_schema_uri=aip.schema.dataset.ioformat.image.single_label_classification,\n",
" import_schema_uri=aiplatform.schema.dataset.ioformat.image.single_label_classification,\n",
")\n",
"\n",
"print(dataset.resource_name)"
@@ -727,7 +875,7 @@
"\n",
"# This will take around half an hour to run\n",
"model = job.run(\n",
" dataset=ds,\n",
" dataset=dataset,\n",
" model_display_name=\"flowers_\" + TIMESTAMP,\n",
" training_fraction_split=0.6,\n",
" validation_fraction_split=0.2,\n",
@@ -827,6 +975,25 @@
"endpoint.undeploy_all()"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "ba77c4e02355"
},
"source": [
"## Cleaning up\n",
"\n",
"To clean up all Google Cloud resources used in this project, you can [delete the Google Cloud\n",
"project](https://cloud.google.com/resource-manager/docs/creating-managing-projects#shutting_down_projects) you used for the tutorial.\n",
"\n",
"Otherwise, you can delete the individual resources you created in this tutorial:\n",
"\n",
"- Model\n",
"- Dataset\n",
"- Cloud Storage Bucket\n",
"- Endpoint"
]
},
{
"cell_type": "code",
"execution_count": null,
@@ -835,17 +1002,54 @@
},
"outputs": [],
"source": [
"# missing\n",
"# Delete endpoint resource\n",
"endpoint.delete()\n",
"\n",
"# Delete model resource\n",
"model.delete()\n",
"\n",
"# Delete dataset resource\n",
"dataset.delete()\n",
"\n",
"! gcloud kms keys versions destroy key-version \\\n",
" --key key {KEY_ID} \\\n",
"# Set this to true only if you'd like to delete your bucket\n",
"delete_bucket = False\n",
"\n",
"if delete_bucket or os.getenv(\"IS_TESTING\"):\n",
" ! gsutil rm -r $BUCKET_URI"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "d88c8a053a90"
},
"source": [
"## Destroying CMEK by providing key-version value and other parameters."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "5d8d2fc34346"
},
"outputs": [],
"source": [
"! gcloud kms keys versions destroy 1 \\\n",
" --key {KEY_ID} \\\n",
" --keyring={KEY_RING_ID} \\\n",
" --location={REGION} "
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "f7e42e642ad3"
},
"source": [
"## List of keys "
]
},
{
"cell_type": "code",
"execution_count": null,
@@ -34,18 +34,18 @@
"<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_with_tabnet.ipynb\">\n",
" <a href=\"https://colab.research.google.com/github/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/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/master/notebooks/community/ml_ops/stage2/get_started_with_tabnet.ipynb\">\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samplestree/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",
" </td>\n",
" <td>\n",
" <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/master/notebooks/community/ml_ops/stage2/get_started_with_tabnet.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_with_tabnet.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",
@@ -132,11 +132,16 @@
"source": [
"import os\n",
"\n",
"# Google Cloud Notebook\n",
"if os.path.exists(\"/opt/deeplearning/metadata/env_version\"):\n",
"# The Vertex AI Workbench Notebook product has specific requirements\n",
"IS_WORKBENCH_NOTEBOOK = os.getenv(\"DL_ANACONDA_HOME\") 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",
"else:\n",
" USER_FLAG = \"\"\n",
"\n",
"! pip3 install {USER_FLAG} --upgrade tensorflow\n",
"! pip3 install {USER_FLAG} --upgrade google-cloud-aiplatform tensorboard-plugin-profile\n",
@@ -193,7 +198,7 @@
"\n",
"2. [Make sure that billing is enabled for your project.](https://cloud.google.com/billing/docs/how-to/modify-project)\n",
"\n",
"3. [Enable the following APIs: Vertex AI APIs, Compute Engine APIs, and Cloud Storage.](https://console.cloud.google.com/flows/enableapi?apiid=ml.googleapis.com,compute_component,storage-component.googleapis.com)\n",
"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",
"\n",
@@ -317,7 +322,7 @@
"source": [
"### Authenticate your Google Cloud account\n",
"\n",
"**If you are using Google Cloud Notebooks**, your environment is already\n",
"**If you are using Vertex AI Workbench Notebooks**, your environment is already\n",
"authenticated. Skip this step."
]
},
@@ -359,20 +364,21 @@
},
"outputs": [],
"source": [
"import os\n",
"import sys\n",
"\n",
"# If you are running this notebook in Colab, run this cell and follow the\n",
"# instructions to authenticate your GCP account. This provides access to your\n",
"# Cloud Storage bucket and lets you submit training jobs and prediction\n",
"# requests.\n",
"\n",
"# The Google Cloud Notebook product has specific requirements\n",
"IS_GOOGLE_CLOUD_NOTEBOOK = os.path.exists(\"/opt/deeplearning/metadata/env_version\")\n",
"import os\n",
"import sys\n",
"\n",
"# If on Google Cloud Notebooks, then don't execute this code\n",
"if not IS_GOOGLE_CLOUD_NOTEBOOK:\n",
"# If on Vertex AI Workbench, then don't execute this code\n",
"IS_COLAB = False\n",
"if not os.path.exists(\"/opt/deeplearning/metadata/env_version\") and not os.getenv(\n",
" \"DL_ANACONDA_HOME\"\n",
"):\n",
" if \"google.colab\" in sys.modules:\n",
" IS_COLAB = True\n",
" from google.colab import auth as google_auth\n",
"\n",
" google_auth.authenticate_user()\n",
@@ -482,8 +488,6 @@
"outputs": [],
"source": [
"import os\n",
"import re\n",
"import time\n",
"from datetime import datetime\n",
"\n",
"import google.cloud.aiplatform as aip\n",
@@ -1312,27 +1316,31 @@
"print(\"Service Account:\", SERVICE_ACCOUNT)\n",
"\n",
"\n",
"MODEL_DIR = OUTPUT_DIR \n",
"MODEL_DIR = OUTPUT_DIR\n",
"\n",
"if TRAIN_GPU:\n",
" model_bq = job.run(model_display_name=f\"{DATASET_NAME}_{TIMESTAMP}\",\n",
" args=CMDARGS, \n",
" replica_count=1, \n",
" machine_type=TRAIN_COMPUTE, \n",
" base_output_dir=MODEL_DIR,\n",
" accelerator_type=TRAIN_GPU.name,\n",
" accelerator_count=TRAIN_NGPU,\n",
" service_account=SERVICE_ACCOUNT,\n",
" sync=True)\n",
" model_bq = job.run(\n",
" model_display_name=f\"{DATASET_NAME}_{TIMESTAMP}\",\n",
" args=CMDARGS,\n",
" replica_count=1,\n",
" machine_type=TRAIN_COMPUTE,\n",
" base_output_dir=MODEL_DIR,\n",
" accelerator_type=TRAIN_GPU.name,\n",
" accelerator_count=TRAIN_NGPU,\n",
" service_account=SERVICE_ACCOUNT,\n",
" sync=True,\n",
" )\n",
"else:\n",
" model_bq = job.run(model_display_name=f\"{DATASET_NAME}_{TIMESTAMP}\",\n",
" args=CMDARGS, \n",
" replica_count=1, \n",
" machine_type=TRAIN_COMPUTE, \n",
" base_output_dir=MODEL_DIR,\n",
" service_account=SERVICE_ACCOUNT,\n",
" sync=True)\n",
" \n",
" model_bq = job.run(\n",
" model_display_name=f\"{DATASET_NAME}_{TIMESTAMP}\",\n",
" args=CMDARGS,\n",
" replica_count=1,\n",
" machine_type=TRAIN_COMPUTE,\n",
" base_output_dir=MODEL_DIR,\n",
" service_account=SERVICE_ACCOUNT,\n",
" sync=True,\n",
" )\n",
"\n",
"print(model_bq.gca_resource)"
]
},
@@ -33,18 +33,19 @@
"\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/stage1/get_started_with_tfhub_models.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/colab-logo-32px.png\" alt=\"Colab logo\"> Run in Colab\n",
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage1/get_started_with_tfhub_models.ipynb\">\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage2/get_started_with_tfhub_models.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/github-logo-32px.png\" alt=\"GitHub logo\">\n",
" View on GitHub\n",
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://console.cloud.google.com/ai/platform/notebooks/deploy-notebook?download_url=https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage1/get_started_with_tfhub_models.ipynb\">\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage2/get_started_with_tfhub_models.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/colab-logo-32px.png\" alt=\"Colab logo\"> Run in Colab\n",
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://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_with_tfhub_models.ipynb\">\n",
" <img src=\"https://lh3.googleusercontent.com/UiNooY4LUgW_oTvpsNhPpQzsstV5W8F7rYgxgGBD85cWJoLmrOzhVs_ksK_vgx40SHs7jCqkTkCk=e14-rj-sc0xffffff-h130-w32\" alt=\"Vertex AI logo\">\n",
" Open in Vertex AI Workbench\n",
" </a>\n",
" </td>\n",
@@ -143,14 +144,20 @@
"source": [
"import os\n",
"\n",
"# Google Cloud Notebook\n",
"if os.path.exists(\"/opt/deeplearning/metadata/env_version\"):\n",
"# The Vertex AI Workbench Notebook product has specific requirements\n",
"IS_WORKBENCH_NOTEBOOK = os.getenv(\"DL_ANACONDA_HOME\") 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",
"else:\n",
" USER_FLAG = \"\"\n",
"\n",
"! pip3 install --upgrade google-cloud-aiplatform $USER_FLAG\n",
"! pip3 install tensorflow-datasets $USER_FLAG"
"! pip3 install --upgrade google-cloud-aiplatform $USER_FLAG -q\n",
"! pip3 install tensorflow-datasets $USER_FLAG -q"
]
},
{
@@ -222,7 +229,7 @@
"\n",
"2. [Make sure that billing is enabled for your project.](https://cloud.google.com/billing/docs/how-to/modify-project)\n",
"\n",
"3. [Enable the following APIs: Vertex AI APIs, Compute Engine APIs, and Cloud Storage.](https://console.cloud.google.com/flows/enableapi?apiid=ml.googleapis.com,compute_component,storage-component.googleapis.com)\n",
"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",
"\n",
@@ -346,7 +353,7 @@
"source": [
"### Authenticate your Google Cloud account\n",
"\n",
"**If you are using Google Cloud Notebooks**, your environment is already authenticated. Skip this step.\n",
"**If you are using Vertex AI Workbench Notebooks**, your environment is already authenticated. 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",
@@ -381,9 +388,13 @@
"import os\n",
"import sys\n",
"\n",
"# If on Google Cloud Notebook, then don't execute this code\n",
"if not os.path.exists(\"/opt/deeplearning/metadata/env_version\"):\n",
"# If on Vertex AI Workbench, then don't execute this code\n",
"IS_COLAB = False\n",
"if not os.path.exists(\"/opt/deeplearning/metadata/env_version\") and not os.getenv(\n",
" \"DL_ANACONDA_HOME\"\n",
"):\n",
" if \"google.colab\" in sys.modules:\n",
" IS_COLAB = True\n",
" from google.colab import auth as google_auth\n",
"\n",
" google_auth.authenticate_user()\n",
@@ -1386,7 +1397,7 @@
},
"outputs": [],
"source": [
"delete_bucket = True\n",
"delete_bucket = False\n",
"\n",
"if delete_bucket and \"BUCKET_URI\" in globals():\n",
" ! gsutil rm -r $BUCKET_URI"
File diff suppressed because it is too large Load Diff
@@ -39,8 +39,14 @@
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://console.cloud.google.com/ai/platform/notebooks/deploy-notebook?download_url=https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage2/mlops_experimentation.ipynb\">\n",
" Open in Google Cloud Notebooks\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage2/mlops_experimentation.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/stage2/mlops_experimentation.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",
@@ -173,6 +179,19 @@
},
"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",
"ONCE_ONLY = False\n",
"if ONCE_ONLY:\n",
" ! pip3 install -U tensorflow==2.5 $USER_FLAG\n",
@@ -220,6 +239,32 @@
" app.kernel.do_shutdown(True)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "2721ef0202d9"
},
"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 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",
"\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": {
@@ -296,7 +341,9 @@
},
"outputs": [],
"source": [
"REGION = \"us-central1\" # @param {type: \"string\"}"
"REGION = \"[your-region]\" # @param {type:\"string\"}\n",
"if REGION == \"[your-region]\":\n",
" REGION = \"us-central1\""
]
},
{
@@ -323,6 +370,75 @@
"TIMESTAMP = datetime.now().strftime(\"%Y%m%d%H%M%S\")"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "648aa9824ac6"
},
"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\n",
"when prompted to authenticate your account via oAuth.\n",
"\n",
"**Otherwise**, follow these steps:\n",
"\n",
"1. In the Cloud Console, go to the [**Create service account key**\n",
" page](https://console.cloud.google.com/apis/credentials/serviceaccountkey).\n",
"\n",
"2. Click **Create service account**.\n",
"\n",
"3. In the **Service account name** field, enter a name, and\n",
" click **Create**.\n",
"\n",
"4. In the **Grant this service account access to project** section, click the **Role** drop-down list. Type \"Vertex AI\"\n",
"into the filter box, and select\n",
" **Vertex AI Administrator**. Type \"Storage Object Admin\" into the filter box, and select **Storage Object Admin**.\n",
"\n",
"5. Click *Create*. A JSON file that contains your key downloads to your\n",
"local environment.\n",
"\n",
"6. Enter the path to your service account key as the\n",
"`GOOGLE_APPLICATION_CREDENTIALS` variable in the cell below and run the cell."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "535223fa4b84"
},
"outputs": [],
"source": [
"# If you are running this notebook in Colab, run this cell and follow the\n",
"# instructions to authenticate your GCP account. This provides access to your\n",
"# Cloud Storage bucket and lets you submit training jobs and prediction\n",
"# requests.\n",
"\n",
"import os\n",
"import sys\n",
"\n",
"# If on Vertex AI Workbench, then don't execute this code\n",
"IS_COLAB = False\n",
"if not os.path.exists(\"/opt/deeplearning/metadata/env_version\") and not os.getenv(\n",
" \"DL_ANACONDA_HOME\"\n",
"):\n",
" if \"google.colab\" in sys.modules:\n",
" IS_COLAB = True\n",
" from google.colab import auth as google_auth\n",
"\n",
" google_auth.authenticate_user()\n",
"\n",
" # If you are running this notebook locally, replace the string below with the\n",
" # path to your service account key and run this cell to authenticate your GCP\n",
" # account.\n",
" elif not os.getenv(\"IS_TESTING\"):\n",
" %env GOOGLE_APPLICATION_CREDENTIALS ''"
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -436,9 +552,16 @@
" or SERVICE_ACCOUNT is None\n",
" or SERVICE_ACCOUNT == \"[your-service-account]\"\n",
"):\n",
" # Get your GCP project id from gcloud\n",
" shell_output = !gcloud auth list 2>/dev/null\n",
" SERVICE_ACCOUNT = shell_output[2].replace(\"*\", \"\").strip()\n",
" # Get your service account from gcloud\n",
" if not IS_COLAB:\n",
" shell_output = !gcloud auth list 2>/dev/null\n",
" SERVICE_ACCOUNT = shell_output[2].replace(\"*\", \"\").strip()\n",
"\n",
" if IS_COLAB:\n",
" shell_output = ! gcloud projects describe $PROJECT_ID\n",
" project_number = shell_output[-1].split(\":\")[1].strip().replace(\"'\", \"\")\n",
" SERVICE_ACCOUNT = f\"{project_number}-compute@developer.gserviceaccount.com\"\n",
"\n",
" print(\"Service Account:\", SERVICE_ACCOUNT)"
]
},
@@ -583,6 +706,8 @@
},
"outputs": [],
"source": [
"import os\n",
"\n",
"if os.getenv(\"IS_TESTING_TRAIN_GPU\"):\n",
" TRAIN_GPU, TRAIN_NGPU = (\n",
" aip.gapic.AcceleratorType.NVIDIA_TESLA_K80,\n",
@@ -1218,7 +1343,7 @@
"setup_cfg = \"[egg_info]\\n\\ntag_build =\\n\\ntag_date = 0\"\n",
"! echo \"$setup_cfg\" > custom/setup.cfg\n",
"\n",
"setup_py = \"import setuptools\\n\\nsetuptools.setup(\\n\\n install_requires=[\\n\\n 'google-cloud-aiplatform',\\n\\n 'cloudml-hypertune',\\n\\n 'tensorflow_datasets==1.3.0',\\n\\n 'tensorflow_data_validation==1.2',\\n\\n ],\\n\\n packages=setuptools.find_packages())\"\n",
"setup_py = \"import setuptools\\n\\nsetuptools.setup(\\n\\n install_requires=[\\n\\n 'google-cloud-aiplatform',\\n\\n 'cloudml-hypertune',\\n\\n 'tensorflow_datasets==1.3.0',\\n\\n 'tensorflow==2.5',\\n\\n 'tensorflow_data_validation==1.2',\\n\\n ],\\n\\n packages=setuptools.find_packages())\"\n",
"! echo \"$setup_py\" > custom/setup.py\n",
"\n",
"pkg_info = \"Metadata-Version: 1.0\\n\\nName: Chicago Taxi tabular binary classifier\\n\\nVersion: 0.0.0\\n\\nSummary: Demostration training script\\n\\nHome-page: www.google.com\\n\\nAuthor: Google\\n\\nAuthor-email: cdpe@google.com\\n\\nLicense: Public\\n\\nDescription: Demo\\n\\nPlatform: Vertex AI\"\n",
@@ -3011,9 +3136,8 @@
},
"source": [
"## Review model evaluation scores\n",
"After your model has finished training, you can review the evaluation scores for it.\n",
"\n",
"First, you need to get a reference to the new model. As with datasets, you can either use the reference to the model variable you created when you deployed the model or you can list all of the models in your project."
"After your model training has finished, you can review the evaluation scores for it using the `list_model_evaluations()` method. This method will return an iterator for each evaluation slice."
]
},
{
@@ -3024,18 +3148,10 @@
},
"outputs": [],
"source": [
"# Get model resource ID\n",
"models = aip.Model.list(filter=\"display_name=chicago_\" + TIMESTAMP)\n",
"model_evaluations = model.list_model_evaluations()\n",
"\n",
"# Get a reference to the Model Service client\n",
"client_options = {\"api_endpoint\": f\"{REGION}-aiplatform.googleapis.com\"}\n",
"model_service_client = aip.gapic.ModelServiceClient(client_options=client_options)\n",
"\n",
"model_evaluations = model_service_client.list_model_evaluations(\n",
" parent=models[0].resource_name\n",
")\n",
"model_evaluation = list(model_evaluations)[0]\n",
"print(model_evaluation)"
"for model_evaluation in model_evaluations:\n",
" print(model_evaluation.to_dict())"
]
},
{
Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 103 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 130 KiB

+34 -1
View File
@@ -27,7 +27,7 @@ The third stage in MLOps is formalization to develop an automated pipeline proce
- Use early stop procedure in training script to detect failure to achieve training objective.
- Store the results of the trained model evaluation in Vertex AI ML Metadata.
<img src='stage3.png'>
<img src='stage3v3.png'>
## Notebooks
@@ -144,6 +144,39 @@ The steps performed include:
- 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`.
```
### E2E Stage Example
[Stage 3: Formalization](mlops_formalization.ipynb)
@@ -40,11 +40,11 @@
" </td>\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_automl_pipeline_components.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/colab-logo-32px.png\\\" alt=\"Colab logo\"> Run in Colab\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://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage3/get_started_with_automl_pipeline_components.ipynb\">\n",
" <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://raw.githubusercontent.com/GoogleCloudPlatform/vertex-ai-samples/main/notebooks/community/ml_ops/stage3/get_started_with_automl_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 Vertex AI Workbench\n",
" </a>\n",
@@ -132,12 +132,15 @@
"source": [
"import os\n",
"\n",
"# The Google Cloud Notebook product has specific requirements\n",
"IS_GOOGLE_CLOUD_NOTEBOOK = os.path.exists(\"/opt/deeplearning/metadata/env_version\")\n",
"# The Vertex AI Workbench Notebook product has specific requirements\n",
"IS_WORKBENCH_NOTEBOOK = os.getenv(\"DL_ANACONDA_HOME\") and not os.getenv(\"VIRTUAL_ENV\")\n",
"IS_USER_MANAGED_WORKBENCH_NOTEBOOK = os.path.exists(\n",
" \"/opt/deeplearning/metadata/env_version\"\n",
")\n",
"\n",
"# Google Cloud Notebook requires dependencies to be installed with '--user'\n",
"# Vertex AI Notebook requires dependencies to be installed with '--user'\n",
"USER_FLAG = \"\"\n",
"if IS_GOOGLE_CLOUD_NOTEBOOK:\n",
"if IS_WORKBENCH_NOTEBOOK:\n",
" USER_FLAG = \"--user\"\n",
" \n",
"! pip3 install tensorflow-io==0.18 $USER_FLAG -q\n",
@@ -177,6 +180,30 @@
" app.kernel.do_shutdown(True)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "BF1j6f9HApxa"
},
"source": [
"### 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 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",
"\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": {
@@ -291,7 +318,7 @@
"source": [
"### Authenticate your Google Cloud account\n",
"\n",
"**If you are using Google Cloud Notebooks**, your environment is already authenticated. Skip this step.\n",
"**If you are using Vertex AI Notebook 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",
@@ -326,9 +353,13 @@
"import os\n",
"import sys\n",
"\n",
"# If on Google Cloud Notebook, then don't execute this code\n",
"if not os.path.exists(\"/opt/deeplearning/metadata/env_version\"):\n",
"# If on Vertex AI Workbench, then don't execute this code\n",
"IS_COLAB = False\n",
"if not os.path.exists(\"/opt/deeplearning/metadata/env_version\") and not os.getenv(\n",
" \"DL_ANACONDA_HOME\"\n",
"):\n",
" if \"google.colab\" in sys.modules:\n",
" IS_COLAB = True\n",
" from google.colab import auth as google_auth\n",
"\n",
" google_auth.authenticate_user()\n",
@@ -451,15 +482,20 @@
"source": [
"if (\n",
" SERVICE_ACCOUNT == \"\"\n",
" or SERVICE_ACCOUNT == \"[your-service-account]\"\n",
" or SERVICE_ACCOUNT is None\n",
" or SERVICE_ACCOUNT == \"[your-service-account]\"\n",
"):\n",
" shell_output = ! gcloud projects describe $PROJECT_ID | sed -nre 's:.*projectNumber\\: (.*):\\1:p'\n",
" SERVICE_ACCOUNT = (\n",
" shell_output[0].replace(\"'\", \"\") + \"-compute@developer.gserviceaccount.com\"\n",
" )\n",
" # Get your service account from gcloud\n",
" if not IS_COLAB:\n",
" shell_output = !gcloud auth list 2>/dev/null\n",
" SERVICE_ACCOUNT = shell_output[2].replace(\"*\", \"\").strip()\n",
"\n",
"print(\"Service Account:\", SERVICE_ACCOUNT)"
" if IS_COLAB:\n",
" shell_output = ! gcloud projects describe $PROJECT_ID\n",
" project_number = shell_output[-1].split(\":\")[1].strip().replace(\"'\", \"\")\n",
" SERVICE_ACCOUNT = f\"{project_number}-compute@developer.gserviceaccount.com\"\n",
"\n",
" print(\"Service Account:\", SERVICE_ACCOUNT)"
]
},
{
@@ -44,7 +44,7 @@
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage3/get_started_with_bq_tfdv_pipeline_components.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_bq_tfdv_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 Vertex AI Workbench\n",
" </a>\n",
@@ -129,7 +129,7 @@
"source": [
"## Installations\n",
"\n",
"Install *one time* the packages for executing the MLOps notebooks."
"Install the packages for executing this notebook."
]
},
{
@@ -142,26 +142,20 @@
"source": [
"import os\n",
"\n",
"# The Google Cloud Notebook product has specific requirements\n",
"IS_GOOGLE_CLOUD_NOTEBOOK = os.path.exists(\"/opt/deeplearning/metadata/env_version\")\n",
"# The Vertex AI Workbench Notebook product has specific requirements\n",
"IS_WORKBENCH_NOTEBOOK = os.getenv(\"DL_ANACONDA_HOME\") and not os.getenv(\"VIRTUAL_ENV\")\n",
"IS_USER_MANAGED_WORKBENCH_NOTEBOOK = os.path.exists(\n",
" \"/opt/deeplearning/metadata/env_version\"\n",
")\n",
"\n",
"# Google Cloud Notebook requires dependencies to be installed with '--user'\n",
"# Vertex AI Notebook requires dependencies to be installed with '--user'\n",
"USER_FLAG = \"\"\n",
"if IS_GOOGLE_CLOUD_NOTEBOOK:\n",
" USER_FLAG = \"--user\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "install_mlops"
},
"outputs": [],
"source": [
"! pip3 install -U tensorflow $USER_FLAG\n",
"! pip3 install --upgrade google-cloud-aiplatform[tensorboard] $USER_FLAG\n",
"! pip3 install --upgrade kfp $USER_FLAG"
"if IS_WORKBENCH_NOTEBOOK:\n",
" USER_FLAG = \"--user\"\n",
"\n",
"! pip3 install -U tensorflow $USER_FLAG -q\n",
"! pip3 install --upgrade google-cloud-aiplatform[tensorboard] $USER_FLAG -q\n",
"! pip3 install --upgrade kfp $USER_FLAG -q"
]
},
{
@@ -193,6 +187,30 @@
" app.kernel.do_shutdown(True)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "BF1j6f9HApxa"
},
"source": [
"### 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 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",
"\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": {
@@ -308,7 +326,7 @@
"source": [
"### Authenticate your Google Cloud account\n",
"\n",
"**If you are using Google Cloud Notebooks**, your environment is already\n",
"**If you are using Vertex AI Workbench Notebooks**, your environment is already\n",
"authenticated. Skip this step."
]
},
@@ -350,20 +368,21 @@
},
"outputs": [],
"source": [
"import os\n",
"import sys\n",
"\n",
"# If you are running this notebook in Colab, run this cell and follow the\n",
"# instructions to authenticate your GCP account. This provides access to your\n",
"# Cloud Storage bucket and lets you submit training jobs and prediction\n",
"# requests.\n",
"\n",
"# The Google Cloud Notebook product has specific requirements\n",
"IS_GOOGLE_CLOUD_NOTEBOOK = os.path.exists(\"/opt/deeplearning/metadata/env_version\")\n",
"import os\n",
"import sys\n",
"\n",
"# If on Google Cloud Notebooks, then don't execute this code\n",
"if not IS_GOOGLE_CLOUD_NOTEBOOK:\n",
"# If on Vertex AI Workbench, then don't execute this code\n",
"IS_COLAB = False\n",
"if not os.path.exists(\"/opt/deeplearning/metadata/env_version\") and not os.getenv(\n",
" \"DL_ANACONDA_HOME\"\n",
"):\n",
" if \"google.colab\" in sys.modules:\n",
" IS_COLAB = True\n",
" from google.colab import auth as google_auth\n",
"\n",
" google_auth.authenticate_user()\n",
@@ -490,9 +509,16 @@
" or SERVICE_ACCOUNT is None\n",
" or SERVICE_ACCOUNT == \"[your-service-account]\"\n",
"):\n",
" # Get your GCP project id from gcloud\n",
" shell_output = !gcloud auth list 2>/dev/null\n",
" SERVICE_ACCOUNT = shell_output[2].replace(\"*\", \"\").strip()\n",
" # Get your service account from gcloud\n",
" if not IS_COLAB:\n",
" shell_output = !gcloud auth list 2>/dev/null\n",
" SERVICE_ACCOUNT = shell_output[2].replace(\"*\", \"\").strip()\n",
"\n",
" if IS_COLAB:\n",
" shell_output = ! gcloud projects describe $PROJECT_ID\n",
" project_number = shell_output[-1].split(\":\")[1].strip().replace(\"'\", \"\")\n",
" SERVICE_ACCOUNT = f\"{project_number}-compute@developer.gserviceaccount.com\"\n",
"\n",
" print(\"Service Account:\", SERVICE_ACCOUNT)"
]
},
@@ -44,7 +44,7 @@
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage3/get_started_with_bqml_pipeline_components.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_bqml_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 Vertex AI Workbench\n",
" </a>\n",
@@ -135,7 +135,7 @@
"source": [
"## Installations\n",
"\n",
"Install *one time* the packages for executing the MLOps notebooks."
"Install the packages required for executing the notebook."
]
},
{
@@ -148,28 +148,22 @@
"source": [
"import os\n",
"\n",
"# The Google Cloud Notebook product has specific requirements\n",
"IS_GOOGLE_CLOUD_NOTEBOOK = os.path.exists(\"/opt/deeplearning/metadata/env_version\")\n",
"# The Vertex AI Workbench Notebook product has specific requirements\n",
"IS_WORKBENCH_NOTEBOOK = os.getenv(\"DL_ANACONDA_HOME\") and not os.getenv(\"VIRTUAL_ENV\")\n",
"IS_USER_MANAGED_WORKBENCH_NOTEBOOK = os.path.exists(\n",
" \"/opt/deeplearning/metadata/env_version\"\n",
")\n",
"\n",
"# Google Cloud Notebook requires dependencies to be installed with '--user'\n",
"# Vertex AI Notebook requires dependencies to be installed with '--user'\n",
"USER_FLAG = \"\"\n",
"if IS_GOOGLE_CLOUD_NOTEBOOK:\n",
" USER_FLAG = \"--user\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "-OxtcyNNJ39g"
},
"outputs": [],
"source": [
"! pip3 install -U tensorflow $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 kfp $USER_FLAG\n"
"if IS_WORKBENCH_NOTEBOOK:\n",
" USER_FLAG = \"--user\"\n",
"\n",
"! pip3 install -U tensorflow $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 kfp $USER_FLAG -q"
]
},
{
@@ -201,6 +195,30 @@
" app.kernel.do_shutdown(True)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "BF1j6f9HApxa"
},
"source": [
"### 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 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",
"\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": {
@@ -314,10 +332,7 @@
"id": "UG2SHSlTJ39k"
},
"source": [
"### Authenticate your Google Cloud account\n",
"\n",
"**If you are using Google Cloud Notebooks**, your environment is already\n",
"authenticated. Skip this step."
"### Authenticate your Google Cloud account\n"
]
},
{
@@ -326,8 +341,11 @@
"id": "ETQR4H1HJ39k"
},
"source": [
"**If you are using Colab**, run the cell below and follow the instructions\n",
"when prompted to authenticate your account via oAuth.\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",
@@ -358,20 +376,21 @@
},
"outputs": [],
"source": [
"import os\n",
"import sys\n",
"\n",
"# If you are running this notebook in Colab, run this cell and follow the\n",
"# instructions to authenticate your GCP account. This provides access to your\n",
"# Cloud Storage bucket and lets you submit training jobs and prediction\n",
"# requests.\n",
"\n",
"# The Google Cloud Notebook product has specific requirements\n",
"IS_GOOGLE_CLOUD_NOTEBOOK = os.path.exists(\"/opt/deeplearning/metadata/env_version\")\n",
"import os\n",
"import sys\n",
"\n",
"# If on Google Cloud Notebooks, then don't execute this code\n",
"if not IS_GOOGLE_CLOUD_NOTEBOOK:\n",
"# If on Vertex AI Workbench, then don't execute this code\n",
"IS_COLAB = False\n",
"if not os.path.exists(\"/opt/deeplearning/metadata/env_version\") and not os.getenv(\n",
" \"DL_ANACONDA_HOME\"\n",
"):\n",
" if \"google.colab\" in sys.modules:\n",
" IS_COLAB = True\n",
" from google.colab import auth as google_auth\n",
"\n",
" google_auth.authenticate_user()\n",
@@ -499,9 +518,17 @@
" or SERVICE_ACCOUNT is None\n",
" or SERVICE_ACCOUNT == \"[your-service-account]\"\n",
"):\n",
" # Get your GCP project id from gcloud\n",
" shell_output = !gcloud auth list 2>/dev/null\n",
" SERVICE_ACCOUNT = shell_output[2].replace(\"*\", \"\").strip()\n",
" # Get your service account from gcloud\n",
" if not IS_COLAB:\n",
" shell_output = !gcloud auth list 2>/dev/null\n",
" SERVICE_ACCOUNT = shell_output[2].replace(\"*\", \"\").strip()\n",
"\n",
" if IS_COLAB:\n",
" shell_output = ! gcloud projects describe $PROJECT_ID\n",
" # print(\"shell_output=\", shell_output)\n",
" project_number = shell_output[-1].split(\":\")[1].strip().replace(\"'\", \"\")\n",
" SERVICE_ACCOUNT = f\"{project_number}-compute@developer.gserviceaccount.com\"\n",
"\n",
" print(\"Service Account:\", SERVICE_ACCOUNT)"
]
},
@@ -44,7 +44,7 @@
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage3/get_started_with_custom_training_pipeline_components.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_custom_training_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 Vertex AI Workbench\n",
" </a>\n",
@@ -139,7 +139,7 @@
"source": [
"## Installations\n",
"\n",
"Install *one time* the packages for executing the MLOps notebooks."
"Install the required packages for executing the notebook."
]
},
{
@@ -152,27 +152,21 @@
"source": [
"import os\n",
"\n",
"# The Google Cloud Notebook product has specific requirements\n",
"IS_GOOGLE_CLOUD_NOTEBOOK = os.path.exists(\"/opt/deeplearning/metadata/env_version\")\n",
"# The Vertex AI Workbench Notebook product has specific requirements\n",
"IS_WORKBENCH_NOTEBOOK = os.getenv(\"DL_ANACONDA_HOME\") and not os.getenv(\"VIRTUAL_ENV\")\n",
"IS_USER_MANAGED_WORKBENCH_NOTEBOOK = os.path.exists(\n",
" \"/opt/deeplearning/metadata/env_version\"\n",
")\n",
"\n",
"# Google Cloud Notebook requires dependencies to be installed with '--user'\n",
"# Vertex AI Notebook requires dependencies to be installed with '--user'\n",
"USER_FLAG = \"\"\n",
"if IS_GOOGLE_CLOUD_NOTEBOOK:\n",
" USER_FLAG = \"--user\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "install_mlops"
},
"outputs": [],
"source": [
"! pip3 install -U tensorflow $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 kfp $USER_FLAG\n"
"if IS_WORKBENCH_NOTEBOOK:\n",
" USER_FLAG = \"--user\"\n",
"\n",
"! pip3 install -U tensorflow $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 kfp $USER_FLAG -q"
]
},
{
@@ -204,6 +198,30 @@
" app.kernel.do_shutdown(True)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "BF1j6f9HApxa"
},
"source": [
"### 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 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",
"\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": {
@@ -317,10 +335,7 @@
"id": "648aa9824ac6"
},
"source": [
"### Authenticate your Google Cloud account\n",
"\n",
"**If you are using Google Cloud Notebooks**, your environment is already\n",
"authenticated. Skip this step."
"### Authenticate your Google Cloud account\n"
]
},
{
@@ -329,8 +344,10 @@
"id": "fc52bba17ee3"
},
"source": [
"**If you are using Colab**, run the cell below and follow the instructions\n",
"when prompted to authenticate your account via oAuth.\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",
"**Otherwise**, follow these steps:\n",
"\n",
@@ -361,20 +378,21 @@
},
"outputs": [],
"source": [
"import os\n",
"import sys\n",
"\n",
"# If you are running this notebook in Colab, run this cell and follow the\n",
"# instructions to authenticate your GCP account. This provides access to your\n",
"# Cloud Storage bucket and lets you submit training jobs and prediction\n",
"# requests.\n",
"\n",
"# The Google Cloud Notebook product has specific requirements\n",
"IS_GOOGLE_CLOUD_NOTEBOOK = os.path.exists(\"/opt/deeplearning/metadata/env_version\")\n",
"import os\n",
"import sys\n",
"\n",
"# If on Google Cloud Notebooks, then don't execute this code\n",
"if not IS_GOOGLE_CLOUD_NOTEBOOK:\n",
"# If on Vertex AI Workbench, then don't execute this code\n",
"IS_COLAB = False\n",
"if not os.path.exists(\"/opt/deeplearning/metadata/env_version\") and not os.getenv(\n",
" \"DL_ANACONDA_HOME\"\n",
"):\n",
" if \"google.colab\" in sys.modules:\n",
" IS_COLAB = True\n",
" from google.colab import auth as google_auth\n",
"\n",
" google_auth.authenticate_user()\n",
@@ -500,9 +518,17 @@
" or SERVICE_ACCOUNT is None\n",
" or SERVICE_ACCOUNT == \"[your-service-account]\"\n",
"):\n",
" # Get your GCP project id from gcloud\n",
" shell_output = !gcloud auth list 2>/dev/null\n",
" SERVICE_ACCOUNT = shell_output[2].replace(\"*\", \"\").strip()\n",
" # Get your service account from gcloud\n",
" if not IS_COLAB:\n",
" shell_output = !gcloud auth list 2>/dev/null\n",
" SERVICE_ACCOUNT = shell_output[2].replace(\"*\", \"\").strip()\n",
"\n",
" if IS_COLAB:\n",
" shell_output = ! gcloud projects describe $PROJECT_ID\n",
" # print(\"shell_output=\", shell_output)\n",
" project_number = shell_output[-1].split(\":\")[1].strip().replace(\"'\", \"\")\n",
" SERVICE_ACCOUNT = f\"{project_number}-compute@developer.gserviceaccount.com\"\n",
"\n",
" print(\"Service Account:\", SERVICE_ACCOUNT)"
]
},
@@ -40,9 +40,17 @@
" </td>\n",
" <td>\n",
" <a href=\"https://console.cloud.google.com/ai/platform/notebooks/deploy-notebook?download_url=https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage3/get_started_with_dataflow_pipeline_components.ipynb\">\n",
" Open in Google Cloud Notebooks\n",
"<img src=\"https://cloud.google.com/ml-engine/images/colab-logo-32px.png\" alt=\"Colab logo\"> \n",
" 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/stage3/get_started_with_dataflow_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 Vertex AI Workbench\n",
" </a>\n",
" </td> \n",
" \n",
"</table>\n",
"<br/><br/><br/>"
]
@@ -101,7 +109,7 @@
"source": [
"## Installations\n",
"\n",
"Install *one time* the packages for executing the MLOps notebooks."
"Install the required packages for executing the notebook."
]
},
{
@@ -112,24 +120,25 @@
},
"outputs": [],
"source": [
"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"
"import os\n",
"\n",
"# The Vertex AI Workbench Notebook product has specific requirements\n",
"IS_WORKBENCH_NOTEBOOK = os.getenv(\"DL_ANACONDA_HOME\")\n",
"IS_USER_MANAGED_WORKBENCH_NOTEBOOK = os.path.exists(\n",
" \"/opt/deeplearning/metadata/env_version\"\n",
")\n",
"\n",
"# Vertex AI Notebook requires dependencies to be installed with '--user'\n",
"USER_FLAG = \"\"\n",
"if IS_WORKBENCH_NOTEBOOK:\n",
" USER_FLAG = \"--user\"\n",
"\n",
"! pip3 install -U tensorflow $USER_FLAG -q\n",
"! pip3 install -U tensorflow-data-validation $USER_FLAG -q\n",
"! pip3 install -U tensorflow-transform $USER_FLAG -q\n",
"! pip3 install -U tensorflow-io $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"
]
},
{
@@ -161,6 +170,30 @@
" app.kernel.do_shutdown(True)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "BF1j6f9HApxa"
},
"source": [
"### 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 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",
"\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": {
@@ -180,7 +213,24 @@
},
"outputs": [],
"source": [
"PROJECT_ID = \"[your-project-id]\" # @param {type:\"string\"}"
"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."
]
},
{
@@ -191,22 +241,8 @@
},
"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"
"if PROJECT_ID == \"\" or PROJECT_ID is None:\n",
" PROJECT_ID = \"[your-project-id]\" # @param {type:\"string\"}"
]
},
{
@@ -237,7 +273,10 @@
},
"outputs": [],
"source": [
"REGION = \"us-central1\" # @param {type: \"string\"}"
"REGION = \"[your-region]\" # @param {type: \"string\"}\n",
"\n",
"if REGION == \"[your-region]\":\n",
" REGION = \"us-central1\""
]
},
{
@@ -264,6 +303,89 @@
"TIMESTAMP = datetime.now().strftime(\"%Y%m%d%H%M%S\")"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "927085b84a07"
},
"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",
"**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": "89788a802687"
},
"outputs": [],
"source": [
"# If you are running this notebook in Colab, run this cell and follow the\n",
"# instructions to authenticate your GCP account. This provides access to your\n",
"# Cloud Storage bucket and lets you submit training jobs and prediction\n",
"# requests.\n",
"\n",
"import os\n",
"import sys\n",
"\n",
"# If on Vertex AI Workbench, then don't execute this code\n",
"IS_COLAB = False\n",
"if not os.path.exists(\"/opt/deeplearning/metadata/env_version\") and not os.getenv(\n",
" \"DL_ANACONDA_HOME\"\n",
"):\n",
" if \"google.colab\" in sys.modules:\n",
" IS_COLAB = True\n",
" from google.colab import auth as google_auth\n",
"\n",
" google_auth.authenticate_user()\n",
"\n",
" # If you are running this notebook locally, replace the string below with the\n",
" # path to your service account key and run this cell to authenticate your GCP\n",
" # account.\n",
" elif not os.getenv(\"IS_TESTING\"):\n",
" %env GOOGLE_APPLICATION_CREDENTIALS ''"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "40ed98f5cc48"
},
"source": [
"#### If you are using Colab Notebooks, set the project using gcloud config."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "fde1a355f1e9"
},
"outputs": [],
"source": [
"if not os.path.exists(\"/opt/deeplearning/metadata/env_version\"):\n",
" if \"google.colab\" in sys.modules:\n",
" ! gcloud config set project $PROJECT_ID"
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -287,7 +409,7 @@
},
"outputs": [],
"source": [
"BUCKET_NAME = \"gs://[your-bucket-name]\" # @param {type:\"string\"}"
"BUCKET_URI = \"gs://[your-bucket-name]\" # @param {type:\"string\"}"
]
},
{
@@ -298,8 +420,8 @@
},
"outputs": [],
"source": [
"if BUCKET_NAME == \"\" or BUCKET_NAME is None or BUCKET_NAME == \"gs://[your-bucket-name]\":\n",
" BUCKET_NAME = \"gs://\" + PROJECT_ID + \"aip-\" + TIMESTAMP"
"if BUCKET_URI == \"\" or BUCKET_URI is None or BUCKET_URI == \"gs://[your-bucket-name]\":\n",
" BUCKET_URI = \"gs://\" + PROJECT_ID + \"aip-\" + TIMESTAMP"
]
},
{
@@ -319,7 +441,7 @@
},
"outputs": [],
"source": [
"! gsutil mb -l $REGION $BUCKET_NAME"
"! gsutil mb -l $REGION $BUCKET_URI"
]
},
{
@@ -339,7 +461,7 @@
},
"outputs": [],
"source": [
"! gsutil ls -al $BUCKET_NAME"
"! gsutil ls -al $BUCKET_URI"
]
},
{
@@ -377,9 +499,16 @@
" or SERVICE_ACCOUNT is None\n",
" or SERVICE_ACCOUNT == \"[your-service-account]\"\n",
"):\n",
" # Get your GCP project id from gcloud\n",
" shell_output = !gcloud auth list 2>/dev/null\n",
" SERVICE_ACCOUNT = shell_output[2].replace(\"*\", \"\").strip()\n",
" # Get your service account from gcloud\n",
" if not IS_COLAB:\n",
" shell_output = !gcloud auth list 2>/dev/null\n",
" SERVICE_ACCOUNT = shell_output[2].replace(\"*\", \"\").strip()\n",
"\n",
" if IS_COLAB:\n",
" shell_output = ! gcloud projects describe $PROJECT_ID\n",
" project_number = shell_output[-1].split(\":\")[1].strip().replace(\"'\", \"\")\n",
" SERVICE_ACCOUNT = f\"{project_number}-compute@developer.gserviceaccount.com\"\n",
"\n",
" print(\"Service Account:\", SERVICE_ACCOUNT)"
]
},
@@ -402,9 +531,9 @@
},
"outputs": [],
"source": [
"! gsutil iam ch serviceAccount:{SERVICE_ACCOUNT}:roles/storage.objectCreator $BUCKET_NAME\n",
"! gsutil iam ch serviceAccount:{SERVICE_ACCOUNT}:roles/storage.objectCreator $BUCKET_URI\n",
"\n",
"! gsutil iam ch serviceAccount:{SERVICE_ACCOUNT}:roles/storage.objectViewer $BUCKET_NAME"
"! gsutil iam ch serviceAccount:{SERVICE_ACCOUNT}:roles/storage.objectViewer $BUCKET_URI"
]
},
{
@@ -427,35 +556,12 @@
},
"outputs": [],
"source": [
"import google.cloud.aiplatform as aip"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "import_kfp"
},
"outputs": [],
"source": [
"import json\n",
"\n",
"from kfp import dsl\n",
"from kfp.v2 import compiler\n",
"from kfp.v2.dsl import component"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "import_gcpc:dataflow"
},
"outputs": [],
"source": [
"import google.cloud.aiplatform as aip\n",
"from google_cloud_pipeline_components.v1.dataflow import DataflowPythonJobOp\n",
"from google_cloud_pipeline_components.v1.wait_gcp_resources import \\\n",
" WaitGcpResourcesOp"
" WaitGcpResourcesOp\n",
"from kfp import dsl\n",
"from kfp.v2 import compiler"
]
},
{
@@ -477,7 +583,7 @@
},
"outputs": [],
"source": [
"aip.init(project=PROJECT_ID, staging_bucket=BUCKET_NAME)"
"aip.init(project=PROJECT_ID, staging_bucket=BUCKET_URI)"
]
},
{
@@ -673,12 +779,12 @@
},
"outputs": [],
"source": [
"GCS_WC_PY = BUCKET_NAME + \"/wc.py\"\n",
"GCS_WC_PY = BUCKET_URI + \"/wc.py\"\n",
"! gsutil cp wc.py $GCS_WC_PY\n",
"GCS_REQUIREMENTS_TXT = BUCKET_NAME + \"/requirements.txt\"\n",
"GCS_REQUIREMENTS_TXT = BUCKET_URI + \"/requirements.txt\"\n",
"! gsutil cp requirements.txt $GCS_REQUIREMENTS_TXT\n",
"\n",
"GCS_WC_OUT = BUCKET_NAME + \"/wc_out.txt\""
"GCS_WC_OUT = BUCKET_URI + \"/wc_out.txt\""
]
},
{
@@ -709,9 +815,7 @@
},
"outputs": [],
"source": [
"import json\n",
"\n",
"PIPELINE_ROOT = \"{}/pipeline_root/dataflow_wc\".format(BUCKET_NAME)\n",
"PIPELINE_ROOT = \"{}/pipeline_root/dataflow_wc\".format(BUCKET_URI)\n",
"\n",
"\n",
"@dsl.pipeline(name=\"dataflow-wc\", description=\"Dataflow word count component pipeline\")\n",
@@ -733,9 +837,7 @@
" args=args,\n",
" )\n",
"\n",
" dataflow_wait_op = WaitGcpResourcesOp(\n",
" gcp_resources=dataflow_python_op.outputs[\"gcp_resources\"]\n",
" )\n",
" _ = WaitGcpResourcesOp(gcp_resources=dataflow_python_op.outputs[\"gcp_resources\"])\n",
"\n",
"\n",
"compiler.Compiler().compile(pipeline_func=pipeline, package_path=\"dataflow_wc.json\")\n",
@@ -813,82 +915,80 @@
"from apache_beam.options.pipeline_options import SetupOptions\n",
"\n",
"def run(argv=None):\n",
" \"\"\"Main entry point; defines and runs the wordcount pipeline.\"\"\"\n",
" \"\"\"Main entry point; defines and runs the wordcount pipeline.\"\"\"\n",
"\n",
" parser = argparse.ArgumentParser()\n",
" parser.add_argument('--bq_table',\n",
" parser = argparse.ArgumentParser()\n",
" parser.add_argument('--bq_table',\n",
" dest='bq_table')\n",
" parser.add_argument('--bucket',\n",
" parser.add_argument('--bucket',\n",
" dest='bucket')\n",
" args, pipeline_args = parser.parse_known_args(argv)\n",
" logging.info(\"ARGS\")\n",
" logging.info(args)\n",
" logging.info(\"PIPELINE ARGS\")\n",
" logging.info(pipeline_args)\n",
" for i in range(0, len(pipeline_args), 2):\n",
" args, pipeline_args = parser.parse_known_args(argv)\n",
" logging.info(\"ARGS\")\n",
" logging.info(args)\n",
" logging.info(\"PIPELINE ARGS\")\n",
" logging.info(pipeline_args)\n",
" for i in range(0, len(pipeline_args), 2):\n",
" if \"--temp_location\" == pipeline_args[i]:\n",
" temp_location = pipeline_args[i+1]\n",
" elif \"--project\" == pipeline_args[i]:\n",
" project = pipeline_args[i+1]\n",
"\n",
" exported_train = args.bucket + '/exported_data/train'\n",
" exported_eval = args.bucket + '/exported_data/eval'\n",
" exported_train = args.bucket + '/exported_data/train'\n",
" exported_eval = args.bucket + '/exported_data/eval'\n",
"\n",
" pipeline_options = PipelineOptions(pipeline_args)\n",
" pipeline_options.view_as(SetupOptions).save_main_session = True\n",
" with beam.Pipeline(options=pipeline_options) as pipeline:\n",
" with tft_beam.Context(temp_location):\n",
" raw_data_query = \"SELECT {0},{1} FROM {2} LIMIT 500\".format(\"CAST(station_number as STRING) AS station_number,year,month,day\",\"mean_temp\", args.bq_table)\n",
"\n",
" pipeline_options = PipelineOptions(pipeline_args)\n",
" pipeline_options.view_as(SetupOptions).save_main_session = True\n",
" with beam.Pipeline(options=pipeline_options) as pipeline:\n",
" with tft_beam.Context(temp_location):\n",
" def parse_bq_record(bq_record):\n",
" \"\"\"Parses a bq_record to a dictionary.\"\"\"\n",
" output = {}\n",
" for key in bq_record:\n",
" output[key] = [bq_record[key]]\n",
" return output\n",
"\n",
" raw_data_query = \"SELECT {0},{1} FROM {2} LIMIT 500\".format(\"CAST(station_number as STRING) AS station_number,year,month,day\",\"mean_temp\", args.bq_table)\n",
" def split_dataset(bq_row, num_partitions, ratio):\n",
" \"\"\"Returns a partition number for a given bq_row.\"\"\"\n",
" import json\n",
"\n",
" def parse_bq_record(bq_record):\n",
" \"\"\"Parses a bq_record to a dictionary.\"\"\"\n",
" output = {}\n",
" for key in bq_record:\n",
" output[key] = [bq_record[key]]\n",
" return output\n",
" assert num_partitions == len(ratio)\n",
" bucket = sum(map(ord, json.dumps(bq_row))) % sum(ratio)\n",
" total = 0\n",
" for i, part in enumerate(ratio):\n",
" total += part\n",
" if bucket < total:\n",
" return i\n",
" return len(ratio) - 1\n",
"\n",
" def split_dataset(bq_row, num_partitions, ratio):\n",
" \"\"\"Returns a partition number for a given bq_row.\"\"\"\n",
" import json\n",
"\n",
" assert num_partitions == len(ratio)\n",
" bucket = sum(map(ord, json.dumps(bq_row))) % sum(ratio)\n",
" total = 0\n",
" for i, part in enumerate(ratio):\n",
" total += part\n",
" if bucket < total:\n",
" return i\n",
" return len(ratio) - 1\n",
"\n",
" # Read raw BigQuery data.\n",
" raw_train_data, raw_eval_data = (\n",
" pipeline\n",
" | \"Read Raw Data\"\n",
" >> beam.io.ReadFromBigQuery(\n",
" query=raw_data_query,\n",
" project=project,\n",
" use_standard_sql=True,\n",
" # Read raw BigQuery data.\n",
" raw_train_data, raw_eval_data = (\n",
" pipeline\n",
" | \"Read Raw Data\"\n",
" >> beam.io.ReadFromBigQuery(\n",
" query=raw_data_query,\n",
" project=project,\n",
" use_standard_sql=True,\n",
" )\n",
" | \"Parse Data\" >> beam.Map(parse_bq_record)\n",
" | \"Split\" >> beam.Partition(split_dataset, 2, ratio=[8, 2])\n",
" )\n",
" | \"Parse Data\" >> beam.Map(parse_bq_record)\n",
" | \"Split\" >> beam.Partition(split_dataset, 2, ratio=[8, 2])\n",
" )\n",
"\n",
" # Write raw train data to GCS .\n",
" _ = raw_train_data | \"Write Raw Train Data\" >> beam.io.WriteToText(\n",
" file_path_prefix=exported_train, file_name_suffix=\".csv\"\n",
" )\n",
" # Write raw train data to GCS .\n",
" _ = raw_train_data | \"Write Raw Train Data\" >> beam.io.WriteToText(\n",
" file_path_prefix=exported_train, file_name_suffix=\".csv\"\n",
" )\n",
"\n",
" # Write raw eval data to GCS .\n",
" _ = raw_eval_data | \"Write Raw Eval Data\" >> beam.io.WriteToText(\n",
" file_path_prefix=exported_eval, file_name_suffix=\".csv\"\n",
" )\n",
" # Write raw eval data to GCS .\n",
" _ = raw_eval_data | \"Write Raw Eval Data\" >> beam.io.WriteToText(\n",
" file_path_prefix=exported_eval, file_name_suffix=\".csv\"\n",
" )\n",
"\n",
"\n",
"if __name__ == '__main__':\n",
" logging.getLogger().setLevel(logging.INFO)\n",
" run()"
" logging.getLogger().setLevel(logging.INFO)\n",
" run()"
]
},
{
@@ -975,11 +1075,11 @@
},
"outputs": [],
"source": [
"GCS_SPLIT_PY = BUCKET_NAME + \"/split.py\"\n",
"GCS_SPLIT_PY = BUCKET_URI + \"/split.py\"\n",
"! gsutil cp split.py $GCS_SPLIT_PY\n",
"GCS_REQUIREMENTS_TXT = BUCKET_NAME + \"/requirements.txt\"\n",
"GCS_REQUIREMENTS_TXT = BUCKET_URI + \"/requirements.txt\"\n",
"! gsutil cp requirements.txt $GCS_REQUIREMENTS_TXT\n",
"GCS_SETUP_PY = BUCKET_NAME + \"/setup.py\"\n",
"GCS_SETUP_PY = BUCKET_URI + \"/setup.py\"\n",
"! gsutil cp setup.py $GCS_SETUP_PY"
]
},
@@ -1036,7 +1136,7 @@
},
"outputs": [],
"source": [
"PIPELINE_ROOT = \"{}/pipeline_root/dataflow_split\".format(BUCKET_NAME)\n",
"PIPELINE_ROOT = \"{}/pipeline_root/dataflow_split\".format(BUCKET_URI)\n",
"\n",
"\n",
"@dsl.pipeline(name=\"dataflow-split\", description=\"Dataflow split dataset\")\n",
@@ -1047,7 +1147,7 @@
" staging_dir: str = PIPELINE_ROOT,\n",
" args: list = [\n",
" \"--bucket\",\n",
" BUCKET_NAME,\n",
" BUCKET_URI,\n",
" \"--bq_table\",\n",
" BQ_TABLE,\n",
" \"--runner\",\n",
@@ -1067,9 +1167,7 @@
" args=args,\n",
" )\n",
"\n",
" dataflow_wait_op = WaitGcpResourcesOp(\n",
" gcp_resources=dataflow_python_op.outputs[\"gcp_resources\"]\n",
" )\n",
" _ = WaitGcpResourcesOp(gcp_resources=dataflow_python_op.outputs[\"gcp_resources\"])\n",
"\n",
"\n",
"compiler.Compiler().compile(pipeline_func=pipeline, package_path=\"dataflow_split.json\")\n",
@@ -1083,7 +1181,7 @@
"\n",
"pipeline.run()\n",
"\n",
"! gsutil ls {BUCKET_NAME}/exported_data\n",
"! gsutil ls {BUCKET_URI}/exported_data\n",
"\n",
"! rm -f dataflow_split.json split.py requirements.txt"
]
@@ -1124,13 +1222,6 @@
"Otherwise, you can delete the individual resources you created in this tutorial:\n",
"\n",
"- Dataset\n",
"- Pipeline\n",
"- Model\n",
"- Endpoint\n",
"- AutoML Training Job\n",
"- Batch Job\n",
"- Custom Job\n",
"- Hyperparameter Tuning Job\n",
"- Cloud Storage Bucket"
]
},
@@ -1142,61 +1233,11 @@
},
"outputs": [],
"source": [
"delete_all = True\n",
"# Warning: Setting this to true will delete everything in your bucket\n",
"delete_bucket = False\n",
"\n",
"if delete_all:\n",
" # Delete the dataset using the Vertex dataset object\n",
" try:\n",
" if \"dataset\" in globals():\n",
" dataset.delete()\n",
" except Exception as e:\n",
" print(e)\n",
"\n",
" # Delete the model using the Vertex model object\n",
" try:\n",
" if \"model\" in globals():\n",
" model.delete()\n",
" except Exception as e:\n",
" print(e)\n",
"\n",
" # Delete the endpoint using the Vertex endpoint object\n",
" try:\n",
" if \"endpoint\" in globals():\n",
" endpoint.undeploy_all()\n",
" endpoint.delete()\n",
" except Exception as e:\n",
" print(e)\n",
"\n",
" # Delete the AutoML or Pipeline training job\n",
" try:\n",
" if \"dag\" in globals():\n",
" dag.delete()\n",
" except Exception as e:\n",
" print(e)\n",
"\n",
" # Delete the custom training job\n",
" try:\n",
" if \"job\" in globals():\n",
" job.delete()\n",
" except Exception as e:\n",
" print(e)\n",
"\n",
" # Delete the batch prediction job using the Vertex batch prediction object\n",
" try:\n",
" if \"batch_predict_job\" in globals():\n",
" batch_predict_job.delete()\n",
" except Exception as e:\n",
" print(e)\n",
"\n",
" # Delete the hyperparameter tuning job using the Vertex hyperparameter tuning object\n",
" try:\n",
" if \"hpt_job\" in globals():\n",
" hpt_job.delete()\n",
" except Exception as e:\n",
" print(e)\n",
"\n",
" if \"BUCKET_NAME\" in globals():\n",
" ! gsutil rm -r $BUCKET_NAME"
"if delete_bucket or os.getenv(\"IS_TESTING\"):\n",
" ! gsutil rm -r $BUCKET_URI"
]
}
],
@@ -44,7 +44,7 @@
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage3/get_started_with_dataproc_serverless_pipeline_components.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_dataproc_serverless_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 Vertex AI Workbench\n",
" </a>\n",
@@ -134,12 +134,15 @@
"source": [
"import os\n",
"\n",
"# The Google Cloud Notebook product has specific requirements\n",
"IS_GOOGLE_CLOUD_NOTEBOOK = os.path.exists(\"/opt/deeplearning/metadata/env_version\")\n",
"# The Vertex AI Workbench Notebook product has specific requirements\n",
"IS_WORKBENCH_NOTEBOOK = os.getenv(\"DL_ANACONDA_HOME\")\n",
"IS_USER_MANAGED_WORKBENCH_NOTEBOOK = os.path.exists(\n",
" \"/opt/deeplearning/metadata/env_version\"\n",
")\n",
"\n",
"# Google Cloud Notebook requires dependencies to be installed with '--user'\n",
"# Vertex AI Notebook requires dependencies to be installed with '--user'\n",
"USER_FLAG = \"\"\n",
"if IS_GOOGLE_CLOUD_NOTEBOOK:\n",
"if IS_WORKBENCH_NOTEBOOK:\n",
" USER_FLAG = \"--user\"\n",
"\n",
"# Install the required packages\n",
@@ -176,6 +179,32 @@
" app.kernel.do_shutdown(True)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "1df9ff75fa88"
},
"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 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",
"\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": {
@@ -290,7 +319,7 @@
"source": [
"### Authenticate your Google Cloud account\n",
"\n",
"**If you are using Google Cloud Notebooks**, your environment is already authenticated. Skip this step.\n",
"**If you are using Vertex AI Workbench Notebooks**, your environment is already authenticated. 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",
@@ -325,9 +354,13 @@
"import os\n",
"import sys\n",
"\n",
"# If on Google Cloud Notebook, then don't execute this code\n",
"if not os.path.exists(\"/opt/deeplearning/metadata/env_version\"):\n",
"# If on Vertex AI Workbench, then don't execute this code\n",
"IS_COLAB = False\n",
"if not os.path.exists(\"/opt/deeplearning/metadata/env_version\") and not os.getenv(\n",
" \"DL_ANACONDA_HOME\"\n",
"):\n",
" if \"google.colab\" in sys.modules:\n",
" IS_COLAB = True\n",
" from google.colab import auth as google_auth\n",
"\n",
" google_auth.authenticate_user()\n",
@@ -450,15 +483,20 @@
"source": [
"if (\n",
" SERVICE_ACCOUNT == \"\"\n",
" or SERVICE_ACCOUNT == \"[your-service-account]\"\n",
" or SERVICE_ACCOUNT is None\n",
" or SERVICE_ACCOUNT == \"[your-service-account]\"\n",
"):\n",
" shell_output = ! gcloud projects describe $PROJECT_ID | sed -nre 's:.*projectNumber\\: (.*):\\1:p'\n",
" SERVICE_ACCOUNT = (\n",
" shell_output[0].replace(\"'\", \"\") + \"-compute@developer.gserviceaccount.com\"\n",
" )\n",
" # Get your service account from gcloud\n",
" if not IS_COLAB:\n",
" shell_output = !gcloud auth list 2>/dev/null\n",
" SERVICE_ACCOUNT = shell_output[2].replace(\"*\", \"\").strip()\n",
"\n",
"print(\"Service Account:\", SERVICE_ACCOUNT)"
" if IS_COLAB:\n",
" shell_output = ! gcloud projects describe $PROJECT_ID\n",
" project_number = shell_output[-1].split(\":\")[1].strip().replace(\"'\", \"\")\n",
" SERVICE_ACCOUNT = f\"{project_number}-compute@developer.gserviceaccount.com\"\n",
"\n",
" print(\"Service Account:\", SERVICE_ACCOUNT)"
]
},
{
@@ -44,7 +44,7 @@
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage3/get_started_with_hpt_pipeline_components.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_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",
" </a>\n",
@@ -124,7 +124,7 @@
"source": [
"## Installations\n",
"\n",
"Install *one time* the packages for executing the MLOps notebooks."
"Install the required packages for executing the notebook."
]
},
{
@@ -135,22 +135,26 @@
},
"outputs": [],
"source": [
"! 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"
"import os\n",
"\n",
"# The Vertex AI Workbench Notebook product has specific requirements\n",
"IS_WORKBENCH_NOTEBOOK = os.getenv(\"DL_ANACONDA_HOME\")\n",
"IS_USER_MANAGED_WORKBENCH_NOTEBOOK = os.path.exists(\n",
" \"/opt/deeplearning/metadata/env_version\"\n",
")\n",
"\n",
"# Vertex AI Notebook requires dependencies to be installed with '--user'\n",
"USER_FLAG = \"\"\n",
"if IS_WORKBENCH_NOTEBOOK:\n",
" USER_FLAG = \"--user\"\n",
"\n",
"! 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 kfp $USER_FLAG -q"
]
},
{
@@ -182,6 +186,32 @@
" app.kernel.do_shutdown(True)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "1df9ff75fa88"
},
"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 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",
"\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": {
@@ -288,6 +318,33 @@
"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 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",
"**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,
@@ -296,20 +353,21 @@
},
"outputs": [],
"source": [
"import os\n",
"import sys\n",
"\n",
"# If you are running this notebook in Colab, run this cell and follow the\n",
"# instructions to authenticate your GCP account. This provides access to your\n",
"# Cloud Storage bucket and lets you submit training jobs and prediction\n",
"# requests.\n",
"\n",
"# The Google Cloud Notebook product has specific requirements\n",
"IS_GOOGLE_CLOUD_NOTEBOOK = os.path.exists(\"/opt/deeplearning/metadata/env_version\")\n",
"import os\n",
"import sys\n",
"\n",
"# If on Google Cloud Notebooks, then don't execute this code\n",
"if not IS_GOOGLE_CLOUD_NOTEBOOK:\n",
"# If on Vertex AI Workbench, then don't execute this code\n",
"IS_COLAB = False\n",
"if not os.path.exists(\"/opt/deeplearning/metadata/env_version\") and not os.getenv(\n",
" \"DL_ANACONDA_HOME\"\n",
"):\n",
" if \"google.colab\" in sys.modules:\n",
" IS_COLAB = True\n",
" from google.colab import auth as google_auth\n",
"\n",
" google_auth.authenticate_user()\n",
@@ -431,15 +489,20 @@
"source": [
"if (\n",
" SERVICE_ACCOUNT == \"\"\n",
" or SERVICE_ACCOUNT == \"[your-service-account]\"\n",
" or SERVICE_ACCOUNT is None\n",
" or SERVICE_ACCOUNT == \"[your-service-account]\"\n",
"):\n",
" shell_output = ! gcloud projects describe $PROJECT_ID | sed -nre 's:.*projectNumber\\: (.*):\\1:p'\n",
" SERVICE_ACCOUNT = (\n",
" shell_output[0].replace(\"'\", \"\") + \"-compute@developer.gserviceaccount.com\"\n",
" )\n",
" # Get your service account from gcloud\n",
" if not IS_COLAB:\n",
" shell_output = !gcloud auth list 2>/dev/null\n",
" SERVICE_ACCOUNT = shell_output[2].replace(\"*\", \"\").strip()\n",
"\n",
"print(\"Service Account:\", SERVICE_ACCOUNT)"
" if IS_COLAB:\n",
" shell_output = ! gcloud projects describe $PROJECT_ID\n",
" project_number = shell_output[-1].split(\":\")[1].strip().replace(\"'\", \"\")\n",
" SERVICE_ACCOUNT = f\"{project_number}-compute@developer.gserviceaccount.com\"\n",
"\n",
" print(\"Service Account:\", SERVICE_ACCOUNT)"
]
},
{
@@ -1457,7 +1520,9 @@
},
"outputs": [],
"source": [
"if os.getenv(\"IS_TESTING\"):\n",
"delete_bucket = False\n",
"\n",
"if delete_bucket or os.getenv(\"IS_TESTING\"):\n",
" ! gsutil rm -r $BUCKET_URI"
]
}
@@ -45,7 +45,7 @@
" </td>\n",
" \n",
" <td>\n",
" <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage3/get_started_with_kubeflow_pipelines.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_kubeflow_pipelines.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",
@@ -106,7 +106,7 @@
"source": [
"## Installations\n",
"\n",
"Install the following packages for executing this MLOps notebooks."
"Install the required packages for executing this MLOps notebook."
]
},
{
@@ -119,12 +119,13 @@
"source": [
"import os\n",
"\n",
"# The Google Cloud Notebook product has specific requirements\n",
"IS_GOOGLE_CLOUD_NOTEBOOK = os.path.exists(\"/opt/deeplearning/metadata/env_version\")\n",
"# The Vertex AI Workbench Notebook product has specific requirements\n",
"IS_WORKBENCH_NOTEBOOK = os.getenv(\"DL_ANACONDA_HOME\")\n",
"IS_USER_MANAGED_WORKBENCH_NOTEBOOK = os.path.exists(\"/opt/deeplearning/metadata/env_version\")\n",
"\n",
"# Google Cloud Notebook requires dependencies to be installed with '--user'\n",
"# Vertex AI Notebook requires dependencies to be installed with '--user'\n",
"USER_FLAG = \"\"\n",
"if IS_GOOGLE_CLOUD_NOTEBOOK:\n",
"if IS_WORKBENCH_NOTEBOOK:\n",
" USER_FLAG = \"--user\"\n",
" \n",
"! pip3 install tensorflow-io==0.18 $USER_FLAG -q\n",
@@ -162,6 +163,32 @@
" app.kernel.do_shutdown(True)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "e56d698e5d52"
},
"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 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",
"\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": {
@@ -276,7 +303,7 @@
"source": [
"### Authenticate your Google Cloud account\n",
"\n",
"**If you are using Google Cloud Notebooks**, your environment is already authenticated. Skip this step.\n",
"**If you are using Vertex AI Workbench Notebooks**, your environment is already authenticated. 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",
@@ -311,9 +338,13 @@
"import os\n",
"import sys\n",
"\n",
"# If on Google Cloud Notebook, then don't execute this code\n",
"if not os.path.exists(\"/opt/deeplearning/metadata/env_version\"):\n",
"# If on Vertex AI Workbench, then don't execute this code\n",
"IS_COLAB = False\n",
"if not os.path.exists(\"/opt/deeplearning/metadata/env_version\") and not os.getenv(\n",
" \"DL_ANACONDA_HOME\"\n",
"):\n",
" if \"google.colab\" in sys.modules:\n",
" IS_COLAB = True\n",
" from google.colab import auth as google_auth\n",
"\n",
" google_auth.authenticate_user()\n",
@@ -436,15 +467,20 @@
"source": [
"if (\n",
" SERVICE_ACCOUNT == \"\"\n",
" or SERVICE_ACCOUNT == \"[your-service-account]\"\n",
" or SERVICE_ACCOUNT is None\n",
" or SERVICE_ACCOUNT == \"[your-service-account]\"\n",
"):\n",
" shell_output = ! gcloud projects describe $PROJECT_ID | sed -nre 's:.*projectNumber\\: (.*):\\1:p'\n",
" SERVICE_ACCOUNT = (\n",
" shell_output[0].replace(\"'\", \"\") + \"-compute@developer.gserviceaccount.com\"\n",
" )\n",
" # Get your service account from gcloud\n",
" if not IS_COLAB:\n",
" shell_output = !gcloud auth list 2>/dev/null\n",
" SERVICE_ACCOUNT = shell_output[2].replace(\"*\", \"\").strip()\n",
"\n",
"print(\"Service Account:\", SERVICE_ACCOUNT)"
" if IS_COLAB:\n",
" shell_output = ! gcloud projects describe $PROJECT_ID\n",
" project_number = shell_output[-1].split(\":\")[1].strip().replace(\"'\", \"\")\n",
" SERVICE_ACCOUNT = f\"{project_number}-compute@developer.gserviceaccount.com\"\n",
"\n",
" print(\"Service Account:\", SERVICE_ACCOUNT)"
]
},
{
File diff suppressed because it is too large Load Diff
@@ -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://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage3/get_started_with_rapid_prototyping_bqml_automl.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_rapid_prototyping_bqml_automl.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",
@@ -241,7 +241,7 @@
"source": [
"## Installation\n",
"\n",
"Install the latest version of Vertex AI SDK for Python."
"Install the packages required for executing this notebook."
]
},
{
@@ -254,33 +254,20 @@
"source": [
"import os\n",
"\n",
"# Google Cloud Notebook\n",
"if os.path.exists(\"/opt/deeplearning/metadata/env_version\"):\n",
"# The Vertex AI Workbench Notebook product has specific requirements\n",
"IS_WORKBENCH_NOTEBOOK = os.getenv(\"DL_ANACONDA_HOME\")\n",
"IS_USER_MANAGED_WORKBENCH_NOTEBOOK = os.path.exists(\n",
" \"/opt/deeplearning/metadata/env_version\"\n",
")\n",
"\n",
"# Vertex AI Notebook requires dependencies to be installed with '--user'\n",
"USER_FLAG = \"\"\n",
"if IS_WORKBENCH_NOTEBOOK:\n",
" USER_FLAG = \"--user\"\n",
"else:\n",
" USER_FLAG = \"\""
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "eeba891a06fc"
},
"source": [
"Install additional packages used in this tutorial."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "739011eb"
},
"outputs": [],
"source": [
"! pip3 install --quiet --upgrade google-cloud-aiplatform {USER_FLAG}\n",
"! pip3 install {USER_FLAG} --quiet -U google-cloud-pipeline-components==1.0 kfp\n",
"! pip3 install {USER_FLAG} --quiet --upgrade google-cloud-bigquery"
"\n",
"! pip3 install --quiet --upgrade google-cloud-aiplatform {USER_FLAG} -q\n",
"! pip3 install {USER_FLAG} --quiet -U google-cloud-pipeline-components==1.0 kfp -q\n",
"! pip3 install {USER_FLAG} --quiet --upgrade google-cloud-bigquery -q"
]
},
{
@@ -321,10 +308,12 @@
"source": [
"### Authenticate your Google Cloud account\n",
"\n",
"**If you are using Google Cloud Notebooks**, your environment is already authenticated. Skip this step.\n",
"**If you are using Vertex AI Workbench Notebooks**, your environment is already\n",
"authenticated. 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",
@@ -356,9 +345,13 @@
"import os\n",
"import sys\n",
"\n",
"# If on Google Cloud Notebook, then don't execute this code\n",
"if not os.path.exists(\"/opt/deeplearning/metadata/env_version\"):\n",
"# If on Vertex AI Workbench, then don't execute this code\n",
"IS_COLAB = \"google.colab\" in sys.modules\n",
"if not os.path.exists(\"/opt/deeplearning/metadata/env_version\") and not os.getenv(\n",
" \"DL_ANACONDA_HOME\"\n",
"):\n",
" if \"google.colab\" in sys.modules:\n",
" IS_COLAB = True\n",
" from google.colab import auth as google_auth\n",
"\n",
" google_auth.authenticate_user()\n",
@@ -390,7 +383,7 @@
"\n",
"2. [Make sure that billing is enabled for your project.](https://cloud.google.com/billing/docs/how-to/modify-project)\n",
"\n",
"3. [Enable the following APIs: Vertex AI APIs, Compute Engine APIs, and Cloud Storage.](https://console.cloud.google.com/flows/enableapi?apiid=ml.googleapis.com,compute_component,storage-component.googleapis.com)\n",
"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",
"\n",
@@ -621,9 +614,17 @@
" or SERVICE_ACCOUNT is None\n",
" or SERVICE_ACCOUNT == \"[your-service-account]\"\n",
"):\n",
" # Get your GCP project id from gcloud\n",
" shell_output = !gcloud auth list 2>/dev/null\n",
" SERVICE_ACCOUNT = shell_output[2].replace(\"*\", \"\").strip()\n",
" # Get your service account from gcloud\n",
" if not IS_COLAB:\n",
" shell_output = !gcloud auth list 2>/dev/null\n",
" SERVICE_ACCOUNT = shell_output[2].replace(\"*\", \"\").strip()\n",
"\n",
" if IS_COLAB:\n",
" shell_output = ! gcloud projects describe $PROJECT_ID\n",
" # print(\"shell_output=\", shell_output)\n",
" project_number = shell_output[-1].split(\":\")[1].strip().replace(\"'\", \"\")\n",
" SERVICE_ACCOUNT = f\"{project_number}-compute@developer.gserviceaccount.com\"\n",
"\n",
" print(\"Service Account:\", SERVICE_ACCOUNT)"
]
},
File diff suppressed because it is too large Load Diff
Binary file not shown.

After

Width:  |  Height:  |  Size: 63 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 68 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 152 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

@@ -32,17 +32,23 @@
"# E2E ML on GCP: MLOps stage 3 : formalization\n",
"\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/mlops_formalization.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/mlops_formalization.ipynb\">\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samplestree/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",
" </td>\n",
" <td>\n",
" <a href=\"https://console.cloud.google.com/ai/platform/notebooks/deploy-notebook?download_url=https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage3/mlops_formalization.ipynb\">\n",
" Open in Google Cloud Notebooks\n",
" <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://raw.githubusercontent.com/GoogleCloudPlatform/vertex-ai-samples/main/notebooks/community/ml_ops/stage3/mlops_formalization.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",
" </td> \n",
"</table>\n",
"<br/><br/><br/>"
]
@@ -182,6 +188,19 @@
},
"outputs": [],
"source": [
"import os\n",
"\n",
"# The Vertex AI Workbench Notebook product has specific requirements\n",
"IS_WORKBENCH_NOTEBOOK = os.getenv(\"DL_ANACONDA_HOME\")\n",
"IS_USER_MANAGED_WORKBENCH_NOTEBOOK = os.path.exists(\n",
" \"/opt/deeplearning/metadata/env_version\"\n",
")\n",
"\n",
"# Vertex AI Notebook requires dependencies to be installed with '--user'\n",
"USER_FLAG = \"\"\n",
"if IS_WORKBENCH_NOTEBOOK:\n",
" USER_FLAG = \"--user\"\n",
"\n",
"ONCE_ONLY = False\n",
"if ONCE_ONLY:\n",
" ! pip3 install -U tensorflow==2.5 $USER_FLAG\n",
@@ -231,6 +250,32 @@
" app.kernel.do_shutdown(True)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "BF1j6f9HApxa"
},
"source": [
"## Before you begin\n",
"\n",
"### Set up your Google Cloud project\n",
"\n",
"**The following steps are required, regardless of your notebook environment.**\n",
"\n",
"1. [Select or create a Google Cloud project](https://console.cloud.google.com/cloud-resource-manager). When you first create an account, you get a $300 free credit towards your compute/storage costs.\n",
"\n",
"1. [Make sure that billing is enabled for your project](https://cloud.google.com/billing/docs/how-to/modify-project).\n",
"\n",
"1. [Enable the Vertex AI API and 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",
"\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": {
@@ -334,6 +379,67 @@
"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 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",
"**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": {
Binary file not shown.

Before

Width:  |  Height:  |  Size: 69 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 92 KiB

+20 -1
View File
@@ -36,7 +36,7 @@ This stage may be done entirely by MLOps. We recommend:
<img src='stage4.png'>
<img src='stage4v3.png'>
## Notebooks
@@ -75,6 +75,25 @@ The steps performed include:
- 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
Binary file not shown.

After

Width:  |  Height:  |  Size: 352 KiB

File diff suppressed because it is too large Load Diff
@@ -33,16 +33,22 @@
"\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/stage4/get_started_with_google_artifact_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/stage4/get_started_with_google_artifact_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/ai/platform/notebooks/deploy-notebook?download_url=https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage4/get_started_with_google_artifact_registry.ipynb\">\n",
" Open in Google Cloud Notebooks\n",
" <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://raw.githubusercontent.com/GoogleCloudPlatform/vertex-ai-samples/main/notebooks/community/ml_ops/stage4/get_started_with_google_artifact_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",
" </td>\n",
" </td> \n",
"</table>\n",
"<br/><br/><br/>"
]
@@ -90,7 +96,7 @@
"source": [
"## Installations\n",
"\n",
"Install *one time* the packages for executing the MLOps notebooks."
"Install the packages required for executing the notebook."
]
},
{
@@ -101,22 +107,20 @@
},
"outputs": [],
"source": [
"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"
"import os\n",
"\n",
"# The Vertex AI Workbench Notebook product has specific requirements\n",
"IS_WORKBENCH_NOTEBOOK = os.getenv(\"DL_ANACONDA_HOME\")\n",
"IS_USER_MANAGED_WORKBENCH_NOTEBOOK = os.path.exists(\n",
" \"/opt/deeplearning/metadata/env_version\"\n",
")\n",
"\n",
"# Vertex AI Notebook requires dependencies to be installed with '--user'\n",
"USER_FLAG = \"\"\n",
"if IS_WORKBENCH_NOTEBOOK:\n",
" USER_FLAG = \"--user\"\n",
"\n",
"! pip3 install --upgrade google-cloud-aiplatform $USER_FLAG -q"
]
},
{
@@ -148,6 +152,36 @@
" app.kernel.do_shutdown(True)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "before_you_begin"
},
"source": [
"## Before you begin\n",
"\n",
"### GPU runtime\n",
"\n",
"*Make sure you're running this notebook in a GPU runtime if you have that option. In Colab, select* **Runtime > Change Runtime Type > GPU**\n",
"\n",
"### Set up your Google Cloud project\n",
"\n",
"**The following steps are required, regardless of your notebook environment.**\n",
"\n",
"1. [Select or create a Google Cloud project](https://console.cloud.google.com/cloud-resource-manager). When you first create an account, you get a $300 free credit towards your compute/storage costs.\n",
"\n",
"2. [Make sure that billing is enabled for your project.](https://cloud.google.com/billing/docs/how-to/modify-project)\n",
"\n",
"3. [Enable the 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",
"\n",
"5. Enter your project ID in the cell below. Then run the cell to make sure the\n",
"Cloud SDK uses the right project for all the commands in this notebook.\n",
"\n",
"**Note**: Jupyter runs lines prefixed with `!` as shell commands, and it interpolates Python variables prefixed with `$`."
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -224,7 +258,10 @@
},
"outputs": [],
"source": [
"REGION = \"us-central1\" # @param {type: \"string\"}"
"REGION = \"[your-region]\" # @param {type: \"string\"}\n",
"\n",
"if REGION == \"[your-region]\":\n",
" REGION = \"us-central1\""
]
},
{
@@ -251,6 +288,67 @@
"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 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",
"**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 = False\n",
"if not os.path.exists(\"/opt/deeplearning/metadata/env_version\") and not os.getenv(\n",
" \"DL_ANACONDA_HOME\"\n",
"):\n",
" if \"google.colab\" in sys.modules:\n",
" IS_COLAB = True\n",
" from google.colab import auth as google_auth\n",
"\n",
" google_auth.authenticate_user()\n",
"\n",
" # If you are running this notebook locally, replace the string below with the\n",
" # path to your service account key and run this cell to authenticate your GCP\n",
" # account.\n",
" elif not os.getenv(\"IS_TESTING\"):\n",
" %env GOOGLE_APPLICATION_CREDENTIALS ''"
]
},
{
"cell_type": "markdown",
"metadata": {
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -44,10 +44,11 @@
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://console.cloud.google.com/ai/platform/notebooks/deploy-notebook?download_url=https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage4/get_started_with_vertex_xai.ipynb\">\n",
" Open in Google Cloud Notebooks\n",
" <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://raw.githubusercontent.com/GoogleCloudPlatform/vertex-ai-samples/main/notebooks/community/ml_ops/stage4/get_started_with_vertex_xai.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",
" </td> \n",
"</table>\n",
"<br/><br/><br/>"
]
@@ -145,7 +146,7 @@
"source": [
"## Installations\n",
"\n",
"Install *one time* the packages for executing the MLOps notebooks."
"Install the packages required for executing the notebook."
]
},
{
@@ -156,24 +157,24 @@
},
"outputs": [],
"source": [
"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"
"import os\n",
"\n",
"# The Vertex AI Workbench Notebook product has specific requirements\n",
"IS_WORKBENCH_NOTEBOOK = os.getenv(\"DL_ANACONDA_HOME\")\n",
"IS_USER_MANAGED_WORKBENCH_NOTEBOOK = os.path.exists(\n",
" \"/opt/deeplearning/metadata/env_version\"\n",
")\n",
"\n",
"# Vertex AI Notebook requires dependencies to be installed with '--user'\n",
"USER_FLAG = \"\"\n",
"if IS_WORKBENCH_NOTEBOOK:\n",
" USER_FLAG = \"--user\"\n",
"\n",
"! pip3 install -U tensorflow==2.5 $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 python-tabulate $USER_FLAG -q\n",
"! pip3 install -U opencv-python-headless==4.5.2.52 $USER_FLAG -q"
]
},
{
@@ -205,6 +206,36 @@
" app.kernel.do_shutdown(True)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "before_you_begin"
},
"source": [
"## Before you begin\n",
"\n",
"### GPU runtime\n",
"\n",
"*Make sure you're running this notebook in a GPU runtime if you have that option. In Colab, select* **Runtime > Change Runtime Type > GPU**\n",
"\n",
"### Set up your Google Cloud project\n",
"\n",
"**The following steps are required, regardless of your notebook environment.**\n",
"\n",
"1. [Select or create a Google Cloud project](https://console.cloud.google.com/cloud-resource-manager). When you first create an account, you get a $300 free credit towards your compute/storage costs.\n",
"\n",
"2. [Make sure that billing is enabled for your project.](https://cloud.google.com/billing/docs/how-to/modify-project)\n",
"\n",
"3. [Enable the 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",
"\n",
"5. Enter your project ID in the cell below. Then run the cell to make sure the\n",
"Cloud SDK uses the right project for all the commands in this notebook.\n",
"\n",
"**Note**: Jupyter runs lines prefixed with `!` as shell commands, and it interpolates Python variables prefixed with `$`."
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -281,7 +312,10 @@
},
"outputs": [],
"source": [
"REGION = \"us-central1\" # @param {type: \"string\"}"
"REGION = \"[your-region]\" # @param {type: \"string\"}\n",
"\n",
"if REGION == \"[your-region]\":\n",
" REGION = \"us-central1\""
]
},
{
@@ -308,6 +342,67 @@
"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 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",
"**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 = False\n",
"if not os.path.exists(\"/opt/deeplearning/metadata/env_version\") and not os.getenv(\n",
" \"DL_ANACONDA_HOME\"\n",
"):\n",
" if \"google.colab\" in sys.modules:\n",
" IS_COLAB = True\n",
" from google.colab import auth as google_auth\n",
"\n",
" google_auth.authenticate_user()\n",
"\n",
" # If you are running this notebook locally, replace the string below with the\n",
" # path to your service account key and run this cell to authenticate your GCP\n",
" # account.\n",
" elif not os.getenv(\"IS_TESTING\"):\n",
" %env GOOGLE_APPLICATION_CREDENTIALS ''"
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -331,7 +426,8 @@
},
"outputs": [],
"source": [
"BUCKET_NAME = \"gs://[your-bucket-name]\" # @param {type:\"string\"}"
"BUCKET_NAME = \"[your-bucket-name]\" # @param {type:\"string\"}\n",
"BUCKET_URI = f\"gs://{BUCKET_NAME}\""
]
},
{
@@ -342,8 +438,9 @@
},
"outputs": [],
"source": [
"if BUCKET_NAME == \"\" or BUCKET_NAME is None or BUCKET_NAME == \"gs://[your-bucket-name]\":\n",
" BUCKET_NAME = \"gs://\" + PROJECT_ID + \"aip-\" + TIMESTAMP"
"if BUCKET_NAME == \"\" or BUCKET_NAME is None or BUCKET_NAME == \"[your-bucket-name]\":\n",
" BUCKET_NAME = PROJECT_ID + \"aip-\" + TIMESTAMP\n",
" BUCKET_URI = \"gs://\" + BUCKET_NAME"
]
},
{
@@ -363,7 +460,7 @@
},
"outputs": [],
"source": [
"! gsutil mb -l $REGION $BUCKET_NAME"
"! gsutil mb -l $REGION $BUCKET_URI"
]
},
{
@@ -383,7 +480,7 @@
},
"outputs": [],
"source": [
"! gsutil ls -al $BUCKET_NAME"
"! gsutil ls -al $BUCKET_URI"
]
},
{
@@ -428,7 +525,7 @@
},
"outputs": [],
"source": [
"aip.init(project=PROJECT_ID, staging_bucket=BUCKET_NAME)"
"aip.init(project=PROJECT_ID, staging_bucket=BUCKET_URI)"
]
},
{
@@ -506,7 +603,7 @@
"if os.getenv(\"IS_TESTING_TF\"):\n",
" TF = os.getenv(\"IS_TESTING_TF\")\n",
"else:\n",
" TF = \"2-1\".replace(\".\", \"-\")\n",
" TF = \"2-5\".replace(\".\", \"-\")\n",
"\n",
"if TF[0] == \"2\":\n",
" if TRAIN_GPU:\n",
@@ -660,7 +757,7 @@
"dataset = aip.TabularDataset.create(\n",
" display_name=\"CIFAR10\" + \"_\" + TIMESTAMP,\n",
" gcs_source=gcs_source,\n",
" labels={\"user_metadata\": BUCKET_NAME[5:]},\n",
" labels={\"user_metadata\": BUCKET_NAME},\n",
")\n",
"\n",
"\n",
@@ -809,7 +906,7 @@
"\n",
"! cut -d, -f1-16 tmp.csv > batch.csv\n",
"\n",
"gcs_input_uri = BUCKET_NAME + \"/test.csv\"\n",
"gcs_input_uri = BUCKET_URI + \"/test.csv\"\n",
"\n",
"! gsutil cp batch.csv $gcs_input_uri"
]
@@ -844,7 +941,7 @@
"batch_predict_job = model.batch_predict(\n",
" job_display_name=\"cifar10_\" + TIMESTAMP,\n",
" gcs_source=gcs_input_uri,\n",
" gcs_destination_prefix=BUCKET_NAME,\n",
" gcs_destination_prefix=BUCKET_URI,\n",
" instances_format=\"csv\",\n",
" predictions_format=\"csv\",\n",
" generate_explanation=True,\n",
@@ -1510,7 +1607,7 @@
"! rm -f custom.tar custom.tar.gz\n",
"! tar cvf custom.tar custom\n",
"! gzip custom.tar\n",
"! gsutil cp custom.tar.gz $BUCKET_NAME/trainer_cifar10.tar.gz"
"! gsutil cp custom.tar.gz $BUCKET_URI/trainer_cifar10.tar.gz"
]
},
{
@@ -1578,7 +1675,7 @@
},
"outputs": [],
"source": [
"MODEL_DIR = \"{}/{}\".format(BUCKET_NAME, TIMESTAMP)\n",
"MODEL_DIR = \"{}/{}\".format(BUCKET_URI, TIMESTAMP)\n",
"\n",
"EPOCHS = 20\n",
"STEPS = 100\n",
@@ -2056,7 +2153,7 @@
"source": [
"import json\n",
"\n",
"gcs_input_uri = BUCKET_NAME + \"/\" + \"test.jsonl\"\n",
"gcs_input_uri = BUCKET_URI + \"/\" + \"test.jsonl\"\n",
"with tf.io.gfile.GFile(gcs_input_uri, \"w\") as f:\n",
" data = {serving_input: test_item_1.tolist()}\n",
" f.write(json.dumps(data) + \"\\n\")\n",
@@ -2097,7 +2194,7 @@
"batch_predict_job = model.batch_predict(\n",
" job_display_name=\"cifar10_\" + TIMESTAMP,\n",
" gcs_source=gcs_input_uri,\n",
" gcs_destination_prefix=BUCKET_NAME,\n",
" gcs_destination_prefix=BUCKET_URI,\n",
" instances_format=\"jsonl\",\n",
" predictions_format=\"jsonl\",\n",
" machine_type=DEPLOY_COMPUTE,\n",
@@ -3018,7 +3115,7 @@
"! rm -f custom.tar custom.tar.gz\n",
"! tar cvf custom.tar custom\n",
"! gzip custom.tar\n",
"! gsutil cp custom.tar.gz $BUCKET_NAME/trainer_cifar10.tar.gz"
"! gsutil cp custom.tar.gz $BUCKET_URI/trainer_cifar10.tar.gz"
]
},
{
@@ -3086,7 +3183,7 @@
},
"outputs": [],
"source": [
"MODEL_DIR = \"{}/{}\".format(BUCKET_NAME, TIMESTAMP)\n",
"MODEL_DIR = \"{}/{}\".format(BUCKET_URI, TIMESTAMP)\n",
"\n",
"EPOCHS = 20\n",
"STEPS = 100\n",
@@ -3635,11 +3732,11 @@
},
"outputs": [],
"source": [
"! gsutil cp tmp1.jpg $BUCKET_NAME/tmp1.jpg\n",
"! gsutil cp tmp2.jpg $BUCKET_NAME/tmp2.jpg\n",
"! gsutil cp tmp1.jpg $BUCKET_URI/tmp1.jpg\n",
"! gsutil cp tmp2.jpg $BUCKET_URI/tmp2.jpg\n",
"\n",
"test_item_1 = BUCKET_NAME + \"/tmp1.jpg\"\n",
"test_item_2 = BUCKET_NAME + \"/tmp2.jpg\""
"test_item_1 = BUCKET_URI + \"/tmp1.jpg\"\n",
"test_item_2 = BUCKET_URI + \"/tmp2.jpg\""
]
},
{
@@ -3677,7 +3774,7 @@
"import base64\n",
"import json\n",
"\n",
"gcs_input_uri = BUCKET_NAME + \"/\" + \"test.jsonl\"\n",
"gcs_input_uri = BUCKET_URI + \"/\" + \"test.jsonl\"\n",
"with tf.io.gfile.GFile(gcs_input_uri, \"w\") as f:\n",
" bytes = tf.io.read_file(test_item_1)\n",
" b64str = base64.b64encode(bytes.numpy()).decode(\"utf-8\")\n",
@@ -3722,7 +3819,7 @@
"batch_predict_job = model.batch_predict(\n",
" job_display_name=\"cifar10_\" + TIMESTAMP,\n",
" gcs_source=gcs_input_uri,\n",
" gcs_destination_prefix=BUCKET_NAME,\n",
" gcs_destination_prefix=BUCKET_URI,\n",
" instances_format=\"jsonl\",\n",
" model_parameters=None,\n",
" machine_type=DEPLOY_COMPUTE,\n",
@@ -4361,7 +4458,7 @@
"! rm -f custom.tar custom.tar.gz\n",
"! tar cvf custom.tar custom\n",
"! gzip custom.tar\n",
"! gsutil cp custom.tar.gz $BUCKET_NAME/trainer_cifar10.tar.gz"
"! gsutil cp custom.tar.gz $BUCKET_URI/trainer_cifar10.tar.gz"
]
},
{
@@ -4401,7 +4498,7 @@
"\n",
"job = aip.CustomPythonPackageTrainingJob(\n",
" display_name=DISPLAY_NAME,\n",
" python_package_gcs_uri=f\"{BUCKET_NAME}/trainer_cifar10.tar.gz\",\n",
" python_package_gcs_uri=f\"{BUCKET_URI}/trainer_cifar10.tar.gz\",\n",
" python_module_name=\"trainer.task\",\n",
" container_uri=TRAIN_IMAGE,\n",
" model_serving_container_image_uri=DEPLOY_IMAGE,\n",
@@ -4436,7 +4533,7 @@
},
"outputs": [],
"source": [
"MODEL_DIR = \"{}/{}\".format(BUCKET_NAME, TIMESTAMP)\n",
"MODEL_DIR = \"{}/{}\".format(BUCKET_URI, TIMESTAMP)\n",
"DATASET_DIR = \"gs://cloud-samples-data/ai-platform/iris\"\n",
"\n",
"ROUNDS = 20\n",
@@ -5233,7 +5330,7 @@
"! rm -f custom.tar custom.tar.gz\n",
"! tar cvf custom.tar custom\n",
"! gzip custom.tar\n",
"! gsutil cp custom.tar.gz $BUCKET_NAME/trainer_cifar10.tar.gz"
"! gsutil cp custom.tar.gz $BUCKET_URI/trainer_cifar10.tar.gz"
]
},
{
@@ -5273,7 +5370,7 @@
"\n",
"job = aip.CustomPythonPackageTrainingJob(\n",
" display_name=DISPLAY_NAME,\n",
" python_package_gcs_uri=f\"{BUCKET_NAME}/trainer_cifar10.tar.gz\",\n",
" python_package_gcs_uri=f\"{BUCKET_URI}/trainer_cifar10.tar.gz\",\n",
" python_module_name=\"trainer.task\",\n",
" container_uri=TRAIN_IMAGE,\n",
" model_serving_container_image_uri=DEPLOY_IMAGE,\n",
@@ -5305,7 +5402,7 @@
},
"outputs": [],
"source": [
"MODEL_DIR = \"{}/{}\".format(BUCKET_NAME, TIMESTAMP)\n",
"MODEL_DIR = \"{}/{}\".format(BUCKET_URI, TIMESTAMP)\n",
"\n",
"DIRECT = False\n",
"if DIRECT:\n",
@@ -5836,17 +5933,7 @@
"To clean up all Google Cloud resources used in this project, you can [delete the Google Cloud\n",
"project](https://cloud.google.com/resource-manager/docs/creating-managing-projects#shutting_down_projects) you used for the tutorial.\n",
"\n",
"Otherwise, you can delete the individual resources you created in this tutorial:\n",
"\n",
"- Dataset\n",
"- Pipeline\n",
"- Model\n",
"- Endpoint\n",
"- AutoML Training Job\n",
"- Batch Job\n",
"- Custom Job\n",
"- Hyperparameter Tuning Job\n",
"- Cloud Storage Bucket"
"Otherwise, you can delete the individual resources you created in this tutorial."
]
},
{
@@ -5857,61 +5944,10 @@
},
"outputs": [],
"source": [
"delete_all = True\n",
"delete_bucket = False\n",
"\n",
"if delete_all:\n",
" # Delete the dataset using the Vertex dataset object\n",
" try:\n",
" if \"dataset\" in globals():\n",
" dataset.delete()\n",
" except Exception as e:\n",
" print(e)\n",
"\n",
" # Delete the model using the Vertex model object\n",
" try:\n",
" if \"model\" in globals():\n",
" model.delete()\n",
" except Exception as e:\n",
" print(e)\n",
"\n",
" # Delete the endpoint using the Vertex endpoint object\n",
" try:\n",
" if \"endpoint\" in globals():\n",
" endpoint.undeploy_all()\n",
" endpoint.delete()\n",
" except Exception as e:\n",
" print(e)\n",
"\n",
" # Delete the AutoML or Pipeline training job\n",
" try:\n",
" if \"dag\" in globals():\n",
" dag.delete()\n",
" except Exception as e:\n",
" print(e)\n",
"\n",
" # Delete the custom training job\n",
" try:\n",
" if \"job\" in globals():\n",
" job.delete()\n",
" except Exception as e:\n",
" print(e)\n",
"\n",
" # Delete the batch prediction job using the Vertex batch prediction object\n",
" try:\n",
" if \"batch_predict_job\" in globals():\n",
" batch_predict_job.delete()\n",
" except Exception as e:\n",
" print(e)\n",
"\n",
" # Delete the hyperparameter tuning job using the Vertex hyperparameter tuning object\n",
" try:\n",
" if \"hpt_job\" in globals():\n",
" hpt_job.delete()\n",
" except Exception as e:\n",
" print(e)\n",
"\n",
" if \"BUCKET_NAME\" in globals():\n",
" ! gsutil rm -r $BUCKET_NAME"
"if delete_bucket or os.getenv(\"IS_TESTING\"):\n",
" ! gsutil rm -r $BUCKET_URI"
]
}
],
Binary file not shown.

Before

Width:  |  Height:  |  Size: 78 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 84 KiB

+45 -1
View File
@@ -2,11 +2,23 @@
## Purpose
Configure compute and networking requirements for containerized serving binaries for a production load.
## Recommendations
The fifth stage in MLOps is deployment to production of the blessed model, which will replace the previous blessed model in production. This stage may be done entirely by MLOps. We recommend:
<img src='stage5.png'>
- Deploy the blessed model from the Vertex Model Registry.
- Use the Google Container Registry for the deployment container.
- Attach, if any, serving function from the Vertex Model Registry to the deployed model.
- Use Vertex Pipelines for the deployment.
- For cloud models, deploy within the Google Cloud infrastructure.
- Use Vertex Prediction traffic split for production rollout.
- Use Vertex Prediction to set your criteria for scaling and load balancing.
<img src='stage5v3.png'>
## Notebooks
@@ -45,3 +57,35 @@ The steps performed include:
- 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.
- Deploy `Model` resource for no-scaling (single node).
- Deploy `Model` resource for manual scaling.
- Deploy `Model` resource for auto-scaling.
- Fine-tune scaling thresholds for CPU utilization.
- Fine-tune scaling thresholds for GPU utilization.
- Deploy mix of CPU and GPU model instances with auto-scaling to an `Endpoint` resource.
```
File diff suppressed because it is too large Load Diff
@@ -32,16 +32,22 @@
"# E2E ML on GCP: MLOps stage 5 : Get started with Vertex AI Endpoints\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/stage5/get_started_with_vertex_endpoints.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/stage5/get_started_with_vertex_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",
" </td>\n",
" <td>\n",
" <a href=\"https://console.cloud.google.com/ai/platform/notebooks/deploy-notebook?download_url=https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage6/get_started_with_vertex_endpoints.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_vertex_endpoints.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",
" </td> \n",
"</table>\n",
"<br/><br/><br/>"
]
@@ -144,15 +150,20 @@
"source": [
"import os\n",
"\n",
"# Google Cloud Notebook\n",
"if os.path.exists(\"/opt/deeplearning/metadata/env_version\"):\n",
" USER_FLAG = \"--user\"\n",
"else:\n",
" USER_FLAG = \"\"\n",
"# The Vertex AI Workbench Notebook product has specific requirements\n",
"IS_WORKBENCH_NOTEBOOK = os.getenv(\"DL_ANACONDA_HOME\")\n",
"IS_USER_MANAGED_WORKBENCH_NOTEBOOK = os.path.exists(\n",
" \"/opt/deeplearning/metadata/env_version\"\n",
")\n",
"\n",
"! pip3 install --upgrade google-cloud-aiplatform $USER_FLAG\n",
"! pip3 install --upgrade google-cloud-pipeline-components $USER_FLAG\n",
"! pip3 install tensorflow-hub $USER_FLAG"
"# Vertex AI Notebook requires dependencies to be installed with '--user'\n",
"USER_FLAG = \"\"\n",
"if IS_WORKBENCH_NOTEBOOK:\n",
" USER_FLAG = \"--user\"\n",
"\n",
"! pip3 install --upgrade google-cloud-aiplatform $USER_FLAG -q\n",
"! pip3 install --upgrade google-cloud-pipeline-components $USER_FLAG -q\n",
"! pip3 install tensorflow-hub $USER_FLAG -q"
]
},
{
@@ -205,7 +216,7 @@
"\n",
"2. [Make sure that billing is enabled for your project.](https://cloud.google.com/billing/docs/how-to/modify-project)\n",
"\n",
"3. [Enable the following APIs: Vertex AI APIs, Compute Engine APIs, and Cloud Storage.](https://console.cloud.google.com/flows/enableapi?apiid=ml.googleapis.com,compute_component,storage-component.googleapis.com)\n",
"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",
"\n",
@@ -329,7 +340,7 @@
"source": [
"### Authenticate your Google Cloud account\n",
"\n",
"**If you are using Google Cloud Notebooks**, your environment is already authenticated. Skip this step.\n",
"**If you are using Vertex AI Workbench Notebooks**, your environment is already authenticated. 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",
@@ -364,9 +375,13 @@
"import os\n",
"import sys\n",
"\n",
"# If on Google Cloud Notebook, then don't execute this code\n",
"if not os.path.exists(\"/opt/deeplearning/metadata/env_version\"):\n",
"# If on Vertex AI Workbench, then don't execute this code\n",
"IS_COLAB = False\n",
"if not os.path.exists(\"/opt/deeplearning/metadata/env_version\") and not os.getenv(\n",
" \"DL_ANACONDA_HOME\"\n",
"):\n",
" if \"google.colab\" in sys.modules:\n",
" IS_COLAB = True\n",
" from google.colab import auth as google_auth\n",
"\n",
" google_auth.authenticate_user()\n",
@@ -1695,7 +1710,7 @@
},
"outputs": [],
"source": [
"delete_bucket = True\n",
"delete_bucket = False\n",
"delete_model = True\n",
"\n",
"if delete_model:\n",
@@ -32,16 +32,22 @@
"# E2E ML on GCP: MLOps stage 5 : Get started with Vertex AI Private Endpoints\n",
"<table align=\"left\">\n",
" <td>\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",
" <a href=\"https://colab.research.google.com/github/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/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/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",
" </td>\n",
" <td>\n",
" <a href=\"https://console.cloud.google.com/ai/platform/notebooks/deploy-notebook?download_url=https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage6/get_started_with_vertex_private_endpoints.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_vertex_private_endpoints.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",
" </td> \n",
"</table>\n",
"<br/><br/><br/>"
]
@@ -148,16 +154,35 @@
"source": [
"import os\n",
"\n",
"# Google Cloud Notebook\n",
"if os.path.exists(\"/opt/deeplearning/metadata/env_version\"):\n",
" USER_FLAG = \"--user\"\n",
"else:\n",
" USER_FLAG = \"\"\n",
"# The Vertex AI Workbench Notebook product has specific requirements\n",
"IS_WORKBENCH_NOTEBOOK = os.getenv(\"DL_ANACONDA_HOME\")\n",
"IS_USER_MANAGED_WORKBENCH_NOTEBOOK = os.path.exists(\n",
" \"/opt/deeplearning/metadata/env_version\"\n",
")\n",
"\n",
"! pip3 install --upgrade google-cloud-aiplatform $USER_FLAG\n",
"! pip3 install --upgrade google-cloud-pipeline-components $USER_FLAG\n",
"! pip3 install tensorflow-hub $USER_FLAG\n",
"! pip3 install --upgrade tensorflow $USER_FLAG"
"# Vertex AI Notebook requires dependencies to be installed with '--user'\n",
"USER_FLAG = \"\"\n",
"if IS_WORKBENCH_NOTEBOOK:\n",
" USER_FLAG = \"--user\"\n",
"\n",
"! pip3 install --upgrade google-cloud-aiplatform $USER_FLAG -q\n",
"! pip3 install --upgrade google-cloud-pipeline-components $USER_FLAG -q\n",
"! pip3 install tensorflow-hub $USER_FLAG -q\n",
"! pip3 install --upgrade tensorflow $USER_FLAG -q"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "38379eb00a31"
},
"outputs": [],
"source": [
"# Temporary, until feature pushed to Pypi\n",
"! pip3 uninstall google-cloud-aiplatform -y\n",
"\n",
"! pip install --user git+https://github.com/googleapis/python-aiplatform.git@private-ep"
]
},
{
@@ -210,7 +235,7 @@
"\n",
"2. [Make sure that billing is enabled for your project.](https://cloud.google.com/billing/docs/how-to/modify-project)\n",
"\n",
"3. [Enable the following APIs: Vertex AI APIs, Compute Engine APIs, and Cloud Storage.](https://console.cloud.google.com/flows/enableapi?apiid=ml.googleapis.com,compute_component,storage-component.googleapis.com)\n",
"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. [Enable the Service Networking API](https://console.cloud.google.com/flows/enableapi?apiid=servicenetworking.googleapis.com).\n",
"\n",
@@ -338,7 +363,7 @@
"source": [
"### Authenticate your Google Cloud account\n",
"\n",
"**If you are using Google Cloud Notebooks**, your environment is already authenticated. Skip this step.\n",
"**If you are using Vertex AI Workbench Notebooks**, your environment is already authenticated. 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",
@@ -373,9 +398,13 @@
"import os\n",
"import sys\n",
"\n",
"# If on Google Cloud Notebook, then don't execute this code\n",
"if not os.path.exists(\"/opt/deeplearning/metadata/env_version\"):\n",
"# If on Vertex AI Workbench, then don't execute this code\n",
"IS_COLAB = False\n",
"if not os.path.exists(\"/opt/deeplearning/metadata/env_version\") and not os.getenv(\n",
" \"DL_ANACONDA_HOME\"\n",
"):\n",
" if \"google.colab\" in sys.modules:\n",
" IS_COLAB = True\n",
" from google.colab import auth as google_auth\n",
"\n",
" google_auth.authenticate_user()\n",
@@ -973,43 +1002,6 @@
"full_network_name = f\"projects/{project_number}/global/networks/{NETWORK}\""
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "16ebc9d67356"
},
"source": [
"## Set up clients\n",
"\n",
"The Vertex AI (GAPIC) client library works as a client/server model. On your side (the Python script) you will create a client that sends requests and receives responses from the Vertex AI server."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "95f474f485ad"
},
"outputs": [],
"source": [
"# API service endpoint\n",
"API_ENDPOINT = \"{}-aiplatform.googleapis.com\".format(REGION)\n",
"# Vertex location root path for your dataset, model and endpoint resources\n",
"PARENT = \"projects/\" + PROJECT_ID + \"/locations/\" + REGION\n",
"\n",
"# client options same for all services\n",
"client_options = {\"api_endpoint\": API_ENDPOINT}\n",
"\n",
"\n",
"def create_endpoint_client():\n",
" client = aip.gapic.EndpointServiceClient(client_options=client_options)\n",
" return client\n",
"\n",
"\n",
"clients = {}\n",
"clients[\"endpoint\"] = create_endpoint_client()"
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -1018,7 +1010,7 @@
"source": [
"## Creating an `Endpoint` resource\n",
"\n",
"You create an `Endpoint` resource using the `EndpointServiceClient.create_endpoint()` method. \n",
"You create an `Endpoint` resource using the `PrivateEndpoint.create()` method. \n",
"\n",
"In this example, the following parameters are specified:\n",
"\n",
@@ -1032,39 +1024,13 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "953f25de3751"
"id": "bb1fe4502e92"
},
"outputs": [],
"source": [
"endpoint_params = {\"display_name\": \"private_\" + TIMESTAMP, \"network\": full_network_name}\n",
"response = clients[\"endpoint\"].create_endpoint(parent=PARENT, endpoint=endpoint_params)\n",
"\n",
"endpoint_id = response.result().name\n",
"print(endpoint_id)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "4680dd783abd"
},
"source": [
"### Get the SDK `Endpoint` resource object\n",
"\n",
"Next, use the full resource ID of the `Endpoint` to get the SDK `Endpoint` resource object."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "0ea443f9593b"
},
"outputs": [],
"source": [
"endpoint = aip.Endpoint(endpoint_id)\n",
"\n",
"print(endpoint)"
"endpoint = aip.PrivateEndpoint.create(\n",
" display_name=\"private_\" + TIMESTAMP, network=full_network_name\n",
")"
]
},
{
@@ -1158,7 +1124,7 @@
},
"outputs": [],
"source": [
"endpoint.gca_resource.deployed_models[0]"
"print(endpoint.gca_resource.deployed_models[0])"
]
},
{
@@ -1254,6 +1220,8 @@
},
"outputs": [],
"source": [
"endpoint_id = endpoint.resource_name\n",
"\n",
"ENDPOINT_URL = ! gcloud beta ai endpoints describe {endpoint_id} \\\n",
" --region={REGION} \\\n",
" --format=\"value(deployedModels.privateEndpoints.predictHttpUri)\"\n",
@@ -1268,9 +1236,9 @@
"id": "27605b5f0c3a"
},
"source": [
"### Make the prediction request usng curl\n",
"### Make the prediction request using curl\n",
"\n",
"Finally, use `curl` to make the prediction request to the private URI."
"Use `curl` to make the prediction request to the private URI."
]
},
{
@@ -1284,7 +1252,34 @@
"output = ! curl -X POST -d@instances.json $private_url\n",
"\n",
"predictions = output[5]\n",
"print(predictions)"
"print(predictions)\n",
"\n",
"! rm test.jpg instances.json"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "ef4b9c97ab71"
},
"source": [
"### Make the prediction request using SDK\n",
"\n",
"Finally, use the `Vertex AI SDK` to make a prediction request."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "e75c3ddd44e6"
},
"outputs": [],
"source": [
"instances = [{serving_input: {\"b64\": b64str}}]\n",
"\n",
"prediction = endpoint.predict(instances=instances)\n",
"print(prediction)"
]
},
{
@@ -1382,7 +1377,7 @@
},
"outputs": [],
"source": [
"delete_bucket = True\n",
"delete_bucket = False\n",
"delete_model = True\n",
"\n",
"if delete_model:\n",

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