Skip to content

Make SupportedHyperParameters optional. #695

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 5 commits into from
Mar 12, 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 @@ -6,6 +6,7 @@ CHANGELOG
======

* feature: ``PipelineModel``: Create a Transformer from a PipelineModel
* bug-fix: ``AlgorithmEstimator``: Make SupportedHyperParameters optional

1.18.4
======
Expand Down
27 changes: 15 additions & 12 deletions src/sagemaker/algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,20 +375,23 @@ def _validate_and_set_default_hyperparameters(self):
raise ValueError('Required hyperparameter: %s is not set' % name)

def _parse_hyperparameters(self):
hyperparameters = self.algorithm_spec['TrainingSpecification']['SupportedHyperParameters']
definitions = {}
for h in hyperparameters:
parameter_type = h['Type']
name = h['Name']
parameter_class, parameter_range = self._hyperparameter_range_and_class(
parameter_type, h
)

definitions[name] = {'spec': h}
if parameter_range:
definitions[name]['range'] = parameter_range
if parameter_class:
definitions[name]['class'] = parameter_class
training_spec = self.algorithm_spec['TrainingSpecification']
if 'SupportedHyperParameters' in training_spec:
hyperparameters = training_spec['SupportedHyperParameters']
for h in hyperparameters:
parameter_type = h['Type']
name = h['Name']
parameter_class, parameter_range = self._hyperparameter_range_and_class(
parameter_type, h
)

definitions[name] = {'spec': h}
if parameter_range:
definitions[name]['range'] = parameter_range
if parameter_class:
definitions[name]['class'] = parameter_class

return definitions

Expand Down
18 changes: 18 additions & 0 deletions tests/unit/test_algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -913,3 +913,21 @@ def test_algorithm_encrypt_inter_container_traffic(sagemaker_session):

encrypt_inter_container_traffic = estimator.encrypt_inter_container_traffic
assert encrypt_inter_container_traffic is True


def test_algorithm_no_required_hyperparameters(sagemaker_session):
some_algo = copy.deepcopy(DESCRIBE_ALGORITHM_RESPONSE)
del some_algo['TrainingSpecification']['SupportedHyperParameters']

sagemaker_session.sagemaker_client.describe_algorithm = Mock(return_value=some_algo)

# Calling AlgorithmEstimator() with unset required hyperparameters
# should fail if they are required.
# Pass training and hyperparameters channels. This should work
assert AlgorithmEstimator(
algorithm_arn='arn:aws:sagemaker:us-east-2:1234:algorithm/scikit-decision-trees',
role='SageMakerRole',
train_instance_type='ml.m4.2xlarge',
train_instance_count=1,
sagemaker_session=sagemaker_session,
)