Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add manual resource removal to model monitoring system tests #1578

Merged
merged 3 commits into from
Aug 10, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 32 additions & 7 deletions tests/system/aiplatform/test_model_monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def temp_endpoint(self, shared_state):
predict_response = endpoint.predict(instances=[_DEFAULT_INPUT])
assert len(predict_response.predictions) == 1
shared_state["resources"].append(endpoint)
return endpoint
return [endpoint, model]

def temp_endpoint_with_two_models(self, shared_state):
aiplatform.init(
Expand Down Expand Up @@ -180,14 +180,14 @@ def temp_endpoint_with_two_models(self, shared_state):
predict_response = endpoint.predict(instances=[_DEFAULT_INPUT])
assert len(predict_response.predictions) == 1
shared_state["resources"].append(endpoint)
return endpoint
return [endpoint, model1, model2]

def test_mdm_one_model_one_valid_config(self, shared_state):
"""
Upload pre-trained churn model from local file and deploy it for prediction.
"""
# test model monitoring configurations
temp_endpoint = self.temp_endpoint(shared_state)
[temp_endpoint, model] = self.temp_endpoint(shared_state)

job = None

Expand Down Expand Up @@ -249,9 +249,16 @@ def test_mdm_one_model_one_valid_config(self, shared_state):
job.delete()
with pytest.raises(core_exceptions.NotFound):
job.api_client.get_model_deployment_monitoring_job(name=job_resource)
temp_endpoint.undeploy_all()
temp_endpoint.delete()
model.delete()

def test_mdm_two_models_two_valid_configs(self, shared_state):
temp_endpoint_with_two_models = self.temp_endpoint_with_two_models(shared_state)
[
temp_endpoint_with_two_models,
model1,
model2,
] = self.temp_endpoint_with_two_models(shared_state)
[deployed_model1, deployed_model2] = list(
map(lambda x: x.id, temp_endpoint_with_two_models.list_models())
)
Expand Down Expand Up @@ -307,9 +314,13 @@ def test_mdm_two_models_two_valid_configs(self, shared_state):
)

job.delete()
temp_endpoint_with_two_models.undeploy_all()
temp_endpoint_with_two_models.delete()
model1.delete()
model2.delete()

def test_mdm_invalid_config_incorrect_model_id(self, shared_state):
temp_endpoint = self.temp_endpoint(shared_state)
[temp_endpoint, model] = self.temp_endpoint(shared_state)
with pytest.raises(ValueError) as e:
aiplatform.ModelDeploymentMonitoringJob.create(
display_name=self._make_display_name(key=JOB_NAME),
Expand All @@ -326,9 +337,12 @@ def test_mdm_invalid_config_incorrect_model_id(self, shared_state):
deployed_model_ids=[""],
)
assert "Invalid model ID" in str(e.value)
temp_endpoint.undeploy_all()
temp_endpoint.delete()
model.delete()

def test_mdm_invalid_config_xai(self, shared_state):
temp_endpoint = self.temp_endpoint(shared_state)
[temp_endpoint, model] = self.temp_endpoint(shared_state)
with pytest.raises(RuntimeError) as e:
objective_config.explanation_config = model_monitoring.ExplanationConfig()
aiplatform.ModelDeploymentMonitoringJob.create(
Expand All @@ -348,9 +362,16 @@ def test_mdm_invalid_config_xai(self, shared_state):
"`explanation_config` should only be enabled if the model has `explanation_spec populated"
in str(e.value)
)
temp_endpoint.undeploy_all()
temp_endpoint.delete()
model.delete()

def test_mdm_two_models_invalid_configs_xai(self, shared_state):
temp_endpoint_with_two_models = self.temp_endpoint_with_two_models(shared_state)
[
temp_endpoint_with_two_models,
model1,
model2,
] = self.temp_endpoint_with_two_models(shared_state)
[deployed_model1, deployed_model2] = list(
map(lambda x: x.id, temp_endpoint_with_two_models.list_models())
)
Expand Down Expand Up @@ -378,3 +399,7 @@ def test_mdm_two_models_invalid_configs_xai(self, shared_state):
"`explanation_config` should only be enabled if the model has `explanation_spec populated"
in str(e.value)
)
temp_endpoint_with_two_models.undeploy_all()
temp_endpoint_with_two_models.delete()
model1.delete()
model2.delete()