From 07ec84687e860f7122da598bca6293f1cb12c5d2 Mon Sep 17 00:00:00 2001 From: Krishna Chaithanya Movva Date: Fri, 11 Aug 2023 02:19:01 +0530 Subject: [PATCH] Reduces the max_steps parameter + Textual content updates and fixes (#2168) * fix: issue 2125 * removes duplicate parameters, reduces max_steps to 100, fixes grammar and updates realted to the writing guidelines * removes f from the string parameter * ran linter test * sets max_steps to 20 and adds lines in the cleanup step to remove the pipeline jobs * ran linter test --------- Co-authored-by: Andrew Ferlitsch --- .../tabnet_on_vertex_pipelines.ipynb | 237 +++++++++--------- 1 file changed, 122 insertions(+), 115 deletions(-) diff --git a/notebooks/official/tabular_workflows/tabnet_on_vertex_pipelines.ipynb b/notebooks/official/tabular_workflows/tabnet_on_vertex_pipelines.ipynb index e28f91138..d0cea0772 100644 --- a/notebooks/official/tabular_workflows/tabnet_on_vertex_pipelines.ipynb +++ b/notebooks/official/tabular_workflows/tabnet_on_vertex_pipelines.ipynb @@ -53,6 +53,17 @@ "


\n" ] }, + { + "cell_type": "markdown", + "metadata": { + "id": "962e636b5cee" + }, + "source": [ + "**_NOTE_**: This notebook has been tested in the following environment:\n", + "\n", + "* Python version = 3.9" + ] + }, { "cell_type": "markdown", "metadata": { @@ -74,7 +85,7 @@ "source": [ "### Objective\n", "\n", - "In this tutorial, you learn how to create two classification models using Vertex AI TabNet Tabular Workflows. Each workflow is a managed instance of [Vertex AI Pipelines](https://cloud.google.com/vertex-ai/docs/pipelines/introduction).\n", + "In this tutorial, you learn how to create classification models on tabular data using two of the Vertex AI TabNet Tabular Workflows. Each workflow is a managed instance of [Vertex AI Pipelines](https://cloud.google.com/vertex-ai/docs/pipelines/introduction).\n", "\n", "This tutorial uses the following Google Cloud ML services and resources:\n", "\n", @@ -98,8 +109,10 @@ "source": [ "### Dataset\n", "\n", - "The dataset you will be using is [Bank Marketing](https://archive.ics.uci.edu/ml/datasets/bank+marketing).\n", - "The data is for direct marketing campaigns (phone calls) of a Portuguese banking institution. The binary classification goal is to predict if a client subscribe a term deposit. For this notebook, you randomly selected 90% of the rows in the original dataset and saved them in a train.csv file hosted on Cloud Storage. To download the file, click [here](https://storage.googleapis.com/cloud-samples-data-us-central1/vertex-ai/tabular-workflows/datasets/bank-marketing/train.csv)." + "The dataset you use in this notebook is the [Bank Marketing](https://archive.ics.uci.edu/ml/datasets/bank+marketing) dataset.\n", + "It consists of data related to direct marketing campaigns (phone calls) of a Portuguese banking institution. The objective of the binary classification task in this notebook is to predict if a client subscribes to a term deposit or not. \n", + "\n", + "For this notebook, a subset of randomly selected rows that makes 90% of the original dataset was saved to `train.csv` file and hosted on Cloud Storage. To download the file, click [here](https://storage.googleapis.com/cloud-samples-data-us-central1/vertex-ai/tabular-workflows/datasets/bank-marketing/train.csv)." ] }, { @@ -141,7 +154,8 @@ }, "outputs": [], "source": [ - "! pip3 install --upgrade --quiet google-cloud-aiplatform google-cloud-pipeline-components" + "! pip3 install --upgrade --quiet google-cloud-aiplatform \\\n", + " google-cloud-pipeline-components" ] }, { @@ -239,37 +253,6 @@ "REGION = \"us-central1\" # @param {type: \"string\"}" ] }, - { - "cell_type": "markdown", - "metadata": { - "id": "timestamp" - }, - "source": [ - "#### UUID\n", - "\n", - "If you are in a live tutorial session, you might be using a shared test account or project. To avoid name collisions between users on resources created, you create a uuid for each instance session, and append it onto the name of resources you create in this tutorial." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "84Vdv7R-QEH6" - }, - "outputs": [], - "source": [ - "import random\n", - "import string\n", - "\n", - "\n", - "# Generate a uuid of a specifed length(default=8)\n", - "def generate_uuid(length: int = 8) -> str:\n", - " return \"\".join(random.choices(string.ascii_lowercase + string.digits, k=length))\n", - "\n", - "\n", - "UUID = generate_uuid()" - ] - }, { "cell_type": "markdown", "metadata": { @@ -353,7 +336,7 @@ }, "outputs": [], "source": [ - "BUCKET_URI = \"gs://your-bucket-name-unique\" # @param {type:\"string\"}" + "BUCKET_URI = f\"gs://your-bucket-name-{PROJECT_ID}-unique\" # @param {type:\"string\"}" ] }, { @@ -373,7 +356,7 @@ }, "outputs": [], "source": [ - "! gsutil mb -l $REGION -p $PROJECT_ID $BUCKET_URI" + "! gsutil mb -l {REGION} -p {PROJECT_ID} {BUCKET_URI}" ] }, { @@ -382,7 +365,7 @@ "id": "zebLBGXOky2A" }, "source": [ - "## Notes about service account and permission\n", + "### Notes about service account and permission\n", "\n", "**By default no configuration is required**, if you run into any permission related issue, please make sure the service accounts have the required roles listed in the [Service accounts for Tabular Workflow for TabNet, and Tabular Workflow for Wide & Deep, and Prophet documentation](https://cloud.google.com/vertex-ai/docs/tabular-data/tabular-workflows/service-accounts#fte-workflow)." ] @@ -467,7 +450,7 @@ "id": "fbbc3479a1da" }, "source": [ - "## Import libraries and define constants" + "### Import libraries" ] }, { @@ -480,11 +463,10 @@ "source": [ "# Import required modules\n", "import os\n", - "import uuid\n", "from typing import Any, Dict, List\n", "\n", "from google.cloud import aiplatform, storage\n", - "from google_cloud_pipeline_components.experimental.automl.tabular import \\\n", + "from google_cloud_pipeline_components.preview.automl.tabular import \\\n", " utils as automl_tabular_utils" ] }, @@ -494,7 +476,7 @@ "id": "c0423f260423" }, "source": [ - "## Initialize Vertex AI SDK for Python\n", + "### Initialize Vertex AI SDK for Python\n", "\n", "Initialize the Vertex AI SDK for Python for your project." ] @@ -516,17 +498,17 @@ "id": "3LWH3PRF5o2v" }, "source": [ - "### Define helper functions\n", + "## Define helper functions\n", "Define the following helper functions:\n", "\n", - "- `get_model_artifacts_path`: Get the model artifacts path from task details.\n", - "- `get_model_uri`: Get the model uri from the task details..\n", - "- `get_bucket_name_and_path`: Get the bucket name and path.\n", - "- `download_from_gcs`: Download the content from the bucket.\n", - "- `write_to_gcs`: Upload content into the bucket.\n", - "- `get_task_detail`: Get the task details by using task name.\n", - "- `get_model_name`: Get the model name from pipeline job ID.\n", - "- `get_evaluation_metrics`: Get the evaluation metrics from pipeline task details.\n" + "- `get_model_artifacts_path`: Gets the model artifacts path from task details.\n", + "- `get_model_uri`: Gets the model uri from the task details.\n", + "- `get_bucket_name_and_path`: Gets the bucket name and path.\n", + "- `download_from_gcs`: Downloads the content from the bucket.\n", + "- `write_to_gcs`: Uploads content into the bucket.\n", + "- `get_task_detail`: Gets the task details by using task name.\n", + "- `get_model_name`: Gets the model name from pipeline job ID.\n", + "- `get_evaluation_metrics`: Gets the evaluation metrics from pipeline task details.\n" ] }, { @@ -538,6 +520,8 @@ "outputs": [], "source": [ "# Get the model artifacts path from task details.\n", + "\n", + "\n", "def get_model_artifacts_path(task_details: List[Dict[str, Any]], task_name: str) -> str:\n", " task = get_task_detail(task_details, task_name)\n", " return task.outputs[\"unmanaged_container_model\"].artifacts[0].uri\n", @@ -604,27 +588,27 @@ " )" ] }, - { - "cell_type": "markdown", - "metadata": { - "id": "gvNFMRmBegZq" - }, - "source": [ - "## Define the training specification" - ] - }, { "cell_type": "markdown", "metadata": { "id": "7a7332a3f8e2" }, "source": [ + "## Define training specifications\n", + "\n", + "Before creating the training job, you create the below steps in this section:\n", + "\n", + "1. Configure the source dataset.\n", + "2. Configure the feature transformation process.\n", + "3. Configure the feature selection process.\n", + "4. Set up the parameters needed for running the training process.\n", + "\n", "### Configure the dataset\n", "\n", "You define either of the following parameters:\n", "\n", - "- `data_source_csv_filenames`: The CSV data source.\n", - "- `data_source_bigquery_table_path`: The BigQuery data source.\n", + "- `data_source_csv_filenames`: The CSV data source. You specify the Cloud Storage path to the `train.csv` file described in the dataset section.\n", + "- `data_source_bigquery_table_path`: The BigQuery data source. As you use the Cloud Storage source, this is kept as none.\n", "\n", "***Notes***: Please note that the dataset's location has to be the same as the same as the service location (i.e., `REGION`) set for launching the training pipeline.\n" ] @@ -653,18 +637,18 @@ "\n", "Transformations can be specified using Feature Transform Engine (FTE) specific configurations. FTE supports both TensorFlow-based row-level and BigQuery-based dataset-level transformations.\n", "\n", - "* TensorFlow-based row-level transformations:\n", + "* **TensorFlow-based row-level transformations**:\n", " * Full automatic transformations: FTE automatically configures a set of built-in transformations for each input column based on its data statistics. This can be set via `tf_auto_transform_features` in the training pipeline.\n", " * Fully specified transformations: All transformations on input columns are explicitly specified with FTE's built-in transformations. Chaining of multiple transformations on a single column is also supported. These transformations can be saved to JSON configuration file and specified via `tf_transformations_path` argument of the training pipeline.\n", " * Custom transformations: Custom, bring-your-own transform function, where you can define and import your own transform function and use it with other FTE's built-in transformations. You can specify custom transformations as an array of JSON object and pass through the `tf_custom_transformation_definitions` argument of the training pipeline.\n", "\n", - "* BigQuery-based dataset-level transformations:\n", + "* **BigQuery-based dataset-level transformations**:\n", " * Fully specified transformations: All transformations on input columns are explicitly specified with FTE's built-in transformations. These transformations can be specified as an array of JSON objects via `dataset_level_transformations` argument of the training pipeline.\n", " * Custom transformations: Custom, bring-your-own transform function, where you can define and import your own transform function and use it with other FTE's built-in transformations. You can specify custom transformations as an array of JSON object and pass through the `dataset_level_custom_transformation_definitions` argument of the training pipeline.\n", "\n", "Below, you configure full automatic transformations by specifying a list of input features to pass to the `tf_auto_transform_features` argument of the training pipeline.\n", "\n", - "For a complete list of supported feature transformation configurations and examples, please go [here](https://google-cloud-pipeline-components.readthedocs.io/en/google-cloud-pipeline-components-1.0.31/google_cloud_pipeline_components.experimental.automl.tabular.html#google_cloud_pipeline_components.experimental.automl.tabular.FeatureTransformEngineOp)." + "Learn more about [feature transformation configurations](https://google-cloud-pipeline-components.readthedocs.io/en/google-cloud-pipeline-components-1.0.31/google_cloud_pipeline_components.experimental.automl.tabular.html#google_cloud_pipeline_components.experimental.automl.tabular.FeatureTransformEngineOp)." ] }, { @@ -707,9 +691,9 @@ "\n", "To enable it, you need to set `run_feature_selection` to True.\n", "\n", - "To configure the algorihtm to use, and number of features to be selected, you need to configure both `feature_selection_algorithm` and `max_selected_features` parameter.\n", + "To configure the algorihtm to use, and number of features to be selected, you need to configure both `feature_selection_algorithm` and `max_selected_features` parameters.\n", "\n", - "For a complete list of supported feature selection algorithms and configurations, please go [here](https://google-cloud-pipeline-components.readthedocs.io/en/google-cloud-pipeline-components-1.0.31/google_cloud_pipeline_components.experimental.automl.tabular.html#google_cloud_pipeline_components.experimental.automl.tabular.FeatureTransformEngineOp)." + "Learn more about [feature selection algorithms and configurations](https://google-cloud-pipeline-components.readthedocs.io/en/google-cloud-pipeline-components-1.0.31/google_cloud_pipeline_components.experimental.automl.tabular.html#google_cloud_pipeline_components.experimental.automl.tabular.FeatureTransformEngineOp)." ] }, { @@ -735,7 +719,7 @@ "source": [ "### Setup training configuration\n", "\n", - "You define the following:\n", + "Now, you define the following parameters for training:\n", "\n", "- `target_column`: The target column name.\n", "- `prediction_type`: The type of prediction the model is to produce.\n", @@ -769,9 +753,6 @@ "\n", "timestamp_split_key = None # timestamp column name when using timestamp split\n", "stratified_split_key = None # target column name when using stratified split\n", - "training_fraction = 0.8\n", - "validation_fraction = 0.1\n", - "test_fraction = 0.1\n", "\n", "predefined_split_key = None\n", "if predefined_split_key:\n", @@ -788,26 +769,26 @@ "id": "zyWGg2s09xOk" }, "source": [ - "## VPC related config\n", + "## Setup VPC configuration for Dataflow\n", "\n", - "You define the following:\n", + "In this section, you define the following parameters:\n", "\n", - "- `dataflow_subnetwork`: Dataflow's fully qualified subnetwork name, when empty the default subnetwork will be used. Example:\n", - "https://cloud.google.com/dataflow/docs/guides/specifying-networks#example_network_and_subnetwork_specifications\n", + "- `dataflow_subnetwork`: Dataflow's fully qualified subnetwork name, when empty the default subnetwork is used. See an [example](\n", + "https://cloud.google.com/dataflow/docs/guides/specifying-networks#example_network_and_subnetwork_specifications).\n", "- `dataflow_use_public_ips`: Specifies whether Dataflow workers use public IP\n", " addresses.\n", "\n", "If you need to use a custom Dataflow subnetwork, you can set it through the `dataflow_subnetwork` parameter. The requirements are:\n", - "1. `dataflow_subnetwork` must be fully qualified subnetwork name.\n", + "1. `dataflow_subnetwork` must be a fully qualified subnetwork name.\n", " [[reference](https://cloud.google.com/dataflow/docs/guides/specifying-networks#example_network_and_subnetwork_specifications)]\n", "1. The following service accounts must have [Compute Network User role](https://cloud.google.com/compute/docs/access/iam#compute.networkUser) assigned on the specified dataflow subnetwork [[reference](https://cloud.google.com/dataflow/docs/guides/specifying-networks#shared)]:\n", " 1. Compute Engine default service account: PROJECT_NUMBER-compute@developer.gserviceaccount.com\n", " 1. Dataflow service account: service-PROJECT_NUMBER@dataflow-service-producer-prod.iam.gserviceaccount.com\n", "\n", - "If your project has VPC-SC enabled, please make sure:\n", + "If your project has VPC-SC enabled, please make sure of the following:\n", "\n", "1. The dataflow subnetwork used in VPC-SC is configured properly for Dataflow.\n", - " [[reference](https://cloud.google.com/dataflow/docs/guides/routes-firewall)]\n", + " See [reference](https://cloud.google.com/dataflow/docs/guides/routes-firewall).\n", "1. `dataflow_use_public_ips` is set to False.\n" ] }, @@ -831,17 +812,19 @@ "source": [ "## Customize TabNet CustomJob configuration and create pipeline\n", "\n", - "This is best choice if you know exactly which hyperparameter values to use for model training. It uses fewer training resources than a HyperparameterTuningJob.\n", + "Creating a TabNet CustomJob is the best choice if you know exactly which hyperparameter values to use for model training. It uses fewer training resources than a HyperparameterTuningJob.\n", "\n", - "In the example below, you configure the following:\n", + "In the example below, you configure the following key parameters:\n", "\n", "- `root_dir`: The root GCS directory for the pipeline components.\n", - "- `worker_pool_specs_override`: The dictionary for overriding training and evaluation worker pool specs. The dictionary should be of [this format]( https://github.com/googleapis/googleapis/blob/4e836c7c257e3e20b1de14d470993a2b1f4736a8/google/cloud/aiplatform/v1beta1/custom_job.proto#L172). TabNet supports both CPU and GPU training.\n", + "- `worker_pool_specs_override`: The dictionary for overriding training and evaluation worker pool specs. The dictionary should follow a [particular format]( https://github.com/googleapis/googleapis/blob/4e836c7c257e3e20b1de14d470993a2b1f4736a8/google/cloud/aiplatform/v1beta1/custom_job.proto#L172). TabNet supports training using both CPUs and GPUs.\n", "- `learning_rate`: The learning rate used by the linear optimizer.\n", "- `max_steps`: Number of steps to run the trainer for.\n", "- `max_train_secs`: Amount of time in seconds to run the trainer for.\n", "\n", - "A complete list of pipeline inputs and model hyperparameters is available [here](https://google-cloud-pipeline-components.readthedocs.io/en/google-cloud-pipeline-components-1.0.23/google_cloud_pipeline_components.experimental.automl.tabular.html#google_cloud_pipeline_components.experimental.automl.tabular.utils.get_tabnet_trainer_pipeline_and_parameters)." + "Learn more about [pipeline inputs and model hyperparameters](https://google-cloud-pipeline-components.readthedocs.io/en/google-cloud-pipeline-components-1.0.23/google_cloud_pipeline_components.experimental.automl.tabular.html#google_cloud_pipeline_components.experimental.automl.tabular.utils.get_tabnet_trainer_pipeline_and_parameters).\n", + "\n", + "Learn more about the parameters needed for [creating a pipeline job](https://cloud.google.com/vertex-ai/docs/pipelines/run-pipeline#create_a_pipeline_run)." ] }, { @@ -852,20 +835,22 @@ }, "outputs": [], "source": [ + "# set a unique display name for your pipeline\n", + "pipeline_job_id = \"tabnet-unique\" # @param {type: \"string\"}\n", + "# set the root dir\n", "pipeline_job_root_dir = os.path.join(BUCKET_URI, \"tabnet_custom_job\")\n", - "\n", - "# max_steps and/or max_train_secs must be set. If both are\n", - "# specified, training stop after either condition is met.\n", - "# By default, max_train_secs is set to -1.\n", - "\n", - "max_steps = 1000\n", - "max_train_secs = -1\n", - "\n", - "learning_rate = 0.01\n", - "\n", + "# set the worker pool specs\n", "worker_pool_specs_override = [\n", " {\"machine_spec\": {\"machine_type\": \"c2-standard-16\"}} # Override for TF chief node\n", "]\n", + "# set the learning rate\n", + "learning_rate = 0.01\n", + "# max_steps and/or max_train_secs must be set. If both are\n", + "# specified, training stop after either condition is met.\n", + "# By default, max_train_secs is set to -1.\n", + "max_steps = 20\n", + "\n", + "max_train_secs = -1\n", "\n", "# To test GPU training, the worker_pool_specs_override can be specified like this.\n", "# worker_pool_specs_override = [\n", @@ -877,6 +862,7 @@ "# }\n", "# ]\n", "\n", + "# define the pipeline\n", "# If your system does not use Python, you can save the JSON file (`template_path`),\n", "# and use another programming language to submit the pipeline.\n", "(\n", @@ -906,10 +892,8 @@ " run_evaluation=run_evaluation,\n", ")\n", "\n", - "pipeline_job_id = f\"tabnet-{uuid.uuid4()}\"\n", - "# More info on parameters PipelineJob accepts:\n", - "# https://cloud.google.com/vertex-ai/docs/pipelines/run-pipeline#create_a_pipeline_run\n", - "pipeline_job = aiplatform.PipelineJob(\n", + "# create the pipeline job\n", + "training_pipeline_job = aiplatform.PipelineJob(\n", " display_name=pipeline_job_id,\n", " template_path=template_path,\n", " job_id=pipeline_job_id,\n", @@ -918,7 +902,8 @@ " enable_caching=False,\n", ")\n", "\n", - "pipeline_job.run(service_account=SERVICE_ACCOUNT)" + "# run the pipeline\n", + "training_pipeline_job.run(service_account=SERVICE_ACCOUNT)" ] }, { @@ -928,7 +913,8 @@ }, "source": [ "### Go to the Vertex Model UI\n", - "From the link below, you can deploy the model and test online prediction or run batch prediction." + "\n", + "Through the link generated from the below cell, you can deploy the model and run online prediction or batch prediction." ] }, { @@ -958,14 +944,20 @@ "source": [ "## Customize TabNet HyperparameterTuningJob configuration and create pipeline\n", "\n", - "To get the best set of hyperparameters for your dataset, it is recommended to run a HyperparameterTuningJob.\n", + "To get the best set of hyperparameters on your dataset, it is recommended to run a HyperparameterTuningJob.\n", "\n", - "Hyperparameters that can be tuned are set in the optional `study_spec_parameters_override` parameter. you provide a helper function called `get_tabnet_study_spec_parameters_override` to get these hyperparameters. You provide `dataset_size_bucket` (one of 'small' (< 1M rows), 'medium' (1M - 100M rows), or 'large' (> 100M rows)), `training_budget_bucket` (one of 'small' (< \\\\$600), 'medium' (\\\\$600 - \\\\$2400), or 'large' (> \\\\$2400)), and `prediction_type` and Vertex AI returns a list of hyperparameters and ranges. `study_spec_parameters_override` can be empty or one or more of these hyperparameters can be specified. For hyperparameters not specified in `study_spec_parameters_override`, you set ranges in the pipeline. For a full list of hyperparameters available for tuning, see [here](https://google-cloud-pipeline-components.readthedocs.io/en/google-cloud-pipeline-components-1.0.23/google_cloud_pipeline_components.experimental.automl.tabular.html#google_cloud_pipeline_components.experimental.automl.tabular.utils.get_tabnet_trainer_pipeline_and_parameters).\n", + "Hyperparameters that can be tuned are set with the optional `study_spec_parameters_override` parameter. You provide a helper function named `get_tabnet_study_spec_parameters_override` to get these hyperparameters. To this helper function, you provide:\n", "\n", - "In addition to hyperparameters, HyperparameterTuningJob takes the following values in the example below:\n", + "- `dataset_size_bucket`: one of 'small' (< 1M rows), 'medium' (1M - 100M rows), or 'large' (> 100M rows)).\n", + "- `training_budget_bucket`: one of 'small' (< \\\\$600), 'medium' (\\\\$600 - \\\\$2400), or 'large' (> \\\\$2400)).\n", + "- `prediction_type`: The type of prediction the model is to produce. “classification” or “regression”.\n", + "\n", + "Then, you get the list of hyperparameters and ranges. `study_spec_parameters_override` can be empty or one or more of the above hyperparameters can be specified. For hyperparameters not specified, you can set their ranges in the pipeline. Learn more about the [hyperparameters available for tuning](https://google-cloud-pipeline-components.readthedocs.io/en/google-cloud-pipeline-components-1.0.23/google_cloud_pipeline_components.experimental.automl.tabular.html#google_cloud_pipeline_components.experimental.automl.tabular.utils.get_tabnet_trainer_pipeline_and_parameters).\n", + "\n", + "In addition to hyperparameters, HyperparameterTuningJob takes the following values:\n", "\n", "- `root_dir`: The root GCS directory for the pipeline components.\n", - "- `worker_pool_specs_override`: The dictionary for overriding training and evaluation worker pool specs. The dictionary should be of [this format]( https://github.com/googleapis/googleapis/blob/4e836c7c257e3e20b1de14d470993a2b1f4736a8/google/cloud/aiplatform/v1beta1/custom_job.proto#L172). TabNet supports both CPU and GPU training.\n", + "- `worker_pool_specs_override`: The dictionary for overriding training and evaluation worker pool specs. The dictionary should follow a [particular format]( https://github.com/googleapis/googleapis/blob/4e836c7c257e3e20b1de14d470993a2b1f4736a8/google/cloud/aiplatform/v1beta1/custom_job.proto#L172). TabNet supports training using both CPUs and GPUs.\n", "- `study_spec_metric_id`: Metric to optimize, possible values: ['loss', 'average_loss', 'rmse', 'mae', 'mql', 'accuracy', 'auc', 'precision', 'recall'].\n", "- `study_spec_metric_goal`: Optimization goal of the metric, possible values: \"MAXIMIZE\", \"MINIMIZE\".\n", "- `max_trial_count`: The desired total number of trials.\n", @@ -974,9 +966,9 @@ "- `study_spec_algorithm`: The search algorithm specified for the study. One of\n", "'ALGORITHM_UNSPECIFIED', 'GRID_SEARCH', or 'RANDOM_SEARCH'.\n", "\n", - "For a full list of HyperparameterTuningJob parameters, see [here](https://google-cloud-pipeline-components.readthedocs.io/en/google-cloud-pipeline-components-1.0.23/google_cloud_pipeline_components.experimental.automl.tabular.html#google_cloud_pipeline_components.experimental.automl.tabular.utils.get_tabnet_hyperparameter_tuning_job_pipeline_and_parameters).\n", + "Learno more about the [HyperparameterTuningJob parameters](https://google-cloud-pipeline-components.readthedocs.io/en/google-cloud-pipeline-components-1.0.23/google_cloud_pipeline_components.experimental.automl.tabular.html#google_cloud_pipeline_components.experimental.automl.tabular.utils.get_tabnet_hyperparameter_tuning_job_pipeline_and_parameters).\n", "\n", - "Multiple trials can be configured. The pipeline returns the best trial based on the metric configured in `study_spec_metrics`. In the example below, you return the trial with the lowest loss value." + "Multiple trials can be configured. The pipeline returns the best trial based on the metric specified in `study_spec_metrics`. In the example below, you return the trial with the lowest loss value." ] }, { @@ -987,11 +979,18 @@ }, "outputs": [], "source": [ + "# set a unique display name for pipeline\n", + "pipeline_job_id = \"tabnet-hpt-unique\" # @param {type: \"string\"}\n", + "# set the root dir\n", "pipeline_job_root_dir = os.path.join(BUCKET_URI, \"tabnet_hyperparameter_tuning_job\")\n", - "\n", + "# set the worker pool specs\n", "worker_pool_specs_override = [\n", " {\"machine_spec\": {\"machine_type\": \"c2-standard-16\"}} # Override for TF chief node\n", "]\n", + "# set the metric\n", + "study_spec_metric_id = \"loss\"\n", + "# set the objective for metric\n", + "study_spec_metric_goal = \"MINIMIZE\"\n", "\n", "# To test GPU training, the worker_pool_specs_override can be specified like this.\n", "# worker_pool_specs_override = [\n", @@ -1004,9 +1003,8 @@ "# }\n", "# ]\n", "\n", - "study_spec_metric_id = \"loss\"\n", - "study_spec_metric_goal = \"MINIMIZE\"\n", "\n", + "# define the component to get the hyperparameters\n", "# max_steps and/or max_train_secs must be set. If both are\n", "# specified, training stop after either condition is met.\n", "# By default, max_train_secs is set to -1 and max_steps is set to\n", @@ -1019,6 +1017,7 @@ " )\n", ")\n", "\n", + "# define the hyperparameter tuning pipeline\n", "# If your system does not use Python, you can save the JSON file (`template_path`),\n", "# and use another programming language to submit the pipeline.\n", "(\n", @@ -1051,10 +1050,8 @@ " run_evaluation=True,\n", ")\n", "\n", - "pipeline_job_id = f\"tabnet-hpt-{uuid.uuid4()}\"\n", - "# More info on parameters PipelineJob accepts:\n", - "# https://cloud.google.com/vertex-ai/docs/pipelines/run-pipeline#create_a_pipeline_run\n", - "pipeline_job = aiplatform.PipelineJob(\n", + "# create the pipeline job\n", + "tuning_pipeline_job = aiplatform.PipelineJob(\n", " display_name=pipeline_job_id,\n", " template_path=template_path,\n", " job_id=pipeline_job_id,\n", @@ -1063,7 +1060,8 @@ " enable_caching=False,\n", ")\n", "\n", - "pipeline_job.run(service_account=SERVICE_ACCOUNT)" + "# run the pipeline job\n", + "tuning_pipeline_job.run(service_account=SERVICE_ACCOUNT)" ] }, { @@ -1073,7 +1071,8 @@ }, "source": [ "### Go to the Vertex Model UI\n", - "From the link below, you can deploy the model and test online prediction or run batch prediction." + "\n", + "Through the link generated from the below cell, you can deploy the model and run online prediction or batch prediction." ] }, { @@ -1111,9 +1110,11 @@ "\n", "Otherwise, you can delete the individual resources you created in this tutorial:\n", "\n", - "- Cloud Storage Bucket\n", + "- Pipeline from CustomJob pipeline\n", + "- Pipeline from HyperparameterTuningJob pipeline\n", "- Model from CustomJob pipeline\n", - "- Model from HyperparameterTuningJob pipeline" + "- Model from HyperparameterTuningJob pipeline\n", + "- Cloud Storage Bucket (set `delete_bucket` to True to delete the bucket)" ] }, { @@ -1124,6 +1125,12 @@ }, "outputs": [], "source": [ + "# Delete the training pipeline job\n", + "training_pipeline_job.delete()\n", + "\n", + "# Delete the tuning pipeline job\n", + "tuning_pipeline_job.delete()\n", + "\n", "# Delete model resources\n", "custom_job_model = aiplatform.Model(CUSTOM_JOB_MODEL)\n", "hpt_job_model = aiplatform.Model(HPT_JOB_MODEL)\n",