Skip to content

Commit 5976f3c

Browse files
committed
Create process to prebuild tensorflow wheels
1 parent e10c4bc commit 5976f3c

File tree

5 files changed

+159
-0
lines changed

5 files changed

+159
-0
lines changed

tensorflow-whl/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1.11.0-py36: Tensorflow 1.11.0 wheels built with python 3.6

tensorflow-whl/Dockerfile

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
FROM nvidia/cuda:9.1-cudnn7-devel-ubuntu16.04 AS nvidia
2+
FROM continuumio/anaconda3:5.0.1
3+
4+
# Avoid interactive configuration prompts/dialogs during apt-get.
5+
ENV DEBIAN_FRONTEND=noninteractive
6+
7+
# This is necessary to for apt to access HTTPS sources
8+
RUN apt-get update && \
9+
apt-get install apt-transport-https
10+
11+
# Cuda support
12+
COPY --from=nvidia /etc/apt/sources.list.d/cuda.list /etc/apt/sources.list.d/
13+
COPY --from=nvidia /etc/apt/sources.list.d/nvidia-ml.list /etc/apt/sources.list.d/
14+
COPY --from=nvidia /etc/apt/trusted.gpg /etc/apt/trusted.gpg.d/cuda.gpg
15+
16+
ENV CUDA_VERSION=9.1.85
17+
ENV CUDA_PKG_VERSION=9-1=$CUDA_VERSION-1
18+
LABEL com.nvidia.volumes.needed="nvidia_driver"
19+
LABEL com.nvidia.cuda.version="${CUDA_VERSION}"
20+
ENV PATH=/usr/local/nvidia/bin:/usr/local/cuda/bin:${PATH}
21+
# The stub is useful to us both for built-time linking and run-time linking, on CPU-only systems.
22+
# When intended to be used with actual GPUs, make sure to (besides providing access to the host
23+
# CUDA user libraries, either manually or through the use of nvidia-docker) exclude them. One
24+
# convenient way to do so is to obscure its contents by a bind mount:
25+
# docker run .... -v /non-existing-directory:/usr/local/cuda/lib64/stubs:ro ...
26+
ENV LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/usr/local/nvidia/lib64:/usr/local/cuda/lib64:/usr/local/cuda/lib64/stubs"
27+
ENV NVIDIA_VISIBLE_DEVICES=all
28+
ENV NVIDIA_DRIVER_CAPABILITIES=compute,utility
29+
ENV NVIDIA_REQUIRE_CUDA="cuda>=9.0"
30+
RUN apt-get update && apt-get install -y --no-install-recommends \
31+
cuda-cudart-$CUDA_PKG_VERSION \
32+
cuda-libraries-$CUDA_PKG_VERSION \
33+
cuda-libraries-dev-$CUDA_PKG_VERSION \
34+
cuda-nvml-dev-$CUDA_PKG_VERSION \
35+
cuda-minimal-build-$CUDA_PKG_VERSION \
36+
cuda-command-line-tools-$CUDA_PKG_VERSION \
37+
libcudnn7=7.0.5.15-1+cuda9.1 \
38+
libcudnn7-dev=7.0.5.15-1+cuda9.1 \
39+
libnccl2=2.2.12-1+cuda9.1 \
40+
libnccl-dev=2.2.12-1+cuda9.1 && \
41+
ln -s /usr/local/cuda-9.1 /usr/local/cuda && \
42+
ln -s /usr/local/cuda/lib64/stubs/libcuda.so /usr/local/cuda/lib64/stubs/libcuda.so.1 && \
43+
rm -rf /var/lib/apt/lists/*
44+
45+
# Install bazel
46+
RUN apt-get update && apt-get install -y python-software-properties zip && \
47+
echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu precise main" | tee -a /etc/apt/sources.list && \
48+
echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu precise main" | tee -a /etc/apt/sources.list && \
49+
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys EEA14886 C857C906 2B90D010 && \
50+
apt-get update && \
51+
echo debconf shared/accepted-oracle-license-v1-1 select true | debconf-set-selections && \
52+
echo debconf shared/accepted-oracle-license-v1-1 seen true | debconf-set-selections && \
53+
apt-get install -y oracle-java8-installer && \
54+
echo "deb [arch=amd64] http://storage.googleapis.com/bazel-apt stable jdk1.8" | tee /etc/apt/sources.list.d/bazel.list && \
55+
curl https://bazel.build/bazel-release.pub.gpg | apt-key add - && \
56+
apt-get update && apt-get install -y bazel && \
57+
apt-get upgrade -y bazel
58+
59+
# Tensorflow doesn't support python 3.7 yet. See https://github.com/tensorflow/tensorflow/issues/20517
60+
RUN conda install -y python=3.6.6 && \
61+
# Another fix for TF 1.10 https://github.com/tensorflow/tensorflow/issues/21518
62+
pip install keras_applications==1.0.4 --no-deps && \
63+
pip install keras_preprocessing==1.0.2 --no-deps
64+
65+
# Fetch tensorflow
66+
RUN cd /usr/local/src && \
67+
git clone https://github.com/tensorflow/tensorflow && \
68+
cd tensorflow && \
69+
git checkout r1.11
70+
71+
# Create a tensorflow wheel for CPU
72+
RUN cd /usr/local/src/tensorflow && \
73+
cat /dev/null | ./configure && \
74+
bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package && \
75+
bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_cpu && \
76+
bazel clean
77+
78+
# Create a tensorflow wheel for GPU/cuda
79+
ENV TF_NEED_CUDA=1
80+
ENV TF_CUDA_VERSION=9.1
81+
ENV TF_CUDA_COMPUTE_CAPABILITIES=3.7,6.0
82+
ENV TF_CUDNN_VERSION=7
83+
ENV TF_NCCL_VERSION=2
84+
ENV NCCL_INSTALL_PATH=/usr/
85+
86+
RUN cd /usr/local/src/tensorflow && \
87+
# TF_NCCL_INSTALL_PATH is used for both libnccl.so.2 and libnccl.h. Make sure they are both accessible from the same directory.
88+
ln -s /usr/lib/x86_64-linux-gnu/libnccl.so.2 /usr/lib/ && \
89+
cat /dev/null | ./configure && \
90+
echo "/usr/local/cuda-${TF_CUDA_VERSION}/targets/x86_64-linux/lib/stubs" > /etc/ld.so.conf.d/cuda-stubs.conf && ldconfig && \
91+
bazel build --config=opt \
92+
--config=cuda \
93+
--cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0" \
94+
//tensorflow/tools/pip_package:build_pip_package && \
95+
rm /etc/ld.so.conf.d/cuda-stubs.conf && ldconfig && \
96+
bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_gpu && \
97+
bazel clean
98+
99+
# Print out the built .whl files
100+
RUN ls -R /tmp/tensorflow*

tensorflow-whl/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Build new Tensorflow wheels
2+
3+
```
4+
./build
5+
```
6+
7+
# Push the new wheels
8+
9+
1. Add an entry in the [CHANGELOG](CHANGELOG.md) with an appropriate `LABEL`.
10+
2. Push the new image using the `LABEL` you picked above.
11+
12+
```
13+
./push LABEL
14+
```
15+
16+
# Use the new wheels
17+
18+
Update the line below in the [CPU Dockerfile](../Dockerfile) and the [GPU Dockerfile](../gpu.Dockerfile) to use the new `LABEL`.
19+
20+
```
21+
FROM gcr.io/kaggle-images/python-tensorflow-whl:<NEW-LABEL> as tensorflow_whl
22+
```

tensorflow-whl/build

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
set -e
3+
set -x
4+
5+
# Default behavior is to do everything from scratch.
6+
# The --use-cache option is useful if you're iterating on a broken build.
7+
if [[ "$1" == "--use-cache" ]]; then
8+
docker build --rm -t kaggle/python-tensorflow-whl .
9+
else
10+
docker build --pull --rm --no-cache -t kaggle/python-tensorflow-whl .
11+
fi

tensorflow-whl/push

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
#
3+
# Push a newly-built image with the given label to gcr.io and DockerHub.
4+
#
5+
# Usage:
6+
# ./push LABEL
7+
#
8+
# Description:
9+
# LABEL: Image label. See CHANGELOG.md
10+
#
11+
set -e
12+
set -x
13+
14+
SOURCE_IMAGE="kaggle/python-tensorflow-whl"
15+
TARGET_IMAGE="gcr.io/kaggle-images/python-tensorflow-whl"
16+
17+
LABEL=$1
18+
19+
if [[ -z "$LABEL" ]]; then
20+
echo "You must provide a label for the image"
21+
exit 1
22+
fi
23+
24+
docker tag $SOURCE_IMAGE:latest $TARGET_IMAGE:$LABEL
25+
gcloud docker -- push $TARGET_IMAGE:$LABEL

0 commit comments

Comments
 (0)