Skip to content

Commit ab5d972

Browse files
committed
Tensorflow 2.0 for CPU & MKL accel.
1 parent 0a4200d commit ab5d972

File tree

1 file changed

+85
-23
lines changed

1 file changed

+85
-23
lines changed

python-tensorflow/Dockerfile.2.0-py36

Lines changed: 85 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,101 @@
1-
# Lablup/Python-TensorFlow 2.0 Python 3.6
1+
FROM lablup/common-base:20.08-py36
22

3-
FROM lablup/common-tensorflow:2.0-py36 as tf-binary
4-
FROM lablup/common-base:19.06-py36
5-
MAINTAINER Mario Cho "[email protected]"
3+
ARG TF_BUILD_VERSION=r2.0
4+
# Install the most recent bazel release.
5+
ENV BAZEL_VERSION 0.26.1
6+
7+
# Set up Bazel.
8+
9+
# Running bazel inside a `docker build` command causes trouble, cf:
10+
# https://github.com/bazelbuild/bazel/issues/134
11+
# The easiest solution is to set up a bazelrc file forcing --batch.
12+
RUN echo "startup --batch" >>/etc/bazel.bazelrc
13+
# Similarly, we need to workaround sandboxing issues:
14+
# https://github.com/bazelbuild/bazel/issues/418
15+
RUN echo "build --spawn_strategy=standalone --genrule_strategy=standalone" \
16+
>>/etc/bazel.bazelrc
17+
18+
WORKDIR /
19+
RUN mkdir /bazel && \
20+
cd /bazel && \
21+
curl -H "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36" -fSsL -O https://github.com/bazelbuild/bazel/releases/download/$BAZEL_VERSION/bazel-$BAZEL_VERSION-installer-linux-x86_64.sh && \
22+
curl -H "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36" -fSsL -o /bazel/LICENSE.txt https://raw.githubusercontent.com/bazelbuild/bazel/master/LICENSE && \
23+
chmod +x bazel-*.sh && \
24+
./bazel-$BAZEL_VERSION-installer-linux-x86_64.sh && \
25+
cd / && \
26+
rm -f /bazel/bazel-$BAZEL_VERSION-installer-linux-x86_64.sh
27+
28+
# Download and build TensorFlow.
29+
WORKDIR /tensorflow
30+
31+
# Download and build TensorFlow.
32+
# Enable checking out both tags and branches
33+
RUN export TAG_PREFIX="v" && \
34+
echo ${TF_BUILD_VERSION} | grep -q ^${TAG_PREFIX}; \
35+
if [ $? -eq 0 ]; then \
36+
git clone --depth=1 https://github.com/tensorflow/tensorflow.git . && \
37+
git fetch --tags && \
38+
git checkout ${TF_BUILD_VERSION}; \
39+
else \
40+
git clone --depth=1 --branch=${TF_BUILD_VERSION} https://github.com/tensorflow/tensorflow.git . ; \
41+
fi
42+
43+
RUN yes "" | python3 configure.py
44+
RUN cp .bazelrc /root/.bazelrc
45+
46+
ENV CI_BUILD_PYTHON ${PYTHON}
47+
ENV WHL_DIR=/tmp/pip3
48+
# Set bazel build parameters in .bazelrc in parameterized_docker_build.sh
49+
# Use --copt=-march values to get optimized builds appropriate for the hardware
50+
# platform of your choice.
51+
# For ivy-bridge or sandy-bridge
52+
# --copt=-march="avx" \
53+
# For haswell, broadwell, or skylake
54+
# --copt=-march="avx2" \
55+
COPY .bazelrc /root/.mkl.bazelrc
56+
RUN echo "import /root/.mkl.bazelrc" >>/root/.bazelrc
57+
58+
RUN tensorflow/tools/ci_build/builds/configured CPU \
59+
bazel --bazelrc=/root/.bazelrc build -c opt \
60+
--config=mkl \
61+
--copt=-mavx \
62+
--copt=-mavx2 \
63+
--config=monolithic \
64+
--cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0" \
65+
tensorflow/tools/pip_package:build_pip_package && \
66+
bazel-bin/tensorflow/tools/pip_package/build_pip_package "${WHL_DIR}" && \
67+
python3 -m pip --no-cache-dir install --upgrade "${WHL_DIR}"/tensorflow-*.whl
68+
RUN python3 -m pip --no-cache-dir install \
69+
tensorboard==2.0 && \
70+
rm -rf /root/.cache
71+
# Clean up Bazel cache when done.
72+
73+
# Install Horovod, temporarily using CUDA stubs
74+
RUN HOROVOD_WITH_TENSORFLOW=1 HOROVOD_WITHOUT_PYTORCH=1 HOROVOD_WITHOUT_MXNET=1 \
75+
pip install --no-cache-dir horovod==0.19.5 && \
76+
ldconfig
77+
78+
RUN python3 -m pip install --no-cache-dir \
79+
mpi4py==3.0.3 \
80+
nni==1.6 \
81+
scikit-nni==0.2.1
682

783
# Install ipython kernelspec
8-
RUN python3 -m ipykernel install --display-name "TensorFlow 2.0 on Python 3.6 (CPU-only)" && \
84+
Run python3 -m ipykernel install --display-name "TensorFlow 2.0 on Python 3.6 (CPU, MKL)" && \
985
cat /usr/local/share/jupyter/kernels/python3/kernel.json
1086

11-
COPY --from=tf-binary /tmp/tensorflow_pkg/tensorflow-*.whl /tmp
12-
13-
RUN python3 -m pip install --no-cache-dir wheel /tmp/*.whl && \
14-
python3 -m pip install --no-cache-dir keras && \
15-
python3 -m pip install --no-cache-dir keras_applications && \
16-
python3 -m pip install --no-cache-dir keras_preprocessing && \
17-
python3 -m pip install --no-cache-dir tensorflow-hub==0.5.0 && \
18-
python3 -m pip install --no-cache-dir tf2onnx && \
19-
rm -rf /root/.cache && \
20-
rm -f /tmp/*.whl
21-
22-
# for apt-get installation using /tmp
23-
RUN mkdir -p /tmp && \
24-
chown root:root /tmp && \
25-
chmod 1777 /tmp
26-
2787
# Backend.AI specifics
2888
LABEL ai.backend.kernelspec="1" \
2989
ai.backend.envs.corecount="OPENBLAS_NUM_THREADS,OMP_NUM_THREADS,NPROC" \
3090
ai.backend.features="batch query uid-match user-input" \
3191
ai.backend.base-distro="ubuntu16.04" \
3292
ai.backend.resource.min.cpu="1" \
3393
ai.backend.resource.min.mem="1g" \
94+
ai.backend.resource.min.cuda.device=0 \
95+
ai.backend.resource.min.cuda.shares=0 \
3496
ai.backend.runtime-type="python" \
35-
ai.backend.runtime-path="/usr/local/bin/python" \
36-
ai.backend.service-ports="ipython:pty:3000,jupyter:http:8080,jupyterlab:http:8090"
97+
ai.backend.runtime-path="/usr/bin/python3" \
98+
ai.backend.service-ports="ipython:pty:3000,jupyter:http:8080,jupyterlab:http:8090,vscode:http:8180,tensorboard:http:6006"
3799

38100
WORKDIR /home/work
39101
# vim: ft=dockerfile

0 commit comments

Comments
 (0)