Skip to content

Commit

Permalink
refactor,chore(egen) : added delete experiment code in cleanup sectio…
Browse files Browse the repository at this point in the history
…n and added required packages in installation section, refactored code according to template guideline
  • Loading branch information
Jayakrishna2801 committed Jul 5, 2024
1 parent 6183a71 commit b1d2cca
Showing 1 changed file with 78 additions and 122 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,28 @@
"# Vertex AI: Track parameters and metrics for locally trained models\n",
"\n",
"<table align=\"left\">\n",
"\n",
" <td>\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/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",
" <td style=\"text-align: center\">\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/pipelines/lightweight_functions_component_io_kfp.ipynb\">\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 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%2Fnotebook_template.ipynb\">\n",
" <img 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>\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/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",
" <td style=\"text-align: center\">\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/pipelines/lightweight_functions_component_io_kfp.ipynb\">\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://github.com/raw/GoogleCloudPlatform/vertex-ai-samples/main/notebooks/official/ml_metadata/sdk-metric-parameter-tracking-for-locally-trained-models.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",
" <td style=\"text-align: center\">\n",
"<a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://github.com/raw/GoogleCloudPlatform/vertex-ai-samples/main/notebooks/official/pipelines/lightweight_functions_component_io_kfp.ipynb\" target='_blank'>\n",
" <img src=\"https://lh3.googleusercontent.com/UiNooY4LUgW_oTvpsNhPpQzsstV5W8F7rYgxgGBD85cWJoLmrOzhVs_ksK_vgx40SHs7jCqkTkCk=e14-rj-sc0xffffff-h130-w32\" alt=\"Vertex AI logo\"><br> Open in Vertex AI Workbench\n",
" </a>\n",
" </td>\n",
"</table>"
" </td>\n",
"</table>\n",
"<br/><br/><br/>"
]
},
{
Expand All @@ -74,12 +77,12 @@
"source": [
"### Objective\n",
"\n",
"In this notebook, you learn how to use `Vertex ML Metadata` to track training parameters and evaluation metrics.\n",
"In this notebook, you learn how to use Vertex ML Metadata to track training parameters and evaluation metrics.\n",
"\n",
"This tutorial uses the following Google Cloud ML services:\n",
"\n",
"- `Vertex ML Metadata`\n",
"- `Vertex AI Experiments`\n",
"- Vertex ML Metadata\n",
"- Vertex AI Experiments\n",
"\n",
"The steps performed include:\n",
"\n",
Expand All @@ -95,7 +98,7 @@
"source": [
"### 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)."
"In this notebook, we 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)."
]
},
{
Expand All @@ -113,11 +116,9 @@
"* 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."
"Learn about [Vertex AI pricing](https://cloud.google.com/vertex-ai/pricing) and \n",
"[Cloud Storage pricing](https://cloud.google.com/storage/pricing), and use the \n",
"[Pricing Calculator](https://cloud.google.com/products/calculator/) to generate a cost estimate based on your projected usage."
]
},
{
Expand All @@ -126,9 +127,8 @@
"id": "i7EUnXsZhAGF"
},
"source": [
"## Installation\n",
"\n",
"Install the packages required for executing this notebook."
"## Get started\n",
"Install Vertex AI SDK for Python and other required packages"
]
},
{
Expand All @@ -140,140 +140,86 @@
"outputs": [],
"source": [
"! pip install --upgrade --quiet google-cloud-aiplatform \\\n",
" tensorflow==2.11"
" tensorflow==2.11 \\\n",
" matplotlib \\\n",
" pandas"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "hhq5zEbGg0XX"
"id": "5eec42e37bcf"
},
"source": [
"### Colab only: Uncomment the following cell to restart the kernel"
"### Restart runtime (Colab only)\n",
"To use the newly installed packages, you must restart the runtime on Google Colab."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "EzrelQZ22IZj"
"id": "dcc98768955f"
},
"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)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "lWEdiXsJg0XY"
},
"source": [
"## Before you begin\n",
"if \"google.colab\" in sys.modules:\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 project list`.\n",
"- See the support page: [Locate the project ID](https://support.google.com/googleapi/answer/7014113)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "oM1iC_MfAts1"
},
"outputs": [],
"source": [
"PROJECT_ID = \"[your-project-id]\" # @param {type:\"string\"}\n",
" import IPython\n",
"\n",
"# Set the project id\n",
"! gcloud config set project $PROJECT_ID"
" app = IPython.Application.instance()\n",
" app.kernel.do_shutdown(True)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "region"
"id": "56e219dbcb9a"
},
"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)"
"### Authenticate your notebook environment (Colab only)\n",
"Authenticate your environment on Google Colab."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "region"
"id": "c97be6a73155"
},
"outputs": [],
"source": [
"REGION = \"us-central1\" # @param {type: \"string\"}"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dr--iN2kAylZ"
},
"source": [
"### Authenticate your Google Cloud account\n",
"Depending on your Jupyter environment, you may have to manually authenticate. Follow the relevant instructions below.\n",
"import sys\n",
"\n",
"**1. Vertex AI Workbench**\n",
"- Do nothing as you are already authenticated.\n",
"if \"google.colab\" in sys.modules:\n",
"\n",
"**2. Local JupyterLab instance, uncomment and run:**"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "457c78b08293"
},
"outputs": [],
"source": [
"# ! gcloud auth login"
" from google.colab import auth\n",
"\n",
" auth.authenticate_user()"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "sBCra4QMA2wR"
"id": "442da99b7efa"
},
"source": [
"**3. Colab, uncomment and run:**"
"### Set Google Cloud project information\n",
"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": "984a0526fb68"
"id": "oM1iC_MfAts1"
},
"outputs": [],
"source": [
"# from google.colab import auth\n",
"# auth.authenticate_user()"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "6679fdd7776b"
},
"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"
"PROJECT_ID = \"vertexai-service-project\" # @param {type:\"string\"}\n",
"LOCATION = \"us-central1\" # @param {type:\"string\"}"
]
},
{
Expand All @@ -282,15 +228,7 @@
"id": "XoEqT2Y4DJmf"
},
"source": [
"### Import libraries and define constants"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "Y9Uo3tifg1kx"
},
"source": [
"### Import libraries and define constants\n",
"Import required libraries."
]
},
Expand Down Expand Up @@ -563,7 +501,7 @@
},
"outputs": [],
"source": [
"aiplatform.init(project=PROJECT_ID, location=REGION, experiment=EXPERIMENT_NAME)"
"aiplatform.init(project=PROJECT_ID, location=LOCATION, experiment=EXPERIMENT_NAME)"
]
},
{
Expand Down Expand Up @@ -594,7 +532,7 @@
"]\n",
"\n",
"for i, params in enumerate(parameters):\n",
" aiplatform.start_run(run=f\"auto-mpg-local-run-{i}\")\n",
" aiplatform.start_run(run=f\"auto-mpg-lcl-run-{i}\")\n",
" aiplatform.log_params(params)\n",
" model, history = train(\n",
" normed_train_data,\n",
Expand Down Expand Up @@ -724,12 +662,30 @@
"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",
"delete the individual resources you created in this tutorial:\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "d02bde73377a"
},
"outputs": [],
"source": [
"from google.cloud import aiplatform\n",
"\n",
"# delete experiment and runs associated with experiment\n",
"experiment_name = (EXPERIMENT_NAME,)\n",
"project = (PROJECT_ID,)\n",
"location = (LOCATION,)\n",
"delete_backing_tensorboard_runs = (True,)\n",
"\n",
"Otherwise, you can delete the individual resources you created in this tutorial:\n",
"experiment = aiplatform.Experiment(\n",
" experiment_name=EXPERIMENT_NAME, project=PROJECT_ID, location=LOCATION\n",
")\n",
"\n",
"- Experiment (Can be deleted manually in the GCP Console UI)"
"experiment.delete(delete_backing_tensorboard_runs=delete_backing_tensorboard_runs)"
]
}
],
Expand Down

0 comments on commit b1d2cca

Please sign in to comment.