mirror of
https://github.com/GoogleCloudPlatform/vertex-ai-samples.git
synced 2026-09-26 14:42:04 +00:00
port: kfp2 (#2304)
* port: kfp2 * fix: import * fix: params * fix: json/yaml
This commit is contained in:
@@ -155,8 +155,8 @@
|
||||
"source": [
|
||||
"! pip3 install --upgrade --quiet google-cloud-aiplatform \\\n",
|
||||
" google-cloud-storage \\\n",
|
||||
" 'kfp<2' \\\n",
|
||||
" 'google-cloud-pipeline-components<2'"
|
||||
" kfp \\\n",
|
||||
" google-cloud-pipeline-components"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -344,10 +344,8 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"IS_COLAB = False\n",
|
||||
"# from google.colab import auth\n",
|
||||
"# auth.authenticate_user()\n",
|
||||
"# IS_COLAB = True"
|
||||
"# auth.authenticate_user()"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -401,7 +399,7 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"! gsutil mb -l $REGION -p $PROJECT_ID $BUCKET_URI"
|
||||
"! gsutil mb -l {REGION} -p {PROJECT_ID} {BUCKET_URI}"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -434,6 +432,9 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import sys\n",
|
||||
"\n",
|
||||
"IS_COLAB = \"google.colab\" in sys.modules\n",
|
||||
"if (\n",
|
||||
" SERVICE_ACCOUNT == \"\"\n",
|
||||
" or SERVICE_ACCOUNT is None\n",
|
||||
@@ -497,9 +498,9 @@
|
||||
"\n",
|
||||
"import kfp\n",
|
||||
"from google.cloud import aiplatform\n",
|
||||
"from kfp.v2 import dsl\n",
|
||||
"from kfp.v2.dsl import (Artifact, ClassificationMetrics, Input, Metrics,\n",
|
||||
" Output, component)"
|
||||
"from kfp import compiler, dsl\n",
|
||||
"from kfp.dsl import (Artifact, ClassificationMetrics, Input, Metrics, Output,\n",
|
||||
" component)"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -585,7 +586,6 @@
|
||||
"source": [
|
||||
"@component(\n",
|
||||
" base_image=\"gcr.io/deeplearning-platform-release/tf2-cpu.2-6:latest\",\n",
|
||||
" output_component_file=\"tabular_eval_component.yaml\",\n",
|
||||
" packages_to_install=[\"google-cloud-aiplatform\"],\n",
|
||||
")\n",
|
||||
"def classification_model_eval_metrics(\n",
|
||||
@@ -695,7 +695,12 @@
|
||||
" dep_decision = \"false\"\n",
|
||||
" logging.info(\"deployment decision is %s\", dep_decision)\n",
|
||||
"\n",
|
||||
" return (dep_decision,)"
|
||||
" return (dep_decision,)\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"compiler.Compiler().compile(\n",
|
||||
" classification_model_eval_metrics, \"tabular_eval_component.yaml\"\n",
|
||||
")"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -729,13 +734,20 @@
|
||||
" gcp_region: str,\n",
|
||||
" thresholds_dict_str: str,\n",
|
||||
"):\n",
|
||||
"\n",
|
||||
" from google_cloud_pipeline_components.aiplatform import (\n",
|
||||
" AutoMLTabularTrainingJobRunOp, EndpointCreateOp, ModelDeployOp,\n",
|
||||
" TabularDatasetCreateOp)\n",
|
||||
" from google_cloud_pipeline_components.v1.automl.training_job import \\\n",
|
||||
" AutoMLTabularTrainingJobRunOp\n",
|
||||
" from google_cloud_pipeline_components.v1.dataset.create_tabular_dataset.component import \\\n",
|
||||
" tabular_dataset_create as TabularDatasetCreateOp\n",
|
||||
" from google_cloud_pipeline_components.v1.endpoint.create_endpoint.component import \\\n",
|
||||
" endpoint_create as EndpointCreateOp\n",
|
||||
" from google_cloud_pipeline_components.v1.endpoint.deploy_model.component import \\\n",
|
||||
" model_deploy as ModelDeployOp\n",
|
||||
"\n",
|
||||
" dataset_create_op = TabularDatasetCreateOp(\n",
|
||||
" project=project, location=gcp_region, display_name=DATASET_DISPLAY_NAME, bq_source=bq_source\n",
|
||||
" project=project,\n",
|
||||
" location=gcp_region,\n",
|
||||
" display_name=DATASET_DISPLAY_NAME,\n",
|
||||
" bq_source=bq_source,\n",
|
||||
" )\n",
|
||||
"\n",
|
||||
" training_op = AutoMLTabularTrainingJobRunOp(\n",
|
||||
@@ -770,10 +782,10 @@
|
||||
" )\n",
|
||||
"\n",
|
||||
" model_eval_task = classification_model_eval_metrics(\n",
|
||||
" project,\n",
|
||||
" gcp_region,\n",
|
||||
" thresholds_dict_str,\n",
|
||||
" training_op.outputs[\"model\"],\n",
|
||||
" project=project,\n",
|
||||
" location=gcp_region,\n",
|
||||
" thresholds_dict_str=thresholds_dict_str,\n",
|
||||
" model=training_op.outputs[\"model\"],\n",
|
||||
" )\n",
|
||||
"\n",
|
||||
" with dsl.Condition(\n",
|
||||
@@ -804,7 +816,7 @@
|
||||
"source": [
|
||||
"## Compile the pipeline\n",
|
||||
"\n",
|
||||
"Next, compile the pipeline to the specified json file."
|
||||
"Next, compile the pipeline to the specified yaml file."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -815,11 +827,9 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from kfp.v2 import compiler\n",
|
||||
"\n",
|
||||
"compiler.Compiler().compile(\n",
|
||||
" pipeline_func=pipeline,\n",
|
||||
" package_path=\"tabular_classification_pipeline.json\",\n",
|
||||
" package_path=\"tabular_classification_pipeline.yaml\",\n",
|
||||
")"
|
||||
]
|
||||
},
|
||||
@@ -899,12 +909,14 @@
|
||||
" assert bq_region in REGION\n",
|
||||
" print(f\"Region validated: {REGION}\")\n",
|
||||
"except AssertionError:\n",
|
||||
" print(\"Please make sure the region of BigQuery (source) and that of the pipeline are the same.\")\n",
|
||||
" print(\n",
|
||||
" \"Please make sure the region of BigQuery (source) and that of the pipeline are the same.\"\n",
|
||||
" )\n",
|
||||
"\n",
|
||||
"# Configure the pipeline\n",
|
||||
"job = aiplatform.PipelineJob(\n",
|
||||
" display_name=PIPELINE_DISPLAY_NAME,\n",
|
||||
" template_path=\"tabular_classification_pipeline.json\",\n",
|
||||
" template_path=\"tabular_classification_pipeline.yaml\",\n",
|
||||
" pipeline_root=PIPELINE_ROOT,\n",
|
||||
" parameter_values={\n",
|
||||
" \"project\": PROJECT_ID,\n",
|
||||
|
||||
Reference in New Issue
Block a user