Skip to content

Commit 9d90dc1

Browse files
authored
feature: install sagemaker-tensorflow-toolkit from PyPI. (#334)
1 parent a7f1cb9 commit 9d90dc1

File tree

6 files changed

+41
-69
lines changed

6 files changed

+41
-69
lines changed

README.rst

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -114,17 +114,6 @@ Before building "final" images:
114114
Build your "base" image. Make sure it is named and tagged in accordance with your "final"
115115
Dockerfile. Skip this step if you want to build image of Tensorflow Version 1.9.0 and above.
116116

117-
Then prepare the SageMaker TensorFlow Container python package in the image folder like below:
118-
119-
::
120-
121-
# Create the SageMaker TensorFlow Container Python package.
122-
cd sagemaker-tensorflow-containers
123-
python setup.py sdist
124-
125-
#. Copy your Python package to "final" Dockerfile directory that you are building.
126-
cp dist/sagemaker_tensorflow_container-<package_version>.tar.gz docker/<tensorflow_version>/final/py2
127-
128117
If you want to build "final" Docker images, for versions 1.6 and above, you will first need to download the appropriate tensorflow pip wheel, then pass in its location as a build argument. These can be obtained from pypi. For example, the files for 1.6.0 are here:
129118

130119
https://pypi.org/project/tensorflow/1.6.0/#files

buildspec.yml

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ version: 0.2
22

33
env:
44
variables:
5-
FRAMEWORK_VERSION: '1.15.0'
5+
FRAMEWORK_VERSION: '2.1.0'
66
ECR_REPO: 'sagemaker-test'
77
GITHUB_REPO: 'sagemaker-tensorflow-container'
88
SETUP_FILE: 'setup_cmds.sh'
@@ -20,66 +20,65 @@ phases:
2020
build:
2121
commands:
2222
# install
23-
- pip3 install -U -e .
2423
- pip3 install -U -e .[test]
2524

2625
# run flake8
2726
- tox -e flake8,twine
2827

29-
# run unit tests
30-
- tox -e py36,py27 test/unit
31-
32-
# Create pip archive
3328
- root_dir=$(pwd)
3429
- build_id="$(echo $CODEBUILD_BUILD_ID | sed -e 's/:/-/g')"
35-
- python3 setup.py sdist
36-
- tar_name=$(ls dist)
3730

3831
# Find build artifacts
39-
- build_artifacts=$root_dir/docker/artifacts
32+
- build_artifacts=$root_dir/docker/build_artifacts
4033

4134
# build py2 images
4235

4336
# prepare build context
4437
- build_dir="$root_dir/docker/$FRAMEWORK_VERSION/py2"
45-
- cp $root_dir/dist/$tar_name $build_dir
4638
- cp $build_artifacts/* $build_dir/
4739
- cd $build_dir
4840

4941
# build cpu image
5042
- cpu_dockerfile="Dockerfile.cpu"
5143
- CPU_TAG_PY2="$FRAMEWORK_VERSION-cpu-py2-$build_id"
52-
- docker build -f $cpu_dockerfile -t $PREPROD_IMAGE:$CPU_TAG_PY2 .
44+
- build_cmd="docker build -f $cpu_dockerfile -t $PREPROD_IMAGE:$CPU_TAG_PY2 . "
45+
- execute-command-if-has-matching-changes "$build_cmd" "test/" "docker/*" "buildspec.yml"
5346

5447
# build gpu image
5548
- gpu_dockerfile="Dockerfile.gpu"
5649
- GPU_TAG_PY2="$FRAMEWORK_VERSION-gpu-py2-$build_id"
57-
- docker build -f $gpu_dockerfile -t $PREPROD_IMAGE:$GPU_TAG_PY2 .
50+
- build_cmd="docker build -f $gpu_dockerfile -t $PREPROD_IMAGE:$GPU_TAG_PY2 . "
51+
- execute-command-if-has-matching-changes "$build_cmd" "test/" "docker/*" "buildspec.yml"
5852

5953
# build py3 images
6054

6155
# prepare build context
6256
- build_dir="$root_dir/docker/$FRAMEWORK_VERSION/py3"
63-
- cp $root_dir/dist/$tar_name $build_dir
6457
- cp $build_artifacts/* $build_dir/
6558
- cd $build_dir
6659

6760
# build cpu image
6861
- cpu_dockerfile="Dockerfile.cpu"
6962
- CPU_TAG_PY3="$FRAMEWORK_VERSION-cpu-py3-$build_id"
70-
- docker build -f $cpu_dockerfile -t $PREPROD_IMAGE:$CPU_TAG_PY3 .
63+
- build_cmd="docker build -f $cpu_dockerfile -t $PREPROD_IMAGE:$CPU_TAG_PY3 . "
64+
- execute-command-if-has-matching-changes "$build_cmd" "test/" "docker/*" "buildspec.yml"
7165

7266
# build gpu image
7367
- gpu_dockerfile="Dockerfile.gpu"
7468
- GPU_TAG_PY3="$FRAMEWORK_VERSION-gpu-py3-$build_id"
75-
- docker build -f $gpu_dockerfile -t $PREPROD_IMAGE:$GPU_TAG_PY3 .
69+
- build_cmd="docker build -f $gpu_dockerfile -t $PREPROD_IMAGE:$GPU_TAG_PY3 . "
70+
- execute-command-if-has-matching-changes "$build_cmd" "test/" "docker/*" "buildspec.yml"
7671

7772
# push images to ecr
7873
- $(aws ecr get-login --registry-ids $ACCOUNT --no-include-email --region $AWS_DEFAULT_REGION)
79-
- docker push $PREPROD_IMAGE:$CPU_TAG_PY2
80-
- docker push $PREPROD_IMAGE:$GPU_TAG_PY2
81-
- docker push $PREPROD_IMAGE:$CPU_TAG_PY3
82-
- docker push $PREPROD_IMAGE:$GPU_TAG_PY3
74+
- push_cmd="docker push $PREPROD_IMAGE:$CPU_TAG_PY2"
75+
- execute-command-if-has-matching-changes "$push_cmd" "test/" "docker/*" "buildspec.yml"
76+
- push_cmd="docker push $PREPROD_IMAGE:$GPU_TAG_PY2"
77+
- execute-command-if-has-matching-changes "$push_cmd" "test/" "docker/*" "buildspec.yml"
78+
- push_cmd="docker push $PREPROD_IMAGE:$CPU_TAG_PY3"
79+
- execute-command-if-has-matching-changes "$push_cmd" "test/" "docker/*" "buildspec.yml"
80+
- push_cmd="docker push $PREPROD_IMAGE:$GPU_TAG_PY3"
81+
- execute-command-if-has-matching-changes "$push_cmd" "test/" "docker/*" "buildspec.yml"
8382

8483
# launch remote gpu instance
8584
- instance_type='p2.xlarge'
@@ -89,36 +88,40 @@ phases:
8988
# run cpu integration tests
9089
- py3_cmd="pytest test/integration/local --region $AWS_DEFAULT_REGION --docker-base-name $PREPROD_IMAGE --tag $CPU_TAG_PY2 --framework-version $FRAMEWORK_VERSION --py-version 2 --processor cpu"
9190
- py2_cmd="pytest test/integration/local --region $AWS_DEFAULT_REGION --docker-base-name $PREPROD_IMAGE --tag $CPU_TAG_PY3 --framework-version $FRAMEWORK_VERSION --py-version 3 --processor cpu"
92-
- execute-command-if-has-matching-changes "$py3_cmd" "test/" "src/*.py" "setup.py" "docker/*" "buildspec.yml"
93-
- execute-command-if-has-matching-changes "$py2_cmd" "test/" "src/*.py" "setup.py" "docker/*" "buildspec.yml"
91+
- execute-command-if-has-matching-changes "$py3_cmd" "test/" "docker/*" "buildspec.yml"
92+
- execute-command-if-has-matching-changes "$py2_cmd" "test/" "docker/*" "buildspec.yml"
9493

9594
# run gpu integration tests
9695
- printf "$SETUP_CMDS" > $SETUP_FILE
9796
- cmd="pytest test/integration/local --region $AWS_DEFAULT_REGION --docker-base-name $PREPROD_IMAGE --tag $GPU_TAG_PY2 --framework-version $FRAMEWORK_VERSION --py-version 2 --processor gpu"
9897
- py3_cmd="remote-test --github-repo $GITHUB_REPO --test-cmd \"$cmd\" --setup-file $SETUP_FILE --pr-number \"$PR_NUM\""
99-
- execute-command-if-has-matching-changes "$py3_cmd" "test/" "src/*.py" "setup.py" "docker/*" "buildspec.yml"
98+
- execute-command-if-has-matching-changes "$py3_cmd" "test/" "docker/*" "buildspec.yml"
10099

101100
- cmd="pytest test/integration/local --region $AWS_DEFAULT_REGION --docker-base-name $PREPROD_IMAGE --tag $GPU_TAG_PY3 --framework-version $FRAMEWORK_VERSION --py-version 3 --processor gpu"
102101
- py2_cmd="remote-test --github-repo $GITHUB_REPO --test-cmd \"$cmd\" --setup-file $SETUP_FILE --pr-number \"$PR_NUM\""
103-
- execute-command-if-has-matching-changes "$py2_cmd" "test/" "src/*.py" "setup.py" "docker/*" "buildspec.yml"
102+
- execute-command-if-has-matching-changes "$py2_cmd" "test/" "docker/*" "buildspec.yml"
104103

105104
# run sagemaker tests
106105
- test_cmd="pytest test/integration/sagemaker -n 8 --region $AWS_DEFAULT_REGION --docker-base-name $ECR_REPO --account-id $ACCOUNT --tag $CPU_TAG_PY2 --py-version 2 --processor cpu"
107-
- execute-command-if-has-matching-changes "$test_cmd" "test/" "src/*.py" "setup.py" "docker/*" "buildspec.yml"
106+
- execute-command-if-has-matching-changes "$test_cmd" "test/" "docker/*" "buildspec.yml"
108107
- test_cmd="pytest test/integration/sagemaker -n 8 --region $AWS_DEFAULT_REGION --docker-base-name $ECR_REPO --account-id $ACCOUNT --tag $GPU_TAG_PY2 --py-version 2 --processor gpu"
109-
- execute-command-if-has-matching-changes "$test_cmd" "test/" "src/*.py" "setup.py" "docker/*" "buildspec.yml"
108+
- execute-command-if-has-matching-changes "$test_cmd" "test/" "docker/*" "buildspec.yml"
110109
- test_cmd="pytest test/integration/sagemaker -n 8 --region $AWS_DEFAULT_REGION --docker-base-name $ECR_REPO --account-id $ACCOUNT --tag $CPU_TAG_PY3 --py-version 3 --processor cpu"
111-
- execute-command-if-has-matching-changes "$test_cmd" "test/" "src/*.py" "setup.py" "docker/*" "buildspec.yml"
110+
- execute-command-if-has-matching-changes "$test_cmd" "test/" "docker/*" "buildspec.yml"
112111
- test_cmd="pytest test/integration/sagemaker -n 8 --region $AWS_DEFAULT_REGION --docker-base-name $ECR_REPO --account-id $ACCOUNT --tag $GPU_TAG_PY3 --py-version 3 --processor gpu"
113-
- execute-command-if-has-matching-changes "$test_cmd" "test/" "src/*.py" "setup.py" "docker/*" "buildspec.yml"
112+
- execute-command-if-has-matching-changes "$test_cmd" "test/" "docker/*" "buildspec.yml"
114113

115114
finally:
116115
# shut down remote gpu instance
117116
- cleanup-gpu-instances
118117
- cleanup-key-pairs
119118

120119
# remove ecr image
121-
- aws ecr batch-delete-image --repository-name $ECR_REPO --region $AWS_DEFAULT_REGION --image-ids imageTag=$CPU_TAG_PY2
122-
- aws ecr batch-delete-image --repository-name $ECR_REPO --region $AWS_DEFAULT_REGION --image-ids imageTag=$GPU_TAG_PY2
123-
- aws ecr batch-delete-image --repository-name $ECR_REPO --region $AWS_DEFAULT_REGION --image-ids imageTag=$CPU_TAG_PY3
124-
- aws ecr batch-delete-image --repository-name $ECR_REPO --region $AWS_DEFAULT_REGION --image-ids imageTag=$GPU_TAG_PY3
120+
- delete_cmd="aws ecr batch-delete-image --repository-name $ECR_REPO --region $AWS_DEFAULT_REGION --image-ids imageTag=$CPU_TAG_PY2"
121+
- execute-command-if-has-matching-changes "$delete_cmd" "test/" "docker/*" "buildspec.yml"
122+
- delete_cmd="aws ecr batch-delete-image --repository-name $ECR_REPO --region $AWS_DEFAULT_REGION --image-ids imageTag=$GPU_TAG_PY2"
123+
- execute-command-if-has-matching-changes "$delete_cmd" "test/" "docker/*" "buildspec.yml"
124+
- delete_cmd="aws ecr batch-delete-image --repository-name $ECR_REPO --region $AWS_DEFAULT_REGION --image-ids imageTag=$CPU_TAG_PY3"
125+
- execute-command-if-has-matching-changes "$delete_cmd" "test/" "docker/*" "buildspec.yml"
126+
- delete_cmd="aws ecr batch-delete-image --repository-name $ECR_REPO --region $AWS_DEFAULT_REGION --image-ids imageTag=$GPU_TAG_PY3"
127+
- execute-command-if-has-matching-changes "$delete_cmd" "test/" "docker/*" "buildspec.yml"

docker/2.1.0/py2/Dockerfile.cpu

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ ENV PYTHONIOENCODING=UTF-8
2020
ENV LANG=C.UTF-8
2121
ENV LC_ALL=C.UTF-8
2222

23-
ARG FRAMEWORK_SUPPORT_INSTALLABLE=sagemaker_tensorflow_training*.tar.gz
2423
ARG TF_URL=https://tensorflow-aws.s3-us-west-2.amazonaws.com/2.1/AmazonLinux/cpu/final/tensorflow-2.1.0-cp27-cp27mu-manylinux2010_x86_64.whl
2524

2625
ARG PYTHON=python
@@ -82,8 +81,6 @@ RUN apt-get update && apt-get install -y \
8281
${PYTHON} \
8382
${PYTHON_PIP}
8483

85-
COPY $FRAMEWORK_SUPPORT_INSTALLABLE .
86-
8784
RUN ${PIP} --no-cache-dir install --upgrade \
8885
pip \
8986
setuptools
@@ -111,13 +108,11 @@ RUN ${PIP} install --no-cache-dir -U \
111108
opencv-python==4.2.0.32 \
112109
"cryptography>=2.3" \
113110
"sagemaker-tensorflow>=2.1,<2.2" \
111+
"sagemaker-tensorflow-training>2,<4" \
114112
# Let's install TensorFlow separately in the end to avoid
115113
# the library version to be overwritten
116114
&& ${PIP} install --no-cache-dir -U \
117115
${TF_URL} \
118-
&& ${PIP} install --no-cache-dir -U \
119-
$FRAMEWORK_SUPPORT_INSTALLABLE \
120-
&& rm -f $FRAMEWORK_SUPPORT_INSTALLABLE \
121116
&& ${PIP} install --no-cache-dir -U \
122117
horovod==0.18.2
123118

docker/2.1.0/py2/Dockerfile.gpu

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ ENV PYTHONIOENCODING=UTF-8
1313
ENV LANG=C.UTF-8
1414
ENV LC_ALL=C.UTF-8
1515

16-
ARG FRAMEWORK_SUPPORT_INSTALLABLE=sagemaker_tensorflow_training*.tar.gz
1716
ARG TF_URL=https://tensorflow-aws.s3-us-west-2.amazonaws.com/2.1/AmazonLinux/gpu/final/tensorflow_gpu-2.1.0-cp27-cp27mu-manylinux2010_x86_64.whl
1817

1918
ARG PYTHON=python
@@ -122,8 +121,6 @@ RUN ${PIP} --no-cache-dir install --upgrade \
122121
# Some TF tools expect a "python" binary
123122
RUN ln -s $(which ${PYTHON}) /usr/local/bin/python
124123

125-
COPY $FRAMEWORK_SUPPORT_INSTALLABLE .
126-
127124
# install PyYAML==5.1.2 to avoid conflict with latest awscli
128125
# # python-dateutil==2.8.0 to satisfy botocore associated with latest awscli
129126
RUN ${PIP} install --no-cache-dir -U \
@@ -144,13 +141,11 @@ RUN ${PIP} install --no-cache-dir -U \
144141
opencv-python==4.2.0.32 \
145142
"cryptography>=2.3" \
146143
"sagemaker-tensorflow>=2.1,<2.2" \
144+
"sagemaker-tensorflow-training>2,<4" \
147145
# Let's install TensorFlow separately in the end to avoid
148146
# the library version to be overwritten
149147
&& ${PIP} install --no-cache-dir -U \
150-
${TF_URL} \
151-
&& ${PIP} install --no-cache-dir -U \
152-
$FRAMEWORK_SUPPORT_INSTALLABLE \
153-
&& rm -f $FRAMEWORK_SUPPORT_INSTALLABLE
148+
${TF_URL}
154149

155150
# Install Horovod, temporarily using CUDA stubs
156151
RUN ldconfig /usr/local/cuda/targets/x86_64-linux/lib/stubs \

docker/2.1.0/py3/Dockerfile.cpu

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ ARG PYTHON=python3
2424
ARG PYTHON_PIP=python3-pip
2525
ARG PIP=pip3
2626

27-
ARG FRAMEWORK_SUPPORT_INSTALLABLE=sagemaker_tensorflow_training*.tar.gz
2827
ARG TF_URL=https://tensorflow-aws.s3-us-west-2.amazonaws.com/2.1/AmazonLinux/cpu/final/tensorflow-2.1.0-cp36-cp36m-manylinux2010_x86_64.whl
2928

3029
RUN apt-get update && apt-get install -y --no-install-recommends \
@@ -81,8 +80,6 @@ RUN mkdir -p /root/.ssh/ \
8180

8281
WORKDIR /
8382

84-
COPY $FRAMEWORK_SUPPORT_INSTALLABLE .
85-
8683
RUN ${PIP} --no-cache-dir install --upgrade \
8784
pip \
8885
setuptools
@@ -113,14 +110,12 @@ RUN ${PIP} install --no-cache-dir -U \
113110
sagemaker==1.50.17 \
114111
sagemaker-experiments==0.1.7 \
115112
"sagemaker-tensorflow>=2.1,<2.2" \
113+
"sagemaker-tensorflow-training>2,<4" \
116114
# Let's install TensorFlow separately in the end to avoid
117115
# the library version to be overwritten
118116
&& ${PIP} install --no-cache-dir -U \
119117
${TF_URL} \
120-
horovod==0.18.2 \
121-
&& ${PIP} install --no-cache-dir -U \
122-
$FRAMEWORK_SUPPORT_INSTALLABLE \
123-
&& rm -f $FRAMEWORK_SUPPORT_INSTALLABLE
118+
horovod==0.18.2
124119

125120
ADD https://raw.githubusercontent.com/aws/aws-deep-learning-containers-utils/master/deep_learning_container.py /usr/local/bin/deep_learning_container.py
126121

docker/2.1.0/py3/Dockerfile.gpu

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ ARG PYTHON=python3
2424
ARG PYTHON_PIP=python3-pip
2525
ARG PIP=pip3
2626

27-
ARG FRAMEWORK_SUPPORT_INSTALLABLE=sagemaker_tensorflow_training*.tar.gz
2827
ARG TF_URL=https://tensorflow-aws.s3-us-west-2.amazonaws.com/2.1/AmazonLinux/gpu/final/tensorflow_gpu-2.1.0-cp36-cp36m-manylinux2010_x86_64.whl
2928

3029
RUN apt-get update && apt-get install -y --no-install-recommends --allow-unauthenticated \
@@ -133,8 +132,6 @@ RUN ${PIP} --no-cache-dir install --upgrade \
133132
RUN ln -s $(which ${PYTHON}) /usr/local/bin/python \
134133
&& ln -s $(which ${PIP}) /usr/bin/pip
135134

136-
COPY $FRAMEWORK_SUPPORT_INSTALLABLE .
137-
138135
# install PyYAML==5.1.2 to avoid conflict with latest awscli
139136
# # python-dateutil==2.8.0 to satisfy botocore associated with latest awscli
140137
RUN ${PIP} install --no-cache-dir -U \
@@ -157,13 +154,11 @@ RUN ${PIP} install --no-cache-dir -U \
157154
sagemaker==1.50.17 \
158155
sagemaker-experiments==0.1.7 \
159156
"sagemaker-tensorflow>=2.1,<2.2" \
157+
"sagemaker-tensorflow-training>2,<4" \
160158
# Let's install TensorFlow separately in the end to avoid
161159
# the library version to be overwritten
162160
&& ${PIP} install --no-cache-dir -U \
163-
${TF_URL} \
164-
&& ${PIP} install --no-cache-dir -U \
165-
$FRAMEWORK_SUPPORT_INSTALLABLE \
166-
&& rm -f $FRAMEWORK_SUPPORT_INSTALLABLE
161+
${TF_URL}
167162

168163
# Install Horovod, temporarily using CUDA stubs
169164
RUN ldconfig /usr/local/cuda-10.1/targets/x86_64-linux/lib/stubs \

0 commit comments

Comments
 (0)