From 32a849a3957b5a09ae6b16187518e7f9c098e980 Mon Sep 17 00:00:00 2001 From: Alexey Volkov Date: Sun, 31 Jul 2022 18:58:22 -0700 Subject: [PATCH] Google Cloud - Vertex_AI - Models - Upload_Scikit-learn_pickle_model - Simplified the component after my Vertex SDK fixes were merged Some of my Vertex SDK fixes: https://github.com/googleapis/python-aiplatform/pull/779 https://github.com/googleapis/python-aiplatform/pull/882 https://github.com/googleapis/python-aiplatform/pull/943 https://github.com/googleapis/python-aiplatform/pull/997 --- .../Upload_Scikit-learn_pickle_model/component.py | 8 ++------ .../Upload_Scikit-learn_pickle_model/component.yaml | 12 ++++-------- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/components/google-cloud/Vertex_AI/Models/Upload_Scikit-learn_pickle_model/component.py b/components/google-cloud/Vertex_AI/Models/Upload_Scikit-learn_pickle_model/component.py index 750eb33..010d1e7 100644 --- a/components/google-cloud/Vertex_AI/Models/Upload_Scikit-learn_pickle_model/component.py +++ b/components/google-cloud/Vertex_AI/Models/Upload_Scikit-learn_pickle_model/component.py @@ -18,7 +18,7 @@ def upload_Scikit_learn_pickle_model_to_Google_Cloud_Vertex_AI( # explanation_parameters: "google.cloud.aiplatform_v1.types.explanation.ExplanationParameters" = None, project: str = None, - location: str = "us-central1", + location: str = None, labels: dict = None, # encryption_spec_key_name: str = None, staging_bucket: str = None, @@ -26,7 +26,6 @@ def upload_Scikit_learn_pickle_model_to_Google_Cloud_Vertex_AI( ("model_name", "GoogleCloudVertexAiModelName"), ("model_dict", dict), ]): - import datetime import json import os import shutil @@ -45,8 +44,6 @@ def upload_Scikit_learn_pickle_model_to_Google_Cloud_Vertex_AI( _, renamed_model_path = tempfile.mkstemp(suffix=".pkl") shutil.copyfile(src=model_path, dst=renamed_model_path) - display_name = display_name or "Scikit-learn model " + datetime.datetime.now().isoformat(sep=" ") - model = aiplatform.Model.upload_scikit_learn_model_file( model_file_path=renamed_model_path, sklearn_version=sklearn_version, @@ -82,8 +79,7 @@ def upload_Scikit_learn_pickle_model_to_Google_Cloud_Vertex_AI( func=upload_Scikit_learn_pickle_model_to_Google_Cloud_Vertex_AI, base_image="python:3.9", packages_to_install=[ - # "google-cloud-aiplatform==1.10.0", - "git+https://github.com/Ark-kun/python-aiplatform@9b50f62b9d1409644656fb3202edc7be19c722f4#egg=google-cloud-aiplatform&subdirectory=." # branch: fix--Fixed-getitng-project-ID-when-running-on-Vertex-AI + "google-cloud-aiplatform==1.16.0", ], annotations={ "author": "Alexey Volkov ", diff --git a/components/google-cloud/Vertex_AI/Models/Upload_Scikit-learn_pickle_model/component.yaml b/components/google-cloud/Vertex_AI/Models/Upload_Scikit-learn_pickle_model/component.yaml index 02c455e..8186b4e 100644 --- a/components/google-cloud/Vertex_AI/Models/Upload_Scikit-learn_pickle_model/component.yaml +++ b/components/google-cloud/Vertex_AI/Models/Upload_Scikit-learn_pickle_model/component.yaml @@ -7,7 +7,7 @@ inputs: - {name: display_name, type: String, optional: true} - {name: description, type: String, optional: true} - {name: project, type: String, optional: true} -- {name: location, type: String, default: us-central1, optional: true} +- {name: location, type: String, optional: true} - {name: labels, type: JsonObject, optional: true} - {name: staging_bucket, type: String, optional: true} outputs: @@ -20,9 +20,8 @@ implementation: - sh - -c - (PIP_DISABLE_PIP_VERSION_CHECK=1 python3 -m pip install --quiet --no-warn-script-location - 'git+https://github.com/Ark-kun/python-aiplatform@9b50f62b9d1409644656fb3202edc7be19c722f4#egg=google-cloud-aiplatform&subdirectory=.' - || PIP_DISABLE_PIP_VERSION_CHECK=1 python3 -m pip install --quiet --no-warn-script-location - 'git+https://github.com/Ark-kun/python-aiplatform@9b50f62b9d1409644656fb3202edc7be19c722f4#egg=google-cloud-aiplatform&subdirectory=.' + 'google-cloud-aiplatform==1.16.0' || PIP_DISABLE_PIP_VERSION_CHECK=1 python3 + -m pip install --quiet --no-warn-script-location 'google-cloud-aiplatform==1.16.0' --user) && "$0" "$@" - sh - -ec @@ -46,12 +45,11 @@ implementation: # explanation_parameters: "google.cloud.aiplatform_v1.types.explanation.ExplanationParameters" = None, project = None, - location = "us-central1", + location = None, labels = None, # encryption_spec_key_name: str = None, staging_bucket = None, ): - import datetime import json import os import shutil @@ -70,8 +68,6 @@ implementation: _, renamed_model_path = tempfile.mkstemp(suffix=".pkl") shutil.copyfile(src=model_path, dst=renamed_model_path) - display_name = display_name or "Scikit-learn model " + datetime.datetime.now().isoformat(sep=" ") - model = aiplatform.Model.upload_scikit_learn_model_file( model_file_path=renamed_model_path, sklearn_version=sklearn_version,