Skip to content

Commit 75d5af2

Browse files
authored
Merge branch 'zwei' into clean-up-tests-bc-no-more-python-2-pickle
2 parents 9d9408f + 124d6e0 commit 75d5af2

File tree

7 files changed

+61
-75
lines changed

7 files changed

+61
-75
lines changed

tests/conftest.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ def pytest_addoption(parser):
4646
parser.addoption("--chainer-full-version", action="store", default="5.0.0")
4747
parser.addoption("--mxnet-full-version", action="store", default="1.6.0")
4848
parser.addoption("--ei-mxnet-full-version", action="store", default="1.5.1")
49-
parser.addoption("--pytorch-full-version", action="store", default="1.5.0")
5049
parser.addoption(
5150
"--rl-coach-mxnet-full-version",
5251
action="store",
@@ -266,8 +265,18 @@ def ei_mxnet_full_version(request):
266265

267266

268267
@pytest.fixture(scope="module")
269-
def pytorch_full_version(request):
270-
return request.config.getoption("--pytorch-full-version")
268+
def pytorch_full_version():
269+
return "1.5.0"
270+
271+
272+
@pytest.fixture(scope="module")
273+
def pytorch_full_py_version():
274+
return "py3"
275+
276+
277+
@pytest.fixture(scope="module")
278+
def pytorch_full_ei_version():
279+
return "1.3.1"
271280

272281

273282
@pytest.fixture(scope="module")

tests/integ/test_airflow_config.py

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -573,39 +573,14 @@ def test_xgboost_airflow_config_uploads_data_source_to_s3(
573573

574574
@pytest.mark.canary_quick
575575
def test_pytorch_airflow_config_uploads_data_source_to_s3_when_inputs_not_provided(
576-
sagemaker_session, cpu_instance_type, pytorch_full_version
576+
sagemaker_session, cpu_instance_type, pytorch_full_version, pytorch_full_py_version,
577577
):
578578
with timeout(seconds=AIRFLOW_CONFIG_TIMEOUT_IN_SECONDS):
579579
estimator = PyTorch(
580580
entry_point=PYTORCH_MNIST_SCRIPT,
581581
role=ROLE,
582582
framework_version=pytorch_full_version,
583-
py_version="py3",
584-
train_instance_count=2,
585-
train_instance_type=cpu_instance_type,
586-
hyperparameters={"epochs": 6, "backend": "gloo"},
587-
sagemaker_session=sagemaker_session,
588-
)
589-
590-
training_config = _build_airflow_workflow(
591-
estimator=estimator, instance_type=cpu_instance_type
592-
)
593-
594-
_assert_that_s3_url_contains_data(
595-
sagemaker_session,
596-
training_config["HyperParameters"]["sagemaker_submit_directory"].strip('"'),
597-
)
598-
599-
600-
def test_pytorch_12_airflow_config_uploads_data_source_to_s3_when_inputs_not_provided(
601-
sagemaker_session, cpu_instance_type
602-
):
603-
with timeout(seconds=AIRFLOW_CONFIG_TIMEOUT_IN_SECONDS):
604-
estimator = PyTorch(
605-
entry_point=PYTORCH_MNIST_SCRIPT,
606-
role=ROLE,
607-
framework_version="1.2.0",
608-
py_version="py3",
583+
py_version=pytorch_full_py_version,
609584
train_instance_count=2,
610585
train_instance_type=cpu_instance_type,
611586
hyperparameters={"epochs": 6, "backend": "gloo"},

tests/integ/test_git.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
from sagemaker.sklearn.model import SKLearnModel
2727
from tests.integ import DATA_DIR, PYTHON_VERSION
2828

29-
MNIST_FOLDER_NAME = "MNIST"
3029

3130
GIT_REPO = "https://github.com/aws/sagemaker-python-sdk.git"
3231
BRANCH = "test-branch-git-config"
@@ -51,33 +50,31 @@
5150

5251

5352
@pytest.mark.local_mode
54-
def test_github(sagemaker_local_session):
53+
def test_github(sagemaker_local_session, pytorch_full_version, pytorch_full_py_version):
5554
script_path = "mnist.py"
56-
data_path = os.path.join(DATA_DIR, "pytorch_mnist")
5755
git_config = {"repo": GIT_REPO, "branch": BRANCH, "commit": COMMIT}
5856

59-
# TODO: fails for newer pytorch versions when using MNIST from torchvision due to missing dataset
60-
# "algo-1-v767u_1 | RuntimeError: Dataset not found. You can use download=True to download it"
6157
pytorch = PyTorch(
6258
entry_point=script_path,
6359
role="SageMakerRole",
6460
source_dir="pytorch",
65-
framework_version="0.4", # hard-code to last known good pytorch for now (see TODO above)
66-
py_version=PYTHON_VERSION,
61+
framework_version=pytorch_full_version,
62+
py_version=pytorch_full_py_version,
6763
train_instance_count=1,
6864
train_instance_type="local",
6965
sagemaker_session=sagemaker_local_session,
7066
git_config=git_config,
7167
)
7268

73-
pytorch.fit({"training": "file://" + os.path.join(data_path, "training", MNIST_FOLDER_NAME)})
69+
data_path = os.path.join(DATA_DIR, "pytorch_mnist")
70+
pytorch.fit({"training": "file://" + os.path.join(data_path, "training")})
7471

7572
with lock.lock(LOCK_PATH):
7673
try:
7774
predictor = pytorch.deploy(initial_instance_count=1, instance_type="local")
7875
data = numpy.zeros(shape=(1, 1, 28, 28)).astype(numpy.float32)
7976
result = predictor.predict(data)
80-
assert result is not None
77+
assert 10 == len(result[0]) # check that there is a probability for each label
8178
finally:
8279
predictor.delete_endpoint()
8380

tests/integ/test_pytorch_train.py

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,13 @@
1515
import numpy
1616
import os
1717
import pytest
18-
from sagemaker.pytorch.defaults import LATEST_PY2_VERSION
18+
1919
from sagemaker.pytorch.estimator import PyTorch
2020
from sagemaker.pytorch.model import PyTorchModel
2121
from sagemaker.utils import sagemaker_timestamp
22-
2322
from tests.integ import (
2423
test_region,
2524
DATA_DIR,
26-
PYTHON_VERSION,
2725
TRAINING_DEFAULT_TIMEOUT_MINUTES,
2826
EI_SUPPORTED_REGIONS,
2927
)
@@ -39,22 +37,21 @@
3937

4038

4139
@pytest.fixture(scope="module", name="pytorch_training_job")
42-
def fixture_training_job(sagemaker_session, pytorch_full_version, cpu_instance_type):
40+
def fixture_training_job(
41+
sagemaker_session, pytorch_full_version, pytorch_full_py_version, cpu_instance_type
42+
):
4343
with timeout(minutes=TRAINING_DEFAULT_TIMEOUT_MINUTES):
44-
pytorch = _get_pytorch_estimator(sagemaker_session, pytorch_full_version, cpu_instance_type)
44+
pytorch = _get_pytorch_estimator(
45+
sagemaker_session, pytorch_full_version, pytorch_full_py_version, cpu_instance_type
46+
)
4547

4648
pytorch.fit({"training": _upload_training_data(pytorch)})
4749
return pytorch.latest_training_job.name
4850

4951

5052
@pytest.mark.canary_quick
5153
@pytest.mark.regional_testing
52-
@pytest.mark.skipif(
53-
PYTHON_VERSION == "py2",
54-
reason="Python 2 is supported by PyTorch {} and lower versions.".format(LATEST_PY2_VERSION),
55-
)
56-
def test_sync_fit_deploy(pytorch_training_job, sagemaker_session, cpu_instance_type):
57-
# TODO: add tests against local mode when it's ready to be used
54+
def test_fit_deploy(pytorch_training_job, sagemaker_session, cpu_instance_type):
5855
endpoint_name = "test-pytorch-sync-fit-attach-deploy{}".format(sagemaker_timestamp())
5956
with timeout_and_delete_endpoint_by_name(endpoint_name, sagemaker_session):
6057
estimator = PyTorch.attach(pytorch_training_job, sagemaker_session=sagemaker_session)
@@ -70,16 +67,12 @@ def test_sync_fit_deploy(pytorch_training_job, sagemaker_session, cpu_instance_t
7067

7168

7269
@pytest.mark.local_mode
73-
@pytest.mark.skipif(
74-
PYTHON_VERSION == "py2",
75-
reason="Python 2 is supported by PyTorch {} and lower versions.".format(LATEST_PY2_VERSION),
76-
)
77-
def test_fit_deploy(sagemaker_local_session, pytorch_full_version):
70+
def test_local_fit_deploy(sagemaker_local_session, pytorch_full_version, pytorch_full_py_version):
7871
pytorch = PyTorch(
7972
entry_point=MNIST_SCRIPT,
8073
role="SageMakerRole",
8174
framework_version=pytorch_full_version,
82-
py_version="py3",
75+
py_version=pytorch_full_py_version,
8376
train_instance_count=1,
8477
train_instance_type="local",
8578
sagemaker_session=sagemaker_local_session,
@@ -99,7 +92,11 @@ def test_fit_deploy(sagemaker_local_session, pytorch_full_version):
9992

10093

10194
def test_deploy_model(
102-
pytorch_training_job, sagemaker_session, cpu_instance_type, pytorch_full_version
95+
pytorch_training_job,
96+
sagemaker_session,
97+
cpu_instance_type,
98+
pytorch_full_version,
99+
pytorch_full_py_version,
103100
):
104101
endpoint_name = "test-pytorch-deploy-model-{}".format(sagemaker_timestamp())
105102

@@ -113,7 +110,7 @@ def test_deploy_model(
113110
"SageMakerRole",
114111
entry_point=MNIST_SCRIPT,
115112
framework_version=pytorch_full_version,
116-
py_version="py3",
113+
py_version=pytorch_full_py_version,
117114
sagemaker_session=sagemaker_session,
118115
)
119116
predictor = model.deploy(1, cpu_instance_type, endpoint_name=endpoint_name)
@@ -125,7 +122,9 @@ def test_deploy_model(
125122
assert output.shape == (batch_size, 10)
126123

127124

128-
def test_deploy_packed_model_with_entry_point_name(sagemaker_session, cpu_instance_type):
125+
def test_deploy_packed_model_with_entry_point_name(
126+
sagemaker_session, cpu_instance_type, pytorch_full_version, pytorch_full_py_version
127+
):
129128
endpoint_name = "test-pytorch-deploy-model-{}".format(sagemaker_timestamp())
130129

131130
with timeout_and_delete_endpoint_by_name(endpoint_name, sagemaker_session):
@@ -134,8 +133,8 @@ def test_deploy_packed_model_with_entry_point_name(sagemaker_session, cpu_instan
134133
model_data,
135134
"SageMakerRole",
136135
entry_point="mnist.py",
137-
framework_version="1.4.0",
138-
py_version="py3",
136+
framework_version=pytorch_full_version,
137+
py_version=pytorch_full_py_version,
139138
sagemaker_session=sagemaker_session,
140139
)
141140
predictor = model.deploy(1, cpu_instance_type, endpoint_name=endpoint_name)
@@ -147,19 +146,20 @@ def test_deploy_packed_model_with_entry_point_name(sagemaker_session, cpu_instan
147146
assert output.shape == (batch_size, 10)
148147

149148

150-
@pytest.mark.skipif(PYTHON_VERSION == "py2", reason="PyTorch EIA does not support Python 2.")
151149
@pytest.mark.skipif(
152150
test_region() not in EI_SUPPORTED_REGIONS, reason="EI isn't supported in that specific region."
153151
)
154-
def test_deploy_model_with_accelerator(sagemaker_session, cpu_instance_type):
152+
def test_deploy_model_with_accelerator(
153+
sagemaker_session, cpu_instance_type, pytorch_full_ei_version, pytorch_full_py_version
154+
):
155155
endpoint_name = "test-pytorch-deploy-eia-{}".format(sagemaker_timestamp())
156156
model_data = sagemaker_session.upload_data(path=EIA_MODEL)
157157
pytorch = PyTorchModel(
158158
model_data,
159159
"SageMakerRole",
160160
entry_point=EIA_SCRIPT,
161-
framework_version="1.3.1",
162-
py_version="py3",
161+
framework_version=pytorch_full_ei_version,
162+
py_version=pytorch_full_py_version,
163163
sagemaker_session=sagemaker_session,
164164
)
165165
with timeout_and_delete_endpoint_by_name(endpoint_name, sagemaker_session):
@@ -185,13 +185,13 @@ def _upload_training_data(pytorch):
185185

186186

187187
def _get_pytorch_estimator(
188-
sagemaker_session, pytorch_full_version, instance_type, entry_point=MNIST_SCRIPT
188+
sagemaker_session, pytorch_version, py_version, instance_type, entry_point=MNIST_SCRIPT
189189
):
190190
return PyTorch(
191191
entry_point=entry_point,
192192
role="SageMakerRole",
193-
framework_version=pytorch_full_version,
194-
py_version="py3",
193+
framework_version=pytorch_version,
194+
py_version=py_version,
195195
train_instance_count=1,
196196
train_instance_type=instance_type,
197197
sagemaker_session=sagemaker_session,

tests/integ/test_source_dirs.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@
1717
import pytest
1818

1919
import tests.integ.lock as lock
20-
from tests.integ import DATA_DIR, PYTHON_VERSION
21-
2220
from sagemaker.pytorch.estimator import PyTorch
21+
from tests.integ import DATA_DIR
2322

2423

2524
@pytest.mark.local_mode
@@ -38,7 +37,7 @@ def test_source_dirs(tmpdir, sagemaker_local_session):
3837
source_dir=source_dir,
3938
dependencies=[lib],
4039
framework_version="0.4", # hard-code to last known good pytorch for now (see TODO above)
41-
py_version=PYTHON_VERSION,
40+
py_version="py3",
4241
train_instance_count=1,
4342
train_instance_type="local",
4443
sagemaker_session=sagemaker_local_session,

tests/integ/test_transformer.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,11 @@ def test_attach_transform_kmeans(sagemaker_session, cpu_instance_type):
149149

150150

151151
def test_transform_pytorch_vpc_custom_model_bucket(
152-
sagemaker_session, pytorch_full_version, cpu_instance_type, custom_bucket_name
152+
sagemaker_session,
153+
pytorch_full_version,
154+
pytorch_full_py_version,
155+
cpu_instance_type,
156+
custom_bucket_name,
153157
):
154158
data_dir = os.path.join(DATA_DIR, "pytorch_mnist")
155159

@@ -167,7 +171,7 @@ def test_transform_pytorch_vpc_custom_model_bucket(
167171
entry_point=os.path.join(data_dir, "mnist.py"),
168172
role="SageMakerRole",
169173
framework_version=pytorch_full_version,
170-
py_version=PYTHON_VERSION,
174+
py_version=pytorch_full_py_version,
171175
sagemaker_session=sagemaker_session,
172176
vpc_config={"Subnets": subnet_ids, "SecurityGroupIds": [security_group_id]},
173177
code_location="s3://{}".format(custom_bucket_name),

tests/integ/test_tuner.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,9 @@ def test_tuning_chainer(sagemaker_session, chainer_full_version, cpu_instance_ty
760760
reason="This test has always failed, but the failure was masked by a bug. "
761761
"This test should be fixed. Details in https://github.com/aws/sagemaker-python-sdk/pull/968"
762762
)
763-
def test_attach_tuning_pytorch(sagemaker_session, cpu_instance_type, pytorch_full_version):
763+
def test_attach_tuning_pytorch(
764+
sagemaker_session, cpu_instance_type, pytorch_full_version, pytorch_full_py_version
765+
):
764766
mnist_dir = os.path.join(DATA_DIR, "pytorch_mnist")
765767
mnist_script = os.path.join(mnist_dir, "mnist.py")
766768

@@ -769,7 +771,7 @@ def test_attach_tuning_pytorch(sagemaker_session, cpu_instance_type, pytorch_ful
769771
role="SageMakerRole",
770772
train_instance_count=1,
771773
framework_version=pytorch_full_version,
772-
py_version="py3",
774+
py_version=pytorch_full_py_version,
773775
train_instance_type=cpu_instance_type,
774776
sagemaker_session=sagemaker_session,
775777
)

0 commit comments

Comments
 (0)