Skip to content

Commit 823b107

Browse files
authored
fix: Parameterize processor and py_version for test runs (#208)
* fix: Parameterize processor and py_version for test runs * move py_version and processor fixture to utils.py * Fix flake8 error * Update buildspec.yml
1 parent 541a724 commit 823b107

File tree

10 files changed

+43
-43
lines changed

10 files changed

+43
-43
lines changed

buildspec-release.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ phases:
1616
build:
1717
commands:
1818
# prepare the release (update versions, changelog etc.)
19-
- git-release --prepare
19+
- git-release --min-version 2.0.0 --prepare
2020

2121
# run linter
2222
- tox -e flake8
@@ -71,10 +71,7 @@ phases:
7171
"dest": ["1.13.1-gpu-py3", "1.13-gpu-py3", "1.13.1-gpu-py3-'${CODEBUILD_BUILD_ID#*:}'"]
7272
}],
7373
"test": [
74-
"IGNORE_COVERAGE=- tox -e py36 -- test/integration/sagemaker -n auto --region {region} --account-id 520713654638 --docker-base-name sagemaker-tensorflow-scriptmode --framework-version 1.13.1 --processor cpu",
75-
"IGNORE_COVERAGE=- tox -e py36 -- test/integration/sagemaker -n auto --region {region} --account-id 520713654638 --docker-base-name sagemaker-tensorflow-scriptmode --py-version 2 --framework-version 1.13.1 --processor cpu",
76-
"IGNORE_COVERAGE=- tox -e py36 -- test/integration/sagemaker -n auto --region {region} --account-id 520713654638 --docker-base-name sagemaker-tensorflow-scriptmode --framework-version 1.13.1 --processor gpu",
77-
"IGNORE_COVERAGE=- tox -e py36 -- test/integration/sagemaker -n auto --region {region} --account-id 520713654638 --docker-base-name sagemaker-tensorflow-scriptmode --py-version 2 --framework-version 1.13.1 --processor gpu"
74+
"IGNORE_COVERAGE=- tox -e py36 -- test/integration/sagemaker -n 32 --region {region} --account-id 520713654638 --docker-base-name sagemaker-tensorflow-scriptmode --framework-version 1.13.1 --processor cpu,gpu --py-version 2,3",
7875
]
7976
}]' > deployments.json
8077

buildspec.yml

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@ env:
55
FRAMEWORK_VERSION: '1.13.1'
66
CPU_FRAMEWORK_BINARY: 'https://s3-us-west-2.amazonaws.com/tensorflow-aws/1.13/AmazonLinux/cpu/latest-patch-latest-patch/tensorflow-1.13.1-cp36-cp36m-linux_x86_64.whl'
77
CPU_PY_VERSION: '3'
8-
CPU_INSTANCE_TYPE: 'ml.c4.xlarge'
98
GPU_FRAMEWORK_BINARY: 'https://s3-us-west-2.amazonaws.com/tensorflow-aws/1.13/AmazonLinux/gpu/latest-patch-latest-patch/tensorflow-1.13.1-cp36-cp36m-linux_x86_64.whl'
109
GPU_PY_VERSION: '3'
11-
GPU_INSTANCE_TYPE: 'ml.p2.xlarge'
1210
ECR_REPO: 'sagemaker-test'
1311
GITHUB_REPO: 'sagemaker-tensorflow-container'
1412
SETUP_FILE: 'setup_cmds.sh'
@@ -74,8 +72,7 @@ phases:
7472
- docker push $PREPROD_IMAGE:$GPU_TAG
7573

7674
# launch remote gpu instance
77-
- prefix='ml.'
78-
- instance_type=${GPU_INSTANCE_TYPE#"$prefix"}
75+
- instance_type='p2.xlarge'
7976
- create-key-pair
8077
- launch-ec2-instance --instance-type $instance_type --ami-name dlami-ubuntu
8178

@@ -97,20 +94,13 @@ phases:
9794
echo "skipping gpu integration tests"
9895
fi
9996
100-
# run cpu sagemaker tests
97+
# run sagemaker tests
10198
- |
10299
if has-matching-changes "test/" "tests/" "src/*.py" "docker/*" "buildspec.yml"; then
103-
pytest test/integration/sagemaker -n auto --region $AWS_DEFAULT_REGION --docker-base-name $ECR_REPO --account-id $ACCOUNT --tag $CPU_TAG --py-version $CPU_PY_VERSION --instance-type $CPU_INSTANCE_TYPE
100+
pytest test/integration/sagemaker -n 8 --region $AWS_DEFAULT_REGION --docker-base-name $ECR_REPO --account-id $ACCOUNT --tag $CPU_TAG --py-version $CPU_PY_VERSION --processor cpu
101+
pytest test/integration/sagemaker -n 8 --region $AWS_DEFAULT_REGION --docker-base-name $ECR_REPO --account-id $ACCOUNT --tag $GPU_TAG --py-version $GPU_PY_VERSION --processor gpu
104102
else
105-
echo "skipping cpu sagemaker tests"
106-
fi
107-
108-
# run gpu sagemaker tests
109-
- |
110-
if has-matching-changes "test/" "tests/" "src/*.py" "docker/*" "buildspec.yml"; then
111-
pytest test/integration/sagemaker -n auto --region $AWS_DEFAULT_REGION --docker-base-name $ECR_REPO --account-id $ACCOUNT --tag $GPU_TAG --py-version $GPU_PY_VERSION --instance-type $GPU_INSTANCE_TYPE
112-
else
113-
echo "skipping gpu sagemaker tests"
103+
echo "skipping sagemaker tests"
114104
fi
115105
116106
finally:

test/conftest.py renamed to test/integration/conftest.py

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
1+
# Copyright 2018-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License").
44
# You may not use this file except in compliance with the License.
@@ -33,42 +33,37 @@
3333

3434

3535
def pytest_addoption(parser):
36-
parser.addoption('--docker-base-name', default='preprod-tensorflow')
36+
parser.addoption('--docker-base-name', default='sagemaker-tensorflow-scriptmode')
3737
parser.addoption('--tag', default=None)
3838
parser.addoption('--region', default='us-west-2')
3939
parser.addoption('--framework-version', default=TensorFlow.LATEST_VERSION)
40-
parser.addoption('--processor', default='cpu', choices=['gpu', 'cpu'])
41-
parser.addoption('--py-version', default='3', choices=['2', '3'])
40+
parser.addoption('--processor', default='cpu', choices=['cpu', 'gpu', 'cpu,gpu'])
41+
parser.addoption('--py-version', default='3', choices=['2', '3', '2,3'])
4242
parser.addoption('--account-id', default='142577830533')
4343
parser.addoption('--instance-type', default=None)
4444

4545

46-
@pytest.fixture(scope='session')
47-
def docker_base_name(request):
48-
return request.config.getoption('--docker-base-name')
46+
def pytest_configure(config):
47+
os.environ['TEST_PY_VERSIONS'] = config.getoption('--py-version')
48+
os.environ['TEST_PROCESSORS'] = config.getoption('--processor')
4949

5050

5151
@pytest.fixture(scope='session')
52-
def processor(request):
53-
return request.config.getoption('--processor')
52+
def docker_base_name(request):
53+
return request.config.getoption('--docker-base-name')
5454

5555

5656
@pytest.fixture(scope='session')
5757
def region(request):
5858
return request.config.getoption('--region')
5959

6060

61-
@pytest.fixture(scope='session')
62-
def py_version(request):
63-
return request.config.getoption('--py-version')
64-
65-
6661
@pytest.fixture(scope='session')
6762
def framework_version(request):
6863
return request.config.getoption('--framework-version')
6964

7065

71-
@pytest.fixture(scope='session')
66+
@pytest.fixture
7267
def tag(request, framework_version, processor, py_version):
7368
provided_tag = request.config.getoption('--tag')
7469
default_tag = '{}-{}-py{}'.format(framework_version, processor, py_version)
@@ -90,7 +85,7 @@ def account_id(request):
9085
return request.config.getoption('--account-id')
9186

9287

93-
@pytest.fixture(scope='session')
88+
@pytest.fixture
9489
def instance_type(request, processor):
9590
provided_instance_type = request.config.getoption('--instance-type')
9691
default_instance_type = 'ml.c4.xlarge' if processor == 'cpu' else 'ml.p2.xlarge'
@@ -112,12 +107,12 @@ def skip_gpu_instance_restricted_regions(region, instance_type):
112107
pytest.skip('Skipping GPU test in region {}'.format(region))
113108

114109

115-
@pytest.fixture(scope='session')
110+
@pytest.fixture
116111
def docker_image(docker_base_name, tag):
117112
return '{}:{}'.format(docker_base_name, tag)
118113

119114

120-
@pytest.fixture(scope='session')
115+
@pytest.fixture
121116
def ecr_image(account_id, docker_base_name, tag, region):
122117
return '{}.dkr.ecr.{}.amazonaws.com/{}:{}'.format(
123118
account_id, region, docker_base_name, tag)

test/integration/local/test_horovod.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import pytest
2020
from sagemaker.tensorflow import TensorFlow
2121

22+
from test.integration.sagemaker.utils import processor, py_version # noqa: F401
23+
2224
RESOURCE_PATH = os.path.join(os.path.dirname(__file__), '..', '..', 'resources')
2325

2426

test/integration/local/test_keras.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from sagemaker.tensorflow import serving, TensorFlow
2121

2222
from test.integration import RESOURCE_PATH
23+
from test.integration.sagemaker.utils import processor, py_version # noqa: F401
2324

2425

2526
logging.basicConfig(level=logging.DEBUG)

test/integration/local/test_training.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@
1818
import pytest
1919
from sagemaker.tensorflow import TensorFlow
2020

21+
from test.integration.sagemaker.utils import processor, py_version # noqa: F401
22+
2123
RESOURCE_PATH = os.path.join(os.path.dirname(__file__), '..', '..', 'resources')
2224
TF_CHECKPOINT_FILES = ['graph.pbtxt', 'model.ckpt-0.index', 'model.ckpt-0.meta']
2325

2426

25-
@pytest.fixture
26-
def py_full_version(py_version):
27+
@pytest.fixture # noqa: F811
28+
def py_full_version(py_version): # noqa: F811
2729
if py_version == '2':
2830
return '2.7'
2931
else:

test/integration/sagemaker/test_horovod.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import sagemaker
1818
from sagemaker.tensorflow import TensorFlow
1919

20-
from utils import unique_name_from_base
20+
from utils import processor, py_version, unique_name_from_base # noqa: F401
2121

2222
RESOURCE_PATH = os.path.join(os.path.dirname(__file__), '..', '..', 'resources')
2323

test/integration/sagemaker/test_mnist.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from six.moves.urllib.parse import urlparse
2020

2121
from sagemaker_tensorflow_container.training import SAGEMAKER_PARAMETER_SERVER_ENABLED
22-
from utils import unique_name_from_base
22+
from utils import processor, py_version, unique_name_from_base # noqa: F401
2323

2424

2525
def test_mnist(sagemaker_session, ecr_image, instance_type, framework_version):

test/integration/sagemaker/test_tuning_model_dir.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from sagemaker.tensorflow import TensorFlow
1818
from sagemaker.tuner import HyperparameterTuner, IntegerParameter
1919

20-
from utils import unique_name_from_base
20+
from utils import processor, py_version, unique_name_from_base # noqa: F401
2121

2222

2323
def test_model_dir_with_training_job_name(sagemaker_session, ecr_image, instance_type, framework_version):

test/integration/sagemaker/utils.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,26 @@
1212
# language governing permissions and limitations under the License.
1313
from __future__ import absolute_import
1414

15+
import os
1516
import random
1617
import time
1718

19+
import pytest
20+
1821

1922
def unique_name_from_base(base, max_length=63):
2023
unique = '%04x' % random.randrange(16**4) # 4-digit hex
2124
ts = str(int(time.time()))
2225
available_length = max_length - 2 - len(ts) - len(unique)
2326
trimmed = base[:available_length]
2427
return '{}-{}-{}'.format(trimmed, ts, unique)
28+
29+
30+
@pytest.fixture(params=os.environ['TEST_PY_VERSIONS'].split(','))
31+
def py_version(request):
32+
return request.param
33+
34+
35+
@pytest.fixture(params=os.environ['TEST_PROCESSORS'].split(','))
36+
def processor(request):
37+
return request.param

0 commit comments

Comments
 (0)