Skip to content

Commit 1ebee3c

Browse files
chuyang-dengnikhil-sk
authored andcommitted
change: add py2 support for TF 1.14 (#232)
* change: enable py2 support for TF 1.14.0 * fix typo * add sagemaker-tensorflow-extensions * add sagemaker-tensorflow-extensions whl
1 parent 43d0bc9 commit 1ebee3c

File tree

5 files changed

+294
-0
lines changed

5 files changed

+294
-0
lines changed

docker/1.14.0/py2/Dockerfile.cpu

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
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+
git \
13+
wget \
14+
vim \
15+
gcc-4.9 \
16+
g++-4.9 \
17+
gcc-4.9-base \
18+
zlib1g-dev \
19+
&& rm -rf /var/lib/apt/lists/*
20+
21+
# Install Open MPI
22+
RUN mkdir /tmp/openmpi && \
23+
cd /tmp/openmpi && \
24+
curl -fSsL -O https://download.open-mpi.org/release/open-mpi/v4.0/openmpi-4.0.1.tar.gz && \
25+
tar zxf openmpi-4.0.1.tar.gz && \
26+
cd openmpi-4.0.1 && \
27+
./configure --enable-orterun-prefix-by-default && \
28+
make -j $(nproc) all && \
29+
make install && \
30+
ldconfig && \
31+
rm -rf /tmp/openmpi
32+
33+
# Create a wrapper for OpenMPI to allow running as root by default
34+
RUN mv /usr/local/bin/mpirun /usr/local/bin/mpirun.real && \
35+
echo '#!/bin/bash' > /usr/local/bin/mpirun && \
36+
echo 'mpirun.real --allow-run-as-root "$@"' >> /usr/local/bin/mpirun && \
37+
chmod a+x /usr/local/bin/mpirun
38+
39+
RUN echo "hwloc_base_binding_policy = none" >> /usr/local/etc/openmpi-mca-params.conf && \
40+
echo "rmaps_base_mapping_policy = slot" >> /usr/local/etc/openmpi-mca-params.conf
41+
42+
ENV LD_LIBRARY_PATH=/usr/local/openmpi/lib:$LD_LIBRARY_PATH
43+
44+
ENV PATH /usr/local/openmpi/bin/:$PATH
45+
46+
# SSH login fix. Otherwise user is kicked off after login
47+
RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
48+
49+
# Create SSH key.
50+
RUN mkdir -p /root/.ssh/ && \
51+
mkdir -p /var/run/sshd && \
52+
ssh-keygen -q -t rsa -N '' -f /root/.ssh/id_rsa && \
53+
cp /root/.ssh/id_rsa.pub /root/.ssh/authorized_keys && \
54+
printf "Host *\n StrictHostKeyChecking no\n" >> /root/.ssh/config
55+
56+
# Set environment variables for MKL
57+
# For more about MKL with TensorFlow see:
58+
# https://www.tensorflow.org/performance/performance_guide#tensorflow_with_intel%C2%AE_mkl_dnn
59+
ENV KMP_AFFINITY=granularity=fine,compact,1,0 KMP_BLOCKTIME=1 KMP_SETTINGS=0
60+
61+
WORKDIR /
62+
63+
ARG PYTHON=python
64+
ARG PYTHON_PIP=python-pip
65+
ARG PIP=pip
66+
67+
RUN apt-get update && apt-get install -y \
68+
${PYTHON} \
69+
${PYTHON_PIP}
70+
71+
ENV PYTHONDONTWRITEBYTECODE=1 PYTHONUNBUFFERED=1 PYTHONIOENCODING=UTF-8 LANG=C.UTF-8 LC_ALL=C.UTF-8
72+
73+
ARG framework_support_installable=sagemaker_tensorflow_container-2.0.0.tar.gz
74+
ARG sagemaker_tensorflow_extensions=sagemaker_tensorflow-1.14.0.1.0.0-cp27-cp27mu-manylinux1_x86_64.whl
75+
COPY $framework_support_installable .
76+
COPY $sagemaker_tensorflow_extensions .
77+
ARG TF_URL="https://tensorflow-aws.s3-us-west-2.amazonaws.com/1.14/AmazonLinux/cpu/final/tensorflow-1.14.0-cp27-cp27mu-linux_x86_64.whl"
78+
79+
# Pin GCC to 4.9 (priority 200) to compile correctly against TensorFlow, PyTorch, and MXNet with horovod
80+
# Backup existing GCC installation as priority 100, so that it can be recovered later.
81+
RUN update-alternatives --install /usr/bin/gcc gcc $(readlink -f $(which gcc)) 100 && \
82+
update-alternatives --install /usr/bin/x86_64-linux-gnu-gcc x86_64-linux-gnu-gcc $(readlink -f $(which gcc)) 100 && \
83+
update-alternatives --install /usr/bin/g++ g++ $(readlink -f $(which g++)) 100 && \
84+
update-alternatives --install /usr/bin/x86_64-linux-gnu-g++ x86_64-linux-gnu-g++ $(readlink -f $(which g++)) 100
85+
RUN update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 200 && \
86+
update-alternatives --install /usr/bin/x86_64-linux-gnu-gcc x86_64-linux-gnu-gcc /usr/bin/gcc-4.9 200 && \
87+
update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.9 200 && \
88+
update-alternatives --install /usr/bin/x86_64-linux-gnu-g++ x86_64-linux-gnu-g++ /usr/bin/g++-4.9 200
89+
90+
RUN ${PIP} --no-cache-dir install --upgrade pip setuptools
91+
92+
# Some TF tools expect a "python" binary
93+
RUN ln -s $(which ${PYTHON}) /usr/local/bin/python
94+
95+
RUN ${PIP} install --no-cache-dir -U \
96+
numpy==1.16.4 \
97+
scipy==1.2.2 \
98+
scikit-learn==0.20.3 \
99+
pandas==0.24.2 \
100+
Pillow==6.1.0 \
101+
h5py==2.9.0 \
102+
keras_applications==1.0.8 \
103+
keras_preprocessing==1.1.0 \
104+
requests==2.22.0 \
105+
keras==2.2.4 \
106+
awscli==1.16.196 \
107+
mpi4py==3.0.2 \
108+
$sagemaker_tensorflow_extensions \
109+
# Let's install TensorFlow separately in the end to avoid
110+
# the library version to be overwritten
111+
&& ${PIP} install --force-reinstall --no-cache-dir -U ${TF_URL} \
112+
&& ${PIP} install --no-cache-dir -U $framework_support_installable && \
113+
rm -f $framework_support_installable \
114+
&& ${PIP} install --no-cache-dir -U horovod==0.16.4 \
115+
&& ${PIP} uninstall -y --no-cache-dir \
116+
markdown
117+
118+
# Remove GCC pinning
119+
RUN update-alternatives --remove gcc /usr/bin/gcc-4.9 && \
120+
update-alternatives --remove x86_64-linux-gnu-gcc /usr/bin/gcc-4.9 && \
121+
update-alternatives --remove g++ /usr/bin/g++-4.9 && \
122+
update-alternatives --remove x86_64-linux-gnu-g++ /usr/bin/g++-4.9
123+
124+
125+
ENV SAGEMAKER_TRAINING_MODULE sagemaker_tensorflow_container.training:main
126+
127+
CMD ["bin/bash"]

docker/1.14.0/py2/Dockerfile.gpu

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
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+
ca-certificates \
7+
cuda-command-line-tools-10-0 \
8+
cuda-cublas-dev-10-0 \
9+
cuda-cudart-dev-10-0 \
10+
cuda-cufft-dev-10-0 \
11+
cuda-curand-dev-10-0 \
12+
cuda-cusolver-dev-10-0 \
13+
cuda-cusparse-dev-10-0 \
14+
curl \
15+
libcudnn7=7.5.1.10-1+cuda10.0 \
16+
# TensorFlow doesn't require libnccl anymore but Open MPI still depends on it
17+
libnccl2=2.4.7-1+cuda10.0 \
18+
libgomp1 \
19+
gcc-4.9 \
20+
g++-4.9 \
21+
gcc-4.9-base \
22+
libnccl-dev=2.4.7-1+cuda10.0 \
23+
libfreetype6-dev \
24+
libhdf5-serial-dev \
25+
libpng12-dev \
26+
libzmq3-dev \
27+
git \
28+
wget \
29+
vim \
30+
build-essential \
31+
openssh-client \
32+
openssh-server \
33+
zlib1g-dev && \
34+
# The 'apt-get install' of nvinfer-runtime-trt-repo-ubuntu1604-4.0.1-ga-cuda9.0
35+
# adds a new list which contains libnvinfer library, so it needs another
36+
# 'apt-get update' to retrieve that list before it can actually install the
37+
# library.
38+
# We don't install libnvinfer-dev since we don't need to build against TensorRT,
39+
# and libnvinfer4 doesn't contain libnvinfer.a static library.
40+
apt-get update && apt-get install -y --no-install-recommends --allow-unauthenticated \
41+
nvinfer-runtime-trt-repo-ubuntu1604-5.0.2-ga-cuda10.0 && \
42+
apt-get update && apt-get install -y --no-install-recommends --allow-unauthenticated \
43+
libnvinfer5=5.0.2-1+cuda10.0 && \
44+
rm /usr/lib/x86_64-linux-gnu/libnvinfer_plugin* && \
45+
rm /usr/lib/x86_64-linux-gnu/libnvcaffe_parser* && \
46+
rm /usr/lib/x86_64-linux-gnu/libnvparsers* && \
47+
rm -rf /var/lib/apt/lists/* && \
48+
mkdir -p /var/run/sshd
49+
50+
# Install Open MPI
51+
RUN mkdir /tmp/openmpi && \
52+
cd /tmp/openmpi && \
53+
curl -fSsL -O https://download.open-mpi.org/release/open-mpi/v4.0/openmpi-4.0.1.tar.gz && \
54+
tar zxf openmpi-4.0.1.tar.gz && \
55+
cd openmpi-4.0.1 && \
56+
./configure --enable-orterun-prefix-by-default && \
57+
make -j $(nproc) all && \
58+
make install && \
59+
ldconfig && \
60+
rm -rf /tmp/openmpi
61+
62+
ARG PYTHON=python
63+
ARG PYTHON_PIP=python-pip
64+
ARG PIP=pip
65+
66+
RUN apt-get update && apt-get install -y \
67+
${PYTHON} \
68+
${PYTHON_PIP}
69+
70+
# Create a wrapper for OpenMPI to allow running as root by default
71+
RUN mv /usr/local/bin/mpirun /usr/local/bin/mpirun.real && \
72+
echo '#!/bin/bash' > /usr/local/bin/mpirun && \
73+
echo 'mpirun.real --allow-run-as-root "$@"' >> /usr/local/bin/mpirun && \
74+
chmod a+x /usr/local/bin/mpirun
75+
76+
# Configure OpenMPI to run good defaults:
77+
# --bind-to none --map-by slot --mca btl_tcp_if_exclude lo,docker0
78+
RUN echo "hwloc_base_binding_policy = none" >> /usr/local/etc/openmpi-mca-params.conf && \
79+
echo "rmaps_base_mapping_policy = slot" >> /usr/local/etc/openmpi-mca-params.conf
80+
81+
# Set default NCCL parameters
82+
RUN echo NCCL_DEBUG=INFO >> /etc/nccl.conf
83+
84+
ENV LD_LIBRARY_PATH=/usr/local/openmpi/lib:$LD_LIBRARY_PATH
85+
ENV PATH /usr/local/openmpi/bin/:$PATH
86+
ENV PATH=/usr/local/nvidia/bin:$PATH
87+
88+
# SSH login fix. Otherwise user is kicked off after login
89+
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
90+
91+
# Create SSH key.
92+
RUN mkdir -p /root/.ssh/ && \
93+
ssh-keygen -q -t rsa -N '' -f /root/.ssh/id_rsa && \
94+
cp /root/.ssh/id_rsa.pub /root/.ssh/authorized_keys && \
95+
printf "Host *\n StrictHostKeyChecking no\n" >> /root/.ssh/config
96+
97+
###########################################################################
98+
# Python won’t try to write .pyc or .pyo files on the import of source modules
99+
ENV PYTHONDONTWRITEBYTECODE=1 PYTHONUNBUFFERED=1 PYTHONIOENCODING=UTF-8 LANG=C.UTF-8 LC_ALL=C.UTF-8
100+
101+
WORKDIR /
102+
103+
ARG TF_URL="https://tensorflow-aws.s3-us-west-2.amazonaws.com/1.14/AmazonLinux/gpu/final/tensorflow-1.14.0-cp27-cp27mu-linux_x86_64.whl"
104+
105+
RUN ${PIP} --no-cache-dir install --upgrade pip setuptools
106+
107+
# Some TF tools expect a "python" binary
108+
RUN ln -s $(which ${PYTHON}) /usr/local/bin/python
109+
110+
ARG framework_support_installable=sagemaker_tensorflow_container-2.0.0.tar.gz
111+
ARG sagemaker_tensorflow_extensions=sagemaker_tensorflow-1.14.0.1.0.0-cp27-cp27mu-manylinux1_x86_64.whl
112+
COPY $framework_support_installable .
113+
COPY $sagemaker_tensorflow_extensions .
114+
115+
RUN ${PIP} install --no-cache-dir -U \
116+
numpy==1.16.4 \
117+
scipy==1.2.2 \
118+
scikit-learn==0.20.3 \
119+
pandas==0.24.2 \
120+
Pillow==6.1.0 \
121+
h5py==2.9.0 \
122+
keras_applications==1.0.8 \
123+
keras_preprocessing==1.1.0 \
124+
requests==2.22.0 \
125+
keras==2.2.4 \
126+
awscli==1.16.196 \
127+
mpi4py==3.0.2 \
128+
$sagemaker_tensorflow_extensions \
129+
# Let's install TensorFlow separately in the end to avoid
130+
# the library version to be overwritten
131+
&& ${PIP} install --force-reinstall --no-cache-dir -U ${TF_URL} \
132+
&& ${PIP} install --no-cache-dir -U $framework_support_installable && \
133+
rm -f $framework_support_installable \
134+
&& ${PIP} uninstall -y --no-cache-dir \
135+
markdown
136+
137+
# Pin GCC to 4.9 (priority 200) to compile correctly against TensorFlow, PyTorch, and MXNet with horovod
138+
# Backup existing GCC installation as priority 100, so that it can be recovered later.
139+
RUN update-alternatives --install /usr/bin/gcc gcc $(readlink -f $(which gcc)) 100 && \
140+
update-alternatives --install /usr/bin/x86_64-linux-gnu-gcc x86_64-linux-gnu-gcc $(readlink -f $(which gcc)) 100 && \
141+
update-alternatives --install /usr/bin/g++ g++ $(readlink -f $(which g++)) 100 && \
142+
update-alternatives --install /usr/bin/x86_64-linux-gnu-g++ x86_64-linux-gnu-g++ $(readlink -f $(which g++)) 100
143+
RUN update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 200 && \
144+
update-alternatives --install /usr/bin/x86_64-linux-gnu-gcc x86_64-linux-gnu-gcc /usr/bin/gcc-4.9 200 && \
145+
update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.9 200 && \
146+
update-alternatives --install /usr/bin/x86_64-linux-gnu-g++ x86_64-linux-gnu-g++ /usr/bin/g++-4.9 200
147+
148+
149+
# Install Horovod, temporarily using CUDA stubs
150+
RUN ldconfig /usr/local/cuda-10.0/targets/x86_64-linux/lib/stubs && \
151+
HOROVOD_GPU_ALLREDUCE=NCCL HOROVOD_WITH_TENSORFLOW=1 ${PIP} install --no-cache-dir horovod==0.16.4 && \
152+
ldconfig
153+
154+
# Remove GCC pinning
155+
RUN update-alternatives --remove gcc /usr/bin/gcc-4.9 && \
156+
update-alternatives --remove x86_64-linux-gnu-gcc /usr/bin/gcc-4.9 && \
157+
update-alternatives --remove g++ /usr/bin/g++-4.9 && \
158+
update-alternatives --remove x86_64-linux-gnu-g++ /usr/bin/g++-4.9
159+
160+
# Allow OpenSSH to talk to containers without asking for confirmation
161+
RUN cat /etc/ssh/ssh_config | grep -v StrictHostKeyChecking > /etc/ssh/ssh_config.new && \
162+
echo " StrictHostKeyChecking no" >> /etc/ssh/ssh_config.new && \
163+
mv /etc/ssh/ssh_config.new /etc/ssh/ssh_config
164+
165+
ENV SAGEMAKER_TRAINING_MODULE sagemaker_tensorflow_container.training:main
166+
167+
CMD ["bin/bash"]
File renamed without changes.
File renamed without changes.
Binary file not shown.

0 commit comments

Comments
 (0)