forked from Helsinki-NLP/Opus-MT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile.gpu
87 lines (72 loc) · 2.23 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
# This is a two-stage Docker build for GPU where we first use the complete Nvidia CUDA Debian image to build Marian-NMT
# and then copy only the necessary artifacts into the much lighter Nvidia CUDA Runtime final image
FROM nvidia/cuda:11.3.1-devel-ubuntu20.04 AS builder
ENV MARIANPATH /marian
# Install necessary system packages
ENV DEBIAN_FRONTEND=noninteractive
RUN set -eux; \
apt-get update; \
apt-get upgrade -yq; \
apt-get install -yq --no-install-recommends \
build-essential \
git-core \
pkg-config \
libtool \
zlib1g-dev \
libbz2-dev \
automake \
perl \
libsparsehash-dev \
libboost-all-dev \
libprotobuf17 \
protobuf-compiler \
libprotobuf-dev \
openssl \
libssl-dev \
libgoogle-perftools-dev \
wget \
apt-transport-https \
ca-certificates \
gnupg \
software-properties-common \
cmake \
intel-mkl \
python3-dev \
python3-pip \
python3-venv; \
rm -rf /var/lib/apt/lists/*;
# Install Marian
RUN set -eux; \
git clone --depth 1 --branch 1.10.0 https://github.com/marian-nmt/marian
WORKDIR $MARIANPATH
RUN mkdir -p build
WORKDIR $MARIANPATH/build
RUN set -eux; \
cmake .. -DCMAKE_BUILD_TYPE=Release -DUSE_SENTENCEPIECE=ON -DUSE_MPI=ON -DCOMPILE_CPU=on -DCOMPILE_SERVER=on; \
make -j4;
COPY requirements.txt .
RUN set -eux; \
python3 -mvenv venv; \
venv/bin/pip install --upgrade pip; \
venv/bin/pip install -r requirements.txt;
# The second stage is based on the smaller CUDA Runtime image
FROM nvidia/cuda:11.3.1-runtime-ubuntu20.04
WORKDIR /usr/src/app
# Copy necessary libraries for CUDA, the marian server, and the python virtual environment from the builder image
COPY --from=builder /usr/lib/x86_64-linux-gnu/ /usr/lib/x86_64-linux-gnu/
COPY --from=builder /usr/local/cuda/lib64/ /usr/local/cuda/lib64/
COPY --from=builder /marian/build/marian-server /usr/local/bin
COPY --from=builder /marian/build/venv/ /usr/src/app/venv/
# Link shared libraries
RUN ldconfig
# Install python on the cuda runtime image
RUN set -eux; \
apt-get update; \
apt-get install -yq \
python3-pip;
COPY . .
RUN set -ex ; \
ln -sf /usr/bin/python3 /usr/src/app/venv/bin/python3
EXPOSE 80
# Run using the virtual environment Python
CMD ["venv/bin/python3", "server.py", "-c", "services.json", "-p", "80"]