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.
2
2
#
3
3
# Licensed under the Apache License, Version 2.0 (the "License"). You
4
4
# may not use this file except in compliance with the License. A copy of
21
21
from sagemaker .chainer .defaults import CHAINER_VERSION
22
22
from sagemaker .chainer .estimator import Chainer
23
23
from sagemaker .chainer .model import ChainerModel
24
- from sagemaker .utils import sagemaker_timestamp
24
+ from sagemaker .utils import unique_name_from_base
25
25
import tests .integ
26
26
from tests .integ import DATA_DIR , PYTHON_VERSION , TRAINING_DEFAULT_TIMEOUT_MINUTES
27
27
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
62
62
test_input = chainer .sagemaker_session .upload_data (path = os .path .join (data_path , 'test' ),
63
63
key_prefix = 'integ-test-data/chainer_mnist/test' )
64
64
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 )
66
67
return chainer .latest_training_job .name
67
68
68
69
69
70
@pytest .mark .canary_quick
70
71
@pytest .mark .regional_testing
71
72
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' )
73
74
74
75
with timeout_and_delete_endpoint_by_name (endpoint_name , sagemaker_session ):
75
76
estimator = Chainer .attach (chainer_training_job , sagemaker_session = sagemaker_session )
@@ -78,7 +79,7 @@ def test_attach_deploy(chainer_training_job, sagemaker_session):
78
79
79
80
80
81
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' )
82
83
with timeout_and_delete_endpoint_by_name (endpoint_name , sagemaker_session ):
83
84
desc = sagemaker_session .sagemaker_client .describe_training_job (TrainingJobName = chainer_training_job )
84
85
model_data = desc ['ModelArtifacts' ]['S3ModelArtifacts' ]
@@ -89,15 +90,14 @@ def test_deploy_model(chainer_training_job, sagemaker_session):
89
90
90
91
91
92
def test_async_fit (sagemaker_session ):
92
- endpoint_name = 'test-chainer-attach-deploy-{}' .format (sagemaker_timestamp ())
93
-
94
93
with timeout (minutes = 5 ):
95
94
training_job_name = _run_mnist_training_job (sagemaker_session , "ml.c4.xlarge" , 1 ,
96
95
chainer_full_version = CHAINER_VERSION , wait = False )
97
96
98
97
print ("Waiting to re-attach to the training job: %s" % training_job_name )
99
98
time .sleep (20 )
100
99
100
+ endpoint_name = unique_name_from_base ('test-chainer-async-fit' )
101
101
with timeout_and_delete_endpoint_by_name (endpoint_name , sagemaker_session ):
102
102
print ("Re-attaching now to: %s" % training_job_name )
103
103
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):
115
115
sagemaker_session = sagemaker_session )
116
116
117
117
with pytest .raises (ValueError ) as e :
118
- chainer .fit ()
118
+ chainer .fit (job_name = unique_name_from_base ( 'test-chainer-training' ) )
119
119
assert 'ExecuteUserScriptError' in str (e .value )
120
120
121
121
@@ -138,7 +138,8 @@ def _run_mnist_training_job(sagemaker_session, instance_type, instance_count,
138
138
test_input = chainer .sagemaker_session .upload_data (path = os .path .join (data_path , 'test' ),
139
139
key_prefix = 'integ-test-data/chainer_mnist/test' )
140
140
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 )
142
143
return chainer .latest_training_job .name
143
144
144
145
0 commit comments