Compare commits

...
Author SHA1 Message Date
Andrew Ferlitsch 6bd8e7efe5 fix: component paths 2023-10-05 18:23:53 +00:00
Andrew Ferlitsch fde49605e0 fix: component paths 2023-10-05 17:24:18 +00:00
Andrew Ferlitsch f4e4d735a0 fix: component paths 2023-10-05 17:02:04 +00:00
Andrew Ferlitsch bed09f0dc6 fix: artifacts_type 2023-10-05 16:33:43 +00:00
Andrew Ferlitsch bb79ade1d1 fix: importer node 2023-10-05 15:47:13 +00:00
Andrew Ferlitsch 28fd201939 fix: model upload 2023-10-04 22:36:24 +00:00
Andrew Ferlitsch 80030835a5 fix: imports 2023-10-04 22:22:26 +00:00
Andrew Ferlitsch fae98fd4df fix: params 2023-10-04 22:01:22 +00:00
Andrew Ferlitsch 68bcd1ca10 fix: params 2023-10-04 21:41:11 +00:00
Andrew Ferlitsch 378957d441 fix: v1 2023-10-04 21:26:37 +00:00
Andrew Ferlitsch c3de32c6c2 fix: imports 2023-10-04 21:05:53 +00:00
Andrew Ferlitsch c36e149787 port: kfp2 2023-10-04 20:47:44 +00:00
@@ -247,7 +247,7 @@
"outputs": [],
"source": [
"# Install Python package dependencies.\n",
"! pip3 install --quiet 'google-cloud-pipeline-components==1.0.20' 'kfp<2'\n",
"! pip3 install --quiet google-cloud-pipeline-components kfp\n",
"! pip3 install --quiet --upgrade google-cloud-aiplatform google-cloud-bigquery"
]
},
@@ -457,7 +457,7 @@
},
"outputs": [],
"source": [
"! gsutil mb -l $REGION -p $PROJECT_ID $BUCKET_URI"
"! gsutil mb -l {REGION} -p {PROJECT_ID} {BUCKET_URI}"
]
},
{
@@ -556,13 +556,15 @@
"from typing import NamedTuple\n",
"\n",
"from google.cloud import aiplatform as vertex\n",
"from google_cloud_pipeline_components import \\\n",
" aiplatform as vertex_pipeline_components\n",
"from google_cloud_pipeline_components.experimental import \\\n",
" bigquery as bq_components\n",
"from kfp import dsl\n",
"from kfp.v2 import compiler\n",
"from kfp.v2.dsl import Artifact, Input, Metrics, Output, component"
"from google_cloud_pipeline_components.v1 import bigquery as bq_components\n",
"from google_cloud_pipeline_components.v1.automl.training_job import \\\n",
" AutoMLTabularTrainingJobRunOp\n",
"from google_cloud_pipeline_components.v1.dataset import TabularDatasetCreateOp\n",
"from google_cloud_pipeline_components.v1.endpoint import (EndpointCreateOp,\n",
" ModelDeployOp)\n",
"from google_cloud_pipeline_components.v1.model import ModelUploadOp\n",
"from kfp import compiler, dsl\n",
"from kfp.dsl import Artifact, Input, Metrics, Output, component"
]
},
{
@@ -595,7 +597,7 @@
},
"outputs": [],
"source": [
"PIPELINE_JSON_PKG_PATH = \"rapid_prototyping.json\"\n",
"PIPELINE_YAML_PKG_PATH = \"rapid_prototyping.yaml\"\n",
"PIPELINE_ROOT = f\"{BUCKET_URI}/pipeline_root\"\n",
"DATA_FOLDER = f\"{BUCKET_URI[5:]}/data\"\n",
"\n",
@@ -1317,18 +1319,26 @@
" endpoint_display_name: str,\n",
" thresholds_dict_str: str,\n",
"):\n",
" from google_cloud_pipeline_components.types import artifact_types\n",
" from kfp.dsl import importer_node\n",
"\n",
" # Imports data to BigQuery using a custom component.\n",
" import_data_to_bigquery_op = import_data_to_bigquery(\n",
" project, bq_location, bq_dataset, gcs_input_file_uri\n",
" project=project,\n",
" bq_location=bq_location,\n",
" bq_dataset=bq_dataset,\n",
" gcs_data_uri=gcs_input_file_uri,\n",
" )\n",
" raw_dataset = import_data_to_bigquery_op.outputs[\"raw_dataset\"]\n",
"\n",
" # Splits the BQ dataset using a custom component.\n",
" split_datasets_op = split_datasets(raw_dataset, bq_location=bq_location)\n",
" split_datasets_op = split_datasets(raw_dataset=raw_dataset, bq_location=bq_location)\n",
"\n",
" # Generates the query to create a BQML using a static function.\n",
" create_model_query = _query_create_model(\n",
" project, bq_dataset, split_datasets_op.outputs[\"dataset_uri\"]\n",
" project_id=project,\n",
" bq_dataset=bq_dataset,\n",
" training_data_uri=split_datasets_op.outputs[\"dataset_uri\"],\n",
" )\n",
"\n",
" # Builds BQML model using pre-built-component.\n",
@@ -1358,18 +1368,27 @@
" ).after(bqml_evaluate_op)\n",
" bqml_exported_gcs_path = bqml_export_op.outputs[\"exported_model_path\"]\n",
"\n",
" unmanaged_model_importer = importer_node.importer(\n",
" artifact_uri=bqml_exported_gcs_path,\n",
" artifact_class=artifact_types.UnmanagedContainerModel,\n",
" metadata={\n",
" \"containerSpec\": {\n",
" \"imageUri\": \"us-docker.pkg.dev/cloud-aiplatform/prediction/tf2-cpu.2-3:latest\"\n",
" }\n",
" },\n",
" )\n",
"\n",
" # Uploads the recently exported the BQML model from GCS into Vertex AI using a pre-built-component.\n",
" bqml_model_upload_op = vertex_pipeline_components.ModelUploadOp(\n",
" bqml_model_upload_op = ModelUploadOp(\n",
" project=project,\n",
" location=region,\n",
" display_name=DISPLAY_NAME + \"_bqml\",\n",
" artifact_uri=bqml_exported_gcs_path,\n",
" serving_container_image_uri=bqml_serving_container_image_uri,\n",
" unmanaged_container_model=unmanaged_model_importer.outputs[\"artifact\"],\n",
" )\n",
" bqml_vertex_model = bqml_model_upload_op.outputs[\"model\"]\n",
"\n",
" # Creates a Vertex AI Tabular dataset using a pre-built-component.\n",
" dataset_create_op = vertex_pipeline_components.TabularDatasetCreateOp(\n",
" dataset_create_op = TabularDatasetCreateOp(\n",
" project=project,\n",
" location=region,\n",
" display_name=DISPLAY_NAME,\n",
@@ -1377,7 +1396,7 @@
" )\n",
"\n",
" # Trains an AutoML Tables model using a pre-built-component.\n",
" automl_training_op = vertex_pipeline_components.AutoMLTabularTrainingJobRunOp(\n",
" automl_training_op = AutoMLTabularTrainingJobRunOp(\n",
" project=project,\n",
" location=region,\n",
" display_name=f\"{DISPLAY_NAME}_automl\",\n",
@@ -1420,7 +1439,7 @@
" name=\"deploy_decision\",\n",
" ):\n",
" # Creates a Vertex AI endpoint using a pre-built-component.\n",
" endpoint_create_op = vertex_pipeline_components.EndpointCreateOp(\n",
" endpoint_create_op = EndpointCreateOp(\n",
" project=project,\n",
" location=region,\n",
" display_name=endpoint_display_name,\n",
@@ -1433,19 +1452,17 @@
" name=\"deploy_bqml\",\n",
" ):\n",
" # Deploys the BQML model (now on Vertex AI) to the recently created endpoint using a pre-built component.\n",
" model_deploy_bqml_op = (\n",
" vertex_pipeline_components.ModelDeployOp( # noqa: F841\n",
" endpoint=endpoint_create_op.outputs[\"endpoint\"],\n",
" model=bqml_vertex_model,\n",
" deployed_model_display_name=DISPLAY_NAME + \"_best_bqml\",\n",
" dedicated_resources_machine_type=\"n1-standard-2\",\n",
" dedicated_resources_min_replica_count=2,\n",
" dedicated_resources_max_replica_count=2,\n",
" traffic_split={\n",
" \"0\": 100\n",
" }, # newly deployed model gets 100% of the traffic\n",
" ).set_caching_options(False)\n",
" )\n",
" model_deploy_bqml_op = ModelDeployOp( # noqa: F841\n",
" endpoint=endpoint_create_op.outputs[\"endpoint\"],\n",
" model=bqml_vertex_model,\n",
" deployed_model_display_name=DISPLAY_NAME + \"_best_bqml\",\n",
" dedicated_resources_machine_type=\"n1-standard-2\",\n",
" dedicated_resources_min_replica_count=2,\n",
" dedicated_resources_max_replica_count=2,\n",
" traffic_split={\n",
" \"0\": 100\n",
" }, # newly deployed model gets 100% of the traffic\n",
" ).set_caching_options(False)\n",
"\n",
" # Sends an online prediction request to the recently deployed model using a custom component.\n",
" validate_infrastructure(\n",
@@ -1458,19 +1475,17 @@
" name=\"deploy_automl\",\n",
" ):\n",
" # Deploys the AutoML model to the recently created endpoint using a pre-built component.\n",
" model_deploy_automl_op = (\n",
" vertex_pipeline_components.ModelDeployOp( # noqa: F841\n",
" endpoint=endpoint_create_op.outputs[\"endpoint\"],\n",
" model=automl_model,\n",
" deployed_model_display_name=DISPLAY_NAME + \"_best_automl\",\n",
" dedicated_resources_machine_type=\"n1-standard-2\",\n",
" dedicated_resources_min_replica_count=2,\n",
" dedicated_resources_max_replica_count=2,\n",
" traffic_split={\n",
" \"0\": 100\n",
" }, # newly deployed model gets 100% of the traffic\n",
" ).set_caching_options(False)\n",
" )\n",
" model_deploy_automl_op = ModelDeployOp( # noqa: F841\n",
" endpoint=endpoint_create_op.outputs[\"endpoint\"],\n",
" model=automl_model,\n",
" deployed_model_display_name=DISPLAY_NAME + \"_best_automl\",\n",
" dedicated_resources_machine_type=\"n1-standard-2\",\n",
" dedicated_resources_min_replica_count=2,\n",
" dedicated_resources_max_replica_count=2,\n",
" traffic_split={\n",
" \"0\": 100\n",
" }, # newly deployed model gets 100% of the traffic\n",
" ).set_caching_options(False)\n",
"\n",
" # Sends an online prediction request to the recently deployed model using a custom component.\n",
" validate_infrastructure(\n",
@@ -1497,7 +1512,7 @@
"source": [
"compiler.Compiler().compile(\n",
" pipeline_func=train_pipeline,\n",
" package_path=PIPELINE_JSON_PKG_PATH,\n",
" package_path=PIPELINE_YAML_PKG_PATH,\n",
")\n",
"\n",
"\n",
@@ -1505,7 +1520,7 @@
"\n",
"pipeline_job = vertex.PipelineJob(\n",
" display_name=DISPLAY_NAME,\n",
" template_path=PIPELINE_JSON_PKG_PATH,\n",
" template_path=PIPELINE_YAML_PKG_PATH,\n",
" pipeline_root=PIPELINE_ROOT,\n",
" parameter_values=pipeline_params,\n",
" enable_caching=False,\n",