Skip to content

Commit c097ca1

Browse files
authored
Upgrade to TensorFlow 1.13.1 (#184)
* Upgrade to TensorFlow 1.13.1 * Add 1.13.1 dockerfiles * Lower process number for one of the horovod local mode test Too many processes running in parallel causes the test fail sometimes. * Use multiprocessing.Process to start ps
1 parent f40f010 commit c097ca1

File tree

7 files changed

+231
-6
lines changed

7 files changed

+231
-6
lines changed

docker/1.13.1/Dockerfile.cpu

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
FROM ubuntu:16.04
2+
3+
LABEL maintainer="Amazon AI"
4+
5+
RUN apt-get update && apt-get install -y --no-install-recommends \
6+
software-properties-common \
7+
build-essential \
8+
openssh-client \
9+
openssh-server \
10+
ca-certificates \
11+
curl \
12+
&& add-apt-repository ppa:deadsnakes/ppa -y \
13+
&& rm -rf /var/lib/apt/lists/*
14+
15+
# Install Open MPI
16+
RUN mkdir /tmp/openmpi && \
17+
cd /tmp/openmpi && \
18+
curl -fSsL -O https://www.open-mpi.org/software/ompi/v3.1/downloads/openmpi-3.1.2.tar.gz && \
19+
tar zxf openmpi-3.1.2.tar.gz && \
20+
cd openmpi-3.1.2 && \
21+
./configure --enable-orterun-prefix-by-default && \
22+
make -j $(nproc) all && \
23+
make install && \
24+
ldconfig && \
25+
rm -rf /tmp/openmpi
26+
27+
# Create a wrapper for OpenMPI to allow running as root by default
28+
RUN mv /usr/local/bin/mpirun /usr/local/bin/mpirun.real && \
29+
echo '#!/bin/bash' > /usr/local/bin/mpirun && \
30+
echo 'mpirun.real --allow-run-as-root "$@"' >> /usr/local/bin/mpirun && \
31+
chmod a+x /usr/local/bin/mpirun
32+
33+
RUN echo "hwloc_base_binding_policy = none" >> /usr/local/etc/openmpi-mca-params.conf && \
34+
echo "rmaps_base_mapping_policy = slot" >> /usr/local/etc/openmpi-mca-params.conf
35+
36+
ENV LD_LIBRARY_PATH=/usr/local/openmpi/lib:$LD_LIBRARY_PATH
37+
38+
ENV PATH /usr/local/openmpi/bin/:$PATH
39+
40+
# SSH login fix. Otherwise user is kicked off after login
41+
RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
42+
43+
# Create SSH key.
44+
RUN mkdir -p /root/.ssh/ && \
45+
mkdir -p /var/run/sshd && \
46+
ssh-keygen -q -t rsa -N '' -f /root/.ssh/id_rsa && \
47+
cp /root/.ssh/id_rsa.pub /root/.ssh/authorized_keys && \
48+
printf "Host *\n StrictHostKeyChecking no\n" >> /root/.ssh/config
49+
50+
# Set environment variables for MKL
51+
# For more about MKL with TensorFlow see:
52+
# https://www.tensorflow.org/performance/performance_guide#tensorflow_with_intel%C2%AE_mkl_dnn
53+
ENV KMP_AFFINITY=granularity=fine,compact,1,0 KMP_BLOCKTIME=1 KMP_SETTINGS=0
54+
55+
WORKDIR /
56+
57+
ARG py_version
58+
ARG framework_installable
59+
ARG framework_support_installable=sagemaker_tensorflow_container-2.0.0.tar.gz
60+
61+
RUN if [ $py_version -eq 3 ]; then PYTHON_VERSION=python3.6; else PYTHON_VERSION=python2.7; fi && \
62+
apt-get update && apt-get install -y --no-install-recommends $PYTHON_VERSION-dev --allow-unauthenticated && \
63+
ln -s -f /usr/bin/$PYTHON_VERSION /usr/bin/python && \
64+
ln -s -f /usr/bin/$PYTHON_VERSION /usr/local/bin/python && \
65+
rm -rf /var/lib/apt/lists/*
66+
67+
ENV PYTHONDONTWRITEBYTECODE=1 PYTHONUNBUFFERED=1 PYTHONIOENCODING=UTF-8 LANG=C.UTF-8 LC_ALL=C.UTF-8
68+
69+
RUN curl -fSsL -O https://bootstrap.pypa.io/get-pip.py && \
70+
python get-pip.py --disable-pip-version-check --no-cache-dir "pip==18.1" && \
71+
rm get-pip.py
72+
73+
COPY $framework_installable tensorflow-1.13.1-py2.py3-none-any.whl
74+
COPY $framework_support_installable .
75+
76+
RUN pip install --no-cache-dir -U \
77+
keras==2.2.4 \
78+
mpi4py==3.0.1 \
79+
"sagemaker-tensorflow>=1.13,<1.14" && \
80+
# Let's install TensorFlow separately in the end to avoid
81+
# the library version to be overwritten
82+
pip install --force-reinstall --no-cache-dir -U \
83+
tensorflow-1.13.1-py2.py3-none-any.whl \
84+
horovod && \
85+
pip install --no-cache-dir -U $framework_support_installable && \
86+
rm -f tensorflow-1.13.1-py2.py3-none-any.whl && \
87+
rm -f $framework_support_installable && \
88+
pip uninstall -y --no-cache-dir \
89+
markdown \
90+
tensorboard
91+
92+
ENV SAGEMAKER_TRAINING_MODULE sagemaker_tensorflow_container.training:main

docker/1.13.1/Dockerfile.gpu

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
FROM nvidia/cuda:10.0-base-ubuntu16.04
2+
3+
LABEL maintainer="Amazon AI"
4+
5+
RUN apt-get update && apt-get install -y --no-install-recommends --allow-unauthenticated \
6+
software-properties-common && \
7+
add-apt-repository ppa:deadsnakes/ppa -y && \
8+
rm -rf /var/lib/apt/lists/*
9+
10+
RUN apt-get update && apt-get install -y --no-install-recommends --allow-unauthenticated \
11+
ca-certificates \
12+
cuda-command-line-tools-10-0 \
13+
cuda-cublas-dev-10-0 \
14+
cuda-cudart-dev-10-0 \
15+
cuda-cufft-dev-10-0 \
16+
cuda-curand-dev-10-0 \
17+
cuda-cusolver-dev-10-0 \
18+
cuda-cusparse-dev-10-0 \
19+
curl \
20+
libcudnn7=7.4.1.5-1+cuda10.0 \
21+
# TensorFlow doesn't require libnccl anymore but Open MPI still depends on it
22+
libnccl2 \
23+
libnccl-dev \
24+
libfreetype6-dev \
25+
libhdf5-serial-dev \
26+
libpng12-dev \
27+
libzmq3-dev \
28+
wget \
29+
openssh-client \
30+
openssh-server \
31+
build-essential && \
32+
# The 'apt-get install' of nvinfer-runtime-trt-repo-ubuntu1604-4.0.1-ga-cuda9.0
33+
# adds a new list which contains libnvinfer library, so it needs another
34+
# 'apt-get update' to retrieve that list before it can actually install the
35+
# library.
36+
# We don't install libnvinfer-dev since we don't need to build against TensorRT,
37+
# and libnvinfer4 doesn't contain libnvinfer.a static library.
38+
apt-get update && apt-get install -y --no-install-recommends --allow-unauthenticated \
39+
nvinfer-runtime-trt-repo-ubuntu1604-5.0.2-ga-cuda10.0 && \
40+
apt-get update && apt-get install -y --no-install-recommends --allow-unauthenticated \
41+
libnvinfer5=5.0.2-1+cuda10.0 && \
42+
rm /usr/lib/x86_64-linux-gnu/libnvinfer_plugin* && \
43+
rm /usr/lib/x86_64-linux-gnu/libnvcaffe_parser* && \
44+
rm /usr/lib/x86_64-linux-gnu/libnvparsers* && \
45+
rm -rf /var/lib/apt/lists/*
46+
47+
###########################################################################
48+
# Horovod & its dependencies
49+
###########################################################################
50+
51+
# Install Open MPI
52+
RUN mkdir /tmp/openmpi && \
53+
cd /tmp/openmpi && \
54+
curl -fSsL -O https://www.open-mpi.org/software/ompi/v3.1/downloads/openmpi-3.1.2.tar.gz && \
55+
tar zxf openmpi-3.1.2.tar.gz && \
56+
cd openmpi-3.1.2 && \
57+
./configure --enable-orterun-prefix-by-default && \
58+
make -j $(nproc) all && \
59+
make install && \
60+
ldconfig && \
61+
rm -rf /tmp/openmpi
62+
63+
ARG py_version
64+
ARG framework_installable
65+
ARG framework_support_installable=sagemaker_tensorflow_container-2.0.0.tar.gz
66+
67+
RUN if [ $py_version -eq 3 ]; then PYTHON_VERSION=python3.6; else PYTHON_VERSION=python2.7; fi && \
68+
apt-get update && apt-get install -y --no-install-recommends $PYTHON_VERSION-dev --allow-unauthenticated && \
69+
ln -s -f /usr/bin/$PYTHON_VERSION /usr/bin/python && \
70+
rm -rf /var/lib/apt/lists/*
71+
72+
# Create a wrapper for OpenMPI to allow running as root by default
73+
RUN mv /usr/local/bin/mpirun /usr/local/bin/mpirun.real && \
74+
echo '#!/bin/bash' > /usr/local/bin/mpirun && \
75+
echo 'mpirun.real --allow-run-as-root "$@"' >> /usr/local/bin/mpirun && \
76+
chmod a+x /usr/local/bin/mpirun
77+
78+
# Configure OpenMPI to run good defaults:
79+
# --bind-to none --map-by slot --mca btl_tcp_if_exclude lo,docker0
80+
RUN echo "hwloc_base_binding_policy = none" >> /usr/local/etc/openmpi-mca-params.conf && \
81+
echo "rmaps_base_mapping_policy = slot" >> /usr/local/etc/openmpi-mca-params.conf
82+
83+
# Set default NCCL parameters
84+
RUN echo NCCL_DEBUG=INFO >> /etc/nccl.conf
85+
86+
ENV LD_LIBRARY_PATH=/usr/local/openmpi/lib:$LD_LIBRARY_PATH
87+
ENV PATH /usr/local/openmpi/bin/:$PATH
88+
ENV PATH=/usr/local/nvidia/bin:$PATH
89+
90+
# SSH login fix. Otherwise user is kicked off after login
91+
RUN mkdir -p /var/run/sshd && sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
92+
93+
# Create SSH key.
94+
RUN mkdir -p /root/.ssh/ && \
95+
ssh-keygen -q -t rsa -N '' -f /root/.ssh/id_rsa && \
96+
cp /root/.ssh/id_rsa.pub /root/.ssh/authorized_keys && \
97+
printf "Host *\n StrictHostKeyChecking no\n" >> /root/.ssh/config
98+
99+
###########################################################################
100+
# Python won’t try to write .pyc or .pyo files on the import of source modules
101+
ENV PYTHONDONTWRITEBYTECODE=1 PYTHONUNBUFFERED=1 PYTHONIOENCODING=UTF-8 LANG=C.UTF-8 LC_ALL=C.UTF-8
102+
103+
RUN curl -fSsL -O https://bootstrap.pypa.io/get-pip.py && \
104+
python get-pip.py --disable-pip-version-check --no-cache-dir "pip==18.1" && \
105+
rm get-pip.py
106+
107+
WORKDIR /
108+
109+
COPY $framework_installable tensorflow-1.13.1-py2.py3-none-any.whl
110+
COPY $framework_support_installable .
111+
112+
RUN pip install --no-cache-dir -U \
113+
keras==2.2.4 \
114+
mpi4py==3.0.1 \
115+
$framework_support_installable \
116+
"sagemaker-tensorflow>=1.13,<1.14" \
117+
# Let's install TensorFlow separately in the end to avoid
118+
# the library version to be overwritten
119+
&& pip install --force-reinstall --no-cache-dir -U tensorflow-1.13.1-py2.py3-none-any.whl \
120+
\
121+
&& rm -f tensorflow-1.13.1-py2.py3-none-any.whl \
122+
&& rm -f $framework_support_installable \
123+
&& pip uninstall -y --no-cache-dir \
124+
markdown \
125+
tensorboard
126+
127+
# Install Horovod, temporarily using CUDA stubs
128+
RUN ldconfig /usr/local/cuda-10.0/targets/x86_64-linux/lib/stubs && \
129+
HOROVOD_GPU_ALLREDUCE=NCCL HOROVOD_WITH_TENSORFLOW=1 pip install --no-cache-dir horovod && \
130+
ldconfig
131+
132+
ENV SAGEMAKER_TRAINING_MODULE sagemaker_tensorflow_container.training:main

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def read(fname):
5353
'pandas', 'Pillow', 'h5py'],
5454
extras_require={
5555
'test': ['tox', 'flake8', 'pytest', 'pytest-cov', 'pytest-xdist', 'mock',
56-
'sagemaker>=1.15.2', 'tensorflow', 'docker-compose'],
56+
'sagemaker==1.19.1', 'tensorflow', 'docker-compose'],
5757
'benchmark': ['click']
5858
},
5959
)

src/sagemaker_tensorflow_container/training.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414

1515
import json
1616
import logging
17+
import multiprocessing
1718
import os
1819
import subprocess
19-
import threading
2020
import time
2121

2222
import sagemaker_containers.beta.framework as framework
@@ -102,7 +102,7 @@ def _run_ps(env, cluster):
102102
cluster_spec, job_name='ps', task_index=task_index, config=no_gpu_config
103103
)
104104

105-
threading.Thread(target=lambda: server.join()).start()
105+
multiprocessing.Process(target=lambda: server.join()).start()
106106

107107

108108
def _run_worker(env, cmd_args, tf_config):

test/integration/local/test_horovod.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
[1, 2],
2828
(2, 1),
2929
(2, 2),
30-
(5, 3)])
30+
(5, 2)])
3131
def test_distributed_training_horovod_basic(instances,
3232
processes,
3333
sagemaker_local_session,

test/integration/local/test_keras.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
logging.basicConfig(level=logging.DEBUG)
2626

2727

28-
@pytest.mark.skip_gpu
28+
@pytest.mark.skip(reason="Serving part fails because of version mismatch.")
2929
def test_keras_training(sagemaker_local_session, docker_image, tmpdir, framework_version):
3030
entry_point = os.path.join(RESOURCE_PATH, 'keras_inception.py')
3131
output_path = 'file://{}'.format(tmpdir)

test/unit/test_training.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def test_train_horovod(run_module, single_machine_training_env):
104104
@patch('tensorflow.train.ClusterSpec')
105105
@patch('tensorflow.train.Server')
106106
@patch('sagemaker_containers.beta.framework.entry_point.run')
107-
@patch('threading.Thread', lambda target: target())
107+
@patch('multiprocessing.Process', lambda target: target())
108108
@patch('time.sleep', MagicMock())
109109
def test_train_distributed_master(run, tf_server, cluster_spec, distributed_training_env):
110110
training.train(distributed_training_env, MODEL_DIR_CMD_LIST)
@@ -134,6 +134,7 @@ def test_train_distributed_master(run, tf_server, cluster_spec, distributed_trai
134134
@patch('tensorflow.train.ClusterSpec')
135135
@patch('tensorflow.train.Server')
136136
@patch('sagemaker_containers.beta.framework.entry_point.run')
137+
@patch('multiprocessing.Process', lambda target: target())
137138
@patch('time.sleep', MagicMock())
138139
def test_train_distributed_worker(run, tf_server, cluster_spec, distributed_training_env):
139140
distributed_training_env.current_host = HOST2

0 commit comments

Comments
 (0)