Skip to content

change: add automatic model tuning integ test for TF script mode #766

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
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
38 changes: 38 additions & 0 deletions tests/integ/test_tuner.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,44 @@ def test_tuning_mxnet(sagemaker_session, mxnet_full_version):
predictor.predict(data)


@pytest.mark.canary_quick
def test_tuning_tf_script_mode(sagemaker_session):
resource_path = os.path.join(DATA_DIR, 'tensorflow_mnist')
script_path = os.path.join(resource_path, 'mnist.py')

estimator = TensorFlow(entry_point=script_path,
role='SageMakerRole',
train_instance_count=1,
train_instance_type='ml.m4.xlarge',
script_mode=True,
sagemaker_session=sagemaker_session,
py_version=PYTHON_VERSION,
framework_version=TensorFlow.LATEST_VERSION)

hyperparameter_ranges = {'epochs': IntegerParameter(1, 2)}
objective_metric_name = 'accuracy'
metric_definitions = [{'Name': objective_metric_name, 'Regex': 'accuracy = ([0-9\\.]+)'}]

tuner = HyperparameterTuner(estimator,
objective_metric_name,
hyperparameter_ranges,
metric_definitions,
max_jobs=2,
max_parallel_jobs=2)

with timeout(minutes=TUNING_DEFAULT_TIMEOUT_MINUTES):
inputs = estimator.sagemaker_session.upload_data(path=os.path.join(resource_path, 'data'),
key_prefix='scriptmode/mnist')

tuning_job_name = unique_name_from_base('tune-tf-script-mode', max_length=32)
tuner.fit(inputs, job_name=tuning_job_name)

print('Started hyperparameter tuning job with name: ' + tuning_job_name)

time.sleep(15)
tuner.wait()


@pytest.mark.canary_quick
@pytest.mark.skipif(PYTHON_VERSION != 'py2', reason="TensorFlow image supports only python 2.")
def test_tuning_tf(sagemaker_session):
Expand Down