39
39
BASE_JOB_NAME = "auto-ml"
40
40
MODE = "ENSEMBLING"
41
41
42
- # use a succeeded AutoML job to test describe and list candidates method, otherwise tests will run too long
43
- AUTO_ML_JOB_NAME = "python-sdk-integ-test-base-automl-job"
44
42
DEFAULT_MODEL_NAME = "python-sdk-automl"
45
43
46
44
50
48
}
51
49
52
50
51
+ # use a succeeded AutoML job to test describe and list candidates method, otherwise tests will run too long
52
+ # reusable-job will be created once if it doesn't exist, and be reused in relevant tests.
53
+ @pytest .fixture (scope = "module" )
54
+ def reusable_job_name ():
55
+ job_name = unique_name_from_base ("reusable-job" , max_length = 32 )
56
+ return job_name
57
+
58
+
53
59
@pytest .mark .slow_test
54
60
@pytest .mark .skipif (
55
61
tests .integ .test_region () in tests .integ .NO_AUTO_ML_REGIONS ,
@@ -64,7 +70,7 @@ def test_auto_ml_fit(sagemaker_session):
64
70
max_candidates = 1 ,
65
71
)
66
72
67
- job_name = unique_name_from_base ("auto-ml" , max_length = 32 )
73
+ job_name = unique_name_from_base (BASE_JOB_NAME , max_length = 32 )
68
74
inputs = sagemaker_session .upload_data (path = TRAINING_DATA , key_prefix = PREFIX + "/input" )
69
75
with timeout (minutes = AUTO_ML_DEFAULT_TIMEMOUT_MINUTES ):
70
76
auto_ml .fit (inputs , job_name = job_name )
@@ -83,7 +89,7 @@ def test_auto_ml_fit_local_input(sagemaker_session):
83
89
)
84
90
85
91
inputs = TRAINING_DATA
86
- job_name = unique_name_from_base ("auto-ml" , max_length = 32 )
92
+ job_name = unique_name_from_base (BASE_JOB_NAME , max_length = 32 )
87
93
with timeout (minutes = AUTO_ML_DEFAULT_TIMEMOUT_MINUTES ):
88
94
auto_ml .fit (inputs , job_name = job_name )
89
95
@@ -100,7 +106,7 @@ def test_auto_ml_input_object_fit(sagemaker_session):
100
106
max_candidates = 1 ,
101
107
generate_candidate_definitions_only = True ,
102
108
)
103
- job_name = unique_name_from_base ("auto-ml" , max_length = 32 )
109
+ job_name = unique_name_from_base (BASE_JOB_NAME , max_length = 32 )
104
110
s3_input = sagemaker_session .upload_data (path = TRAINING_DATA , key_prefix = PREFIX + "/input" )
105
111
inputs = AutoMLInput (inputs = s3_input , target_attribute_name = TARGET_ATTRIBUTE_NAME )
106
112
with timeout (minutes = AUTO_ML_DEFAULT_TIMEMOUT_MINUTES ):
@@ -119,7 +125,7 @@ def test_auto_ml_input_object_list_fit(sagemaker_session):
119
125
max_candidates = 1 ,
120
126
mode = MODE ,
121
127
)
122
- job_name = unique_name_from_base ("auto-ml" , max_length = 32 )
128
+ job_name = unique_name_from_base (BASE_JOB_NAME , max_length = 32 )
123
129
s3_input_training = sagemaker_session .upload_data (
124
130
path = TRAINING_DATA , key_prefix = PREFIX + "/input"
125
131
)
@@ -179,7 +185,7 @@ def test_auto_ml_invalid_target_attribute(sagemaker_session):
179
185
auto_ml = AutoML (
180
186
role = ROLE , target_attribute_name = "y" , sagemaker_session = sagemaker_session , max_candidates = 1
181
187
)
182
- job_name = unique_name_from_base ("auto-ml" , max_length = 32 )
188
+ job_name = unique_name_from_base (BASE_JOB_NAME , max_length = 32 )
183
189
inputs = sagemaker_session .upload_data (path = TRAINING_DATA , key_prefix = PREFIX + "/input" )
184
190
with pytest .raises (
185
191
ClientError ,
@@ -193,7 +199,7 @@ def test_auto_ml_invalid_target_attribute(sagemaker_session):
193
199
tests .integ .test_region () in tests .integ .NO_AUTO_ML_REGIONS ,
194
200
reason = "AutoML is not supported in the region yet." ,
195
201
)
196
- def test_auto_ml_describe_auto_ml_job (sagemaker_session ):
202
+ def test_auto_ml_describe_auto_ml_job (sagemaker_session , reusable_job_name ):
197
203
expected_default_input_config = [
198
204
{
199
205
"DataSource" : {
@@ -215,13 +221,13 @@ def test_auto_ml_describe_auto_ml_job(sagemaker_session):
215
221
)
216
222
}
217
223
218
- auto_ml_utils .create_auto_ml_job_if_not_exist (sagemaker_session )
224
+ auto_ml_utils .create_auto_ml_job_if_not_exist (sagemaker_session , reusable_job_name )
219
225
auto_ml = AutoML (
220
226
role = ROLE , target_attribute_name = TARGET_ATTRIBUTE_NAME , sagemaker_session = sagemaker_session
221
227
)
222
228
223
- desc = auto_ml .describe_auto_ml_job (job_name = AUTO_ML_JOB_NAME )
224
- assert desc ["AutoMLJobName" ] == AUTO_ML_JOB_NAME
229
+ desc = auto_ml .describe_auto_ml_job (job_name = reusable_job_name )
230
+ assert desc ["AutoMLJobName" ] == reusable_job_name
225
231
assert desc ["AutoMLJobStatus" ] == "Completed"
226
232
assert isinstance (desc ["BestCandidate" ], dict )
227
233
assert desc ["InputDataConfig" ] == expected_default_input_config
@@ -233,7 +239,7 @@ def test_auto_ml_describe_auto_ml_job(sagemaker_session):
233
239
tests .integ .test_region () in tests .integ .NO_AUTO_ML_REGIONS ,
234
240
reason = "AutoML is not supported in the region yet." ,
235
241
)
236
- def test_auto_ml_attach (sagemaker_session ):
242
+ def test_auto_ml_attach (sagemaker_session , reusable_job_name ):
237
243
expected_default_input_config = [
238
244
{
239
245
"DataSource" : {
@@ -255,13 +261,13 @@ def test_auto_ml_attach(sagemaker_session):
255
261
)
256
262
}
257
263
258
- auto_ml_utils .create_auto_ml_job_if_not_exist (sagemaker_session )
264
+ auto_ml_utils .create_auto_ml_job_if_not_exist (sagemaker_session , reusable_job_name )
259
265
260
266
attached_automl_job = AutoML .attach (
261
- auto_ml_job_name = AUTO_ML_JOB_NAME , sagemaker_session = sagemaker_session
267
+ auto_ml_job_name = reusable_job_name , sagemaker_session = sagemaker_session
262
268
)
263
269
attached_desc = attached_automl_job .describe_auto_ml_job ()
264
- assert attached_desc ["AutoMLJobName" ] == AUTO_ML_JOB_NAME
270
+ assert attached_desc ["AutoMLJobName" ] == reusable_job_name
265
271
assert attached_desc ["AutoMLJobStatus" ] == "Completed"
266
272
assert isinstance (attached_desc ["BestCandidate" ], dict )
267
273
assert attached_desc ["InputDataConfig" ] == expected_default_input_config
@@ -273,28 +279,28 @@ def test_auto_ml_attach(sagemaker_session):
273
279
tests .integ .test_region () in tests .integ .NO_AUTO_ML_REGIONS ,
274
280
reason = "AutoML is not supported in the region yet." ,
275
281
)
276
- def test_list_candidates (sagemaker_session ):
277
- auto_ml_utils .create_auto_ml_job_if_not_exist (sagemaker_session )
282
+ def test_list_candidates (sagemaker_session , reusable_job_name ):
283
+ auto_ml_utils .create_auto_ml_job_if_not_exist (sagemaker_session , reusable_job_name )
278
284
279
285
auto_ml = AutoML (
280
286
role = ROLE , target_attribute_name = TARGET_ATTRIBUTE_NAME , sagemaker_session = sagemaker_session
281
287
)
282
288
283
- candidates = auto_ml .list_candidates (job_name = AUTO_ML_JOB_NAME )
289
+ candidates = auto_ml .list_candidates (job_name = reusable_job_name )
284
290
assert len (candidates ) == 3
285
291
286
292
287
293
@pytest .mark .skipif (
288
294
tests .integ .test_region () in tests .integ .NO_AUTO_ML_REGIONS ,
289
295
reason = "AutoML is not supported in the region yet." ,
290
296
)
291
- def test_best_candidate (sagemaker_session ):
292
- auto_ml_utils .create_auto_ml_job_if_not_exist (sagemaker_session )
297
+ def test_best_candidate (sagemaker_session , reusable_job_name ):
298
+ auto_ml_utils .create_auto_ml_job_if_not_exist (sagemaker_session , reusable_job_name )
293
299
294
300
auto_ml = AutoML (
295
301
role = ROLE , target_attribute_name = TARGET_ATTRIBUTE_NAME , sagemaker_session = sagemaker_session
296
302
)
297
- best_candidate = auto_ml .best_candidate (job_name = AUTO_ML_JOB_NAME )
303
+ best_candidate = auto_ml .best_candidate (job_name = reusable_job_name )
298
304
assert len (best_candidate ["InferenceContainers" ]) == 3
299
305
assert len (best_candidate ["CandidateSteps" ]) == 4
300
306
assert best_candidate ["CandidateStatus" ] == "Completed"
@@ -305,13 +311,13 @@ def test_best_candidate(sagemaker_session):
305
311
reason = "AutoML is not supported in the region yet." ,
306
312
)
307
313
@pytest .mark .release
308
- def test_deploy_best_candidate (sagemaker_session , cpu_instance_type ):
309
- auto_ml_utils .create_auto_ml_job_if_not_exist (sagemaker_session )
314
+ def test_deploy_best_candidate (sagemaker_session , cpu_instance_type , reusable_job_name ):
315
+ auto_ml_utils .create_auto_ml_job_if_not_exist (sagemaker_session , reusable_job_name )
310
316
311
317
auto_ml = AutoML (
312
318
role = ROLE , target_attribute_name = TARGET_ATTRIBUTE_NAME , sagemaker_session = sagemaker_session
313
319
)
314
- best_candidate = auto_ml .best_candidate (job_name = AUTO_ML_JOB_NAME )
320
+ best_candidate = auto_ml .best_candidate (job_name = reusable_job_name )
315
321
endpoint_name = unique_name_from_base ("sagemaker-auto-ml-best-candidate-test" )
316
322
317
323
with timeout (minutes = AUTO_ML_DEFAULT_TIMEMOUT_MINUTES ):
@@ -336,14 +342,14 @@ def test_deploy_best_candidate(sagemaker_session, cpu_instance_type):
336
342
@pytest .mark .skip (
337
343
reason = "" ,
338
344
)
339
- def test_candidate_estimator_default_rerun_and_deploy (sagemaker_session , cpu_instance_type ):
340
- auto_ml_utils .create_auto_ml_job_if_not_exist (sagemaker_session )
345
+ def test_candidate_estimator_default_rerun_and_deploy (sagemaker_session , cpu_instance_type , reusable_job_name ):
346
+ auto_ml_utils .create_auto_ml_job_if_not_exist (sagemaker_session , reusable_job_name )
341
347
342
348
auto_ml = AutoML (
343
349
role = ROLE , target_attribute_name = TARGET_ATTRIBUTE_NAME , sagemaker_session = sagemaker_session
344
350
)
345
351
346
- candidates = auto_ml .list_candidates (job_name = AUTO_ML_JOB_NAME )
352
+ candidates = auto_ml .list_candidates (job_name = reusable_job_name )
347
353
candidate = candidates [1 ]
348
354
349
355
candidate_estimator = CandidateEstimator (candidate , sagemaker_session )
@@ -369,13 +375,13 @@ def test_candidate_estimator_default_rerun_and_deploy(sagemaker_session, cpu_ins
369
375
tests .integ .test_region () in tests .integ .NO_AUTO_ML_REGIONS ,
370
376
reason = "AutoML is not supported in the region yet." ,
371
377
)
372
- def test_candidate_estimator_get_steps (sagemaker_session ):
373
- auto_ml_utils .create_auto_ml_job_if_not_exist (sagemaker_session )
378
+ def test_candidate_estimator_get_steps (sagemaker_session , reusable_job_name ):
379
+ auto_ml_utils .create_auto_ml_job_if_not_exist (sagemaker_session , reusable_job_name )
374
380
375
381
auto_ml = AutoML (
376
382
role = ROLE , target_attribute_name = TARGET_ATTRIBUTE_NAME , sagemaker_session = sagemaker_session
377
383
)
378
- candidates = auto_ml .list_candidates (job_name = AUTO_ML_JOB_NAME )
384
+ candidates = auto_ml .list_candidates (job_name = reusable_job_name )
379
385
candidate = candidates [1 ]
380
386
381
387
candidate_estimator = CandidateEstimator (candidate , sagemaker_session )
0 commit comments