Skip to content

Estimator.attach should work with a job without hps #665

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 1 commit into from
Feb 26, 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 CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ CHANGELOG
* doc-fix: Remove incorrect parameter for EI TFS Python README
* feature: ``Predictor``: delete SageMaker model
* feature: ``Pipeline``: delete SageMaker model
* bug-fix: Estimator.attach works with training jobs without hyperparameters

1.18.3.post1
============
Expand Down
4 changes: 3 additions & 1 deletion src/sagemaker/estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,9 @@ def _prepare_init_params_from_job_description(cls, job_details, model_channel_na
init_params['output_path'] = job_details['OutputDataConfig']['S3OutputPath']
init_params['output_kms_key'] = job_details['OutputDataConfig']['KmsKeyId']

init_params['hyperparameters'] = job_details['HyperParameters']
has_hps = 'HyperParameters' in job_details
init_params['hyperparameters'] = job_details['HyperParameters'] if has_hps else {}

if 'TrainingImage' in job_details['AlgorithmSpecification']:
init_params['image'] = job_details['AlgorithmSpecification']['TrainingImage']
elif 'AlgorithmName' in job_details['AlgorithmSpecification']:
Expand Down
14 changes: 14 additions & 0 deletions tests/unit/test_estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,20 @@ def test_attach_framework(sagemaker_session):
assert framework_estimator.encrypt_inter_container_traffic is False


def test_attach_without_hyperparameters(sagemaker_session):
returned_job_description = RETURNED_JOB_DESCRIPTION.copy()
del returned_job_description['HyperParameters']

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 = Estimator.attach(training_job_name='job',
sagemaker_session=sagemaker_session)

assert estimator.hyperparameters() == {}


def test_attach_framework_with_tuning(sagemaker_session):
returned_job_description = RETURNED_JOB_DESCRIPTION.copy()
returned_job_description['HyperParameters']['_tuning_objective_metric'] = 'Validation-accuracy'
Expand Down