Skip to content

Commit d89e577

Browse files
committed
use unique_name_from_base for Chainer integ tests
1 parent 59e306f commit d89e577

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

tests/integ/test_chainer_train.py

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
1+
# Copyright 2017-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License"). You
44
# may not use this file except in compliance with the License. A copy of
@@ -21,7 +21,7 @@
2121
from sagemaker.chainer.defaults import CHAINER_VERSION
2222
from sagemaker.chainer.estimator import Chainer
2323
from sagemaker.chainer.model import ChainerModel
24-
from sagemaker.utils import sagemaker_timestamp
24+
from sagemaker.utils import unique_name_from_base
2525
import tests.integ
2626
from tests.integ import DATA_DIR, PYTHON_VERSION, TRAINING_DEFAULT_TIMEOUT_MINUTES
2727
from tests.integ.timeout import timeout, timeout_and_delete_endpoint_by_name
@@ -62,14 +62,15 @@ def test_training_with_additional_hyperparameters(sagemaker_session, chainer_ful
6262
test_input = chainer.sagemaker_session.upload_data(path=os.path.join(data_path, 'test'),
6363
key_prefix='integ-test-data/chainer_mnist/test')
6464

65-
chainer.fit({'train': train_input, 'test': test_input})
65+
job_name = unique_name_from_base('test-chainer-training')
66+
chainer.fit({'train': train_input, 'test': test_input}, job_name=job_name)
6667
return chainer.latest_training_job.name
6768

6869

6970
@pytest.mark.canary_quick
7071
@pytest.mark.regional_testing
7172
def test_attach_deploy(chainer_training_job, sagemaker_session):
72-
endpoint_name = 'test-chainer-attach-deploy-{}'.format(sagemaker_timestamp())
73+
endpoint_name = unique_name_from_base('test-chainer-attach-deploy')
7374

7475
with timeout_and_delete_endpoint_by_name(endpoint_name, sagemaker_session):
7576
estimator = Chainer.attach(chainer_training_job, sagemaker_session=sagemaker_session)
@@ -78,7 +79,7 @@ def test_attach_deploy(chainer_training_job, sagemaker_session):
7879

7980

8081
def test_deploy_model(chainer_training_job, sagemaker_session):
81-
endpoint_name = 'test-chainer-deploy-model-{}'.format(sagemaker_timestamp())
82+
endpoint_name = unique_name_from_base('test-chainer-deploy-model')
8283
with timeout_and_delete_endpoint_by_name(endpoint_name, sagemaker_session):
8384
desc = sagemaker_session.sagemaker_client.describe_training_job(TrainingJobName=chainer_training_job)
8485
model_data = desc['ModelArtifacts']['S3ModelArtifacts']
@@ -89,15 +90,14 @@ def test_deploy_model(chainer_training_job, sagemaker_session):
8990

9091

9192
def test_async_fit(sagemaker_session):
92-
endpoint_name = 'test-chainer-attach-deploy-{}'.format(sagemaker_timestamp())
93-
9493
with timeout(minutes=5):
9594
training_job_name = _run_mnist_training_job(sagemaker_session, "ml.c4.xlarge", 1,
9695
chainer_full_version=CHAINER_VERSION, wait=False)
9796

9897
print("Waiting to re-attach to the training job: %s" % training_job_name)
9998
time.sleep(20)
10099

100+
endpoint_name = unique_name_from_base('test-chainer-async-fit')
101101
with timeout_and_delete_endpoint_by_name(endpoint_name, sagemaker_session):
102102
print("Re-attaching now to: %s" % training_job_name)
103103
estimator = Chainer.attach(training_job_name=training_job_name, sagemaker_session=sagemaker_session)
@@ -115,7 +115,7 @@ def test_failed_training_job(sagemaker_session, chainer_full_version):
115115
sagemaker_session=sagemaker_session)
116116

117117
with pytest.raises(ValueError) as e:
118-
chainer.fit()
118+
chainer.fit(job_name=unique_name_from_base('test-chainer-training'))
119119
assert 'ExecuteUserScriptError' in str(e.value)
120120

121121

@@ -138,7 +138,8 @@ def _run_mnist_training_job(sagemaker_session, instance_type, instance_count,
138138
test_input = chainer.sagemaker_session.upload_data(path=os.path.join(data_path, 'test'),
139139
key_prefix='integ-test-data/chainer_mnist/test')
140140

141-
chainer.fit({'train': train_input, 'test': test_input}, wait=wait)
141+
job_name = unique_name_from_base('test-chainer-training')
142+
chainer.fit({'train': train_input, 'test': test_input}, wait=wait, job_name=job_name)
142143
return chainer.latest_training_job.name
143144

144145

0 commit comments

Comments
 (0)