Compare commits

...
Author SHA1 Message Date
Andrew Ferlitsch 98e425695f port: kfp2 2023-10-02 23:28:13 +00:00
@@ -150,8 +150,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"
]
},
{
@@ -530,18 +530,20 @@
"def pipeline(\n",
" project: str = PROJECT_ID, region: str = REGION, import_file: str = IMPORT_FILE\n",
"):\n",
" from google_cloud_pipeline_components import aiplatform as gcc_aip\n",
" from google_cloud_pipeline_components.v1.automl.training_job import \\\n",
" AutoMLTextTrainingJobRunOp\n",
" from google_cloud_pipeline_components.v1.dataset import TextDatasetCreateOp\n",
" from google_cloud_pipeline_components.v1.endpoint import (EndpointCreateOp,\n",
" ModelDeployOp)\n",
"\n",
" dataset_create_task = gcc_aip.TextDatasetCreateOp(\n",
" dataset_create_task = TextDatasetCreateOp(\n",
" display_name=\"train-automl-happydb\",\n",
" gcs_source=import_file,\n",
" import_schema_uri=aip.schema.dataset.ioformat.text.multi_label_classification,\n",
" project=project,\n",
" )\n",
"\n",
" training_run_task = gcc_aip.AutoMLTextTrainingJobRunOp(\n",
" training_run_task = AutoMLTextTrainingJobRunOp(\n",
" dataset=dataset_create_task.outputs[\"dataset\"],\n",
" display_name=\"train-automl-happydb\",\n",
" prediction_type=\"classification\",\n",
@@ -590,7 +592,7 @@
"\n",
"compiler.Compiler().compile(\n",
" pipeline_func=pipeline,\n",
" package_path=\"text_classification_pipeline.json\",\n",
" package_path=\"text_classification_pipeline.yaml\",\n",
")"
]
},
@@ -617,14 +619,14 @@
"\n",
"job = aip.PipelineJob(\n",
" display_name=DISPLAY_NAME,\n",
" template_path=\"text_classification_pipeline.json\",\n",
" template_path=\"text_classification_pipeline.yaml\",\n",
" pipeline_root=PIPELINE_ROOT,\n",
" enable_caching=False,\n",
")\n",
"\n",
"job.run()\n",
"\n",
"! rm text_classification_pipeline.json"
"! rm text_classification_pipeline.yaml"
]
},
{
@@ -655,16 +657,7 @@
"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",
"\n",
"Otherwise, you can delete the individual resources you created in this tutorial -- *Note:* this is auto-generated and not all resources may be applicable for this tutorial:\n",
"\n",
"- Dataset\n",
"- Pipeline\n",
"- Model\n",
"- Endpoint\n",
"- Batch Job\n",
"- Custom Job\n",
"- Hyperparameter Tuning Job\n",
"- Cloud Storage Bucket"
"Otherwise, you can delete the individual resources you created in this tutorial -- *Note:* this is auto-generated and not all resources may be applicable for this tutorial."
]
},
{
@@ -675,17 +668,10 @@
},
"outputs": [],
"source": [
"delete_dataset = True\n",
"delete_pipeline = True\n",
"delete_model = True\n",
"delete_endpoint = True\n",
"delete_batchjob = True\n",
"delete_customjob = True\n",
"delete_hptjob = True\n",
"delete_bucket = True\n",
"delete_bucket = False\n",
"\n",
"try:\n",
" if delete_model and \"DISPLAY_NAME\" in globals():\n",
" if \"DISPLAY_NAME\" in globals():\n",
" models = aip.Model.list(\n",
" filter=f\"display_name={DISPLAY_NAME}\", order_by=\"create_time\"\n",
" )\n",
@@ -707,53 +693,20 @@
"except Exception as e:\n",
" print(e)\n",
"\n",
"if delete_dataset and \"DISPLAY_NAME\" in globals():\n",
" if \"text\" == \"tabular\":\n",
" try:\n",
" datasets = aip.TabularDataset.list(\n",
" filter=f\"display_name={DISPLAY_NAME}\", order_by=\"create_time\"\n",
" )\n",
" dataset = datasets[0]\n",
" aip.TabularDataset.delete(dataset.resource_name)\n",
" print(\"Deleted dataset:\", dataset)\n",
" except Exception as e:\n",
" print(e)\n",
"if \"DISPLAY_NAME\" in globals():\n",
"\n",
" if \"text\" == \"image\":\n",
" try:\n",
" datasets = aip.ImageDataset.list(\n",
" filter=f\"display_name={DISPLAY_NAME}\", order_by=\"create_time\"\n",
" )\n",
" dataset = datasets[0]\n",
" aip.ImageDataset.delete(dataset.resource_name)\n",
" print(\"Deleted dataset:\", dataset)\n",
" except Exception as e:\n",
" print(e)\n",
"\n",
" if \"text\" == \"text\":\n",
" try:\n",
" datasets = aip.TextDataset.list(\n",
" filter=f\"display_name={DISPLAY_NAME}\", order_by=\"create_time\"\n",
" )\n",
" dataset = datasets[0]\n",
" aip.TextDataset.delete(dataset.resource_name)\n",
" print(\"Deleted dataset:\", dataset)\n",
" except Exception as e:\n",
" print(e)\n",
"\n",
" if \"text\" == \"video\":\n",
" try:\n",
" datasets = aip.VideoDataset.list(\n",
" filter=f\"display_name={DISPLAY_NAME}\", order_by=\"create_time\"\n",
" )\n",
" dataset = datasets[0]\n",
" aip.VideoDataset.delete(dataset.resource_name)\n",
" print(\"Deleted dataset:\", dataset)\n",
" except Exception as e:\n",
" print(e)\n",
" try:\n",
" datasets = aip.TextDataset.list(\n",
" filter=f\"display_name={DISPLAY_NAME}\", order_by=\"create_time\"\n",
" )\n",
" dataset = datasets[0]\n",
" aip.TextDataset.delete(dataset.resource_name)\n",
" print(\"Deleted dataset:\", dataset)\n",
" except Exception as e:\n",
" print(e)\n",
"\n",
"try:\n",
" if delete_pipeline and \"DISPLAY_NAME\" in globals():\n",
" if \"DISPLAY_NAME\" in globals():\n",
" pipelines = aip.PipelineJob.list(\n",
" filter=f\"display_name={DISPLAY_NAME}\", order_by=\"create_time\"\n",
" )\n",