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