26
26
)
27
27
from sagemaker import image_uris
28
28
29
+ JOB_NAME_PREFIX = "my-prefix"
30
+ TIMESTAMP = "2021-06-17-22-29-54-685"
31
+ JOB_NAME = "{}-{}" .format (JOB_NAME_PREFIX , TIMESTAMP )
32
+
29
33
30
34
def test_uri ():
31
35
uri = image_uris .retrieve ("clarify" , "us-west-2" )
@@ -248,6 +252,17 @@ def clarify_processor(sagemaker_session):
248
252
)
249
253
250
254
255
+ @pytest .fixture (scope = "module" )
256
+ def clarify_processor_with_job_name_prefix (sagemaker_session ):
257
+ return SageMakerClarifyProcessor (
258
+ role = "AmazonSageMaker-ExecutionRole" ,
259
+ instance_count = 1 ,
260
+ instance_type = "ml.c5.xlarge" ,
261
+ sagemaker_session = sagemaker_session ,
262
+ job_name_prefix = JOB_NAME_PREFIX ,
263
+ )
264
+
265
+
251
266
@pytest .fixture (scope = "module" )
252
267
def data_config ():
253
268
return DataConfig (
@@ -302,7 +317,14 @@ def shap_config():
302
317
)
303
318
304
319
305
- def test_pre_training_bias (clarify_processor , data_config , data_bias_config ):
320
+ @patch ("sagemaker.utils.name_from_base" , return_value = JOB_NAME )
321
+ def test_pre_training_bias (
322
+ name_from_base ,
323
+ clarify_processor ,
324
+ clarify_processor_with_job_name_prefix ,
325
+ data_config ,
326
+ data_bias_config ,
327
+ ):
306
328
with patch .object (SageMakerClarifyProcessor , "_run" , return_value = None ) as mock_method :
307
329
clarify_processor .run_pre_training_bias (
308
330
data_config ,
@@ -325,7 +347,7 @@ def test_pre_training_bias(clarify_processor, data_config, data_bias_config):
325
347
"group_variable" : "F2" ,
326
348
"methods" : {"pre_training_bias" : {"methods" : "all" }},
327
349
}
328
- mock_method .assert_called_once_with (
350
+ mock_method .assert_called_with (
329
351
data_config ,
330
352
expected_analysis_config ,
331
353
True ,
@@ -334,10 +356,33 @@ def test_pre_training_bias(clarify_processor, data_config, data_bias_config):
334
356
None ,
335
357
{"ExperimentName" : "AnExperiment" },
336
358
)
359
+ clarify_processor_with_job_name_prefix .run_pre_training_bias (
360
+ data_config ,
361
+ data_bias_config ,
362
+ wait = True ,
363
+ experiment_config = {"ExperimentName" : "AnExperiment" },
364
+ )
365
+ name_from_base .assert_called_with (JOB_NAME_PREFIX )
366
+ mock_method .assert_called_with (
367
+ data_config ,
368
+ expected_analysis_config ,
369
+ True ,
370
+ True ,
371
+ JOB_NAME ,
372
+ None ,
373
+ {"ExperimentName" : "AnExperiment" },
374
+ )
337
375
338
376
377
+ @patch ("sagemaker.utils.name_from_base" , return_value = JOB_NAME )
339
378
def test_post_training_bias (
340
- clarify_processor , data_config , data_bias_config , model_config , model_predicted_label_config
379
+ name_from_base ,
380
+ clarify_processor ,
381
+ clarify_processor_with_job_name_prefix ,
382
+ data_config ,
383
+ data_bias_config ,
384
+ model_config ,
385
+ model_predicted_label_config ,
341
386
):
342
387
with patch .object (SageMakerClarifyProcessor , "_run" , return_value = None ) as mock_method :
343
388
clarify_processor .run_post_training_bias (
@@ -368,7 +413,7 @@ def test_post_training_bias(
368
413
"initial_instance_count" : 1 ,
369
414
},
370
415
}
371
- mock_method .assert_called_once_with (
416
+ mock_method .assert_called_with (
372
417
data_config ,
373
418
expected_analysis_config ,
374
419
True ,
@@ -377,9 +422,35 @@ def test_post_training_bias(
377
422
None ,
378
423
{"ExperimentName" : "AnExperiment" },
379
424
)
425
+ clarify_processor_with_job_name_prefix .run_post_training_bias (
426
+ data_config ,
427
+ data_bias_config ,
428
+ model_config ,
429
+ model_predicted_label_config ,
430
+ wait = True ,
431
+ experiment_config = {"ExperimentName" : "AnExperiment" },
432
+ )
433
+ name_from_base .assert_called_with (JOB_NAME_PREFIX )
434
+ mock_method .assert_called_with (
435
+ data_config ,
436
+ expected_analysis_config ,
437
+ True ,
438
+ True ,
439
+ JOB_NAME ,
440
+ None ,
441
+ {"ExperimentName" : "AnExperiment" },
442
+ )
380
443
381
444
382
- def test_shap (clarify_processor , data_config , model_config , shap_config ):
445
+ @patch ("sagemaker.utils.name_from_base" , return_value = JOB_NAME )
446
+ def test_shap (
447
+ name_from_base ,
448
+ clarify_processor ,
449
+ clarify_processor_with_job_name_prefix ,
450
+ data_config ,
451
+ model_config ,
452
+ shap_config ,
453
+ ):
383
454
with patch .object (SageMakerClarifyProcessor , "_run" , return_value = None ) as mock_method :
384
455
clarify_processor .run_explainability (
385
456
data_config ,
@@ -420,7 +491,7 @@ def test_shap(clarify_processor, data_config, model_config, shap_config):
420
491
"initial_instance_count" : 1 ,
421
492
},
422
493
}
423
- mock_method .assert_called_once_with (
494
+ mock_method .assert_called_with (
424
495
data_config ,
425
496
expected_analysis_config ,
426
497
True ,
@@ -429,3 +500,21 @@ def test_shap(clarify_processor, data_config, model_config, shap_config):
429
500
None ,
430
501
{"ExperimentName" : "AnExperiment" },
431
502
)
503
+ clarify_processor_with_job_name_prefix .run_explainability (
504
+ data_config ,
505
+ model_config ,
506
+ shap_config ,
507
+ model_scores = None ,
508
+ wait = True ,
509
+ experiment_config = {"ExperimentName" : "AnExperiment" },
510
+ )
511
+ name_from_base .assert_called_with (JOB_NAME_PREFIX )
512
+ mock_method .assert_called_with (
513
+ data_config ,
514
+ expected_analysis_config ,
515
+ True ,
516
+ True ,
517
+ JOB_NAME ,
518
+ None ,
519
+ {"ExperimentName" : "AnExperiment" },
520
+ )
0 commit comments