Skip to content

fix: create auto ml job for tests that based on existing job #1151

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tests/integ/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@

NO_LDA_REGIONS = ["eu-west-3", "eu-north-1", "sa-east-1", "ap-east-1", "me-south-1"]
NO_MARKET_PLACE_REGIONS = ["eu-west-3", "eu-north-1", "sa-east-1", "ap-east-1", "me-south-1"]
NO_AUTO_ML_REGIONS = ["sa-east-1", "me-south-1", "ap-east-1", "eu-west-3"]

EFS_TEST_ENABLED_REGION = []

Expand Down
42 changes: 42 additions & 0 deletions tests/integ/auto_ml_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
from __future__ import absolute_import

import os

from sagemaker import AutoML
from tests.integ import DATA_DIR, AUTO_ML_DEFAULT_TIMEMOUT_MINUTES
from tests.integ.timeout import timeout

ROLE = "SageMakerRole"
DATA_DIR = os.path.join(DATA_DIR, "automl", "data")
PREFIX = "sagemaker/beta-automl-xgboost"
TRAINING_DATA = os.path.join(DATA_DIR, "iris_training.csv")
TARGET_ATTRIBUTE_NAME = "virginica"


def create_auto_ml_job_if_not_exist(sagemaker_session):
auto_ml_job_name = "python-sdk-integ-test-base-job"
auto_ml = AutoML(
role=ROLE,
target_attribute_name=TARGET_ATTRIBUTE_NAME,
sagemaker_session=sagemaker_session,
max_candidates=3,
)

try:
auto_ml.describe_auto_ml_job(job_name=auto_ml_job_name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't fix it as part of this PR, but we should have a session method for this if the base object isn't needed. Feel free to chat in person if I'm missing something.

i.e.:
session.describe_auto_ml_job(job_name)

Meaning that, if we don't need anything from the object, we should just use a session method.

Copy link
Contributor Author

@chuyang-deng chuyang-deng Dec 5, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it! Thanks! Yes a session method doing that makes more sense!

except Exception as e: # noqa: F841
inputs = sagemaker_session.upload_data(path=TRAINING_DATA, key_prefix=PREFIX + "/input")
with timeout(minutes=AUTO_ML_DEFAULT_TIMEMOUT_MINUTES):
auto_ml.fit(inputs, job_name=auto_ml_job_name)
67 changes: 65 additions & 2 deletions tests/integ/test_auto_ml.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
import time

import pytest
import tests.integ
from sagemaker import AutoML, CandidateEstimator, AutoMLInput

from sagemaker.exceptions import UnexpectedStatusException
from sagemaker.utils import unique_name_from_base
from tests.integ import DATA_DIR, AUTO_ML_DEFAULT_TIMEMOUT_MINUTES
from tests.integ import DATA_DIR, AUTO_ML_DEFAULT_TIMEMOUT_MINUTES, auto_ml_utils
from tests.integ.timeout import timeout

DEV_ACCOUNT = 142577830533
Expand All @@ -38,7 +39,7 @@
JOB_NAME = "auto-ml-{}".format(time.strftime("%y%m%d-%H%M%S"))

# use a succeeded AutoML job to test describe and list candidates method, otherwise tests will run too long
AUTO_ML_JOB_NAME = "sagemaker-auto-gamma-ml-test"
AUTO_ML_JOB_NAME = "python-sdk-integ-test-base-job"

EXPECTED_DEFAULT_INPUT_CONFIG = [
{
Expand All @@ -62,6 +63,10 @@
}


@pytest.mark.skipif(
tests.integ.test_region() in tests.integ.NO_AUTO_ML_REGIONS,
reason="AutoML is not supported in the region yet.",
)
def test_auto_ml_fit(sagemaker_session):
auto_ml = AutoML(
role=ROLE,
Expand All @@ -75,6 +80,10 @@ def test_auto_ml_fit(sagemaker_session):
auto_ml.fit(inputs)


@pytest.mark.skipif(
tests.integ.test_region() in tests.integ.NO_AUTO_ML_REGIONS,
reason="AutoML is not supported in the region yet.",
)
def test_auto_ml_fit_local_input(sagemaker_session):
auto_ml = AutoML(
role=ROLE,
Expand All @@ -88,6 +97,10 @@ def test_auto_ml_fit_local_input(sagemaker_session):
auto_ml.fit(inputs)


@pytest.mark.skipif(
tests.integ.test_region() in tests.integ.NO_AUTO_ML_REGIONS,
reason="AutoML is not supported in the region yet.",
)
def test_auto_ml_input_object_fit(sagemaker_session):
auto_ml = AutoML(
role=ROLE,
Expand All @@ -101,6 +114,10 @@ def test_auto_ml_input_object_fit(sagemaker_session):
auto_ml.fit(inputs)


@pytest.mark.skipif(
tests.integ.test_region() in tests.integ.NO_AUTO_ML_REGIONS,
reason="AutoML is not supported in the region yet.",
)
def test_auto_ml_fit_optional_args(sagemaker_session):
output_path = "s3://sagemaker-us-east-2-{}/{}".format(DEV_ACCOUNT, "specified_ouput_path")
problem_type = "MulticlassClassification"
Expand All @@ -126,6 +143,10 @@ def test_auto_ml_fit_optional_args(sagemaker_session):
assert auto_ml_desc["OutputDataConfig"]["S3OutputPath"] == output_path


@pytest.mark.skipif(
tests.integ.test_region() in tests.integ.NO_AUTO_ML_REGIONS,
reason="AutoML is not supported in the region yet.",
)
def test_auto_ml_invalid_target_attribute(sagemaker_session):
auto_ml = AutoML(
role=ROLE, target_attribute_name="y", sagemaker_session=sagemaker_session, max_candidates=1
Expand All @@ -137,7 +158,13 @@ def test_auto_ml_invalid_target_attribute(sagemaker_session):
auto_ml.fit(inputs)


@pytest.mark.skipif(
tests.integ.test_region() in tests.integ.NO_AUTO_ML_REGIONS,
reason="AutoML is not supported in the region yet.",
)
def test_auto_ml_describe_auto_ml_job(sagemaker_session):
auto_ml_utils.create_auto_ml_job_if_not_exist(sagemaker_session)

auto_ml = AutoML(
role=ROLE, target_attribute_name=TARGET_ATTRIBUTE_NAME, sagemaker_session=sagemaker_session
)
Expand All @@ -151,7 +178,13 @@ def test_auto_ml_describe_auto_ml_job(sagemaker_session):
assert desc["OutputDataConfig"] == EXPECTED_DEFAULT_OUTPUT_CONFIG


@pytest.mark.skipif(
tests.integ.test_region() in tests.integ.NO_AUTO_ML_REGIONS,
reason="AutoML is not supported in the region yet.",
)
def test_list_candidates(sagemaker_session):
auto_ml_utils.create_auto_ml_job_if_not_exist(sagemaker_session)

auto_ml = AutoML(
role=ROLE, target_attribute_name=TARGET_ATTRIBUTE_NAME, sagemaker_session=sagemaker_session
)
Expand All @@ -160,7 +193,13 @@ def test_list_candidates(sagemaker_session):
assert len(candidates) == 3


@pytest.mark.skipif(
tests.integ.test_region() in tests.integ.NO_AUTO_ML_REGIONS,
reason="AutoML is not supported in the region yet.",
)
def test_best_candidate(sagemaker_session):
auto_ml_utils.create_auto_ml_job_if_not_exist(sagemaker_session)

auto_ml = AutoML(
role=ROLE, target_attribute_name=TARGET_ATTRIBUTE_NAME, sagemaker_session=sagemaker_session
)
Expand All @@ -170,7 +209,13 @@ def test_best_candidate(sagemaker_session):
assert best_candidate["CandidateStatus"] == "Completed"


@pytest.mark.skipif(
tests.integ.test_region() in tests.integ.NO_AUTO_ML_REGIONS,
reason="AutoML is not supported in the region yet.",
)
def test_deploy_best_candidate(sagemaker_session):
auto_ml_utils.create_auto_ml_job_if_not_exist(sagemaker_session)

auto_ml = AutoML(
role=ROLE, target_attribute_name=TARGET_ATTRIBUTE_NAME, sagemaker_session=sagemaker_session
)
Expand All @@ -192,7 +237,13 @@ def test_deploy_best_candidate(sagemaker_session):
sagemaker_session.sagemaker_client.delete_endpoint(EndpointName=endpoint_name)


@pytest.mark.skipif(
tests.integ.test_region() in tests.integ.NO_AUTO_ML_REGIONS,
reason="AutoML is not supported in the region yet.",
)
def test_candidate_estimator_default_rerun_and_deploy(sagemaker_session):
auto_ml_utils.create_auto_ml_job_if_not_exist(sagemaker_session)

auto_ml = AutoML(
role=ROLE, target_attribute_name=TARGET_ATTRIBUTE_NAME, sagemaker_session=sagemaker_session
)
Expand All @@ -219,7 +270,13 @@ def test_candidate_estimator_default_rerun_and_deploy(sagemaker_session):
sagemaker_session.sagemaker_client.delete_endpoint(EndpointName=endpoint_name)


@pytest.mark.skipif(
tests.integ.test_region() in tests.integ.NO_AUTO_ML_REGIONS,
reason="AutoML is not supported in the region yet.",
)
def test_candidate_estimator_rerun_with_optional_args(sagemaker_session):
auto_ml_utils.create_auto_ml_job_if_not_exist(sagemaker_session)

auto_ml = AutoML(
role=ROLE, target_attribute_name=TARGET_ATTRIBUTE_NAME, sagemaker_session=sagemaker_session
)
Expand All @@ -246,7 +303,13 @@ def test_candidate_estimator_rerun_with_optional_args(sagemaker_session):
sagemaker_session.sagemaker_client.delete_endpoint(EndpointName=endpoint_name)


@pytest.mark.skipif(
tests.integ.test_region() in tests.integ.NO_AUTO_ML_REGIONS,
reason="AutoML is not supported in the region yet.",
)
def test_candidate_estimator_get_steps(sagemaker_session):
auto_ml_utils.create_auto_ml_job_if_not_exist(sagemaker_session)

auto_ml = AutoML(
role=ROLE, target_attribute_name=TARGET_ATTRIBUTE_NAME, sagemaker_session=sagemaker_session
)
Expand Down