Skip to content

Commit d734381

Browse files
olegkachur-eOleg Kachur
andauthored
Mark VertexAI AutoMLText deprecation (#42251)
- Label deprecated items with deprecated decorator. - Refactor vertex_ai AutoMLHook.create_auto_ml_text_training_job, to avoid calling get_auto_ml_text_training_job, to not trigger mypy errors after applying @deprecate on hook method. - Update docs. - Delete irrelevant system tests. Co-authored-by: Oleg Kachur
1 parent 3b5cc50 commit d734381

10 files changed

Lines changed: 83 additions & 725 deletions

File tree

‎airflow/providers/google/cloud/hooks/vertex_ai/auto_ml.py‎

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
from google.cloud.aiplatform_v1 import JobServiceClient, PipelineServiceClient
3737

3838
from airflow.exceptions import AirflowException, AirflowProviderDeprecationWarning
39+
from airflow.providers.google.common.deprecated import deprecated
3940
from airflow.providers.google.common.hooks.base_google import GoogleBaseHook
4041

4142
if TYPE_CHECKING:
@@ -185,6 +186,11 @@ def get_auto_ml_image_training_job(
185186
model_encryption_spec_key_name=model_encryption_spec_key_name,
186187
)
187188

189+
@deprecated(
190+
planned_removal_date="June 15, 2025",
191+
category=AirflowProviderDeprecationWarning,
192+
reason="Deprecation of AutoMLText API",
193+
)
188194
def get_auto_ml_text_training_job(
189195
self,
190196
display_name: str,
@@ -197,7 +203,12 @@ def get_auto_ml_text_training_job(
197203
training_encryption_spec_key_name: str | None = None,
198204
model_encryption_spec_key_name: str | None = None,
199205
) -> AutoMLTextTrainingJob:
200-
"""Return AutoMLTextTrainingJob object."""
206+
"""
207+
Return AutoMLTextTrainingJob object.
208+
209+
WARNING: Text creation API is deprecated since September 15, 2024
210+
(https://cloud.google.com/vertex-ai/docs/tutorials/text-classification-automl/overview).
211+
"""
201212
return AutoMLTextTrainingJob(
202213
display_name=display_name,
203214
prediction_type=prediction_type,
@@ -980,6 +991,11 @@ def create_auto_ml_image_training_job(
980991
return model, training_id
981992

982993
@GoogleBaseHook.fallback_to_default_project_id
994+
@deprecated(
995+
planned_removal_date="September 15, 2025",
996+
category=AirflowProviderDeprecationWarning,
997+
reason="Deprecation of AutoMLText API",
998+
)
983999
def create_auto_ml_text_training_job(
9841000
self,
9851001
project_id: str,
@@ -1009,6 +1025,9 @@ def create_auto_ml_text_training_job(
10091025
"""
10101026
Create an AutoML Text Training Job.
10111027
1028+
WARNING: Text creation API is deprecated since September 15, 2024
1029+
(https://cloud.google.com/vertex-ai/docs/tutorials/text-classification-automl/overview).
1030+
10121031
:param project_id: Required. Project to run training in.
10131032
:param region: Required. Location to run training in.
10141033
:param display_name: Required. The user-defined name of this TrainingPipeline.
@@ -1101,13 +1120,14 @@ def create_auto_ml_text_training_job(
11011120
concurrent Future and any downstream object will be immediately returned and synced when the
11021121
Future has completed.
11031122
"""
1104-
self._job = self.get_auto_ml_text_training_job(
1105-
project=project_id,
1106-
location=region,
1123+
self._job = AutoMLTextTrainingJob(
11071124
display_name=display_name,
11081125
prediction_type=prediction_type,
11091126
multi_label=multi_label,
11101127
sentiment_max=sentiment_max,
1128+
project=project_id,
1129+
location=region,
1130+
credentials=self.get_credentials(),
11111131
labels=labels,
11121132
training_encryption_spec_key_name=training_encryption_spec_key_name,
11131133
model_encryption_spec_key_name=model_encryption_spec_key_name,
@@ -1117,13 +1137,13 @@ def create_auto_ml_text_training_job(
11171137
raise AirflowException("AutoMLTextTrainingJob was not created")
11181138

11191139
model = self._job.run(
1120-
dataset=dataset,
1121-
training_fraction_split=training_fraction_split,
1122-
validation_fraction_split=validation_fraction_split,
1140+
dataset=dataset, # type: ignore[arg-type]
1141+
training_fraction_split=training_fraction_split, # type: ignore[call-arg]
1142+
validation_fraction_split=validation_fraction_split, # type: ignore[call-arg]
11231143
test_fraction_split=test_fraction_split,
11241144
training_filter_split=training_filter_split,
11251145
validation_filter_split=validation_filter_split,
1126-
test_filter_split=test_filter_split,
1146+
test_filter_split=test_filter_split, # type: ignore[call-arg]
11271147
model_display_name=model_display_name,
11281148
model_labels=model_labels,
11291149
sync=sync,

‎airflow/providers/google/cloud/operators/vertex_ai/auto_ml.py‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,8 +455,22 @@ def execute(self, context: Context):
455455
return result
456456

457457

458+
@deprecated(
459+
planned_removal_date="September 15, 2024",
460+
use_instead="SupervisedFineTuningTrainOperator",
461+
instructions=(
462+
"Please consider using Fine Tuning over the Gemini model. "
463+
"More info: https://cloud.google.com/vertex-ai/docs/start/automl-gemini-comparison"
464+
),
465+
category=AirflowProviderDeprecationWarning,
466+
)
458467
class CreateAutoMLTextTrainingJobOperator(AutoMLTrainingJobBaseOperator):
459-
"""Create Auto ML Text Training job."""
468+
"""
469+
Create Auto ML Text Training job.
470+
471+
WARNING: Text creation API is deprecated since September 15, 2024
472+
(https://cloud.google.com/vertex-ai/docs/tutorials/text-classification-automl/overview).
473+
"""
460474

461475
template_fields = [
462476
"parent_model",

‎docs/apache-airflow-providers-google/operators/cloud/automl.rst‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,12 @@ available on the Vertex AI platform. Please use
109109
:class:`~airflow.providers.google.cloud.operators.vertex_ai.auto_ml.CreateAutoMLImageTrainingJobOperator` or
110110
:class:`~airflow.providers.google.cloud.operators.vertex_ai.auto_ml.CreateAutoMLVideoTrainingJobOperator`.
111111

112-
You can find example on how to use VertexAI operators for AutoML Natural Language classification here:
112+
The Vertex AutoMLText API for model training is deprecated on September 15, 2024 and the other part will be deprecated
113+
on June 15, 2025.
114+
Please consider using fine tuning with Gemini model -
115+
https://cloud.google.com/vertex-ai/generative-ai/docs/models/gemini-tuning.
113116

114-
.. exampleinclude:: /../../tests/system/providers/google/cloud/automl/example_automl_nl_text_classification.py
115-
:language: python
116-
:dedent: 4
117-
:start-after: [START howto_cloud_create_text_classification_training_job_operator]
118-
:end-before: [END howto_cloud_create_text_classification_training_job_operator]
119-
120-
Additionally, you can find example on how to use VertexAI operators for AutoML Vision classification here:
117+
You can find example on how to use VertexAI operators for AutoML Vision classification here:
121118

122119
.. exampleinclude:: /../../tests/system/providers/google/cloud/automl/example_automl_vision_classification.py
123120
:language: python

‎docs/apache-airflow-providers-google/operators/cloud/vertex_ai.rst‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -260,14 +260,11 @@ put dataset id to ``dataset_id`` parameter in operator.
260260
How to run AutoML Text Training Job
261261
:class:`~airflow.providers.google.cloud.operators.vertex_ai.auto_ml.CreateAutoMLTextTrainingJobOperator`
262262

263-
Before start running this Job you must prepare and create ``Text`` dataset. After that you should
264-
put dataset id to ``dataset_id`` parameter in operator.
263+
Operator is deprecated, please use
264+
:class:`~airflow.providers.google.cloud.operators.vertex_ai.generative_model.SupervisedFineTuningTrainOperator` over
265+
the Gemini model.
266+
More info: https://cloud.google.com/vertex-ai/generative-ai/docs/models/gemini-tuning#tuning-gemini
265267

266-
.. exampleinclude:: /../../tests/system/providers/google/cloud/vertex_ai/example_vertex_ai_auto_ml_text_training.py
267-
:language: python
268-
:dedent: 4
269-
:start-after: [START how_to_cloud_vertex_ai_create_auto_ml_text_training_job_operator]
270-
:end-before: [END how_to_cloud_vertex_ai_create_auto_ml_text_training_job_operator]
271268

272269
How to run AutoML Video Training Job
273270
:class:`~airflow.providers.google.cloud.operators.vertex_ai.auto_ml.CreateAutoMLVideoTrainingJobOperator`

‎tests/always/test_project_structure.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@ class TestGoogleProviderProjectStructure(ExampleCoverageTest, AssetsCoverageTest
389389
"airflow.providers.google.cloud.operators.bigquery.BigQueryPatchDatasetOperator",
390390
"airflow.providers.google.cloud.operators.dataflow.DataflowCreatePythonJobOperator",
391391
"airflow.providers.google.cloud.operators.bigquery.BigQueryExecuteQueryOperator",
392+
"airflow.providers.google.cloud.operators.vertex_ai.auto_ml.CreateAutoMLTextTrainingJobOperator",
392393
"airflow.providers.google.cloud.sensors.bigquery.BigQueryTableExistenceAsyncSensor",
393394
"airflow.providers.google.cloud.sensors.bigquery.BigQueryTableExistencePartitionAsyncSensor",
394395
"airflow.providers.google.cloud.sensors.cloud_composer.CloudComposerEnvironmentSensor",

‎tests/providers/google/cloud/operators/test_vertex_ai.py‎

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1833,20 +1833,21 @@ class TestVertexAICreateAutoMLTextTrainingJobOperator:
18331833
@mock.patch(VERTEX_AI_PATH.format("auto_ml.AutoMLHook"))
18341834
def test_execute(self, mock_hook, mock_dataset):
18351835
mock_hook.return_value.create_auto_ml_text_training_job.return_value = (None, "training_id")
1836-
op = CreateAutoMLTextTrainingJobOperator(
1837-
task_id=TASK_ID,
1838-
gcp_conn_id=GCP_CONN_ID,
1839-
impersonation_chain=IMPERSONATION_CHAIN,
1840-
display_name=DISPLAY_NAME,
1841-
dataset_id=TEST_DATASET_ID,
1842-
prediction_type=None,
1843-
multi_label=False,
1844-
sentiment_max=10,
1845-
sync=True,
1846-
region=GCP_LOCATION,
1847-
project_id=GCP_PROJECT,
1848-
parent_model=TEST_PARENT_MODEL,
1849-
)
1836+
with pytest.warns(AirflowProviderDeprecationWarning):
1837+
op = CreateAutoMLTextTrainingJobOperator(
1838+
task_id=TASK_ID,
1839+
gcp_conn_id=GCP_CONN_ID,
1840+
impersonation_chain=IMPERSONATION_CHAIN,
1841+
display_name=DISPLAY_NAME,
1842+
dataset_id=TEST_DATASET_ID,
1843+
prediction_type=None,
1844+
multi_label=False,
1845+
sentiment_max=10,
1846+
sync=True,
1847+
region=GCP_LOCATION,
1848+
project_id=GCP_PROJECT,
1849+
parent_model=TEST_PARENT_MODEL,
1850+
)
18501851
op.execute(context={"ti": mock.MagicMock()})
18511852
mock_hook.assert_called_once_with(gcp_conn_id=GCP_CONN_ID, impersonation_chain=IMPERSONATION_CHAIN)
18521853
mock_dataset.assert_called_once_with(dataset_name=TEST_DATASET_ID)
@@ -1880,20 +1881,21 @@ def test_execute(self, mock_hook, mock_dataset):
18801881
@mock.patch(VERTEX_AI_PATH.format("auto_ml.AutoMLHook"))
18811882
def test_execute__parent_model_version_index_is_removed(self, mock_hook, mock_dataset):
18821883
mock_hook.return_value.create_auto_ml_text_training_job.return_value = (None, "training_id")
1883-
op = CreateAutoMLTextTrainingJobOperator(
1884-
task_id=TASK_ID,
1885-
gcp_conn_id=GCP_CONN_ID,
1886-
impersonation_chain=IMPERSONATION_CHAIN,
1887-
display_name=DISPLAY_NAME,
1888-
dataset_id=TEST_DATASET_ID,
1889-
prediction_type=None,
1890-
multi_label=False,
1891-
sentiment_max=10,
1892-
sync=True,
1893-
region=GCP_LOCATION,
1894-
project_id=GCP_PROJECT,
1895-
parent_model=VERSIONED_TEST_PARENT_MODEL,
1896-
)
1884+
with pytest.warns(AirflowProviderDeprecationWarning):
1885+
op = CreateAutoMLTextTrainingJobOperator(
1886+
task_id=TASK_ID,
1887+
gcp_conn_id=GCP_CONN_ID,
1888+
impersonation_chain=IMPERSONATION_CHAIN,
1889+
display_name=DISPLAY_NAME,
1890+
dataset_id=TEST_DATASET_ID,
1891+
prediction_type=None,
1892+
multi_label=False,
1893+
sentiment_max=10,
1894+
sync=True,
1895+
region=GCP_LOCATION,
1896+
project_id=GCP_PROJECT,
1897+
parent_model=VERSIONED_TEST_PARENT_MODEL,
1898+
)
18971899
op.execute(context={"ti": mock.MagicMock()})
18981900
mock_hook.return_value.create_auto_ml_text_training_job.assert_called_once_with(
18991901
project_id=GCP_PROJECT,

0 commit comments

Comments
 (0)