1
- # Copyright 2017- 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
1
+ # Copyright 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
24
24
from sagemaker .pytorch .defaults import PYTORCH_VERSION
25
25
from sagemaker .pytorch .estimator import PyTorch
26
26
from sagemaker .sklearn .estimator import SKLearn
27
- from sagemaker .mxnet .model import MXNetModel
28
27
from sagemaker .sklearn .model import SKLearnModel
29
28
from tests .integ import DATA_DIR , PYTHON_VERSION
30
29
33
32
GIT_REPO = "https://github.com/aws/sagemaker-python-sdk.git"
34
33
BRANCH = "test-branch-git-config"
35
34
COMMIT = "ae15c9d7d5b97ea95ea451e4662ee43da3401d73"
35
+
36
36
PRIVATE_GIT_REPO = "https://github.com/git-support-test/test-git.git"
37
37
PRIVATE_BRANCH = "master"
38
38
PRIVATE_COMMIT = "a46d6f9add3532ca3e4e231e4108b6bad15b7373"
39
+
39
40
PRIVATE_GIT_REPO_2FA = "https://github.com/git-support-test-2fa/test-git.git"
40
41
PRIVATE_GIT_REPO_2FA_SSH = "[email protected] :git-support-test-2fa/test-git.git"
41
42
PRIVATE_BRANCH_2FA = "master"
42
43
PRIVATE_COMMIT_2FA = "52381dee030eb332a7e42d9992878d7261eb21d4"
44
+
43
45
CODECOMMIT_REPO = (
44
46
"https://git-codecommit.us-west-2.amazonaws.com/v1/repos/sagemaker-python-sdk-git-testing-repo/"
45
47
)
46
48
CODECOMMIT_BRANCH = "master"
47
49
48
- # Since personal access tokens will delete themselves if they are committed to GitHub repos,
49
- # we cannot hard code them here, but have to encrypt instead
50
- ENCRYPTED_PRIVATE_REPO_TOKEN = "e-4_1-1dc_71-f0e_f7b54a0f3b7db2757163da7b5e8c3"
51
- PRIVATE_REPO_TOKEN = ENCRYPTED_PRIVATE_REPO_TOKEN .replace ("-" , "" ).replace ("_" , "" )
52
-
53
50
# endpoint tests all use the same port, so we use this lock to prevent concurrent execution
54
51
LOCK_PATH = os .path .join (tempfile .gettempdir (), "sagemaker_test_git_lock" )
55
52
56
53
57
54
@pytest .mark .local_mode
58
- def test_git_support_with_pytorch (sagemaker_local_session ):
55
+ def test_github (sagemaker_local_session ):
59
56
script_path = "mnist.py"
60
57
data_path = os .path .join (DATA_DIR , "pytorch_mnist" )
61
58
git_config = {"repo" : GIT_REPO , "branch" : BRANCH , "commit" : COMMIT }
@@ -85,7 +82,7 @@ def test_git_support_with_pytorch(sagemaker_local_session):
85
82
86
83
@pytest .mark .local_mode
87
84
@pytest .mark .skip ("needs a secure authentication approach" )
88
- def test_git_support_with_mxnet (sagemaker_local_session ):
85
+ def test_private_github (sagemaker_local_session ):
89
86
script_path = "mnist.py"
90
87
data_path = os .path .join (DATA_DIR , "mxnet_mnist" )
91
88
git_config = {
@@ -94,7 +91,7 @@ def test_git_support_with_mxnet(sagemaker_local_session):
94
91
"commit" : PRIVATE_COMMIT ,
95
92
"2FA_enabled" : False ,
96
93
"username" : "git-support-test" ,
97
- "password" : "" , # TODO: find a more secure approach
94
+ "password" : "" , # TODO: find a secure approach
98
95
}
99
96
source_dir = "mxnet"
100
97
dependencies = ["foo/bar.py" ]
@@ -126,46 +123,34 @@ def test_git_support_with_mxnet(sagemaker_local_session):
126
123
with lock .lock (LOCK_PATH ):
127
124
try :
128
125
serving_script_path = "mnist_hosting_with_custom_handlers.py"
129
- client = sagemaker_local_session .sagemaker_client
130
- desc = client .describe_training_job (TrainingJobName = mx .latest_training_job .name )
131
- model_data = desc ["ModelArtifacts" ]["S3ModelArtifacts" ]
132
- model = MXNetModel (
133
- model_data ,
134
- "SageMakerRole" ,
135
- entry_point = serving_script_path ,
136
- source_dir = source_dir ,
137
- dependencies = dependencies ,
138
- py_version = PYTHON_VERSION ,
139
- sagemaker_session = sagemaker_local_session ,
140
- framework_version = MXNet .LATEST_VERSION ,
141
- git_config = git_config ,
142
- )
143
- predictor = model .deploy (initial_instance_count = 1 , instance_type = "local" )
126
+ predictor = mx .deploy (1 , "local" , entry_point = serving_script_path )
127
+
144
128
data = numpy .zeros (shape = (1 , 1 , 28 , 28 ))
145
129
result = predictor .predict (data )
146
130
assert result is not None
147
131
finally :
148
132
predictor .delete_endpoint ()
149
133
150
134
151
- @pytest .mark .skipif (PYTHON_VERSION != "py3" , reason = "Scikit-learn image supports only python 3." )
152
135
@pytest .mark .local_mode
153
- def test_git_support_with_sklearn (sagemaker_local_session , sklearn_full_version ):
136
+ @pytest .mark .skip ("needs a secure authentication approach" )
137
+ def test_private_github_with_2fa (sagemaker_local_session , sklearn_full_version ):
154
138
script_path = "mnist.py"
155
139
data_path = os .path .join (DATA_DIR , "sklearn_mnist" )
156
140
git_config = {
157
141
"repo" : PRIVATE_GIT_REPO_2FA ,
158
142
"branch" : PRIVATE_BRANCH_2FA ,
159
143
"commit" : PRIVATE_COMMIT_2FA ,
160
144
"2FA_enabled" : True ,
161
- "token" : PRIVATE_REPO_TOKEN ,
145
+ "token" : "" , # TODO: find a secure approach
162
146
}
163
147
source_dir = "sklearn"
148
+
164
149
sklearn = SKLearn (
165
150
entry_point = script_path ,
166
151
role = "SageMakerRole" ,
167
152
source_dir = source_dir ,
168
- py_version = PYTHON_VERSION ,
153
+ py_version = "py3" , # Scikit-learn supports only Python 3
169
154
train_instance_count = 1 ,
170
155
train_instance_type = "local" ,
171
156
sagemaker_session = sagemaker_local_session ,
@@ -202,9 +187,7 @@ def test_git_support_with_sklearn(sagemaker_local_session, sklearn_full_version)
202
187
203
188
204
189
@pytest .mark .local_mode
205
- def test_git_support_with_sklearn_ssh_passphrase_not_configured (
206
- sagemaker_local_session , sklearn_full_version
207
- ):
190
+ def test_github_with_ssh_passphrase_not_configured (sagemaker_local_session , sklearn_full_version ):
208
191
script_path = "mnist.py"
209
192
data_path = os .path .join (DATA_DIR , "sklearn_mnist" )
210
193
git_config = {
@@ -213,11 +196,12 @@ def test_git_support_with_sklearn_ssh_passphrase_not_configured(
213
196
"commit" : PRIVATE_COMMIT_2FA ,
214
197
}
215
198
source_dir = "sklearn"
199
+
216
200
sklearn = SKLearn (
217
201
entry_point = script_path ,
218
202
role = "SageMakerRole" ,
219
203
source_dir = source_dir ,
220
- py_version = PYTHON_VERSION ,
204
+ py_version = "py3" , # Scikit-learn supports only Python 3
221
205
train_instance_count = 1 ,
222
206
train_instance_type = "local" ,
223
207
sagemaker_session = sagemaker_local_session ,
@@ -227,14 +211,15 @@ def test_git_support_with_sklearn_ssh_passphrase_not_configured(
227
211
)
228
212
train_input = "file://" + os .path .join (data_path , "train" )
229
213
test_input = "file://" + os .path .join (data_path , "test" )
214
+
230
215
with pytest .raises (subprocess .CalledProcessError ) as error :
231
216
sklearn .fit ({"train" : train_input , "test" : test_input })
232
217
assert "returned non-zero exit status" in str (error )
233
218
234
219
235
220
@pytest .mark .local_mode
236
221
@pytest .mark .skip ("needs a secure authentication approach" )
237
- def test_git_support_codecommit_with_mxnet (sagemaker_local_session ):
222
+ def test_codecommit (sagemaker_local_session ):
238
223
script_path = "mnist.py"
239
224
data_path = os .path .join (DATA_DIR , "mxnet_mnist" )
240
225
git_config = {
@@ -272,21 +257,7 @@ def test_git_support_codecommit_with_mxnet(sagemaker_local_session):
272
257
273
258
with lock .lock (LOCK_PATH ):
274
259
try :
275
- client = sagemaker_local_session .sagemaker_client
276
- desc = client .describe_training_job (TrainingJobName = mx .latest_training_job .name )
277
- model_data = desc ["ModelArtifacts" ]["S3ModelArtifacts" ]
278
- model = MXNetModel (
279
- model_data ,
280
- "SageMakerRole" ,
281
- entry_point = script_path ,
282
- source_dir = source_dir ,
283
- dependencies = dependencies ,
284
- py_version = PYTHON_VERSION ,
285
- sagemaker_session = sagemaker_local_session ,
286
- framework_version = MXNet .LATEST_VERSION ,
287
- git_config = git_config ,
288
- )
289
- predictor = model .deploy (1 , "local" )
260
+ predictor = mx .deploy (1 , "local" )
290
261
291
262
data = numpy .zeros (shape = (1 , 1 , 28 , 28 ))
292
263
result = predictor .predict (data )
0 commit comments