Skip to content

change: separate logs() from attach() #1708

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 6 commits into from
Jul 17, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 7 additions & 1 deletion src/sagemaker/estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -630,9 +630,15 @@ def attach(cls, training_job_name, sagemaker_session=None, model_channel_name="m
sagemaker_session=sagemaker_session, job_name=training_job_name
)
estimator._current_job_name = estimator.latest_training_job.name
estimator.latest_training_job.wait()
estimator.latest_training_job.wait(logs="None")
return estimator

def logs(self):
"""Display the logs for Estimator's training job. If the output is a tty or a Jupyter
Copy link
Contributor

Choose a reason for hiding this comment

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

nit pep-0257: single line, continue with detail after blank line

cell, it will be color-coded based on which instance the log entry is from.
"""
self.sagemaker_session.logs_for_job(self.latest_training_job, wait=True)

def deploy(
self,
initial_instance_count,
Expand Down
21 changes: 21 additions & 0 deletions tests/unit/test_estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,27 @@ def test_attach_framework(sagemaker_session):
assert framework_estimator.enable_network_isolation() is True


def test_attach_no_logs(sagemaker_session):
returned_job_description = RETURNED_JOB_DESCRIPTION.copy()
mock_describe_training_job = Mock(
name="describe_training_job", return_value=returned_job_description
)
sagemaker_session.sagemaker_client.describe_training_job = mock_describe_training_job
Estimator.attach(training_job_name="job", sagemaker_session=sagemaker_session)
sagemaker_session.logs_for_job.assert_not_called()


def test_logs(sagemaker_session):
returned_job_description = RETURNED_JOB_DESCRIPTION.copy()
mock_describe_training_job = Mock(
name="describe_training_job", return_value=returned_job_description
)
Copy link
Contributor

Choose a reason for hiding this comment

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

is this an opportunity for a fixture?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea, there are in total 5 tests using this training job description

sagemaker_session.sagemaker_client.describe_training_job = mock_describe_training_job
estimator = Estimator.attach(training_job_name="job", sagemaker_session=sagemaker_session)
estimator.logs()
sagemaker_session.logs_for_job.assert_called_with(estimator.latest_training_job, wait=True)


def test_attach_without_hyperparameters(sagemaker_session):
returned_job_description = RETURNED_JOB_DESCRIPTION.copy()
del returned_job_description["HyperParameters"]
Expand Down