Skip to content

Add SageMaker integ test for hyperparameter tuning model_dir logic #183

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 3 commits into from
Apr 25, 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
7 changes: 3 additions & 4 deletions docker/1.12.0/Dockerfile.gpu
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,11 @@ WORKDIR /
ARG framework_installable
ARG framework_support_installable=sagemaker_tensorflow_container-2.0.0.tar.gz

COPY $framework_installable tensorflow-1.12.0-py2.py3-none-any.whl
COPY $framework_installable tensorflow-1.12.0-py2.py3-none-any.whl
COPY $framework_support_installable .

RUN pip install --no-cache-dir -U \
keras==2.2.4 \
sagemaker-containers==2.4.2 \
$framework_support_installable \
"sagemaker-tensorflow>=1.12,<1.13" \
# Let's install TensorFlow separately in the end to avoid
Expand All @@ -129,5 +128,5 @@ RUN pip install --no-cache-dir -U \
RUN ldconfig /usr/local/cuda-9.0/targets/x86_64-linux/lib/stubs && \
HOROVOD_GPU_ALLREDUCE=NCCL HOROVOD_WITH_TENSORFLOW=1 pip install --no-cache-dir horovod && \
ldconfig
ENV SAGEMAKER_TRAINING_MODULE sagemaker_tensorflow_container.training:main

ENV SAGEMAKER_TRAINING_MODULE sagemaker_tensorflow_container.training:main
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def read(fname):
'Programming Language :: Python :: 3.6',
],

install_requires=['sagemaker-containers>=2.4.4', 'numpy', 'scipy', 'sklearn',
install_requires=['sagemaker-containers>=2.4.6', 'numpy', 'scipy', 'sklearn',
'pandas', 'Pillow', 'h5py'],
extras_require={
'test': ['tox', 'flake8', 'pytest', 'pytest-cov', 'pytest-xdist', 'mock',
Expand Down
44 changes: 44 additions & 0 deletions test/integration/sagemaker/test_tuning_model_dir.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# 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.tensorflow import TensorFlow
from sagemaker.tuner import HyperparameterTuner, IntegerParameter


def test_model_dir_with_training_job_name(sagemaker_session, ecr_image, instance_type, framework_version):
resource_path = os.path.join(os.path.dirname(__file__), '../..', 'resources')
script = os.path.join(resource_path, 'tuning_model_dir', 'entry.py')

estimator = TensorFlow(entry_point=script,
role='SageMakerRole',
train_instance_type=instance_type,
train_instance_count=1,
image_name=ecr_image,
framework_version=framework_version,
py_version='py3',
sagemaker_session=sagemaker_session)

tuner = HyperparameterTuner(estimator=estimator,
objective_metric_name='accuracy',
hyperparameter_ranges={'arbitrary_value': IntegerParameter(0, 1)},
metric_definitions=[{'Name': 'accuracy', 'Regex': 'accuracy=([01])'}],
max_jobs=1,
max_parallel_jobs=1,
base_tuning_job_name='test-tf-tuning-model-dir')

# User script has logic to check for the correct model_dir
tuner.fit()
tuner.wait()
26 changes: 26 additions & 0 deletions test/resources/tuning_model_dir/entry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# 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 argparse
import os

parser = argparse.ArgumentParser()
parser.add_argument('--model_dir', type=str)
parser.add_argument('--arbitrary_value', type=int, default=0)
args = parser.parse_args()

assert os.environ['TRAINING_JOB_NAME'] in args.model_dir, 'model_dir not unique to training job: %s' % args.model_dir

# For the "hyperparameter tuning" to work
print('accuracy=1')