-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dockerfile.cudnn7
300 lines (280 loc) · 13.2 KB
/
Dockerfile.cudnn7
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
# A good explanation of the job flag for makefiles: https://www.gnu.org/software/make/manual/html_node/Parallel.html
# Base image is from Ubuntu 18.04 that has CUDA 11.1 installed
# This is because Azure Kinect SDK only has official releases for Ubuntu 18.04
# Changed CUDA to 10.2 because of nvcc error when building chainer-ctc, warp-transducer for ESPnet. Fix was to downgrade from CUDA 11 to CUDA 10.2: https://github.com/espnet/espnet/issues/2177
FROM nvidia/cuda:10.2-cudnn7-devel-ubuntu18.04
# Arguments for OpenCV
ARG DEBIAN_FRONTEND=noninteractive
ARG OPENCV_VERSION=4.5.0
# ----------------------------Linux Dependencies-------------------------
RUN rm -f /etc/apt/sources.list.d/cuda.list && \
rm -f /etc/apt/sources.list.d/nvidia-ml.list && \
apt-get update && apt-get upgrade -y &&\
# Install Overall Dependencies
apt-get install -y --no-install-recommends \
g++ \
make \
cmake \
automake \
autoconf \
bzip2 \
unzip \
wget \
sox \
libtool \
subversion \
zlib1g-dev \
gfortran \
ca-certificates \
patch \
ffmpeg \
libsndfile1-dev \
flac \
vim \
curl \
nkf \
nano \
libfreetype6-dev \
software-properties-common \
# Install Dependencies for HTK
&& apt-get update && apt-get upgrade -y && apt-get install -y libc6-dev-i386 \
ksh \
bc \
libx11-dev \
# Since Guru has a Windows Computer, he needs to convert the Windows Line Endings to Unix Line Endings
dos2unix \
# Install Dependencies for OpenCV
&& apt-get update && apt-get upgrade -y && apt-get install -y \
python3-pip \
build-essential \
yasm \
pkg-config \
libtbb2 \
libtbb-dev \
libjpeg-dev \
libpng-dev \
libtiff-dev \
libpq-dev \
libxine2-dev \
libglew-dev \
libtiff5-dev \
zlib1g-dev \
libavcodec-dev \
libavformat-dev \
libavutil-dev \
libpostproc-dev \
libswscale-dev \
libeigen3-dev \
libgtk2.0-dev \
# Installs numpy for Python 2.7
python-numpy \
# ESPnet only works for Python 3.7 and above -- installing 3.8 because Python 3.7 failed for the "pip install -e ." command
python3-dev \
python3-pip \
# Install dependencies for ESPnet
&& apt-get update && apt-get upgrade -y && apt-get -y install --no-install-recommends \
apt-utils \
gawk \
libboost-all-dev \
libbz2-dev \
liblzma-dev \
unzip \
wget \
zip \
# Needed for installation of phonemizer (used by ESPnet)
libncurses5-dev \
libncursesw5-dev \
&& apt-get clean && rm -rf /var/lib/apt/lists/*
# -----------------------------------------------------------------------
# -------------------------------Python Setup----------------------------
RUN add-apt-repository ppa:git-core/ppa -y && apt-get update && apt-get install git -y
# Install Miniconda
ENV CONDA_DIR /opt/conda
RUN rm -rf /opt/conda && \
wget --quiet https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda.sh && \
/bin/bash ~/miniconda.sh -b -p /opt/conda && \
# Needed for chainer_ctc install
/opt/conda/bin/python3 -m pip install --upgrade pip setuptools
ENV PATH=$CONDA_DIR/bin:$PATH
# -----------------------------------------------------------------------
# ---------------------------------HTK-----------------------------------
COPY ./htk ./htk
COPY ./gt2k ./gt2k
COPY ./prepare ./htk/prepare
# Deleted LetterLevel and WordLevel folders because they are not used in this project
WORKDIR /htk
# This prepare script is where htk is built from scratch
RUN dos2unix prepare && chmod +x prepare && ./prepare
# -----------------------------------------------------------------------
# -------------------------------ESPnet----------------------------------
WORKDIR /
# Install Kaldi inside of ESPnet (source: http://jrmeyer.github.io/asr/2016/01/26/Installing-Kaldi.html)
RUN rm -rf /espnet && git clone https://github.com/espnet/espnet && \
cd espnet/tools && \
git clone https://github.com/kaldi-asr/kaldi.git && \
# Ran the check_dependencies.sh script to check dependencies and saw that this needed to be run
./kaldi/tools/extras/install_mkl.sh && \
cd kaldi/tools && \
# Could not use -j due to packages not compiling. Removing -j fixed the issue: https://github.com/kaldi-asr/kaldi/issues/3987
# Added -j back since I had Ebisu's RAM to use
make -j "$(($(($((`free -g | grep '^Mem:' | grep -o '[^ ]*$'`/2)) < $(nproc) ? $((`free -g | grep '^Mem:' | grep -o '[^ ]*$'`/2)) : $(nproc)))>1 ? $(($((`free -g | grep '^Mem:' | grep -o '[^ ]*$'`/2)) < $(nproc) ? $((`free -g | grep '^Mem:' | grep -o '[^ ]*$'`/2)) : $(nproc))) : 1))" && \
./extras/install_irstlm.sh && \
cd ../src && \
# Run configure script with the fix from this source: https://github.com/kaldi-asr/kaldi/issues/4391
./configure --shared --use-cuda && \
make -j clean depend && \
make -j "$(($(($((`free -g | grep '^Mem:' | grep -o '[^ ]*$'`/2)) < $(nproc) ? $((`free -g | grep '^Mem:' | grep -o '[^ ]*$'`/2)) : $(nproc)))>1 ? $(($((`free -g | grep '^Mem:' | grep -o '[^ ]*$'`/2)) < $(nproc) ? $((`free -g | grep '^Mem:' | grep -o '[^ ]*$'`/2)) : $(nproc))) : 1))"
# Install ESPnet (source: https://espnet.github.io/espnet/installation.html)
# Additional resource: https://github.com/espnet/interspeech2019-tutorial/blob/master/notebooks/meetup/an4_meetup.ipynb
WORKDIR /espnet/tools
# Setting up system Python environment
RUN ./setup_anaconda.sh ${CONDA_DIR} base 3.8 && \
make -j "$(($(($((`free -g | grep '^Mem:' | grep -o '[^ ]*$'`/2)) < $(nproc) ? $((`free -g | grep '^Mem:' | grep -o '[^ ]*$'`/2)) : $(nproc)))>1 ? $(($((`free -g | grep '^Mem:' | grep -o '[^ ]*$'`/2)) < $(nproc) ? $((`free -g | grep '^Mem:' | grep -o '[^ ]*$'`/2)) : $(nproc))) : 1))" && \
./setup_cuda_env.sh /usr/local/cuda && \
# Based on running the python3 check_install.py, these packages need to be installed
./installers/install_chainer_ctc.sh && \
./installers/install_kenlm.sh && \
./installers/install_py3mmseg.sh && \
./installers/install_phonemizer.sh && \
./installers/install_gtn.sh && \
./installers/install_s3prl.sh && \
./installers/install_transformers.sh && \
./installers/install_speechbrain.sh && \
./installers/install_k2.sh && \
./installers/install_longformer.sh && \
./installers/install_pesq.sh && \
./installers/install_beamformit.sh && \
./installers/install_tdmelodic_pyopenjtalk.sh && \
./installers/install_fairseq.sh && \
./installers/install_sctk.sh && \
./installers/install_sph2pipe.sh && \
# Optional packages for ESPnet
./installers/install_warp-ctc.sh && \
./installers/install_warp-transducer.sh && \
./installers/install_pyopenjtalk.sh && \
python3 check_install.py
# -----------------------------------------------------------------------
# ----------------------------Azure Kinect SDK---------------------------
# In order to use apt-add-repository, we need to go back to Python3.6 as the default
WORKDIR /
RUN curl -sSL https://packages.microsoft.com/keys/microsoft.asc | apt-key add - && \
apt-add-repository https://packages.microsoft.com/ubuntu/18.04/prod && \
apt-get update && \
ACCEPT_EULA=Y apt-get install k4a-tools -y && \
apt-get install -y \
libk4a1.4 \
libk4a1.4-dev && \
bash /espnet/tools/activate_python.sh && python3 -m pip install pyk4a
# -----------------------------------------------------------------------
# --------------------------Python Dependencies--------------------------
# Will install all dependencies for the project simply by looking at the imports for the CopyCat-HTK repo.
# ESPnet already installs a majority of them
# However, pip will just say "requirement installed" if it is already installed
RUN bash /espnet/tools/activate_python.sh && python3 -m pip install \
numpy \
torch \
matplotlib \
plotly \
scipy \
scikit-learn \
pandas \
tqdm \
pytransform3d \
joblib \
mediapipe \
filterpy \
pympi-ling \
ffprobe-python \
tf-bodypix \
tfjs-graph-converter \
typing-extensions \
kaldiio \
humanfriendly \
soundfile \
typeguard \
jupyter \
numba \
cupy-cuda102 \
p-tqdm && \
python3 -m pip uninstall -y opencv-contrib-python==4.6.0.66 tensorflow && \
ldconfig /usr/local/cuda-10.2/compat
# Install Tensorflow from source since there isn't a TF Version for CUDA 10.2
RUN apt install apt-transport-https curl gnupg && \
curl -fsSL https://bazel.build/bazel-release.pub.gpg | gpg --dearmor >bazel-archive-keyring.gpg && \
mv bazel-archive-keyring.gpg /usr/share/keyrings && \
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/bazel-archive-keyring.gpg] https://storage.googleapis.com/bazel-apt stable jdk1.8" | tee /etc/apt/sources.list.d/bazel.list && \
apt-get update && \
apt-get install -y bazel-5.0.0 && \
ln -s /usr/bin/bazel-5.0.0 /usr/bin/bazel && \
apt-get install -y openjdk-11-jdk && \
apt-get update && \
rm -rf /var/lib/apt/lists/*
# Install Tensorflow built from source by Ebisu
ENV TF_NEED_CUDA=1 \
TF_CUDA_VERSION=10.2 \
CUDA_TOOLKIT_PATH=/usr/local/cuda \
TF_CUDNN_VERSION=7.6 \
CUDNN_INSTALL_PATH=/usr \
TF_CUDA_COMPUTE_CAPABILITIES=6.1,7.0,7.5 \
CC_OPT_FLAGS="--config=cuda" \
PYTHON_BIN_PATH="/opt/conda/bin/python"
# Create symlinks for cublas and cudnn
RUN ln -s /usr/include/cublas.h /usr/local/cuda/include/cublas.h && \
ln -s /usr/include/cublasLt.h /usr/local/cuda/include/cublasLt.h && \
ln -s /usr/include/cublasXt.h /usr/local/cuda/include/cublasXt.h && \
ln -s /usr/include/cublas_api.h /usr/local/cuda/include/cublas_api.h && \
ln -s /usr/include/cublas_v2.h /usr/local/cuda/include/cublas_v2.h && \
ln -s /usr/include/cudnn.h /usr/local/cuda/include/cudnn.h
# Uncomment this for cuDNN 8
# ln -s /usr/include/cudnn_adv_infer.h /usr/local/cuda/include/cudnn_adv_infer.h && \
# ln -s /usr/include/cudnn_adv_train.h /usr/local/cuda/include/cudnn_adv_train.h && \
# ln -s /usr/include/cudnn_backend.h /usr/local/cuda/include/cudnn_backend.h && \
# ln -s /usr/include/cudnn_cnn_infer.h /usr/local/cuda/include/cudnn_cnn_infer.h && \
# ln -s /usr/include/cudnn_cnn_train.h /usr/local/cuda/include/cudnn_cnn_train.h && \
# ln -s /usr/include/cudnn_ops_infer.h /usr/local/cuda/include/cudnn_ops_infer.h && \
# ln -s /usr/include/cudnn_ops_train.h /usr/local/cuda/include/cudnn_ops_train.h && \
# ln -s /usr/include/cudnn_version.h /usr/local/cuda/include/cudnn_version.h
# Build tensorflow from source
RUN rm -rf /tensorflow && git clone https://github.com/tensorflow/tensorflow.git && \
cd tensorflow && \
git checkout r2.9 && \
./configure && \
bazel clean --expunge && \
bazel build --config=cuda --local_ram_resources="$(free -m | grep '^Mem:' | grep -o '[^ ]*$')" //tensorflow/tools/pip_package:build_pip_package && \
bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg && \
python3 -m pip install /tmp/tensorflow_pkg/tensorflow-2.9.1-cp38-cp38-linux_x86_64.whl
# -----------------------------------------------------------------------
# -------------------------------OpenCV----------------------------------
# Source: https://github.com/JulianAssmann/opencv-cuda-docker/blob/master/ubuntu-20.04/opencv-4.5/cuda-11.1/Dockerfile
RUN bash /espnet/tools/activate_python.sh && cd /opt/ &&\
# Download and unzip OpenCV and opencv_contrib and delete zip files
wget --quiet https://github.com/opencv/opencv/archive/$OPENCV_VERSION.zip &&\
unzip -qq ${OPENCV_VERSION}.zip &&\
rm ${OPENCV_VERSION}.zip &&\
wget --quiet https://github.com/opencv/opencv_contrib/archive/$OPENCV_VERSION.zip &&\
unzip -qq ${OPENCV_VERSION}.zip &&\
rm ${OPENCV_VERSION}.zip &&\
# Create build folder and switch to it
mkdir /opt/opencv-${OPENCV_VERSION}/build && cd /opt/opencv-${OPENCV_VERSION}/build &&\
# Cmake configure
cmake \
-DOPENCV_EXTRA_MODULES_PATH=/opt/opencv_contrib-${OPENCV_VERSION}/modules \
-DBUILD_opencv_python2=OFF \
-DBUILD_opencv_python3=ON \
-DWITH_CUDA=ON \
-DCUDA_ARCH_BIN=6.1,7.0,7.5 \
-DCMAKE_BUILD_TYPE=RELEASE \
-DCUDNN_VERSION=7.6 \
-DPYTHON3_LIBRARY=/opt/conda/lib/python3.8 \
-DPYTHON3_INCLUDE_DIR=/opt/conda/include/python3.8 \
-DPYTHON3_EXECUTABLE=/opt/conda/bin/python \
-DPYTHON3_PACKAGES_PATH=/opt/conda/lib/python3.8/site-packages \
.. &&\
# Make
make -j "$(($(($((`free -g | grep '^Mem:' | grep -o '[^ ]*$'`/2)) < $(nproc) ? $((`free -g | grep '^Mem:' | grep -o '[^ ]*$'`/2)) : $(nproc)))>1 ? $(($((`free -g | grep '^Mem:' | grep -o '[^ ]*$'`/2)) < $(nproc) ? $((`free -g | grep '^Mem:' | grep -o '[^ ]*$'`/2)) : $(nproc))) : 1))" && \
# Install to /usr/local/lib
make install && \
ldconfig && \
# Remove OpenCV sources and build folder
rm -rf /opt/opencv-${OPENCV_VERSION} && rm -rf /opt/opencv_contrib-${OPENCV_VERSION}
# -----------------------------------------------------------------------