-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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) | ||
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) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ | |
|
||
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 | ||
|
@@ -38,7 +38,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 = [ | ||
{ | ||
|
@@ -62,6 +62,11 @@ | |
} | ||
|
||
|
||
@pytest.fixture(scope="module", autouse=True) | ||
def create_auto_ml_job_if_not_exist(sagemaker_session): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what test is using this fixture? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This fixture is autouse, all test methods in the class will use this fixture without a need to state it in the test function signature. But now a second thought made me realized not all tests in the class are using this fixture, I will apply it to individual tests. |
||
auto_ml_utils.create_auto_ml_job_if_not_exist(sagemaker_session) | ||
|
||
|
||
def test_auto_ml_fit(sagemaker_session): | ||
auto_ml = AutoML( | ||
role=ROLE, | ||
|
There was a problem hiding this comment.
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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!