Skip to content

Commit fb2936d

Browse files
authored
chore: e2e tabular system test improvement (#1627)
* chore: refactor tabular system test to reduce time * update e2e tabular test to remove automl model training * update to deploy perm automl model to temp endpoint * remove extra lines after comments
1 parent cc7c968 commit fb2936d

File tree

2 files changed

+32
-23
lines changed

2 files changed

+32
-23
lines changed

tests/system/aiplatform/e2e_base.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@
3535
_VPC_NETWORK_URI = os.getenv("_VPC_NETWORK_URI")
3636
_LOCATION = "us-central1"
3737

38+
_PROJECT_NUMBER = (
39+
resourcemanager.ProjectsClient()
40+
.get_project(name=f"projects/{_PROJECT}")
41+
.name.split("/", 1)[1]
42+
)
43+
3844

3945
class TestEndToEnd(metaclass=abc.ABCMeta):
4046
@property
@@ -86,13 +92,7 @@ def prepare_staging_bucket(
8692

8793
# TODO(#1415) Once PR Is merged, use the added utilities to
8894
# provide create/view access to Pipeline's default service account (compute)
89-
project_number = (
90-
resourcemanager.ProjectsClient()
91-
.get_project(name=f"projects/{_PROJECT}")
92-
.name.split("/", 1)[1]
93-
)
94-
95-
service_account = f"{project_number}[email protected]"
95+
service_account = f"{_PROJECT_NUMBER}[email protected]"
9696
bucket_iam_policy = bucket.get_iam_policy()
9797
bucket_iam_policy.setdefault("roles/storage.objectCreator", set()).add(
9898
f"serviceAccount:{service_account}"

tests/system/aiplatform/test_e2e_tabular.py

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#
1717

1818
import os
19+
import time
1920
from urllib import request
2021

2122
import pytest
@@ -45,6 +46,8 @@
4546
"median_income": 3.014700,
4647
}
4748

49+
_PERMANENT_AUTOML_MODEL_RESOURCE_NAME = f"projects/{e2e_base._PROJECT_NUMBER}/locations/us-central1/models/6591277539400876032"
50+
4851

4952
@pytest.mark.usefixtures(
5053
"prepare_staging_bucket", "delete_staging_bucket", "tear_down_resources"
@@ -78,7 +81,6 @@ def test_end_to_end_tabular(self, shared_state):
7881
)
7982

8083
# Create and import to single managed dataset for both training jobs
81-
8284
dataset_gcs_source = f'gs://{shared_state["staging_bucket_name"]}/{_BLOB_PATH}'
8385

8486
ds = aiplatform.TabularDataset.create(
@@ -91,7 +93,6 @@ def test_end_to_end_tabular(self, shared_state):
9193
shared_state["resources"].extend([ds])
9294

9395
# Define both training jobs
94-
9596
custom_job = aiplatform.CustomTrainingJob(
9697
display_name=self._make_display_name("train-housing-custom"),
9798
script_path=_LOCAL_TRAINING_SCRIPT_PATH,
@@ -106,8 +107,7 @@ def test_end_to_end_tabular(self, shared_state):
106107
optimization_objective="minimize-rmse",
107108
)
108109

109-
# Kick off both training jobs, AutoML job will take approx one hour to run
110-
110+
# Kick off both training jobs to check they are started correctly, then cancel the AutoML job
111111
custom_model = custom_job.run(
112112
ds,
113113
replica_count=1,
@@ -119,21 +119,32 @@ def test_end_to_end_tabular(self, shared_state):
119119
create_request_timeout=None,
120120
)
121121

122-
automl_model = automl_job.run(
122+
automl_job.run(
123123
dataset=ds,
124124
target_column="median_house_value",
125125
model_display_name=self._make_display_name("automl-housing-model"),
126126
sync=False,
127127
)
128128

129-
shared_state["resources"].extend(
130-
[automl_job, automl_model, custom_job, custom_model]
131-
)
129+
while (
130+
automl_job.state != gca_pipeline_state.PipelineState.PIPELINE_STATE_RUNNING
131+
):
132+
time.sleep(5)
133+
134+
# Cancel the AutoML job once it's successfully been created, this is async
135+
automl_job.cancel()
132136

133-
# Deploy both models after training completes
137+
shared_state["resources"].extend([custom_job, custom_model])
138+
139+
# Deploy the custom model after training completes
134140
custom_endpoint = custom_model.deploy(machine_type="n1-standard-4", sync=False)
141+
142+
# Create a reference to the permanent AutoML model and deloy it to a temporary endpoint
143+
automl_model = aiplatform.Model(
144+
model_name=_PERMANENT_AUTOML_MODEL_RESOURCE_NAME
145+
)
135146
automl_endpoint = automl_model.deploy(machine_type="n1-standard-4", sync=False)
136-
shared_state["resources"].extend([automl_endpoint, custom_endpoint])
147+
shared_state["resources"].extend([custom_endpoint, automl_endpoint])
137148

138149
custom_batch_prediction_job = custom_model.batch_predict(
139150
job_display_name=self._make_display_name("automl-housing-model"),
@@ -149,7 +160,6 @@ def test_end_to_end_tabular(self, shared_state):
149160
in_progress_done_check = custom_job.done()
150161
custom_job.wait_for_resource_creation()
151162

152-
automl_job.wait_for_resource_creation()
153163
custom_batch_prediction_job.wait_for_resource_creation()
154164

155165
# Send online prediction with same instance to both deployed models
@@ -172,7 +182,6 @@ def test_end_to_end_tabular(self, shared_state):
172182

173183
custom_batch_prediction_job.wait()
174184

175-
automl_endpoint.wait()
176185
automl_prediction = automl_endpoint.predict(
177186
[{k: str(v) for k, v in _INSTANCE.items()}], # Cast int values to strings
178187
timeout=180.0,
@@ -189,14 +198,14 @@ def test_end_to_end_tabular(self, shared_state):
189198
custom_job.state
190199
== gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED
191200
)
192-
assert (
193-
automl_job.state
194-
== gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED
195-
)
196201
assert (
197202
custom_batch_prediction_job.state
198203
== gca_job_state.JobState.JOB_STATE_SUCCEEDED
199204
)
205+
assert (
206+
automl_job.state
207+
== gca_pipeline_state.PipelineState.PIPELINE_STATE_CANCELLED
208+
)
200209

201210
# Ensure a single prediction was returned
202211
assert len(custom_prediction.predictions) == 1

0 commit comments

Comments
 (0)