31
31
32
32
# constants used for testing
33
33
34
- PERMANENT_CHURN_ENDPOINT_ID = "1843089351408353280 "
34
+ PERMANENT_CHURN_MODEL_ID = "5295507484113371136 "
35
35
CHURN_MODEL_PATH = "gs://mco-mm/churn"
36
36
DEFAULT_INPUT = {
37
37
"cnt_ad_reward" : 0 ,
117
117
objective_config2 = model_monitoring .ObjectiveConfig (skew_config , drift_config2 )
118
118
119
119
120
+ @pytest .mark .usefixtures ("tear_down_resources" )
120
121
class TestModelDeploymentMonitoring (e2e_base .TestEndToEnd ):
121
122
_temp_prefix = "temp_e2e_model_monitoring_test_"
122
- aiplatform .init (project = e2e_base ._PROJECT , location = e2e_base ._LOCATION )
123
- endpoint = aiplatform .Endpoint (PERMANENT_CHURN_ENDPOINT_ID )
124
123
125
- def test_mdm_two_models_one_valid_config (self ):
124
+ def test_create_endpoint (self , shared_state ):
125
+ # initial setup
126
+ aiplatform .init (project = e2e_base ._PROJECT , location = e2e_base ._LOCATION )
127
+ self .endpoint = aiplatform .Endpoint .create (self ._make_display_name ("endpoint" ))
128
+ shared_state ["resources" ] = [self .endpoint ]
129
+ self .model = aiplatform .Model (PERMANENT_CHURN_MODEL_ID )
130
+ self .endpoint .deploy (self .model )
131
+ self .endpoint .deploy (self .model , traffic_percentage = 50 )
132
+
133
+ def test_mdm_two_models_one_valid_config (self , shared_state ):
126
134
"""
127
135
Enable model monitoring on two existing models deployed to the same endpoint.
128
136
"""
137
+ assert len (shared_state ["resources" ]) == 1
138
+ self .endpoint = shared_state ["resources" ][0 ]
139
+ aiplatform .init (project = e2e_base ._PROJECT , location = e2e_base ._LOCATION )
129
140
# test model monitoring configurations
130
141
job = aiplatform .ModelDeploymentMonitoringJob .create (
131
142
display_name = self ._make_display_name (key = JOB_NAME ),
@@ -153,6 +164,7 @@ def test_mdm_two_models_one_valid_config(self):
153
164
== [USER_EMAIL ]
154
165
)
155
166
assert gapic_job .model_monitoring_alert_config .enable_logging
167
+ assert len (gapic_job .model_deployment_monitoring_objective_configs ) == 2
156
168
157
169
gca_obj_config = gapic_job .model_deployment_monitoring_objective_configs [
158
170
0
@@ -181,8 +193,11 @@ def test_mdm_two_models_one_valid_config(self):
181
193
with pytest .raises (core_exceptions .NotFound ):
182
194
job .api_client .get_model_deployment_monitoring_job (name = job_resource )
183
195
184
- def test_mdm_pause_and_update_config (self ):
196
+ def test_mdm_pause_and_update_config (self , shared_state ):
185
197
"""Test objective config updates for existing MDM job"""
198
+ assert len (shared_state ["resources" ]) == 1
199
+ self .endpoint = shared_state ["resources" ][0 ]
200
+ aiplatform .init (project = e2e_base ._PROJECT , location = e2e_base ._LOCATION )
186
201
job = aiplatform .ModelDeploymentMonitoringJob .create (
187
202
display_name = self ._make_display_name (key = JOB_NAME ),
188
203
logging_sampling_strategy = sampling_strategy ,
@@ -245,7 +260,10 @@ def test_mdm_pause_and_update_config(self):
245
260
with pytest .raises (core_exceptions .NotFound ):
246
261
job .state
247
262
248
- def test_mdm_two_models_two_valid_configs (self ):
263
+ def test_mdm_two_models_two_valid_configs (self , shared_state ):
264
+ assert len (shared_state ["resources" ]) == 1
265
+ self .endpoint = shared_state ["resources" ][0 ]
266
+ aiplatform .init (project = e2e_base ._PROJECT , location = e2e_base ._LOCATION )
249
267
[deployed_model1 , deployed_model2 ] = list (
250
268
map (lambda x : x .id , self .endpoint .list_models ())
251
269
)
@@ -302,7 +320,10 @@ def test_mdm_two_models_two_valid_configs(self):
302
320
303
321
job .delete ()
304
322
305
- def test_mdm_invalid_config_incorrect_model_id (self ):
323
+ def test_mdm_invalid_config_incorrect_model_id (self , shared_state ):
324
+ assert len (shared_state ["resources" ]) == 1
325
+ self .endpoint = shared_state ["resources" ][0 ]
326
+ aiplatform .init (project = e2e_base ._PROJECT , location = e2e_base ._LOCATION )
306
327
with pytest .raises (ValueError ) as e :
307
328
aiplatform .ModelDeploymentMonitoringJob .create (
308
329
display_name = self ._make_display_name (key = JOB_NAME ),
@@ -318,7 +339,10 @@ def test_mdm_invalid_config_incorrect_model_id(self):
318
339
)
319
340
assert "Invalid model ID" in str (e .value )
320
341
321
- def test_mdm_invalid_config_xai (self ):
342
+ def test_mdm_invalid_config_xai (self , shared_state ):
343
+ assert len (shared_state ["resources" ]) == 1
344
+ self .endpoint = shared_state ["resources" ][0 ]
345
+ aiplatform .init (project = e2e_base ._PROJECT , location = e2e_base ._LOCATION )
322
346
with pytest .raises (RuntimeError ) as e :
323
347
objective_config .explanation_config = model_monitoring .ExplanationConfig ()
324
348
aiplatform .ModelDeploymentMonitoringJob .create (
@@ -337,7 +361,10 @@ def test_mdm_invalid_config_xai(self):
337
361
in str (e .value )
338
362
)
339
363
340
- def test_mdm_two_models_invalid_configs_xai (self ):
364
+ def test_mdm_two_models_invalid_configs_xai (self , shared_state ):
365
+ assert len (shared_state ["resources" ]) == 1
366
+ self .endpoint = shared_state ["resources" ][0 ]
367
+ aiplatform .init (project = e2e_base ._PROJECT , location = e2e_base ._LOCATION )
341
368
[deployed_model1 , deployed_model2 ] = list (
342
369
map (lambda x : x .id , self .endpoint .list_models ())
343
370
)
0 commit comments