Skip to content

Instantly share code, notes, and snippets.

@ageron
Created January 21, 2019 08:21
Show Gist options
  • Save ageron/2a4cd2412ad104b95e452cece5c04fd9 to your computer and use it in GitHub Desktop.
Save ageron/2a4cd2412ad104b95e452cece5c04fd9 to your computer and use it in GitHub Desktop.
Installs everything you need to run TF 2.0-preview on an Ubuntu 18.04 server (includes the Colab connector) - run as regular user with sudo rights
#!/bin/bash
cat <<EOF > install_cuda_10_and_nvidia_driver_384.sh
#!/bin/bash
apt-get update && apt-get install -y --no-install-recommends gnupg2 curl ca-certificates && \
curl -fsSL https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub | apt-key add - && \
echo "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64 /" > /etc/apt/sources.list.d/cuda.list && \
echo "deb https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64 /" > /etc/apt/sources.list.d/nvidia-ml.list
export CUDA_VERSION=10.0.130
export CUDA_PKG_VERSION="10-0=$CUDA_VERSION-1"
# For libraries in the cuda-compat-* package: https://docs.nvidia.com/cuda/eula/index.html#attachment-a
apt-get update && apt-get install -y --no-install-recommends \
cuda-cudart-$CUDA_PKG_VERSION \
cuda-compat-10-0=410.48-1 && \
ln -s cuda-10.0 /usr/local/cuda
export PATH=/usr/local/cuda/bin:${PATH}
# nvidia-container-runtime
export NVIDIA_VISIBLE_DEVICES=all
export NVIDIA_DRIVER_CAPABILITIES=compute,utility
export NVIDIA_REQUIRE_CUDA="cuda>=10.0 brand=tesla,driver>=384,driver<385"
export CUDNN_VERSION=7.4.1.5
apt-get install -y --no-install-recommends \
libcudnn7=$CUDNN_VERSION-1+cuda10.0 \
libcudnn7-dev=$CUDNN_VERSION-1+cuda10.0 && \
apt-mark hold libcudnn7
apt-get install -y --no-install-recommends \
build-essential \
cuda-command-line-tools-10-0 \
cuda-cublas-10-0 \
cuda-cufft-10-0 \
cuda-curand-10-0 \
cuda-cusolver-10-0 \
cuda-cusparse-10-0 \
libcudnn7=$CUDNN_VERSION-1+cuda10.0 \
libfreetype6-dev \
libhdf5-serial-dev \
libpng-dev \
libzmq3-dev \
pkg-config \
software-properties-common \
unzip
apt-get install -y nvidia-384
apt-get install -y nvinfer-runtime-trt-repo-ubuntu1804-5.0.2-ga-cuda10.0 \
&& apt-get update \
&& apt-get install -y --no-install-recommends libnvinfer5=5.0.2-1+cuda10.0 \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# For CUDA profiling, TensorFlow requires CUPTI.
export LD_LIBRARY_PATH=/usr/local/cuda/extras/CUPTI/lib64:$LD_LIBRARY_PATH
export PYTHON=python3
export PIP=pip3
# See http://bugs.python.org/issue19846
export LANG=C.UTF-8
apt-get update && apt-get install -y \
python3 \
python3-pip
pip3 --no-cache-dir install --upgrade \
pip \
setuptools
hash -d pip
# Some TF tools expect a "python" binary
ln -s $(which python3) /usr/local/bin/python
nvidia-smi
EOF
chmod +x install_cuda_10_and_nvidia_driver_384.sh
sudo ./install_cuda_10_and_nvidia_driver_384.sh
grep export install_cuda_10_and_nvidia_driver_384.sh > ~/.bashrc
echo 'export PATH=$HOME/.local/bin:$PATH' >> ~/.bashrc
source ~/.bashrc
# Options:
# tensorflow
# tensorflow-gpu
# tf-nightly
# tf-nightly-gpu
# tf-nightly-2.0-preview
# tf-nightly-gpu-2.0-preview
export TF_PACKAGE=tf-nightly-gpu-2.0-preview
pip3 install --user ${TF_PACKAGE}
pip3 install --user jupyter jupyter_http_over_ws matplotlib numpy scipy Pillow pandas scikit-learn pydot graphviz
jupyter serverextension enable --py jupyter_http_over_ws
cat <<EOF > start-colab-server.sh
#!/bin/bash
jupyter notebook \
--NotebookApp.allow_origin='https://colab.research.google.com' \
--port=8888 \
--NotebookApp.port_retries=0
EOF
chmod +x start-colab-server.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment