Skip to content

Commit 875744a

Browse files
authored
fix: set logs to False if wait is False in AutoML (#1585)
1 parent b37b4dc commit 875744a

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

src/sagemaker/automl/automl.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"""A class for SageMaker AutoML Jobs."""
1414
from __future__ import absolute_import
1515

16+
import logging
1617
from six import string_types
1718

1819
from sagemaker import Model, PipelineModel
@@ -21,6 +22,8 @@
2122
from sagemaker.session import Session
2223
from sagemaker.utils import name_from_base
2324

25+
logger = logging.getLogger("sagemaker")
26+
2427

2528
class AutoML(object):
2629
"""A class for creating and interacting with SageMaker AutoML jobs
@@ -78,16 +81,15 @@ def fit(self, inputs=None, wait=True, logs=True, job_name=None):
7881
is stored. Or an AutoMLInput object. If a local path is provided, the dataset will
7982
be uploaded to an S3 location.
8083
wait (bool): Whether the call should wait until the job completes (default: True).
81-
logs (bool): Whether to show the logs produced by the job.
82-
Only meaningful when wait is True (default: True).
84+
logs (bool): Whether to show the logs produced by the job. Only meaningful when wait
85+
is True (default: True). if ``wait`` is False, ``logs`` will be set to False as
86+
well.
8387
job_name (str): Training job name. If not specified, the estimator generates
8488
a default job name, based on the training image name and current timestamp.
8589
"""
86-
if logs and not wait:
87-
raise ValueError(
88-
"""Logs can only be shown if wait is set to True.
89-
Please either set wait to True or set logs to False."""
90-
)
90+
if not wait and logs:
91+
logs = False
92+
logger.warning("Setting logs to False. logs is only meaningful when wait is True.")
9193

9294
# upload data for users if provided local path
9395
# validations are done in _Job._format_inputs_to_input_config

tests/unit/sagemaker/automl/test_auto_ml.py

+11
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,17 @@ def test_auto_ml_only_one_of_problem_type_and_job_objective_provided(sagemaker_s
294294
)
295295

296296

297+
@patch("sagemaker.automl.automl.AutoMLJob.start_new")
298+
def test_auto_ml_fit_set_logs_to_false(start_new, sagemaker_session, caplog):
299+
auto_ml = AutoML(
300+
role=ROLE, target_attribute_name=TARGET_ATTRIBUTE_NAME, sagemaker_session=sagemaker_session
301+
)
302+
inputs = DEFAULT_S3_INPUT_DATA
303+
auto_ml.fit(inputs, job_name=JOB_NAME, wait=False, logs=True)
304+
start_new.wait.assert_not_called()
305+
assert "Setting logs to False. logs is only meaningful when wait is True." in caplog.text
306+
307+
297308
def test_auto_ml_additional_optional_params(sagemaker_session):
298309
auto_ml = AutoML(
299310
role=ROLE,

0 commit comments

Comments
 (0)