From 3c3727b48ce4ba12bdaf36806cda4907a788d38e Mon Sep 17 00:00:00 2001 From: Amy Wu Date: Fri, 3 May 2024 12:15:21 -0700 Subject: [PATCH] fix: Add DeprecationWarning to vertexai.preview predictive models SDK PiperOrigin-RevId: 630461931 --- vertexai/preview/_workflow/driver/remote.py | 6 +++++- vertexai/preview/_workflow/shared/constants.py | 18 ++++++++++++++++++ .../preview/_workflow/shared/model_utils.py | 10 +++++----- vertexai/preview/developer/__init__.py | 8 +++++++- .../preview/hyperparameter_tuning/__init__.py | 5 ++++- vertexai/preview/initializer.py | 8 ++++++-- vertexai/preview/tabular_models/__init__.py | 4 ++++ 7 files changed, 49 insertions(+), 10 deletions(-) diff --git a/vertexai/preview/_workflow/driver/remote.py b/vertexai/preview/_workflow/driver/remote.py index e8364e9221..b26a12b575 100644 --- a/vertexai/preview/_workflow/driver/remote.py +++ b/vertexai/preview/_workflow/driver/remote.py @@ -18,7 +18,7 @@ import abc import inspect from typing import Any, Callable, Dict, Optional, Type - +import warnings from vertexai.preview._workflow import driver from vertexai.preview._workflow.executor import ( training, @@ -27,6 +27,7 @@ any_serializer, ) from vertexai.preview._workflow.shared import ( + constants, supported_frameworks, ) from vertexai.preview.developer import remote_specs @@ -41,6 +42,9 @@ def remote_method_decorator( return driver.VertexRemoteFunctor(method, remote_executor, remote_executor_kwargs) +warnings.warn(constants._V2_0_WARNING_MSG, DeprecationWarning, stacklevel=1) + + def remote_class_decorator(cls: Type) -> Type: """Add Vertex attributes to a class object.""" diff --git a/vertexai/preview/_workflow/shared/constants.py b/vertexai/preview/_workflow/shared/constants.py index 8cf36a2cca..4c7e5cd644 100644 --- a/vertexai/preview/_workflow/shared/constants.py +++ b/vertexai/preview/_workflow/shared/constants.py @@ -19,3 +19,21 @@ _START_EXECUTION_MSG = "Start remote execution on Vertex..." _END_EXECUTION_MSG = "Remote execution is completed." + +_V2_0_WARNING_MSG = """ +After May 30, 2024, importing any code below will result in an error. +Please verify that you are explicitly pinning to a version of `google-cloud-aiplatform` +(e.g., google-cloud-aiplatform==[1.32.0, 1.49.0]) if you need to continue using this +library. + +from vertexai.preview import ( + init, + remote, + VertexModel, + register, + from_pretrained, + developer, + hyperparameter_tuning, + tabular_models, +) +""" diff --git a/vertexai/preview/_workflow/shared/model_utils.py b/vertexai/preview/_workflow/shared/model_utils.py index 663a4740b3..f64a3fa25d 100644 --- a/vertexai/preview/_workflow/shared/model_utils.py +++ b/vertexai/preview/_workflow/shared/model_utils.py @@ -24,6 +24,7 @@ import os import re from typing import Any, Dict, Optional, Union +import warnings from google.cloud import aiplatform from google.cloud.aiplatform import base @@ -35,14 +36,12 @@ any_serializer, serializers_base, ) +from vertexai.preview._workflow.shared import constants # These need to be imported to be included in _ModelGardenModel.__init_subclass__ from vertexai.language_models import ( _language_models, ) # pylint:disable=unused-import -from vertexai.vision_models import ( - _vision_models, -) # pylint:disable=unused-import from vertexai._model_garden import _model_garden_models from google.cloud.aiplatform import _publisher_models from vertexai.preview._workflow.executor import training @@ -60,9 +59,10 @@ _OUTPUT_ESTIMATOR_DIR = "output_estimator" _OUTPUT_PREDICTIONS_DIR = "output_predictions" - _LOGGER = base.Logger("vertexai.remote_execution") +warnings.warn(constants._V2_0_WARNING_MSG, DeprecationWarning, stacklevel=1) + def _get_model_file_from_image_uri(container_image_uri: str) -> str: """Gets the model file from the container image URI. @@ -121,7 +121,7 @@ def _generate_remote_job_output_path(base_gcs_dir: str) -> str: def _get_model_from_successful_custom_job( job_dir: str, -) -> Union["sklearn.base.BaseEstimator", "tf.Module", "torch.nn.Module"]: +) -> Union["sklearn.base.BaseEstimator", "tf.Module", "torch.nn.Module"]: # noqa: F821 serializer = any_serializer.AnySerializer() diff --git a/vertexai/preview/developer/__init__.py b/vertexai/preview/developer/__init__.py index 7df80244b5..0039dc8e04 100644 --- a/vertexai/preview/developer/__init__.py +++ b/vertexai/preview/developer/__init__.py @@ -15,17 +15,23 @@ # limitations under the License. # +import warnings from vertexai.preview._workflow.serialization_engine import ( any_serializer, ) from vertexai.preview._workflow.serialization_engine import ( serializers_base, ) -from vertexai.preview._workflow.shared import configs +from vertexai.preview._workflow.shared import ( + configs, + constants, +) from vertexai.preview.developer import mark from vertexai.preview.developer import remote_specs +warnings.warn(constants._V2_0_WARNING_MSG, DeprecationWarning, stacklevel=1) + PersistentResourceConfig = configs.PersistentResourceConfig Serializer = serializers_base.Serializer SerializationMetadata = serializers_base.SerializationMetadata diff --git a/vertexai/preview/hyperparameter_tuning/__init__.py b/vertexai/preview/hyperparameter_tuning/__init__.py index 16a54be359..461acffc4b 100644 --- a/vertexai/preview/hyperparameter_tuning/__init__.py +++ b/vertexai/preview/hyperparameter_tuning/__init__.py @@ -15,11 +15,14 @@ # limitations under the License. # - +import warnings from vertexai.preview.hyperparameter_tuning import ( vizier_hyperparameter_tuner, ) +from vertexai.preview._workflow.shared import constants + +warnings.warn(constants._V2_0_WARNING_MSG, DeprecationWarning, stacklevel=1) VizierHyperparameterTuner = vizier_hyperparameter_tuner.VizierHyperparameterTuner diff --git a/vertexai/preview/initializer.py b/vertexai/preview/initializer.py index 2d4babdab9..08e7b1dc54 100644 --- a/vertexai/preview/initializer.py +++ b/vertexai/preview/initializer.py @@ -14,13 +14,16 @@ # from typing import Optional - +import warnings from google.cloud import aiplatform from google.cloud.aiplatform import base from vertexai.preview._workflow.executor import ( persistent_resource_util, ) -from vertexai.preview._workflow.shared import configs +from vertexai.preview._workflow.shared import ( + configs, + constants, +) _LOGGER = base.Logger(__name__) @@ -30,6 +33,7 @@ class _Config: """Store common configurations and current workflow for remote execution.""" def __init__(self): + warnings.warn(constants._V2_0_WARNING_MSG, DeprecationWarning, stacklevel=1) self._remote = False self._cluster = None diff --git a/vertexai/preview/tabular_models/__init__.py b/vertexai/preview/tabular_models/__init__.py index d96f82480a..5ee4607d17 100644 --- a/vertexai/preview/tabular_models/__init__.py +++ b/vertexai/preview/tabular_models/__init__.py @@ -15,10 +15,14 @@ # limitations under the License. # +import warnings +from vertexai.preview._workflow.shared import constants from vertexai.preview.tabular_models import tabnet_trainer +warnings.warn(constants._V2_0_WARNING_MSG, DeprecationWarning, stacklevel=1) + TabNetTrainer = tabnet_trainer.TabNetTrainer