|
32 | 32 | DATA_DIR = os.path.join(DATA_DIR, "automl", "data")
|
33 | 33 | TRAINING_DATA = os.path.join(DATA_DIR, "iris_training.csv")
|
34 | 34 | TEST_DATA = os.path.join(DATA_DIR, "iris_test.csv")
|
| 35 | +TRANSFORM_DATA = os.path.join(DATA_DIR, "iris_transform.csv") |
35 | 36 | PROBLEM_TYPE = "MultiClassClassification"
|
36 | 37 | BASE_JOB_NAME = "auto-ml"
|
37 | 38 |
|
38 | 39 | # use a succeeded AutoML job to test describe and list candidates method, otherwise tests will run too long
|
39 | 40 | AUTO_ML_JOB_NAME = "python-sdk-integ-test-base-job"
|
| 41 | +DEFAULT_MODEL_NAME = "python-sdk-automl" |
| 42 | + |
40 | 43 |
|
41 | 44 | EXPECTED_DEFAULT_JOB_CONFIG = {
|
42 | 45 | "CompletionCriteria": {"MaxCandidates": 3},
|
@@ -180,6 +183,42 @@ def test_auto_ml_describe_auto_ml_job(sagemaker_session):
|
180 | 183 | assert desc["OutputDataConfig"] == expected_default_output_config
|
181 | 184 |
|
182 | 185 |
|
| 186 | +@pytest.mark.skipif( |
| 187 | + tests.integ.test_region() in tests.integ.NO_AUTO_ML_REGIONS, |
| 188 | + reason="AutoML is not supported in the region yet.", |
| 189 | +) |
| 190 | +def test_auto_ml_attach(sagemaker_session): |
| 191 | + expected_default_input_config = [ |
| 192 | + { |
| 193 | + "DataSource": { |
| 194 | + "S3DataSource": { |
| 195 | + "S3DataType": "S3Prefix", |
| 196 | + "S3Uri": "s3://{}/{}/input/iris_training.csv".format( |
| 197 | + sagemaker_session.default_bucket(), PREFIX |
| 198 | + ), |
| 199 | + } |
| 200 | + }, |
| 201 | + "TargetAttributeName": TARGET_ATTRIBUTE_NAME, |
| 202 | + } |
| 203 | + ] |
| 204 | + expected_default_output_config = { |
| 205 | + "S3OutputPath": "s3://{}/".format(sagemaker_session.default_bucket()) |
| 206 | + } |
| 207 | + |
| 208 | + auto_ml_utils.create_auto_ml_job_if_not_exist(sagemaker_session) |
| 209 | + |
| 210 | + attached_automl_job = AutoML.attach( |
| 211 | + auto_ml_job_name=AUTO_ML_JOB_NAME, sagemaker_session=sagemaker_session |
| 212 | + ) |
| 213 | + attached_desc = attached_automl_job.describe_auto_ml_job() |
| 214 | + assert attached_desc["AutoMLJobName"] == AUTO_ML_JOB_NAME |
| 215 | + assert attached_desc["AutoMLJobStatus"] == "Completed" |
| 216 | + assert isinstance(attached_desc["BestCandidate"], dict) |
| 217 | + assert attached_desc["InputDataConfig"] == expected_default_input_config |
| 218 | + assert attached_desc["AutoMLJobConfig"] == EXPECTED_DEFAULT_JOB_CONFIG |
| 219 | + assert attached_desc["OutputDataConfig"] == expected_default_output_config |
| 220 | + |
| 221 | + |
183 | 222 | @pytest.mark.skipif(
|
184 | 223 | tests.integ.test_region() in tests.integ.NO_AUTO_ML_REGIONS,
|
185 | 224 | reason="AutoML is not supported in the region yet.",
|
@@ -240,6 +279,38 @@ def test_deploy_best_candidate(sagemaker_session, cpu_instance_type):
|
240 | 279 | sagemaker_session.sagemaker_client.delete_endpoint(EndpointName=endpoint_name)
|
241 | 280 |
|
242 | 281 |
|
| 282 | +@pytest.mark.skipif( |
| 283 | + tests.integ.test_region() in tests.integ.NO_AUTO_ML_REGIONS, |
| 284 | + reason="AutoML is not supported in the region yet.", |
| 285 | +) |
| 286 | +def test_create_model_best_candidate(sagemaker_session, cpu_instance_type): |
| 287 | + auto_ml_utils.create_auto_ml_job_if_not_exist(sagemaker_session) |
| 288 | + |
| 289 | + auto_ml = AutoML.attach(auto_ml_job_name=AUTO_ML_JOB_NAME, sagemaker_session=sagemaker_session) |
| 290 | + best_candidate = auto_ml.best_candidate() |
| 291 | + |
| 292 | + with timeout(minutes=5): |
| 293 | + pipeline_model = auto_ml.create_model( |
| 294 | + name=DEFAULT_MODEL_NAME, |
| 295 | + candidate=best_candidate, |
| 296 | + sagemaker_session=sagemaker_session, |
| 297 | + vpc_config=None, |
| 298 | + enable_network_isolation=False, |
| 299 | + model_kms_key=None, |
| 300 | + predictor_cls=None, |
| 301 | + ) |
| 302 | + inputs = sagemaker_session.upload_data( |
| 303 | + path=TRANSFORM_DATA, key_prefix=PREFIX + "/transform_input" |
| 304 | + ) |
| 305 | + pipeline_model.transformer( |
| 306 | + instance_count=1, |
| 307 | + instance_type=cpu_instance_type, |
| 308 | + assemble_with="Line", |
| 309 | + output_path="s3://{}/{}".format(sagemaker_session.default_bucket(), "transform_test"), |
| 310 | + accept="text/csv", |
| 311 | + ).transform(data=inputs, content_type="text/csv", split_type="Line", join_source="Input") |
| 312 | + |
| 313 | + |
243 | 314 | @pytest.mark.skipif(
|
244 | 315 | tests.integ.test_region() in tests.integ.NO_AUTO_ML_REGIONS,
|
245 | 316 | reason="AutoML is not supported in the region yet.",
|
|
0 commit comments