fix, chore, refactor(egen): hardcodes scikit-learn version to 1.2, changes python version from 3.9 to 3.10, adds numpy==1.26.4 installation, adds code to undeploy model from endpoints (#3228)

* fix, chore, refactor(egen): hardcodes scikit-learn version to 1.2, changes python version from 3.9 to 3.10, adds numpy==1.26.4 installation, adds code to undeploy model from endpoints, rusage of future tense

* wording changes

* markdown wording changes as per PR comments
This commit is contained in:
sumanvita
2024-07-10 21:51:01 +00:00
committed by GitHub
parent f22fee6f84
commit 0583f152ac
@@ -32,24 +32,26 @@
"# Vertex AI: Track artifacts and metrics across Vertex AI Pipelines runs using Vertex ML Metadata\n",
"\n",
"<table align=\"left\">\n",
"\n",
" <td>\n",
" <td style=\"text-align: center\">\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/ml_metadata/vertex-pipelines-ml-metadata.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=\"Google Colaboratory logo\"><br> Open in Colab\n",
" </a>\n",
" </td>\n",
" <td>\n",
" <td style=\"text-align: center\">\n",
" <a href=\"https://console.cloud.google.com/vertex-ai/colab/import/https:%2F%2Fraw.githubusercontent.com%2FGoogleCloudPlatform%2Fvertex-ai-samples%2Fmain%2Fnotebooks%2Fofficial%2Fml_metadata%2Fvertex-pipelines-ml-metadata.ipynb\">\n",
" <img width=\"32px\" src=\"https://cloud.google.com/ml-engine/images/colab-enterprise-logo-32px.png\" alt=\"Google Cloud Colab Enterprise logo\"><br> Open in Colab Enterprise\n",
" </a>\n",
" </td> \n",
" <td style=\"text-align: center\">\n",
" <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://raw.githubusercontent.com/GoogleCloudPlatform/vertex-ai-samples/main/notebooks/official/ml_metadata/vertex-pipelines-ml-metadata.ipynb\">\n",
" <img src=\"https://lh3.googleusercontent.com/UiNooY4LUgW_oTvpsNhPpQzsstV5W8F7rYgxgGBD85cWJoLmrOzhVs_ksK_vgx40SHs7jCqkTkCk=e14-rj-sc0xffffff-h130-w32\" alt=\"Vertex AI logo\"><br> Open in Workbench\n",
" </a>\n",
" </td>\n",
" <td style=\"text-align: center\">\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/ml_metadata/vertex-pipelines-ml-metadata.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/github-logo-32px.png\" alt=\"GitHub logo\"><br> View on GitHub\n",
" </a>\n",
" </td>\n",
" <td>\n",
"<a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://raw.githubusercontent.com/GoogleCloudPlatform/vertex-ai-samples/main/notebooks/official/ml_metadata/vertex-pipelines-ml-metadata.ipynb\" target='_blank'>\n",
" <img src=\"https://lh3.googleusercontent.com/UiNooY4LUgW_oTvpsNhPpQzsstV5W8F7rYgxgGBD85cWJoLmrOzhVs_ksK_vgx40SHs7jCqkTkCk=e14-rj-sc0xffffff-h130-w32\" alt=\"Vertex AI logo\">\n",
" Open in Vertex AI Workbench\n",
" </a>\n",
" </td>\n",
"</table>"
]
},
@@ -61,7 +63,7 @@
"source": [
"## Overview\n",
"\n",
"This notebook demonstrates how to track metrics and artifacts across Vertex AI Pipelines runs, and analyze this metadata using the Vertex AI SDK for Pyrhon. If you'd prefer to follow a step-by-step tutorial, check out the [codelab version](https://codelabs.developers.google.com/vertex-mlmd-pipelines#0) of this notebook.\n",
"This notebook demonstrates how to track metrics and artifacts across Vertex AI Pipeline runs, and analyze this metadata using the Vertex AI Python SDK. If you'd prefer to follow a step-by-step tutorial, check out the [codelab version](https://codelabs.developers.google.com/vertex-mlmd-pipelines#0) of this notebook.\n",
"\n",
"Learn more about [Vertex ML Metadata](https://cloud.google.com/vertex-ai/docs/ml-metadata) and [Vertex AI Pipelines](https://cloud.google.com/vertex-ai/docs/pipelines/introduction)."
]
@@ -86,7 +88,7 @@
"* Use the Kubeflow Pipelines SDK to build an ML pipeline that runs on Vertex AI.\n",
"* The pipeline creates a dataset, trains a scikit-learn model, and deploys the model to an endpoint.\n",
"* Write custom pipeline components that generate artifacts and metadata.\n",
"* Compare Vertex AI Pipelines runs, both in the Google Cloud console and programmatically.\n",
"* Compare Vertex AI Pipeline runs, both in the Google Cloud console and programmatically.\n",
"* Trace the lineage for pipeline-generated artifacts.\n",
"* Query your pipeline run metadata."
]
@@ -99,7 +101,7 @@
"source": [
"### Dataset\n",
"\n",
"In this notebook, you'll train a model using scikit-learn to classify bean types using the [Dry Beans Dataset](https://archive.ics.uci.edu/ml/datasets/Dry+Bean+Dataset) from UCI Machine Learning. This is a tabular dataset that includes measurements and characteristics of seven different types of beans taken from images."
"This notebook uses scikit-learn to train a model and classify bean types using the [Dry Beans Dataset](https://archive.ics.uci.edu/ml/datasets/Dry+Bean+Dataset) from UCI Machine Learning. This is a tabular dataset that includes measurements and characteristics of seven different types of beans taken from images."
]
},
{
@@ -127,12 +129,19 @@
{
"cell_type": "markdown",
"metadata": {
"id": "i7EUnXsZhAGF"
"id": "61RBz8LLbxCR"
},
"source": [
"### Install additional packages\n",
"\n",
"Run the following commands to install the Vertex AI SDK for Python and packages used in this notebook."
"## Get started"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "No17Cw5hgx12"
},
"source": [
"### Install Vertex AI SDK for Python and other required packages\n"
]
},
{
@@ -150,137 +159,97 @@
{
"cell_type": "markdown",
"metadata": {
"id": "restart"
"id": "R5Xep4W9lq-Z"
},
"source": [
"### Colab only: Uncomment the following cell to restart the kernel"
"### Restart runtime (Colab only)\n",
"\n",
"To use the newly installed packages, you must restart the runtime on Google Colab."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "D-ZBOjErv5mM"
"id": "XRvKdaPDTznN"
},
"outputs": [],
"source": [
"# Automatically restart kernel after installs so that your environment can access the new packages\n",
"# import IPython\n",
"import sys\n",
"\n",
"# app = IPython.Application.instance()\n",
"# app.kernel.do_shutdown(True)"
"if \"google.colab\" in sys.modules:\n",
"\n",
" import IPython\n",
"\n",
" app = IPython.Application.instance()\n",
" app.kernel.do_shutdown(True)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "yfEglUHQk9S3"
"id": "SbmM4z7FOBpM"
},
"source": [
"## Before you begin\n",
"<div class=\"alert alert-block alert-warning\">\n",
"<b>⚠️ The kernel is going to restart. Wait until it's finished before continuing to the next step. ⚠️</b>\n",
"</div>\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dmWOrTJ3gx13"
},
"source": [
"### Authenticate your notebook environment (Colab only)\n",
"\n",
"### Set your project ID\n",
"\n",
"**If you don't know your project ID**, try the following:\n",
"* Run `gcloud config list`.\n",
"* Run `gcloud projects list`.\n",
"* See the support page: [Locate the project ID](https://support.google.com/googleapi/answer/7014113)"
"Authenticate your environment on Google Colab.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "set_project_id"
"id": "NyKGtVQjgx13"
},
"outputs": [],
"source": [
"import sys\n",
"\n",
"if \"google.colab\" in sys.modules:\n",
"\n",
" from google.colab import auth\n",
"\n",
" auth.authenticate_user()"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "DF4l8DTdWgPY"
},
"source": [
"### Set Google Cloud project information\n",
"\n",
"To get started using Vertex AI, you must have an existing Google Cloud project. Learn more about [setting up a project and a development environment](https://cloud.google.com/vertex-ai/docs/start/cloud-environment)."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "Nqwi-5ufWp_B"
},
"outputs": [],
"source": [
"PROJECT_ID = \"[your-project-id]\" # @param {type:\"string\"}\n",
"LOCATION = \"us-central1\" # @param {type:\"string\"}\n",
"\n",
"# Set the project id\n",
"! gcloud config set project {PROJECT_ID}"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "region"
},
"source": [
"#### Region\n",
"\n",
"You can also change the `REGION` variable used by Vertex AI. Learn more about [Vertex AI regions](https://cloud.google.com/vertex-ai/docs/general/locations)."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "region"
},
"outputs": [],
"source": [
"REGION = \"us-central1\" # @param {type: \"string\"}"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "gcp_authenticate"
},
"source": [
"### Authenticate your Google Cloud account\n",
"\n",
"Depending on your Jupyter environment, you may have to manually authenticate. Follow the relevant instructions below.\n",
"\n",
"**1. Vertex AI Workbench**\n",
"* Do nothing as you are already authenticated.\n",
"\n",
"**2. Local JupyterLab instance, uncomment and run:**"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "ce6043da7b33"
},
"outputs": [],
"source": [
"# ! gcloud auth login"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "0367eac06a10"
},
"source": [
"**3. Colab, uncomment and run:**"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "21ad4dbb4a61"
},
"outputs": [],
"source": [
"# from google.colab import auth\n",
"# auth.authenticate_user()"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "c13224697bfb"
},
"source": [
"**4. Service account or other**\n",
"* See how to grant Cloud Storage permissions to your service account at https://cloud.google.com/storage/docs/gsutil/commands/iam#ch-examples."
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -344,7 +313,7 @@
},
"outputs": [],
"source": [
"! gsutil mb -l $REGION $BUCKET_URI"
"! gsutil mb -l {LOCATION} -p {PROJECT_ID} {BUCKET_URI}"
]
},
{
@@ -491,7 +460,7 @@
"id": "2937d462a96a"
},
"source": [
"Initialize the Vertex AI SDK"
"### Initialize Vertex AI SDK for Python"
]
},
{
@@ -502,7 +471,7 @@
},
"outputs": [],
"source": [
"aiplatform.init(project=PROJECT_ID, location=REGION)"
"aiplatform.init(project=PROJECT_ID, location=LOCATION)"
]
},
{
@@ -523,7 +492,7 @@
},
"source": [
"### Pipeline Run\n",
"The term “run” refers to a single execution of your pipeline in Vertex AI Pipelines. Each run generates artifacts, metrics, and associated metadata."
"The term “run” refers to a single execution of your pipeline in Vertex AI Pipelines, during which artifacts, metrics, and associated metadata are generated."
]
},
{
@@ -534,7 +503,7 @@
"source": [
"### Artifact\n",
"\n",
"An artifact is a resource generated by your pipeline. Artifacts could datasets, models, endpoints, or custom resources defined in your pipeline."
"An artifact is a resource generated by your pipeline. Artifacts can be datasets, models, endpoints, or custom resources defined in your pipeline."
]
},
{
@@ -545,7 +514,7 @@
"source": [
"### Metric\n",
"\n",
"A metric is a way to measure the performance of your pipeline runs and artifacts. For example, a metric could be the accuracy of a classification model artifact created in your pipeline, or the size of the dataset used to train your model."
"A metric is a way to measure the performance of your pipeline runs and artifacts. For example, a metric can be the accuracy of a classification model artifact created in your pipeline, or the size of the dataset used to train your model."
]
},
{
@@ -556,7 +525,7 @@
"source": [
"### Metadata\n",
"\n",
"Metadata describes the artifacts and metrics generated by your pipeline runs. Metadata on a model, for example, could include the URL of the model artifacts, its name, and the time it was created."
"Metadata describes the artifacts and metrics generated by your pipeline runs. Metadata on a model, for example, includes the URL of the model artifacts, its name, and the time it was created."
]
},
{
@@ -567,7 +536,7 @@
"source": [
"## Creating a 3-step pipeline with custom components\n",
"\n",
"The focus of this lab is on understanding metadata from pipeline runs. In order to do that, you'll need a pipeline to run on Vertex AI Pipelines, which is where you’ll start. Here you’ll define a 3-step pipeline with the following custom components:\n",
"The focus of this lab is on understanding metadata from pipeline runs. To do that, you need a pipeline to run on Vertex AI Pipelines, which is where you start. Here, you define a 3-step pipeline with the following custom components:\n",
"\n",
"* `get_dataframe`: Retrieve data from a BigQuery table and convert it into a pandas DataFrame.\n",
"* `train_sklearn_model`: Use the pandas DataFrame to train and export a scikit-learn model, along with some metrics.\n",
@@ -604,14 +573,16 @@
"outputs": [],
"source": [
"@component(\n",
" packages_to_install=[\"google-cloud-bigquery\", \"pandas\", \"pyarrow\"],\n",
" base_image=\"python:3.9\",\n",
" packages_to_install=[\"google-cloud-bigquery[pandas]\", \"pyarrow\"],\n",
" base_image=\"python:3.10\",\n",
" output_component_file=\"create_dataset.yaml\",\n",
")\n",
"def get_dataframe(bq_table: str, output_data_path: OutputPath(\"Dataset\")):\n",
"def get_dataframe(\n",
" project_id: str, bq_table: str, output_data_path: OutputPath(\"Dataset\")\n",
"):\n",
" from google.cloud import bigquery\n",
"\n",
" bqclient = bigquery.Client(project=PROJECT_ID)\n",
" bqclient = bigquery.Client(project=project_id)\n",
" table = bigquery.TableReference.from_string(bq_table)\n",
" rows = bqclient.list_rows(table)\n",
" dataframe = rows.to_dataframe(\n",
@@ -644,8 +615,8 @@
"outputs": [],
"source": [
"@component(\n",
" packages_to_install=[\"scikit-learn\", \"pandas\", \"joblib\"],\n",
" base_image=\"python:3.9\",\n",
" packages_to_install=[\"scikit-learn==1.2\", \"pandas\", \"joblib\", \"numpy==1.26.4\"],\n",
" base_image=\"python:3.10\",\n",
" output_component_file=\"beans_model_component.yaml\",\n",
")\n",
"def sklearn_train(\n",
@@ -691,7 +662,7 @@
"source": [
"@component(\n",
" packages_to_install=[\"google-cloud-aiplatform\"],\n",
" base_image=\"python:3.9\",\n",
" base_image=\"python:3.10\",\n",
" output_component_file=\"beans_deploy_component.yaml\",\n",
")\n",
"def deploy_model(\n",
@@ -708,7 +679,7 @@
" deployed_model = aiplatform.Model.upload(\n",
" display_name=\"beans-model-pipeline\",\n",
" artifact_uri=model.uri.replace(\"model\", \"\"),\n",
" serving_container_image_uri=\"us-docker.pkg.dev/vertex-ai/prediction/sklearn-cpu.0-24:latest\",\n",
" serving_container_image_uri=\"us-docker.pkg.dev/vertex-ai/prediction/sklearn-cpu.1-2:latest\",\n",
" )\n",
" endpoint = deployed_model.deploy(machine_type=\"n1-standard-4\")\n",
"\n",
@@ -741,12 +712,12 @@
" name=\"mlmd-pipeline\",\n",
")\n",
"def pipeline(\n",
" bq_table: str = \"\",\n",
" output_data_path: str = \"data.csv\",\n",
" project: str = PROJECT_ID,\n",
" region: str = REGION,\n",
" bq_table: str,\n",
" output_data_path: str,\n",
" project: str,\n",
" region: str,\n",
"):\n",
" dataset_task = get_dataframe(bq_table)\n",
" dataset_task = get_dataframe(project, bq_table)\n",
"\n",
" model_task = sklearn_train(dataset_task.output)\n",
"\n",
@@ -759,7 +730,7 @@
"id": "910541af051c"
},
"source": [
"The following generates a JSON file that you'll use to run the pipeline:"
"The following generates a JSON file that is then used to run the pipeline:"
]
},
{
@@ -779,9 +750,22 @@
"id": "u-iTnzt3B6Z_"
},
"source": [
"### Start two pipeline runs\n",
"### Initiate pipeline runs\n",
"\n",
"Next you'll kick ofg **two** runs of our pipeline. First, define a timestamp to use for our pipeline job IDs:"
"First, define a timestamp to use as your pipeline job IDs.\n",
"\n",
"Then for each run, create an instance of `PipelineJob` from the `pipeline_jobs` module.\n",
" For each instance provide the following details:\n",
"\n",
"* `display_name` : Human-readable name for the pipeline job.\n",
"* `template_path` : This specifies the path to the pipeline template file in JSON format, which contains the pipeline's configuration and structure created in the previous steps.\n",
"* `job_id` : This sets a unique identifier for the job.\n",
"* `parameter_values` : This dictionary contains key-value pairs for the parameters required by the pipeline which are metioned during pipeline definition.\n",
" * `bq_table` : Specifies the BigQuery table to use.\n",
" * `output_data_path` : Defines the path for the output data file.\n",
" * `project` : Specifies the Google Cloud project ID.\n",
" * `region` : Defines the region where the pipeline will run.\n",
"* enable_caching : When set to `True`, caching is enabled for the pipeline run. This lets the system reuse previous results, if the same job has been executed before with identical parameters, thereby saving time and resources"
]
},
{
@@ -803,7 +787,7 @@
"id": "3d380ed72490"
},
"source": [
"The pipeline takes one parameter when you run it: the `bq_table` we want to use for training data you’ll use for training data. This pipeline run uses a smaller version of the beans dataset:"
"Create a pipeline run using the smaller version beans dataset."
]
},
{
@@ -818,7 +802,12 @@
" display_name=\"mlmd-pipeline\",\n",
" template_path=\"mlmd_pipeline.json\",\n",
" job_id=\"mlmd-pipeline-small-{}\".format(TIMESTAMP),\n",
" parameter_values={\"bq_table\": \"sara-vertex-demos.beans_demo.small_dataset\"},\n",
" parameter_values={\n",
" \"bq_table\": \"sara-vertex-demos.beans_demo.small_dataset\",\n",
" \"output_data_path\": \"data.csv\",\n",
" \"project\": PROJECT_ID,\n",
" \"region\": REGION,\n",
" },\n",
" enable_caching=True,\n",
")"
]
@@ -844,7 +833,12 @@
" display_name=\"mlmd-pipeline\",\n",
" template_path=\"mlmd_pipeline.json\",\n",
" job_id=\"mlmd-pipeline-large-{}\".format(TIMESTAMP),\n",
" parameter_values={\"bq_table\": \"sara-vertex-demos.beans_demo.large_dataset\"},\n",
" parameter_values={\n",
" \"bq_table\": \"sara-vertex-demos.beans_demo.large_dataset\",\n",
" \"output_data_path\": \"data.csv\",\n",
" \"project\": PROJECT_ID,\n",
" \"region\": REGION,\n",
" },\n",
" enable_caching=True,\n",
")"
]
@@ -895,7 +889,7 @@
"id": "cc15017be48e"
},
"source": [
"After running this cell, you'll see a link to view each pipeline in the Google Cloud console. Open that link to see more details on your pipeline.\n",
"After running this cell, there is a link to view each pipeline in the Google Cloud console. Open that link to get more details about your pipeline.\n",
"\n",
"**These pipeline runs will take 10-15 minutes to complete.**"
]
@@ -915,9 +909,9 @@
"id": "A1PqKxlpOZa2"
},
"source": [
"Now that you have two pipeline completed pipeline runs, you're ready to take a closer look at pipeline metrics using the Vertex AI SDK for Python.\n",
"Once both the pipelines run successfully, you're ready to take a closer look at pipeline metrics using the Vertex AI SDK for Python.\n",
"\n",
"**For guidance on inspecting pipeline artifacts and metadata in the Google Cloud console, see [this codelab](https://codelabs.developers.google.com/vertex-mlmd-pipelines#5).**"
"For guidance on inspecting pipeline artifacts and metadata in the Google Cloud console, check out this codelab: [Understanding pipeline artifacts and lineage](https://codelabs.developers.google.com/vertex-mlmd-pipelines#5)\n"
]
},
{
@@ -926,7 +920,8 @@
"id": "jbRf1WoH_vbY"
},
"source": [
"You can use the `aiplatform.get_pipeline_df()` method to access run metadata. Here, you'll get metadata for the last two runs of the same pipeline and load it into a Pandas DataFrame. The `mlmd-pipeline` parameter here refers to the name you gave your pipeline in the pipeline definition:"
"Use `aiplatform.get_pipeline_df()` method to retrieve the metadata for the last two runs of the pipeline. Then, load it into a Pandas DataFrame. \n",
"The `pipeline` parameter specifies the name of your pipeline as defined in the pipeline configuration, which in this case is *mlmd-pipeline*."
]
},
{
@@ -947,7 +942,7 @@
"id": "d23e2cb66265"
},
"source": [
"You’ve only executed the pipeline twice here, but you can imagine how many metrics you'd have with more executions. Next, create a custom visualization with matplotlib to see the relationship between the model's accuracy and the amount of data used for training. Run the following to generate a graph:"
"You’ve only executed the pipeline twice here, but you can imagine how many metrics you'd have with more executions. Next, create a custom visualization with matplotlib to see the relationship between the model accuracy and the amount of data used for training. Run the following to generate a graph:"
]
},
{
@@ -979,7 +974,7 @@
"id": "4431b5d062f3"
},
"source": [
"In addition to getting a DataFrame of all pipeline metrics, you may want to programmatically query artifacts created in your ML system. From there you can create a custom dashboard or let others in your organizaiton get details on specific artifacts."
"In addition to creating a DataFrame of all pipeline metrics, you can programmatically query artifacts created in your ML system. From there you can create a custom dashboard or let others in your organizaiton get details on specific artifacts."
]
},
{
@@ -990,7 +985,7 @@
"source": [
"### Getting all Model artifacts\n",
"\n",
"To query artifacts in this way, you'll create a `MetadataServiceClient`:"
"To query artifacts in this way, create a `MetadataServiceClient`:"
]
},
{
@@ -1056,7 +1051,7 @@
"id": "F19_5lw0MqXv"
},
"source": [
"Next, get all artifacts created after August 10, 2021 with a `LIVE` state. After you run this request, display the results in a pandas DataFrame. First, execute the request:"
"Next, get all artifacts created after August 10, 2021 that are in `LIVE` state. "
]
},
{
@@ -1122,7 +1117,9 @@
"\n",
"* The pipeline runs you executed deployed endpoints in Vertex AI. Navigate to the [Google Cloud console](https://console.cloud.google.com/vertex-ai/endpoints) to delete those endpoints.\n",
"\n",
"* Delete the [Cloud Storage bucket](https://console.cloud.google.com/storage/browser/) you created."
"* Delete the [Cloud Storage bucket](https://console.cloud.google.com/storage/browser/) you created.\n",
"\n",
"Alternatively, you can execute the below cell to clean up the resources used in this notebook."
]
},
{
@@ -1133,16 +1130,36 @@
},
"outputs": [],
"source": [
"import os\n",
"\n",
"# delete pipelines\n",
"try:\n",
" run1.delete()\n",
" run2.delete()\n",
"except Exception as e:\n",
" print(e)\n",
"\n",
"delete_bucket = False\n",
"if delete_bucket or os.getenv(\"IS_TESTING\"):\n",
"# undeploy model from endpoints\n",
"endpoints = aiplatform.Endpoint.list(\n",
" filter='display_name=\"beans-model-pipeline_endpoint\"'\n",
")\n",
"for endpoint in endpoints:\n",
" deployed_models = endpoint.list_models()\n",
" for deployed_model in deployed_models:\n",
" endpoint.undeploy(deployed_model_id=deployed_model.id)\n",
" # delete endpoint\n",
" endpoint.delete()\n",
"\n",
"# delete model\n",
"model_ids = aiplatform.Model.list(filter='display_name=\"beans-model-pipeline\"')\n",
"for model_id in model_ids:\n",
" model = aiplatform.Model(model_name=model_id.resource_name)\n",
" model.delete()\n",
"\n",
"# delete locally generated files\n",
"! rm -rf beans_deploy_component.yaml beans_model_component.yaml create_dataset.yaml mlmd_pipeline.json\n",
"\n",
"# delete cloud storage bucket\n",
"delete_bucket = False # set True for deletion\n",
"if delete_bucket:\n",
" ! gsutil rm -rf {BUCKET_URI}"
]
}